each_ref_fn: change to take an object_id parameter

Change typedef each_ref_fn to take a "const struct object_id *oid" parameter instead of "const unsigned char *sha1". To aid this transition, implement an adapter that can be used to wrap old-style functions matching the old typedef, which is now called "each_ref_sha1_fn"), and make such functions callable via the new interface. This requires the old function and its cb_data to be wrapped in a "struct each_ref_fn_sha1_adapter", and that object to be used as the cb_data for an adapter function, each_ref_fn_adapter(). This is an enormous diff, but most of it consists of simple, mechanical changes to the sites that call any of the "for_each_ref" family of functions. Subsequent to this change, the call sites can be rewritten one by one to use the new interface. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed May 25, 2015 at 18:38 UTC 2b2a5be394bc67bed86bc009195c664dca740bd6
36 files changed +275 -97
Documentation/technical/api-ref-iteration.txt
+1 -1
@@ -6,7 +6,7 @@ Iteration of refs is done by using an iterate function which will call a
6 callback function for every ref. The callback function has this
7 signature:
8
9 - int handle_one_ref(const char *refname, const unsigned char *sha1,
9 + int handle_one_ref(const char *refname, const struct object_id *oid,
10 int flags, void *cb_data);
11
12 There are different kinds of iterate functions which all take a
bisect.c
+4 -1
@@ -417,7 +417,10 @@ static int register_ref(const char *refname, const unsigned char *sha1,
417
418 static int read_bisect_refs(void)
419 {
420 - return for_each_ref_in("refs/bisect/", register_ref, NULL);
420 + struct each_ref_fn_sha1_adapter wrapped_register_ref =
421 + {register_ref, NULL};
422 +
423 + return for_each_ref_in("refs/bisect/", each_ref_fn_adapter, &wrapped_register_ref);
424 }
425
426 static void read_bisect_paths(struct argv_array *array)
builtin/branch.c
+3 -1
@@ -631,6 +631,8 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
631 int i;
632 struct append_ref_cb cb;
633 struct ref_list ref_list;
634 + struct each_ref_fn_sha1_adapter wrapped_append_ref =
635 + {append_ref, &cb};
636
637 memset(&ref_list, 0, sizeof(ref_list));
638 ref_list.kinds = kinds;
@@ -642,7 +644,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
644 cb.ref_list = &ref_list;
645 cb.pattern = pattern;
646 cb.ret = 0;
645 - for_each_rawref(append_ref, &cb);
647 + for_each_rawref(each_ref_fn_adapter, &wrapped_append_ref);
648 if (merge_filter != NO_FILTER) {
649 struct commit *filter;
650 filter = lookup_commit_reference_gently(merge_filter_ref, 0);
builtin/checkout.c
+3 -1
@@ -784,6 +784,8 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new)
784 struct rev_info revs;
785 struct object *object = &old->object;
786 struct object_array refs;
787 + struct each_ref_fn_sha1_adapter wrapped_add_pending_uninteresting_ref =
788 + {add_pending_uninteresting_ref, &revs};
789
790 init_revisions(&revs, NULL);
791 setup_revisions(0, NULL, &revs, NULL);
@@ -791,7 +793,7 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new)
793 object->flags &= ~UNINTERESTING;
794 add_pending_object(&revs, object, sha1_to_hex(object->sha1));
795
794 - for_each_ref(add_pending_uninteresting_ref, &revs);
796 + for_each_ref(each_ref_fn_adapter, &wrapped_add_pending_uninteresting_ref);
797 add_pending_sha1(&revs, "HEAD", new->object.sha1, UNINTERESTING);
798
799 refs = revs.pending;
builtin/describe.c
+3 -1
@@ -413,6 +413,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
413 PARSE_OPT_OPTARG, NULL, (intptr_t) "-dirty"},
414 OPT_END(),
415 };
416 + struct each_ref_fn_sha1_adapter wrapped_get_name =
417 + {get_name, NULL};
418
419 git_config(git_default_config, NULL);
420 argc = parse_options(argc, argv, prefix, options, describe_usage, 0);
@@ -451,7 +453,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
453 }
454
455 hashmap_init(&names, (hashmap_cmp_fn) commit_name_cmp, 0);
454 - for_each_rawref(get_name, NULL);
456 + for_each_rawref(each_ref_fn_adapter, &wrapped_get_name);
457 if (!names.size && !always)
458 die(_("No names found, cannot describe anything."));
459
builtin/fetch.c
+6 -2
@@ -208,8 +208,10 @@ static void find_non_local_tags(struct transport *transport,
208 struct string_list remote_refs = STRING_LIST_INIT_NODUP;
209 const struct ref *ref;
210 struct string_list_item *item = NULL;
211 + struct each_ref_fn_sha1_adapter wrapped_add_existing =
212 + {add_existing, &existing_refs};
213
212 - for_each_ref(add_existing, &existing_refs);
214 + for_each_ref(each_ref_fn_adapter, &wrapped_add_existing);
215 for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
216 if (!starts_with(ref->name, "refs/tags/"))
217 continue;
@@ -884,8 +886,10 @@ static int do_fetch(struct transport *transport,
886 struct ref *rm;
887 int autotags = (transport->remote->fetch_tags == 1);
888 int retcode = 0;
889 + struct each_ref_fn_sha1_adapter wrapped_add_existing =
890 + {add_existing, &existing_refs};
891
888 - for_each_ref(add_existing, &existing_refs);
892 + for_each_ref(each_ref_fn_adapter, &wrapped_add_existing);
893
894 if (tags == TAGS_DEFAULT) {
895 if (transport->remote->fetch_tags == 2)
builtin/for-each-ref.c
+3 -1
@@ -1072,6 +1072,8 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
1072 int maxcount = 0, quote_style = 0;
1073 struct refinfo **refs;
1074 struct grab_ref_cbdata cbdata;
1075 + struct each_ref_fn_sha1_adapter wrapped_grab_single_ref =
1076 + {grab_single_ref, &cbdata};
1077
1078 struct option opts[] = {
1079 OPT_BIT('s', "shell", &quote_style,
@@ -1111,7 +1113,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
1113
1114 memset(&cbdata, 0, sizeof(cbdata));
1115 cbdata.grab_pattern = argv;
1114 - for_each_rawref(grab_single_ref, &cbdata);
1116 + for_each_rawref(each_ref_fn_adapter, &wrapped_grab_single_ref);
1117 refs = cbdata.grab_array;
1118 num_refs = cbdata.grab_cnt;
1119
builtin/fsck.c
+7 -2
@@ -504,11 +504,16 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
504
505 static void get_default_heads(void)
506 {
507 + struct each_ref_fn_sha1_adapter wrapped_fsck_handle_ref =
508 + {fsck_handle_ref, NULL};
509 + struct each_ref_fn_sha1_adapter wrapped_fsck_handle_reflog =
510 + {fsck_handle_reflog, NULL};
511 +
512 if (head_points_at && !is_null_sha1(head_sha1))
513 fsck_handle_ref("HEAD", head_sha1, 0, NULL);
509 - for_each_rawref(fsck_handle_ref, NULL);
514 + for_each_rawref(each_ref_fn_adapter, &wrapped_fsck_handle_ref);
515 if (include_reflogs)
511 - for_each_reflog(fsck_handle_reflog, NULL);
516 + for_each_reflog(each_ref_fn_adapter, &wrapped_fsck_handle_reflog);
517
518 /*
519 * Not having any default heads isn't really fatal, but
builtin/name-rev.c
+3 -1
@@ -305,6 +305,8 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
305 struct object_array revs = OBJECT_ARRAY_INIT;
306 int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0;
307 struct name_ref_data data = { 0, 0, NULL };
308 + struct each_ref_fn_sha1_adapter wrapped_name_ref =
309 + {name_ref, &data};
310 struct option opts[] = {
311 OPT_BOOL(0, "name-only", &data.name_only, N_("print only names (no SHA-1)")),
312 OPT_BOOL(0, "tags", &data.tags_only, N_("only use tags to name the commits")),
@@ -377,7 +379,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
379
380 if (cutoff)
381 cutoff = cutoff - CUTOFF_DATE_SLOP;
380 - for_each_ref(name_ref, &data);
382 + for_each_ref(each_ref_fn_adapter, &wrapped_name_ref);
383
384 if (transform_stdin) {
385 char buffer[2048];
builtin/pack-objects.c
+9 -3
@@ -626,6 +626,8 @@ static struct object_entry **compute_write_order(void)
626
627 struct object_entry **wo = xmalloc(to_pack.nr_objects * sizeof(*wo));
628 struct object_entry *objects = to_pack.objects;
629 + struct each_ref_fn_sha1_adapter wrapped_mark_tagged =
630 + {mark_tagged, NULL};
631
632 for (i = 0; i < to_pack.nr_objects; i++) {
633 objects[i].tagged = 0;
@@ -651,7 +653,7 @@ static struct object_entry **compute_write_order(void)
653 /*
654 * Mark objects that are at the tip of tags.
655 */
654 - for_each_tag_ref(mark_tagged, NULL);
656 + for_each_tag_ref(each_ref_fn_adapter, &wrapped_mark_tagged);
657
658 /*
659 * Give the objects in the original recency order until
@@ -2784,8 +2786,12 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2786 argv_array_clear(&rp);
2787 }
2788 cleanup_preferred_base();
2787 - if (include_tag && nr_result)
2788 - for_each_ref(add_ref_tag, NULL);
2789 + if (include_tag && nr_result) {
2790 + struct each_ref_fn_sha1_adapter wrapped_add_ref_tag =
2791 + {add_ref_tag, NULL};
2792 +
2793 + for_each_ref(each_ref_fn_adapter, &wrapped_add_ref_tag);
2794 + }
2795 stop_progress(&progress_state);
2796
2797 if (non_empty && !nr_result)
builtin/receive-pack.c
+4 -1
@@ -228,10 +228,13 @@ static void collect_one_alternate_ref(const struct ref *ref, void *data)
228 static void write_head_info(void)
229 {
230 struct sha1_array sa = SHA1_ARRAY_INIT;
231 + struct each_ref_fn_sha1_adapter wrapped_show_ref_cb =
232 + {show_ref_cb, NULL};
233 +
234 for_each_alternate_ref(collect_one_alternate_ref, &sa);
235 sha1_array_for_each_unique(&sa, show_one_alternate_sha1, NULL);
236 sha1_array_clear(&sa);
234 - for_each_ref(show_ref_cb, NULL);
237 + for_each_ref(each_ref_fn_adapter, &wrapped_show_ref_cb);
238 if (!sent_capabilities)
239 show_ref("capabilities^{}", null_sha1);
240
builtin/reflog.c
+7 -2
@@ -352,7 +352,10 @@ static void reflog_expiry_prepare(const char *refname,
352 if (cb->unreachable_expire_kind != UE_ALWAYS) {
353 if (cb->unreachable_expire_kind == UE_HEAD) {
354 struct commit_list *elem;
355 - for_each_ref(push_tip_to_list, &cb->tips);
355 + struct each_ref_fn_sha1_adapter wrapped_push_tip_to_list =
356 + {push_tip_to_list, &cb->tips};
357 +
358 + for_each_ref(each_ref_fn_adapter, &wrapped_push_tip_to_list);
359 for (elem = cb->tips; elem; elem = elem->next)
360 commit_list_insert(elem->item, &cb->mark_list);
361 } else {
@@ -588,9 +591,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
591 if (do_all) {
592 struct collect_reflog_cb collected;
593 int i;
594 + struct each_ref_fn_sha1_adapter wrapped_collect_reflog =
595 + {collect_reflog, &collected};
596
597 memset(&collected, 0, sizeof(collected));
593 - for_each_reflog(collect_reflog, &collected);
598 + for_each_reflog(each_ref_fn_adapter, &wrapped_collect_reflog);
599 for (i = 0; i < collected.nr; i++) {
600 struct collected_reflog *e = collected.e[i];
601 set_reflog_expiry_param(&cb.cmd, explicit_expiry, e->reflog);
builtin/remote.c
+10 -3
@@ -623,6 +623,8 @@ static int mv(int argc, const char **argv)
623 struct string_list remote_branches = STRING_LIST_INIT_NODUP;
624 struct rename_info rename;
625 int i, refspec_updated = 0;
626 + struct each_ref_fn_sha1_adapter wrapped_read_remote_branches =
627 + {read_remote_branches, &rename};
628
629 if (argc != 3)
630 usage_with_options(builtin_remote_rename_usage, options);
@@ -700,7 +702,7 @@ static int mv(int argc, const char **argv)
702 * First remove symrefs, then rename the rest, finally create
703 * the new symrefs.
704 */
703 - for_each_ref(read_remote_branches, &rename);
705 + for_each_ref(each_ref_fn_adapter, &wrapped_read_remote_branches);
706 for (i = 0; i < remote_branches.nr; i++) {
707 struct string_list_item *item = remote_branches.items + i;
708 int flag = 0;
@@ -781,6 +783,8 @@ static int rm(int argc, const char **argv)
783 struct string_list skipped = STRING_LIST_INIT_DUP;
784 struct branches_for_remote cb_data;
785 int i, result;
786 + struct each_ref_fn_sha1_adapter wrapped_add_branch_for_removal =
787 + {add_branch_for_removal, &cb_data};
788
789 memset(&cb_data, 0, sizeof(cb_data));
790 cb_data.branches = &branches;
@@ -821,7 +825,7 @@ static int rm(int argc, const char **argv)
825 * refs, which are invalidated when deleting a branch.
826 */
827 cb_data.remote = remote;
824 - result = for_each_ref(add_branch_for_removal, &cb_data);
828 + result = for_each_ref(each_ref_fn_adapter, &wrapped_add_branch_for_removal);
829 strbuf_release(&buf);
830
831 if (!result)
@@ -910,7 +914,10 @@ static int get_remote_ref_states(const char *name,
914 if (query & GET_PUSH_REF_STATES)
915 get_push_ref_states(remote_refs, states);
916 } else {
913 - for_each_ref(append_ref_to_tracked_list, states);
917 + struct each_ref_fn_sha1_adapter wrapped_append_ref_to_tracked_list =
918 + {append_ref_to_tracked_list, states};
919 +
920 + for_each_ref(each_ref_fn_adapter, &wrapped_append_ref_to_tracked_list);
921 string_list_sort(&states->tracked);
922 get_push_ref_states_noquery(states);
923 }
builtin/replace.c
+3 -1
@@ -66,6 +66,8 @@ static int show_reference(const char *refname, const unsigned char *sha1,
66 static int list_replace_refs(const char *pattern, const char *format)
67 {
68 struct show_data data;
69 + struct each_ref_fn_sha1_adapter wrapped_show_reference =
70 + {show_reference, (void *) &data};
71
72 if (pattern == NULL)
73 pattern = "*";
@@ -82,7 +84,7 @@ static int list_replace_refs(const char *pattern, const char *format)
84 "valid formats are 'short', 'medium' and 'long'\n",
85 format);
86
85 - for_each_replace_ref(show_reference, (void *) &data);
87 + for_each_replace_ref(each_ref_fn_adapter, &wrapped_show_reference);
88
89 return 0;
90 }
builtin/rev-parse.c
+20 -13
@@ -511,6 +511,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
511 unsigned int flags = 0;
512 const char *name = NULL;
513 struct object_context unused;
514 + struct each_ref_fn_sha1_adapter wrapped_show_reference =
515 + {show_reference, NULL};
516 + struct each_ref_fn_sha1_adapter wrapped_anti_reference =
517 + {anti_reference, NULL};
518
519 if (argc > 1 && !strcmp("--parseopt", argv[1]))
520 return cmd_parseopt(argc - 1, argv + 1, prefix);
@@ -652,7 +656,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
656 continue;
657 }
658 if (!strcmp(arg, "--all")) {
655 - for_each_ref(show_reference, NULL);
659 + for_each_ref(each_ref_fn_adapter, &wrapped_show_reference);
660 continue;
661 }
662 if (starts_with(arg, "--disambiguate=")) {
@@ -660,45 +664,48 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
664 continue;
665 }
666 if (!strcmp(arg, "--bisect")) {
663 - for_each_ref_in("refs/bisect/bad", show_reference, NULL);
664 - for_each_ref_in("refs/bisect/good", anti_reference, NULL);
667 + for_each_ref_in("refs/bisect/bad",
668 + each_ref_fn_adapter, &wrapped_show_reference);
669 + for_each_ref_in("refs/bisect/good",
670 + each_ref_fn_adapter, &wrapped_anti_reference);
671 continue;
672 }
673 if (starts_with(arg, "--branches=")) {
668 - for_each_glob_ref_in(show_reference, arg + 11,
669 - "refs/heads/", NULL);
674 + for_each_glob_ref_in(each_ref_fn_adapter, arg + 11,
675 + "refs/heads/", &wrapped_show_reference);
676 clear_ref_exclusion(&ref_excludes);
677 continue;
678 }
679 if (!strcmp(arg, "--branches")) {
674 - for_each_branch_ref(show_reference, NULL);
680 + for_each_branch_ref(each_ref_fn_adapter, &wrapped_show_reference);
681 clear_ref_exclusion(&ref_excludes);
682 continue;
683 }
684 if (starts_with(arg, "--tags=")) {
679 - for_each_glob_ref_in(show_reference, arg + 7,
680 - "refs/tags/", NULL);
685 + for_each_glob_ref_in(each_ref_fn_adapter, arg + 7,
686 + "refs/tags/", &wrapped_show_reference);
687 clear_ref_exclusion(&ref_excludes);
688 continue;
689 }
690 if (!strcmp(arg, "--tags")) {
685 - for_each_tag_ref(show_reference, NULL);
691 + for_each_tag_ref(each_ref_fn_adapter, &wrapped_show_reference);
692 clear_ref_exclusion(&ref_excludes);
693 continue;
694 }
695 if (starts_with(arg, "--glob=")) {
690 - for_each_glob_ref(show_reference, arg + 7, NULL);
696 + for_each_glob_ref(each_ref_fn_adapter, arg + 7,
697 + &wrapped_show_reference);
698 clear_ref_exclusion(&ref_excludes);
699 continue;
700 }
701 if (starts_with(arg, "--remotes=")) {
695 - for_each_glob_ref_in(show_reference, arg + 10,
696 - "refs/remotes/", NULL);
702 + for_each_glob_ref_in(each_ref_fn_adapter, arg + 10,
703 + "refs/remotes/", &wrapped_show_reference);
704 clear_ref_exclusion(&ref_excludes);
705 continue;
706 }
707 if (!strcmp(arg, "--remotes")) {
701 - for_each_remote_ref(show_reference, NULL);
708 + for_each_remote_ref(each_ref_fn_adapter, &wrapped_show_reference);
709 clear_ref_exclusion(&ref_excludes);
710 continue;
711 }
builtin/show-branch.c
+12 -3
@@ -466,12 +466,18 @@ static void snarf_refs(int head, int remotes)
466 {
467 if (head) {
468 int orig_cnt = ref_name_cnt;
469 - for_each_ref(append_head_ref, NULL);
469 + struct each_ref_fn_sha1_adapter wrapped_append_head_ref =
470 + {append_head_ref, NULL};
471 +
472 + for_each_ref(each_ref_fn_adapter, &wrapped_append_head_ref);
473 sort_ref_range(orig_cnt, ref_name_cnt);
474 }
475 if (remotes) {
476 int orig_cnt = ref_name_cnt;
474 - for_each_ref(append_remote_ref, NULL);
477 + struct each_ref_fn_sha1_adapter wrapped_append_remote_ref =
478 + {append_remote_ref, NULL};
479 +
480 + for_each_ref(each_ref_fn_adapter, &wrapped_append_remote_ref);
481 sort_ref_range(orig_cnt, ref_name_cnt);
482 }
483 }
@@ -538,9 +544,12 @@ static void append_one_rev(const char *av)
544 if (strchr(av, '*') || strchr(av, '?') || strchr(av, '[')) {
545 /* glob style match */
546 int saved_matches = ref_name_cnt;
547 + struct each_ref_fn_sha1_adapter wrapped_append_matching_ref =
548 + {append_matching_ref, NULL};
549 +
550 match_ref_pattern = av;
551 match_ref_slash = count_slash(av);
543 - for_each_ref(append_matching_ref, NULL);
552 + for_each_ref(each_ref_fn_adapter, &wrapped_append_matching_ref);
553 if (saved_matches == ref_name_cnt &&
554 ref_name_cnt < MAX_REVS)
555 error("no matching refs with %s", av);
builtin/show-ref.c
+8 -3
@@ -109,8 +109,10 @@ static int exclude_existing(const char *match)
109 static struct string_list existing_refs = STRING_LIST_INIT_DUP;
110 char buf[1024];
111 int matchlen = match ? strlen(match) : 0;
112 + struct each_ref_fn_sha1_adapter wrapped_add_existing =
113 + {add_existing, &existing_refs};
114
113 - for_each_ref(add_existing, &existing_refs);
115 + for_each_ref(each_ref_fn_adapter, &wrapped_add_existing);
116 while (fgets(buf, sizeof(buf), stdin)) {
117 char *ref;
118 int len = strlen(buf);
@@ -191,6 +193,9 @@ static const struct option show_ref_options[] = {
193
194 int cmd_show_ref(int argc, const char **argv, const char *prefix)
195 {
196 + struct each_ref_fn_sha1_adapter wrapped_show_ref =
197 + {show_ref, NULL};
198 +
199 if (argc == 2 && !strcmp(argv[1], "-h"))
200 usage_with_options(show_ref_usage, show_ref_options);
201
@@ -225,8 +230,8 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
230 }
231
232 if (show_head)
228 - head_ref(show_ref, NULL);
229 - for_each_ref(show_ref, NULL);
233 + head_ref(each_ref_fn_adapter, &wrapped_show_ref);
234 + for_each_ref(each_ref_fn_adapter, &wrapped_show_ref);
235 if (!found_match) {
236 if (verify && !quiet)
237 die("No match");
builtin/tag.c
+3 -1
@@ -260,6 +260,8 @@ static int list_tags(const char **patterns, int lines,
260 struct commit_list *with_commit, int sort)
261 {
262 struct tag_filter filter;
263 + struct each_ref_fn_sha1_adapter wrapped_show_reference =
264 + {show_reference, (void *)&filter};
265
266 filter.patterns = patterns;
267 filter.lines = lines;
@@ -268,7 +270,7 @@ static int list_tags(const char **patterns, int lines,
270 memset(&filter.tags, 0, sizeof(filter.tags));
271 filter.tags.strdup_strings = 1;
272
271 - for_each_tag_ref(show_reference, (void *) &filter);
273 + for_each_tag_ref(each_ref_fn_adapter, &wrapped_show_reference);
274 if (sort) {
275 int i;
276 if ((sort & SORT_MASK) == VERCMP_SORT)
fetch-pack.c
+13 -4
@@ -256,14 +256,20 @@ static int find_common(struct fetch_pack_args *args,
256 int got_ready = 0;
257 struct strbuf req_buf = STRBUF_INIT;
258 size_t state_len = 0;
259 + struct each_ref_fn_sha1_adapter wrapped_rev_list_insert_ref =
260 + {rev_list_insert_ref, NULL};
261
262 if (args->stateless_rpc && multi_ack == 1)
263 die("--stateless-rpc requires multi_ack_detailed");
262 - if (marked)
263 - for_each_ref(clear_marks, NULL);
264 + if (marked) {
265 + struct each_ref_fn_sha1_adapter wrapped_clear_marks =
266 + {clear_marks, NULL};
267 +
268 + for_each_ref(each_ref_fn_adapter, &wrapped_clear_marks);
269 + }
270 marked = 1;
271
266 - for_each_ref(rev_list_insert_ref, NULL);
272 + for_each_ref(each_ref_fn_adapter, &wrapped_rev_list_insert_ref);
273 for_each_alternate_ref(insert_one_alternate_ref, NULL);
274
275 fetching = 0;
@@ -599,7 +605,10 @@ static int everything_local(struct fetch_pack_args *args,
605 }
606
607 if (!args->depth) {
602 - for_each_ref(mark_complete, NULL);
608 + struct each_ref_fn_sha1_adapter wrapped_mark_complete =
609 + {mark_complete, NULL};
610 +
611 + for_each_ref(each_ref_fn_adapter, &wrapped_mark_complete);
612 for_each_alternate_ref(mark_alternate_complete, NULL);
613 commit_list_sort_by_date(&complete);
614 if (cutoff)
help.c
+3 -1
@@ -425,10 +425,12 @@ static struct string_list guess_refs(const char *ref)
425 {
426 struct similar_ref_cb ref_cb;
427 struct string_list similar_refs = STRING_LIST_INIT_NODUP;
428 + struct each_ref_fn_sha1_adapter wrapped_append_similar_ref =
429 + {append_similar_ref, &ref_cb};
430
431 ref_cb.base_ref = ref;
432 ref_cb.similar_refs = &similar_refs;
431 - for_each_ref(append_similar_ref, &ref_cb);
433 + for_each_ref(each_ref_fn_adapter, &wrapped_append_similar_ref);
434 return similar_refs;
435 }
436
http-backend.c
+7 -2
@@ -395,8 +395,11 @@ static void get_info_refs(char *arg)
395 run_service(argv);
396
397 } else {
398 + struct each_ref_fn_sha1_adapter wrapped_show_text_ref =
399 + {show_text_ref, &buf};
400 +
401 select_getanyfile();
399 - for_each_namespaced_ref(show_text_ref, &buf);
402 + for_each_namespaced_ref(each_ref_fn_adapter, &wrapped_show_text_ref);
403 send_strbuf("text/plain", &buf);
404 }
405 strbuf_release(&buf);
@@ -425,9 +428,11 @@ static int show_head_ref(const char *refname, const unsigned char *sha1,
428 static void get_head(char *arg)
429 {
430 struct strbuf buf = STRBUF_INIT;
431 + struct each_ref_fn_sha1_adapter wrapped_show_head_ref =
432 + {show_head_ref, &buf};
433
434 select_getanyfile();
430 - head_ref_namespaced(show_head_ref, &buf);
435 + head_ref_namespaced(each_ref_fn_adapter, &wrapped_show_head_ref);
436 send_strbuf("text/plain", &buf);
437 strbuf_release(&buf);
438 }
log-tree.c
+5 -2
@@ -149,10 +149,13 @@ static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
149 void load_ref_decorations(int flags)
150 {
151 if (!decoration_loaded) {
152 + struct each_ref_fn_sha1_adapter wrapped_add_ref_decoration =
153 + {add_ref_decoration, NULL};
154 +
155 decoration_loaded = 1;
156 decoration_flags = flags;
154 - for_each_ref(add_ref_decoration, NULL);
155 - head_ref(add_ref_decoration, NULL);
157 + for_each_ref(each_ref_fn_adapter, &wrapped_add_ref_decoration);
158 + head_ref(each_ref_fn_adapter, &wrapped_add_ref_decoration);
159 for_each_commit_graft(add_graft_decoration, NULL);
160 }
161 }
notes.c
+4 -1
@@ -932,9 +932,12 @@ static int string_list_add_one_ref(const char *refname, const unsigned char *sha
932 */
933 void string_list_add_refs_by_glob(struct string_list *list, const char *glob)
934 {
935 + struct each_ref_fn_sha1_adapter wrapped_string_list_add_one_ref =
936 + {string_list_add_one_ref, list};
937 +
938 assert(list->strdup_strings);
939 if (has_glob_specials(glob)) {
937 - for_each_glob_ref(string_list_add_one_ref, glob, list);
940 + for_each_glob_ref(each_ref_fn_adapter, glob, &wrapped_string_list_add_one_ref);
941 } else {
942 unsigned char sha1[20];
943 if (get_sha1(glob, sha1))
reachable.c
+4 -2
@@ -155,6 +155,8 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
155 struct progress *progress)
156 {
157 struct connectivity_progress cp;
158 + struct each_ref_fn_sha1_adapter wrapped_add_one_ref =
159 + {add_one_ref, revs};
160
161 /*
162 * Set up revision parsing, and mark us as being interested
@@ -168,10 +170,10 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
170 add_index_objects_to_pending(revs, 0);
171
172 /* Add all external refs */
171 - for_each_ref(add_one_ref, revs);
173 + for_each_ref(each_ref_fn_adapter, &wrapped_add_one_ref);
174
175 /* detached HEAD is not included in the list above */
174 - head_ref(add_one_ref, revs);
176 + head_ref(each_ref_fn_adapter, &wrapped_add_one_ref);
177
178 /* Add all reflog info */
179 if (mark_reflog)
refs.c
+26 -16
@@ -722,7 +722,7 @@ static int do_one_ref(struct ref_entry *entry, void *cb_data)
722 /* Store the old value, in case this is a recursive call: */
723 old_current_ref = current_ref;
724 current_ref = entry;
725 - retval = data->fn(entry->name + data->trim, entry->u.value.oid.hash,
725 + retval = data->fn(entry->name + data->trim, &entry->u.value.oid,
726 entry->flag, data->cb_data);
727 current_ref = old_current_ref;
728 return retval;
@@ -1756,13 +1756,14 @@ int ref_exists(const char *refname)
1756 return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, sha1, NULL);
1757 }
1758
1759 -static int filter_refs(const char *refname, const unsigned char *sha1, int flags,
1760 - void *data)
1759 +static int filter_refs(const char *refname, const struct object_id *oid,
1760 + int flags, void *data)
1761 {
1762 struct ref_filter *filter = (struct ref_filter *)data;
1763 +
1764 if (wildmatch(filter->pattern, refname, 0, NULL))
1765 return 0;
1765 - return filter->fn(refname, sha1, flags, filter->cb_data);
1766 + return filter->fn(refname, oid, flags, filter->cb_data);
1767 }
1768
1769 enum peel_status {
@@ -1897,7 +1898,7 @@ struct warn_if_dangling_data {
1898 const char *msg_fmt;
1899 };
1900
1900 -static int warn_if_dangling_symref(const char *refname, const unsigned char *sha1,
1901 +static int warn_if_dangling_symref(const char *refname, const struct object_id *oid,
1902 int flags, void *cb_data)
1903 {
1904 struct warn_if_dangling_data *d = cb_data;
@@ -2027,18 +2028,18 @@ static int do_for_each_ref(struct ref_cache *refs, const char *base,
2028
2029 static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data)
2030 {
2030 - unsigned char sha1[20];
2031 + struct object_id oid;
2032 int flag;
2033
2034 if (submodule) {
2034 - if (resolve_gitlink_ref(submodule, "HEAD", sha1) == 0)
2035 - return fn("HEAD", sha1, 0, cb_data);
2035 + if (resolve_gitlink_ref(submodule, "HEAD", oid.hash) == 0)
2036 + return fn("HEAD", &oid, 0, cb_data);
2037
2038 return 0;
2039 }
2040
2040 - if (!read_ref_full("HEAD", RESOLVE_REF_READING, sha1, &flag))
2041 - return fn("HEAD", sha1, flag, cb_data);
2041 + if (!read_ref_full("HEAD", RESOLVE_REF_READING, oid.hash, &flag))
2042 + return fn("HEAD", &oid, flag, cb_data);
2043
2044 return 0;
2045 }
@@ -2113,12 +2114,12 @@ int head_ref_namespaced(each_ref_fn fn, void *cb_data)
2114 {
2115 struct strbuf buf = STRBUF_INIT;
2116 int ret = 0;
2116 - unsigned char sha1[20];
2117 + struct object_id oid;
2118 int flag;
2119
2120 strbuf_addf(&buf, "%sHEAD", get_git_namespace());
2120 - if (!read_ref_full(buf.buf, RESOLVE_REF_READING, sha1, &flag))
2121 - ret = fn(buf.buf, sha1, flag, cb_data);
2121 + if (!read_ref_full(buf.buf, RESOLVE_REF_READING, oid.hash, &flag))
2122 + ret = fn(buf.buf, &oid, flag, cb_data);
2123 strbuf_release(&buf);
2124
2125 return ret;
@@ -2175,6 +2176,14 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
2176 DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
2177 }
2178
2179 +int each_ref_fn_adapter(const char *refname,
2180 + const struct object_id *oid, int flags, void *cb_data)
2181 +{
2182 + struct each_ref_fn_sha1_adapter *cb = cb_data;
2183 +
2184 + return cb->original_fn(refname, oid->hash, flags, cb->original_cb_data);
2185 +}
2186 +
2187 const char *prettify_refname(const char *name)
2188 {
2189 return name + (
@@ -3616,11 +3625,12 @@ static int do_for_each_reflog(struct strbuf *name, each_ref_fn fn, void *cb_data
3625 strbuf_addch(name, '/');
3626 retval = do_for_each_reflog(name, fn, cb_data);
3627 } else {
3619 - unsigned char sha1[20];
3620 - if (read_ref_full(name->buf, 0, sha1, NULL))
3628 + struct object_id oid;
3629 +
3630 + if (read_ref_full(name->buf, 0, oid.hash, NULL))
3631 retval = error("bad ref for %s", name->buf);
3632 else
3623 - retval = fn(name->buf, sha1, 0, cb_data);
3633 + retval = fn(name->buf, &oid, 0, cb_data);
3634 }
3635 if (retval)
3636 break;
refs.h
+12 -1
@@ -67,7 +67,18 @@ struct ref_transaction;
67 * single callback invocation.
68 */
69 typedef int each_ref_fn(const char *refname,
70 - const unsigned char *sha1, int flags, void *cb_data);
70 + const struct object_id *oid, int flags, void *cb_data);
71 +
72 +typedef int each_ref_sha1_fn(const char *refname,
73 + const unsigned char *sha1, int flags, void *cb_data);
74 +
75 +struct each_ref_fn_sha1_adapter {
76 + each_ref_sha1_fn *original_fn;
77 + void *original_cb_data;
78 +};
79 +
80 +extern int each_ref_fn_adapter(const char *refname,
81 + const struct object_id *oid, int flags, void *cb_data);
82
83 /*
84 * The following functions invoke the specified callback function for
remote.c
+8 -2
@@ -2046,7 +2046,10 @@ static int one_local_ref(const char *refname, const unsigned char *sha1, int fla
2046 struct ref *get_local_heads(void)
2047 {
2048 struct ref *local_refs = NULL, **local_tail = &local_refs;
2049 - for_each_ref(one_local_ref, &local_tail);
2049 + struct each_ref_fn_sha1_adapter wrapped_one_local_ref =
2050 + {one_local_ref, &local_tail};
2051 +
2052 + for_each_ref(each_ref_fn_adapter, &wrapped_one_local_ref);
2053 return local_refs;
2054 }
2055
@@ -2141,6 +2144,9 @@ struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fet
2144 struct ref *ref, *stale_refs = NULL;
2145 struct string_list ref_names = STRING_LIST_INIT_NODUP;
2146 struct stale_heads_info info;
2147 + struct each_ref_fn_sha1_adapter wrapped_get_stale_heads_cb =
2148 + {get_stale_heads_cb, &info};
2149 +
2150 info.ref_names = &ref_names;
2151 info.stale_refs_tail = &stale_refs;
2152 info.refs = refs;
@@ -2148,7 +2154,7 @@ struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fet
2154 for (ref = fetch_map; ref; ref = ref->next)
2155 string_list_append(&ref_names, ref->name);
2156 string_list_sort(&ref_names);
2151 - for_each_ref(get_stale_heads_cb, &info);
2157 + for_each_ref(each_ref_fn_adapter, &wrapped_get_stale_heads_cb);
2158 string_list_clear(&ref_names, 0);
2159 return stale_refs;
2160 }
replace_object.c
+3 -1
@@ -80,11 +80,13 @@ static int register_replace_ref(const char *refname,
80 static void prepare_replace_object(void)
81 {
82 static int replace_object_prepared;
83 + struct each_ref_fn_sha1_adapter wrapped_register_replace_ref =
84 + {register_replace_ref, NULL};
85
86 if (replace_object_prepared)
87 return;
88
87 - for_each_replace_ref(register_replace_ref, NULL);
89 + for_each_replace_ref(each_ref_fn_adapter, &wrapped_register_replace_ref);
90 replace_object_prepared = 1;
91 if (!replace_object_nr)
92 check_replace_refs = 0;
revision.c
+27 -6
@@ -1261,8 +1261,11 @@ static void handle_refs(const char *submodule, struct rev_info *revs, unsigned f
1261 int (*for_each)(const char *, each_ref_fn, void *))
1262 {
1263 struct all_refs_cb cb;
1264 + struct each_ref_fn_sha1_adapter wrapped_handle_one_ref =
1265 + {handle_one_ref, &cb};
1266 +
1267 init_all_refs_cb(&cb, revs, flags);
1265 - for_each(submodule, handle_one_ref, &cb);
1268 + for_each(submodule, each_ref_fn_adapter, &wrapped_handle_one_ref);
1269 }
1270
1271 static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)
@@ -1304,9 +1307,12 @@ static int handle_one_reflog(const char *path, const unsigned char *sha1, int fl
1307 void add_reflogs_to_pending(struct rev_info *revs, unsigned flags)
1308 {
1309 struct all_refs_cb cb;
1310 + struct each_ref_fn_sha1_adapter wrapped_handle_one_reflog =
1311 + {handle_one_reflog, &cb};
1312 +
1313 cb.all_revs = revs;
1314 cb.all_flags = flags;
1309 - for_each_reflog(handle_one_reflog, &cb);
1315 + for_each_reflog(each_ref_fn_adapter, &wrapped_handle_one_reflog);
1316 }
1317
1318 static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
@@ -2120,8 +2126,11 @@ static int handle_revision_pseudo_opt(const char *submodule,
2126 clear_ref_exclusion(&revs->ref_excludes);
2127 } else if ((argcount = parse_long_opt("glob", argv, &optarg))) {
2128 struct all_refs_cb cb;
2129 + struct each_ref_fn_sha1_adapter wrapped_handle_one_ref =
2130 + {handle_one_ref, &cb};
2131 +
2132 init_all_refs_cb(&cb, revs, *flags);
2124 - for_each_glob_ref(handle_one_ref, optarg, &cb);
2133 + for_each_glob_ref(each_ref_fn_adapter, optarg, &wrapped_handle_one_ref);
2134 clear_ref_exclusion(&revs->ref_excludes);
2135 return argcount;
2136 } else if ((argcount = parse_long_opt("exclude", argv, &optarg))) {
@@ -2129,18 +2138,30 @@ static int handle_revision_pseudo_opt(const char *submodule,
2138 return argcount;
2139 } else if (starts_with(arg, "--branches=")) {
2140 struct all_refs_cb cb;
2141 + struct each_ref_fn_sha1_adapter wrapped_handle_one_ref =
2142 + {handle_one_ref, &cb};
2143 +
2144 init_all_refs_cb(&cb, revs, *flags);
2133 - for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb);
2145 + for_each_glob_ref_in(each_ref_fn_adapter, arg + 11, "refs/heads/",
2146 + &wrapped_handle_one_ref);
2147 clear_ref_exclusion(&revs->ref_excludes);
2148 } else if (starts_with(arg, "--tags=")) {
2149 struct all_refs_cb cb;
2150 + struct each_ref_fn_sha1_adapter wrapped_handle_one_ref =
2151 + {handle_one_ref, &cb};
2152 +
2153 init_all_refs_cb(&cb, revs, *flags);
2138 - for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb);
2154 + for_each_glob_ref_in(each_ref_fn_adapter, arg + 7, "refs/tags/",
2155 + &wrapped_handle_one_ref);
2156 clear_ref_exclusion(&revs->ref_excludes);
2157 } else if (starts_with(arg, "--remotes=")) {
2158 struct all_refs_cb cb;
2159 + struct each_ref_fn_sha1_adapter wrapped_handle_one_ref =
2160 + {handle_one_ref, &cb};
2161 +
2162 init_all_refs_cb(&cb, revs, *flags);
2143 - for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb);
2163 + for_each_glob_ref_in(each_ref_fn_adapter, arg + 10, "refs/remotes/",
2164 + &wrapped_handle_one_ref);
2165 clear_ref_exclusion(&revs->ref_excludes);
2166 } else if (!strcmp(arg, "--reflog")) {
2167 add_reflogs_to_pending(revs, *flags);
server-info.c
+4 -1
@@ -69,7 +69,10 @@ static int add_info_ref(const char *path, const unsigned char *sha1, int flag, v
69
70 static int generate_info_refs(FILE *fp)
71 {
72 - return for_each_ref(add_info_ref, fp);
72 + struct each_ref_fn_sha1_adapter wrapped_add_info_ref =
73 + {add_info_ref, fp};
74 +
75 + return for_each_ref(each_ref_fn_adapter, &wrapped_add_info_ref);
76 }
77
78 static int update_info_refs(int force)
sha1_name.c
+4 -1
@@ -1371,7 +1371,10 @@ static int get_sha1_with_context_1(const char *name,
1371 int pos;
1372 if (!only_to_die && namelen > 2 && name[1] == '/') {
1373 struct commit_list *list = NULL;
1374 - for_each_ref(handle_one_ref, &list);
1374 + struct each_ref_fn_sha1_adapter wrapped_handle_one_ref =
1375 + {handle_one_ref, &list};
1376 +
1377 + for_each_ref(each_ref_fn_adapter, &wrapped_handle_one_ref);
1378 commit_list_sort_by_date(&list);
1379 return get_sha1_oneline(name + 2, sha1, list);
1380 }
shallow.c
+13 -6
@@ -512,6 +512,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
512 unsigned int i, nr;
513 int *shallow, nr_shallow = 0;
514 struct paint_info pi;
515 + struct each_ref_fn_sha1_adapter wrapped_mark_uninteresting =
516 + {mark_uninteresting, NULL};
517
518 trace_printf_key(&trace_shallow, "shallow: assign_shallow_commits_to_refs\n");
519 shallow = xmalloc(sizeof(*shallow) * (info->nr_ours + info->nr_theirs));
@@ -542,8 +544,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
544 * connect to old refs. If not (e.g. force ref updates) it'll
545 * have to go down to the current shallow commits.
546 */
545 - head_ref(mark_uninteresting, NULL);
546 - for_each_ref(mark_uninteresting, NULL);
547 + head_ref(each_ref_fn_adapter, &wrapped_mark_uninteresting);
548 + for_each_ref(each_ref_fn_adapter, &wrapped_mark_uninteresting);
549
550 /* Mark potential bottoms so we won't go out of bound */
551 for (i = 0; i < nr_shallow; i++) {
@@ -618,6 +620,8 @@ static void post_assign_shallow(struct shallow_info *info,
620 int dst, i, j;
621 int bitmap_nr = (info->ref->nr + 31) / 32;
622 struct commit_array ca;
623 + struct each_ref_fn_sha1_adapter wrapped_add_ref =
624 + {add_ref, &ca};
625
626 trace_printf_key(&trace_shallow, "shallow: post_assign_shallow\n");
627 if (ref_status)
@@ -641,8 +645,8 @@ static void post_assign_shallow(struct shallow_info *info,
645 info->nr_theirs = dst;
646
647 memset(&ca, 0, sizeof(ca));
644 - head_ref(add_ref, &ca);
645 - for_each_ref(add_ref, &ca);
648 + head_ref(each_ref_fn_adapter, &wrapped_add_ref);
649 + for_each_ref(each_ref_fn_adapter, &wrapped_add_ref);
650
651 /* Remove unreachable shallow commits from "ours" */
652 for (i = dst = 0; i < info->nr_ours; i++) {
@@ -674,9 +678,12 @@ int delayed_reachability_test(struct shallow_info *si, int c)
678
679 if (!si->commits) {
680 struct commit_array ca;
681 + struct each_ref_fn_sha1_adapter wrapped_add_ref =
682 + {add_ref, &ca};
683 +
684 memset(&ca, 0, sizeof(ca));
678 - head_ref(add_ref, &ca);
679 - for_each_ref(add_ref, &ca);
685 + head_ref(each_ref_fn_adapter, &wrapped_add_ref);
686 + for_each_ref(each_ref_fn_adapter, &wrapped_add_ref);
687 si->commits = ca.commits;
688 si->nr_commits = ca.nr;
689 }
submodule.c
+12 -3
@@ -429,10 +429,13 @@ static int has_remote(const char *refname, const unsigned char *sha1, int flags,
429
430 static int submodule_needs_pushing(const char *path, const unsigned char sha1[20])
431 {
432 + struct each_ref_fn_sha1_adapter wrapped_has_remote =
433 + {has_remote, NULL};
434 +
435 if (add_submodule_odb(path) || !lookup_commit_reference(sha1))
436 return 0;
437
435 - if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) {
438 + if (for_each_remote_ref_submodule(path, each_ref_fn_adapter, &wrapped_has_remote) > 0) {
439 struct child_process cp = CHILD_PROCESS_INIT;
440 const char *argv[] = {"rev-list", NULL, "--not", "--remotes", "-n", "1" , NULL};
441 struct strbuf buf = STRBUF_INIT;
@@ -519,10 +522,13 @@ int find_unpushed_submodules(unsigned char new_sha1[20],
522
523 static int push_submodule(const char *path)
524 {
525 + struct each_ref_fn_sha1_adapter wrapped_has_remote =
526 + {has_remote, NULL};
527 +
528 if (add_submodule_odb(path))
529 return 1;
530
525 - if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) {
531 + if (for_each_remote_ref_submodule(path, each_ref_fn_adapter, &wrapped_has_remote) > 0) {
532 struct child_process cp = CHILD_PROCESS_INIT;
533 const char *argv[] = {"push", NULL};
534
@@ -626,7 +632,10 @@ static int add_sha1_to_array(const char *ref, const unsigned char *sha1,
632 void check_for_new_submodule_commits(unsigned char new_sha1[20])
633 {
634 if (!initialized_fetch_ref_tips) {
629 - for_each_ref(add_sha1_to_array, &ref_tips_before_fetch);
635 + struct each_ref_fn_sha1_adapter wrapped_add_sha1_to_array =
636 + {add_sha1_to_array, &ref_tips_before_fetch};
637 +
638 + for_each_ref(each_ref_fn_adapter, &wrapped_add_sha1_to_array);
639 initialized_fetch_ref_tips = 1;
640 }
641
transport.c
+4 -1
@@ -363,7 +363,10 @@ static int rsync_transport_push(struct transport *transport,
363 strbuf_addch(&temp_dir, '/');
364
365 if (flags & TRANSPORT_PUSH_ALL) {
366 - if (for_each_ref(write_one_ref, &temp_dir))
366 + struct each_ref_fn_sha1_adapter wrapped_write_one_ref =
367 + {write_one_ref, &temp_dir};
368 +
369 + if (for_each_ref(each_ref_fn_adapter, &wrapped_write_one_ref))
370 return -1;
371 } else if (write_refs_to_temp_dir(&temp_dir, refspec_nr, refspec))
372 return -1;
upload-pack.c
+13 -5
@@ -761,18 +761,26 @@ static int find_symref(const char *refname, const unsigned char *sha1, int flag,
761 static void upload_pack(void)
762 {
763 struct string_list symref = STRING_LIST_INIT_DUP;
764 + struct each_ref_fn_sha1_adapter wrapped_find_symref =
765 + {find_symref, &symref};
766
765 - head_ref_namespaced(find_symref, &symref);
767 + head_ref_namespaced(each_ref_fn_adapter, &wrapped_find_symref);
768
769 if (advertise_refs || !stateless_rpc) {
770 + struct each_ref_fn_sha1_adapter wrapped_send_ref =
771 + {send_ref, &symref};
772 +
773 reset_timeout();
769 - head_ref_namespaced(send_ref, &symref);
770 - for_each_namespaced_ref(send_ref, &symref);
774 + head_ref_namespaced(each_ref_fn_adapter, &wrapped_send_ref);
775 + for_each_namespaced_ref(each_ref_fn_adapter, &wrapped_send_ref);
776 advertise_shallow_grafts(1);
777 packet_flush(1);
778 } else {
774 - head_ref_namespaced(check_ref, NULL);
775 - for_each_namespaced_ref(check_ref, NULL);
779 + struct each_ref_fn_sha1_adapter wrapped_check_ref =
780 + {check_ref, NULL};
781 +
782 + head_ref_namespaced(each_ref_fn_adapter, &wrapped_check_ref);
783 + for_each_namespaced_ref(each_ref_fn_adapter, &wrapped_check_ref);
784 }
785 string_list_clear(&symref, 1);
786 if (advertise_refs)
walker.c
+4 -1
@@ -269,7 +269,10 @@ int walker_fetch(struct walker *walker, int targets, char **target,
269 }
270
271 if (!walker->get_recover) {
272 - for_each_ref(mark_complete, NULL);
272 + struct each_ref_fn_sha1_adapter wrapped_mark_complete =
273 + {mark_complete, NULL};
274 +
275 + for_each_ref(each_ref_fn_adapter, &wrapped_mark_complete);
276 commit_list_sort_by_date(&complete);
277 }
278