mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-14 09:36:08 +00:00
examples: diff: parse correct types for line-diffopts
This commit is contained in:
parent
7314da1055
commit
5c2a8361d7
@ -146,6 +146,25 @@ int match_uint16_arg(
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int match_uint32_arg(
|
||||||
|
uint32_t *out, struct args_info *args, const char *opt)
|
||||||
|
{
|
||||||
|
const char *found = match_numeric_arg(args, opt);
|
||||||
|
uint16_t val;
|
||||||
|
char *endptr = NULL;
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
val = (uint32_t)strtoul(found, &endptr, 0);
|
||||||
|
if (!endptr || *endptr != '\0')
|
||||||
|
fatal("expected number after argument", opt);
|
||||||
|
|
||||||
|
if (out)
|
||||||
|
*out = val;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int match_int_internal(
|
static int match_int_internal(
|
||||||
int *out, const char *str, int allow_negative, const char *opt)
|
int *out, const char *str, int allow_negative, const char *opt)
|
||||||
{
|
{
|
||||||
|
@ -72,6 +72,15 @@ extern int match_str_arg(
|
|||||||
extern int match_uint16_arg(
|
extern int match_uint16_arg(
|
||||||
uint16_t *out, struct args_info *args, const char *opt);
|
uint16_t *out, struct args_info *args, const char *opt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check current `args` entry against `opt` string parsing as uint32. If
|
||||||
|
* `opt` matches exactly, take the next arg as a uint16_t value; if `opt`
|
||||||
|
* is a prefix (equal sign optional), take the remainder of the arg as a
|
||||||
|
* uint32_t value; otherwise return 0.
|
||||||
|
*/
|
||||||
|
extern int match_uint32_arg(
|
||||||
|
uint32_t *out, struct args_info *args, const char *opt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check current `args` entry against `opt` string parsing as int. If
|
* Check current `args` entry against `opt` string parsing as int. If
|
||||||
* `opt` matches exactly, take the next arg as an int value; if it matches
|
* `opt` matches exactly, take the next arg as an int value; if it matches
|
||||||
|
@ -293,11 +293,11 @@ static void parse_opts(struct opts *o, int argc, char *argv[])
|
|||||||
else if (is_prefixed(a, "-B") || is_prefixed(a, "--break-rewrites"))
|
else if (is_prefixed(a, "-B") || is_prefixed(a, "--break-rewrites"))
|
||||||
/* TODO: parse thresholds */
|
/* TODO: parse thresholds */
|
||||||
o->findopts.flags |= GIT_DIFF_FIND_REWRITES;
|
o->findopts.flags |= GIT_DIFF_FIND_REWRITES;
|
||||||
else if (!match_uint16_arg(
|
else if (!match_uint32_arg(
|
||||||
&o->diffopts.context_lines, &args, "-U") &&
|
&o->diffopts.context_lines, &args, "-U") &&
|
||||||
!match_uint16_arg(
|
!match_uint32_arg(
|
||||||
&o->diffopts.context_lines, &args, "--unified") &&
|
&o->diffopts.context_lines, &args, "--unified") &&
|
||||||
!match_uint16_arg(
|
!match_uint32_arg(
|
||||||
&o->diffopts.interhunk_lines, &args, "--inter-hunk-context") &&
|
&o->diffopts.interhunk_lines, &args, "--inter-hunk-context") &&
|
||||||
!match_uint16_arg(
|
!match_uint16_arg(
|
||||||
&o->diffopts.id_abbrev, &args, "--abbrev") &&
|
&o->diffopts.id_abbrev, &args, "--abbrev") &&
|
||||||
|
Loading…
Reference in New Issue
Block a user