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