Skip to content

Commit dcd759b

Browse files
authored
Merge pull request libgit2#3897 from pks-t/pks/squelch-example-warnings
Squelch example warnings, enable CI
2 parents 610cff1 + ec3f5a9 commit dcd759b

File tree

7 files changed

+720
-508
lines changed

7 files changed

+720
-508
lines changed

examples/add.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,14 @@ int print_matched_cb(const char *path, const char *matched_pathspec, void *paylo
7575
{
7676
struct print_payload p = *(struct print_payload*)(payload);
7777
int ret;
78-
git_status_t status;
78+
unsigned status;
7979
(void)matched_pathspec;
8080

81-
if (git_status_file((unsigned int*)(&status), p.repo, path)) {
82-
return -1; //abort
81+
if (git_status_file(&status, p.repo, path)) {
82+
return -1;
8383
}
8484

85-
if (status & GIT_STATUS_WT_MODIFIED ||
86-
status & GIT_STATUS_WT_NEW) {
85+
if (status & GIT_STATUS_WT_MODIFIED || status & GIT_STATUS_WT_NEW) {
8786
printf("add '%s'\n", path);
8887
ret = 0;
8988
} else {

examples/common.c

+19
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,25 @@ int match_uint16_arg(
146146
return 1;
147147
}
148148

149+
int match_uint32_arg(
150+
uint32_t *out, struct args_info *args, const char *opt)
151+
{
152+
const char *found = match_numeric_arg(args, opt);
153+
uint16_t val;
154+
char *endptr = NULL;
155+
156+
if (!found)
157+
return 0;
158+
159+
val = (uint32_t)strtoul(found, &endptr, 0);
160+
if (!endptr || *endptr != '\0')
161+
fatal("expected number after argument", opt);
162+
163+
if (out)
164+
*out = val;
165+
return 1;
166+
}
167+
149168
static int match_int_internal(
150169
int *out, const char *str, int allow_negative, const char *opt)
151170
{

examples/common.h

+9
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ extern int match_str_arg(
7272
extern int match_uint16_arg(
7373
uint16_t *out, struct args_info *args, const char *opt);
7474

75+
/**
76+
* Check current `args` entry against `opt` string parsing as uint32. If
77+
* `opt` matches exactly, take the next arg as a uint16_t value; if `opt`
78+
* is a prefix (equal sign optional), take the remainder of the arg as a
79+
* uint32_t value; otherwise return 0.
80+
*/
81+
extern int match_uint32_arg(
82+
uint32_t *out, struct args_info *args, const char *opt);
83+
7584
/**
7685
* Check current `args` entry against `opt` string parsing as int. If
7786
* `opt` matches exactly, take the next arg as an int value; if it matches

examples/diff.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,11 @@ static void parse_opts(struct opts *o, int argc, char *argv[])
293293
else if (is_prefixed(a, "-B") || is_prefixed(a, "--break-rewrites"))
294294
/* TODO: parse thresholds */
295295
o->findopts.flags |= GIT_DIFF_FIND_REWRITES;
296-
else if (!match_uint16_arg(
296+
else if (!match_uint32_arg(
297297
&o->diffopts.context_lines, &args, "-U") &&
298-
!match_uint16_arg(
298+
!match_uint32_arg(
299299
&o->diffopts.context_lines, &args, "--unified") &&
300-
!match_uint16_arg(
300+
!match_uint32_arg(
301301
&o->diffopts.interhunk_lines, &args, "--inter-hunk-context") &&
302302
!match_uint16_arg(
303303
&o->diffopts.id_abbrev, &args, "--abbrev") &&

0 commit comments

Comments
 (0)