Git fork

shallow: fix -Wsign-compare warnings

Fix a couple of -Wsign-compare issues in "shallow.c" and mark the file
as -Wsign-compare-clean. This change prepares the code for a refactoring
of `repo_in_merge_bases_many()`, which will be adapted to accept the
number of commits as `size_t` instead of `int`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
455ac070 1ab59481

+21 -23
+18 -20
shallow.c
··· 1 1 #define USE_THE_REPOSITORY_VARIABLE 2 - #define DISABLE_SIGN_COMPARE_WARNINGS 3 2 4 3 #include "git-compat-util.h" 5 4 #include "hex.h" ··· 134 133 struct commit_list *get_shallow_commits(struct object_array *heads, int depth, 135 134 int shallow_flag, int not_shallow_flag) 136 135 { 137 - int i = 0, cur_depth = 0; 136 + size_t i = 0; 137 + int cur_depth = 0; 138 138 struct commit_list *result = NULL; 139 139 struct object_array stack = OBJECT_ARRAY_INIT; 140 140 struct commit *commit = NULL; ··· 335 335 const struct oid_array *extra, 336 336 unsigned flags) 337 337 { 338 - struct write_shallow_data data; 339 - int i; 340 - data.out = out; 341 - data.use_pack_protocol = use_pack_protocol; 342 - data.count = 0; 343 - data.flags = flags; 338 + struct write_shallow_data data = { 339 + .out = out, 340 + .use_pack_protocol = use_pack_protocol, 341 + .flags = flags, 342 + }; 343 + 344 344 for_each_commit_graft(write_one_shallow, &data); 345 345 if (!extra) 346 346 return data.count; 347 - for (i = 0; i < extra->nr; i++) { 347 + for (size_t i = 0; i < extra->nr; i++) { 348 348 strbuf_addstr(out, oid_to_hex(extra->oid + i)); 349 349 strbuf_addch(out, '\n'); 350 350 data.count++; ··· 466 466 */ 467 467 void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa) 468 468 { 469 - int i; 470 469 trace_printf_key(&trace_shallow, "shallow: prepare_shallow_info\n"); 471 470 memset(info, 0, sizeof(*info)); 472 471 info->shallow = sa; ··· 474 473 return; 475 474 ALLOC_ARRAY(info->ours, sa->nr); 476 475 ALLOC_ARRAY(info->theirs, sa->nr); 477 - for (i = 0; i < sa->nr; i++) { 476 + for (size_t i = 0; i < sa->nr; i++) { 478 477 if (repo_has_object_file(the_repository, sa->oid + i)) { 479 478 struct commit_graft *graft; 480 479 graft = lookup_commit_graft(the_repository, ··· 507 506 void remove_nonexistent_theirs_shallow(struct shallow_info *info) 508 507 { 509 508 struct object_id *oid = info->shallow->oid; 510 - int i, dst; 509 + size_t i, dst; 511 510 trace_printf_key(&trace_shallow, "shallow: remove_nonexistent_theirs_shallow\n"); 512 511 for (i = dst = 0; i < info->nr_theirs; i++) { 513 512 if (i != dst) ··· 560 559 { 561 560 unsigned int i, nr; 562 561 struct commit_list *head = NULL; 563 - int bitmap_nr = DIV_ROUND_UP(info->nr_bits, 32); 562 + size_t bitmap_nr = DIV_ROUND_UP(info->nr_bits, 32); 564 563 size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr); 565 564 struct commit *c = lookup_commit_reference_gently(the_repository, oid, 566 565 1); ··· 660 659 struct object_id *oid = info->shallow->oid; 661 660 struct oid_array *ref = info->ref; 662 661 unsigned int i, nr; 663 - int *shallow, nr_shallow = 0; 662 + size_t *shallow, nr_shallow = 0; 664 663 struct paint_info pi; 665 664 666 665 trace_printf_key(&trace_shallow, "shallow: assign_shallow_commits_to_refs\n"); ··· 735 734 736 735 struct commit_array { 737 736 struct commit **commits; 738 - int nr, alloc; 737 + size_t nr, alloc; 739 738 }; 740 739 741 740 static int add_ref(const char *refname UNUSED, ··· 753 752 return 0; 754 753 } 755 754 756 - static void update_refstatus(int *ref_status, int nr, uint32_t *bitmap) 755 + static void update_refstatus(int *ref_status, size_t nr, uint32_t *bitmap) 757 756 { 758 - unsigned int i; 759 757 if (!ref_status) 760 758 return; 761 - for (i = 0; i < nr; i++) 759 + for (size_t i = 0; i < nr; i++) 762 760 if (bitmap[i / 32] & (1U << (i % 32))) 763 761 ref_status[i]++; 764 762 } ··· 773 771 struct object_id *oid = info->shallow->oid; 774 772 struct commit *c; 775 773 uint32_t **bitmap; 776 - int dst, i, j; 777 - int bitmap_nr = DIV_ROUND_UP(info->ref->nr, 32); 774 + size_t dst, i, j; 775 + size_t bitmap_nr = DIV_ROUND_UP(info->ref->nr, 32); 778 776 struct commit_array ca; 779 777 780 778 trace_printf_key(&trace_shallow, "shallow: post_assign_shallow\n");
+3 -3
shallow.h
··· 59 59 */ 60 60 struct shallow_info { 61 61 struct oid_array *shallow; 62 - int *ours, nr_ours; 63 - int *theirs, nr_theirs; 62 + size_t *ours, nr_ours; 63 + size_t *theirs, nr_theirs; 64 64 struct oid_array *ref; 65 65 66 66 /* for receive-pack */ ··· 69 69 int *reachable; 70 70 int *shallow_ref; 71 71 struct commit **commits; 72 - int nr_commits; 72 + size_t nr_commits; 73 73 }; 74 74 75 75 void prepare_shallow_info(struct shallow_info *, struct oid_array *);