Skip to content

Commit e1c1433

Browse files
authored
Merge pull request libgit2#4002 from pks-t/pks/giterr-format
giterr format
2 parents cc5966b + b81fe7c commit e1c1433

File tree

10 files changed

+44
-43
lines changed

10 files changed

+44
-43
lines changed

src/apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static int apply_hunk(
173173
git_diff_line *line = git_array_get(patch->lines, linenum);
174174

175175
if (!line) {
176-
error = apply_err("Preimage does not contain line %d", linenum);
176+
error = apply_err("Preimage does not contain line %"PRIuZ, linenum);
177177
goto done;
178178
}
179179

src/checkout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,7 @@ static int checkout_path_suffixed(git_buf *path, const char *suffix)
19661966
if (i == INT_MAX) {
19671967
git_buf_truncate(path, path_len);
19681968

1969-
giterr_set(GITERR_CHECKOUT, "Could not write '%s': working directory file exists", path);
1969+
giterr_set(GITERR_CHECKOUT, "Could not write '%s': working directory file exists", path->ptr);
19701970
return GIT_EEXISTS;
19711971
}
19721972

@@ -2469,7 +2469,7 @@ static int checkout_data_init(
24692469
data->opts.checkout_strategy |= GIT_CHECKOUT_CONFLICT_STYLE_DIFF3;
24702470
else {
24712471
giterr_set(GITERR_CHECKOUT, "unknown style '%s' given for 'merge.conflictstyle'",
2472-
conflict_style);
2472+
conflict_style->value);
24732473
error = -1;
24742474
git_config_entry_free(conflict_style);
24752475
goto cleanup;

src/common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@
103103
/**
104104
* Set the error message for this thread, formatting as needed.
105105
*/
106-
void giterr_set(int error_class, const char *string, ...);
106+
107+
void giterr_set(int error_class, const char *string, ...) GIT_FORMAT_PRINTF(2, 3);
107108

108109
/**
109110
* Set the error message for a regex failure, using the internal regex

src/fetchhead.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static int fetchhead_ref_parse(
149149

150150
if (!*line) {
151151
giterr_set(GITERR_FETCHHEAD,
152-
"Empty line in FETCH_HEAD line %d", line_num);
152+
"Empty line in FETCH_HEAD line %"PRIuZ, line_num);
153153
return -1;
154154
}
155155

@@ -163,15 +163,15 @@ static int fetchhead_ref_parse(
163163

164164
if (strlen(oid_str) != GIT_OID_HEXSZ) {
165165
giterr_set(GITERR_FETCHHEAD,
166-
"Invalid object ID in FETCH_HEAD line %d", line_num);
166+
"Invalid object ID in FETCH_HEAD line %"PRIuZ, line_num);
167167
return -1;
168168
}
169169

170170
if (git_oid_fromstr(oid, oid_str) < 0) {
171171
const git_error *oid_err = giterr_last();
172172
const char *err_msg = oid_err ? oid_err->message : "Invalid object ID";
173173

174-
giterr_set(GITERR_FETCHHEAD, "%s in FETCH_HEAD line %d",
174+
giterr_set(GITERR_FETCHHEAD, "%s in FETCH_HEAD line %"PRIuZ,
175175
err_msg, line_num);
176176
return -1;
177177
}
@@ -180,7 +180,7 @@ static int fetchhead_ref_parse(
180180
if (*line) {
181181
if ((is_merge_str = git__strsep(&line, "\t")) == NULL) {
182182
giterr_set(GITERR_FETCHHEAD,
183-
"Invalid description data in FETCH_HEAD line %d", line_num);
183+
"Invalid description data in FETCH_HEAD line %"PRIuZ, line_num);
184184
return -1;
185185
}
186186

@@ -190,13 +190,13 @@ static int fetchhead_ref_parse(
190190
*is_merge = 0;
191191
else {
192192
giterr_set(GITERR_FETCHHEAD,
193-
"Invalid for-merge entry in FETCH_HEAD line %d", line_num);
193+
"Invalid for-merge entry in FETCH_HEAD line %"PRIuZ, line_num);
194194
return -1;
195195
}
196196

197197
if ((desc = line) == NULL) {
198198
giterr_set(GITERR_FETCHHEAD,
199-
"Invalid description in FETCH_HEAD line %d", line_num);
199+
"Invalid description in FETCH_HEAD line %"PRIuZ, line_num);
200200
return -1;
201201
}
202202

@@ -213,7 +213,7 @@ static int fetchhead_ref_parse(
213213
if ((desc = strstr(name, "' ")) == NULL ||
214214
git__prefixcmp(desc, "' of ") != 0) {
215215
giterr_set(GITERR_FETCHHEAD,
216-
"Invalid description in FETCH_HEAD line %d", line_num);
216+
"Invalid description in FETCH_HEAD line %"PRIuZ, line_num);
217217
return -1;
218218
}
219219

@@ -277,7 +277,7 @@ int git_repository_fetchhead_foreach(git_repository *repo,
277277
}
278278

279279
if (*buffer) {
280-
giterr_set(GITERR_FETCHHEAD, "No EOL at line %d", line_num+1);
280+
giterr_set(GITERR_FETCHHEAD, "No EOL at line %"PRIuZ, line_num+1);
281281
error = -1;
282282
goto done;
283283
}

src/iterator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ static int filesystem_iterator_frame_push(
13111311

13121312
if (iter->frames.size == FILESYSTEM_MAX_DEPTH) {
13131313
giterr_set(GITERR_REPOSITORY,
1314-
"directory nesting too deep (%d)", iter->frames.size);
1314+
"directory nesting too deep (%"PRIuZ")", iter->frames.size);
13151315
return -1;
13161316
}
13171317

src/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ int git_repository_mergehead_foreach(
591591
}
592592

593593
if (*buffer) {
594-
giterr_set(GITERR_MERGE, "No EOL at line %d", line_num);
594+
giterr_set(GITERR_MERGE, "No EOL at line %"PRIuZ, line_num);
595595
error = -1;
596596
goto cleanup;
597597
}

src/odb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ int git_odb__error_notfound(
14001400
char oid_str[GIT_OID_HEXSZ + 1];
14011401
git_oid_tostr(oid_str, oid_len+1, oid);
14021402
giterr_set(GITERR_ODB, "Object not found - %s (%.*s)",
1403-
message, oid_len, oid_str);
1403+
message, (int) oid_len, oid_str);
14041404
} else
14051405
giterr_set(GITERR_ODB, "Object not found - %s", message);
14061406

src/patch_parse.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static int parse_header_mode(uint16_t *mode, git_patch_parse_ctx *ctx)
176176
int ret;
177177

178178
if (ctx->line_len < 1 || !git__isdigit(ctx->line[0]))
179-
return parse_err("invalid file mode at line %d", ctx->line_num);
179+
return parse_err("invalid file mode at line %"PRIuZ, ctx->line_num);
180180

181181
if ((ret = git__strntol32(&m, ctx->line, ctx->line_len, &end, 8)) < 0)
182182
return ret;
@@ -205,7 +205,7 @@ static int parse_header_oid(
205205

206206
if (len < GIT_OID_MINPREFIXLEN || len > GIT_OID_HEXSZ ||
207207
git_oid_fromstrn(oid, ctx->line, len) < 0)
208-
return parse_err("invalid hex formatted object id at line %d",
208+
return parse_err("invalid hex formatted object id at line %"PRIuZ,
209209
ctx->line_num);
210210

211211
parse_advance_chars(ctx, len);
@@ -350,7 +350,7 @@ static int parse_header_similarity(
350350
git_patch_parsed *patch, git_patch_parse_ctx *ctx)
351351
{
352352
if (parse_header_percent(&patch->base.delta->similarity, ctx) < 0)
353-
return parse_err("invalid similarity percentage at line %d",
353+
return parse_err("invalid similarity percentage at line %"PRIuZ,
354354
ctx->line_num);
355355

356356
return 0;
@@ -362,7 +362,7 @@ static int parse_header_dissimilarity(
362362
uint16_t dissimilarity;
363363

364364
if (parse_header_percent(&dissimilarity, ctx) < 0)
365-
return parse_err("invalid similarity percentage at line %d",
365+
return parse_err("invalid similarity percentage at line %"PRIuZ,
366366
ctx->line_num);
367367

368368
patch->base.delta->similarity = 100 - dissimilarity;
@@ -406,15 +406,15 @@ static int parse_header_git(
406406

407407
/* Parse the diff --git line */
408408
if (parse_advance_expected_str(ctx, "diff --git ") < 0)
409-
return parse_err("corrupt git diff header at line %d", ctx->line_num);
409+
return parse_err("corrupt git diff header at line %"PRIuZ, ctx->line_num);
410410

411411
if (parse_header_path(&patch->header_old_path, ctx) < 0)
412-
return parse_err("corrupt old path in git diff header at line %d",
412+
return parse_err("corrupt old path in git diff header at line %"PRIuZ,
413413
ctx->line_num);
414414

415415
if (parse_advance_ws(ctx) < 0 ||
416416
parse_header_path(&patch->header_new_path, ctx) < 0)
417-
return parse_err("corrupt new path in git diff header at line %d",
417+
return parse_err("corrupt new path in git diff header at line %"PRIuZ,
418418
ctx->line_num);
419419

420420
/* Parse remaining header lines */
@@ -447,7 +447,7 @@ static int parse_header_git(
447447
parse_advance_expected_str(ctx, "\n");
448448

449449
if (ctx->line_len > 0) {
450-
error = parse_err("trailing data at line %d", ctx->line_num);
450+
error = parse_err("trailing data at line %"PRIuZ, ctx->line_num);
451451
goto done;
452452
}
453453

@@ -456,7 +456,7 @@ static int parse_header_git(
456456
}
457457

458458
if (!found) {
459-
error = parse_err("invalid patch header at line %d",
459+
error = parse_err("invalid patch header at line %"PRIuZ,
460460
ctx->line_num);
461461
goto done;
462462
}
@@ -536,7 +536,7 @@ static int parse_hunk_header(
536536

537537
hunk->hunk.header_len = ctx->line - header_start;
538538
if (hunk->hunk.header_len > (GIT_DIFF_HUNK_HEADER_SIZE - 1))
539-
return parse_err("oversized patch hunk header at line %d",
539+
return parse_err("oversized patch hunk header at line %"PRIuZ,
540540
ctx->line_num);
541541

542542
memcpy(hunk->hunk.header, header_start, hunk->hunk.header_len);
@@ -545,7 +545,7 @@ static int parse_hunk_header(
545545
return 0;
546546

547547
fail:
548-
giterr_set(GITERR_PATCH, "invalid patch hunk header at line %d",
548+
giterr_set(GITERR_PATCH, "invalid patch hunk header at line %"PRIuZ,
549549
ctx->line_num);
550550
return -1;
551551
}
@@ -570,7 +570,7 @@ static int parse_hunk_body(
570570
int prefix = 1;
571571

572572
if (ctx->line_len == 0 || ctx->line[ctx->line_len - 1] != '\n') {
573-
error = parse_err("invalid patch instruction at line %d",
573+
error = parse_err("invalid patch instruction at line %"PRIuZ,
574574
ctx->line_num);
575575
goto done;
576576
}
@@ -596,7 +596,7 @@ static int parse_hunk_body(
596596
break;
597597

598598
default:
599-
error = parse_err("invalid patch hunk at line %d", ctx->line_num);
599+
error = parse_err("invalid patch hunk at line %"PRIuZ, ctx->line_num);
600600
goto done;
601601
}
602602

@@ -672,7 +672,7 @@ static int parse_patch_header(
672672
continue;
673673
}
674674

675-
error = parse_err("invalid hunk header outside patch at line %d",
675+
error = parse_err("invalid hunk header outside patch at line %"PRIuZ,
676676
line_num);
677677
goto done;
678678
}
@@ -715,12 +715,12 @@ static int parse_patch_binary_side(
715715
parse_advance_chars(ctx, 6);
716716
} else {
717717
error = parse_err(
718-
"unknown binary delta type at line %d", ctx->line_num);
718+
"unknown binary delta type at line %"PRIuZ, ctx->line_num);
719719
goto done;
720720
}
721721

722722
if (parse_number(&len, ctx) < 0 || parse_advance_nl(ctx) < 0 || len < 0) {
723-
error = parse_err("invalid binary size at line %d", ctx->line_num);
723+
error = parse_err("invalid binary size at line %"PRIuZ, ctx->line_num);
724724
goto done;
725725
}
726726

@@ -736,7 +736,7 @@ static int parse_patch_binary_side(
736736
decoded_len = c - 'a' + (('z' - 'a') + 1) + 1;
737737

738738
if (!decoded_len) {
739-
error = parse_err("invalid binary length at line %d", ctx->line_num);
739+
error = parse_err("invalid binary length at line %"PRIuZ, ctx->line_num);
740740
goto done;
741741
}
742742

@@ -745,7 +745,7 @@ static int parse_patch_binary_side(
745745
encoded_len = ((decoded_len / 4) + !!(decoded_len % 4)) * 5;
746746

747747
if (encoded_len > ctx->line_len - 1) {
748-
error = parse_err("truncated binary data at line %d", ctx->line_num);
748+
error = parse_err("truncated binary data at line %"PRIuZ, ctx->line_num);
749749
goto done;
750750
}
751751

@@ -754,14 +754,14 @@ static int parse_patch_binary_side(
754754
goto done;
755755

756756
if (decoded.size - decoded_orig != decoded_len) {
757-
error = parse_err("truncated binary data at line %d", ctx->line_num);
757+
error = parse_err("truncated binary data at line %"PRIuZ, ctx->line_num);
758758
goto done;
759759
}
760760

761761
parse_advance_chars(ctx, encoded_len);
762762

763763
if (parse_advance_nl(ctx) < 0) {
764-
error = parse_err("trailing data at line %d", ctx->line_num);
764+
error = parse_err("trailing data at line %"PRIuZ, ctx->line_num);
765765
goto done;
766766
}
767767
}
@@ -785,15 +785,15 @@ static int parse_patch_binary(
785785

786786
if (parse_advance_expected_str(ctx, "GIT binary patch") < 0 ||
787787
parse_advance_nl(ctx) < 0)
788-
return parse_err("corrupt git binary header at line %d", ctx->line_num);
788+
return parse_err("corrupt git binary header at line %"PRIuZ, ctx->line_num);
789789

790790
/* parse old->new binary diff */
791791
if ((error = parse_patch_binary_side(
792792
&patch->base.binary.new_file, ctx)) < 0)
793793
return error;
794794

795795
if (parse_advance_nl(ctx) < 0)
796-
return parse_err("corrupt git binary separator at line %d",
796+
return parse_err("corrupt git binary separator at line %"PRIuZ,
797797
ctx->line_num);
798798

799799
/* parse new->old binary diff */
@@ -802,7 +802,7 @@ static int parse_patch_binary(
802802
return error;
803803

804804
if (parse_advance_nl(ctx) < 0)
805-
return parse_err("corrupt git binary patch separator at line %d",
805+
return parse_err("corrupt git binary patch separator at line %"PRIuZ,
806806
ctx->line_num);
807807

808808
patch->base.binary.contains_data = 1;
@@ -820,7 +820,7 @@ static int parse_patch_binary_nodata(
820820
parse_advance_expected_str(ctx, patch->header_new_path) < 0 ||
821821
parse_advance_expected_str(ctx, " differ") < 0 ||
822822
parse_advance_nl(ctx) < 0)
823-
return parse_err("corrupt git binary header at line %d", ctx->line_num);
823+
return parse_err("corrupt git binary header at line %"PRIuZ, ctx->line_num);
824824

825825
patch->base.binary.contains_data = 0;
826826
patch->base.delta->flags |= GIT_DIFF_FLAG_BINARY;
@@ -912,7 +912,7 @@ static int check_prefix(
912912

913913
if (remain_len || !*path)
914914
return parse_err(
915-
"header filename does not contain %d path components",
915+
"header filename does not contain %"PRIuZ" path components",
916916
prefix_len);
917917

918918
done:

src/path.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ int git_path_diriter_next(git_path_diriter *diriter)
13471347
return GIT_ITEROVER;
13481348

13491349
giterr_set(GITERR_OS,
1350-
"Could not read directory '%s'", diriter->path);
1350+
"Could not read directory '%s'", diriter->path.ptr);
13511351
return -1;
13521352
}
13531353
} while (skip_dot && git_path_is_dot_or_dotdot(de->d_name));

src/tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ int git_tree_entry_bypath(
917917

918918
if (entry == NULL) {
919919
giterr_set(GITERR_TREE,
920-
"the path '%.*s' does not exist in the given tree", filename_len, path);
920+
"the path '%.*s' does not exist in the given tree", (int) filename_len, path);
921921
return GIT_ENOTFOUND;
922922
}
923923

@@ -927,7 +927,7 @@ int git_tree_entry_bypath(
927927
* then this entry *must* be a tree */
928928
if (!git_tree_entry__is_tree(entry)) {
929929
giterr_set(GITERR_TREE,
930-
"the path '%.*s' exists but is not a tree", filename_len, path);
930+
"the path '%.*s' exists but is not a tree", (int) filename_len, path);
931931
return GIT_ENOTFOUND;
932932
}
933933

0 commit comments

Comments
 (0)