refs: introduce wrapper struct for `each_ref_fn`

The `each_ref_fn` callback function type is used across our code base for several different functions that iterate through reference. There's a bunch of callbacks implementing this type, which makes any changes to the callback signature extremely noisy. An example of the required churn is e8207717f1 (refs: add referent to each_ref_fn, 2024-08-09): adding a single argument required us to change 48 files. It was already proposed back then [1] that we might want to introduce a wrapper structure to alleviate the pain going forward. While this of course requires the same kind of global refactoring as just introducing a new parameter, it at least allows us to more change the callback type afterwards by just extending the wrapper structure. One counterargument to this refactoring is that it makes the structure more opaque. While it is obvious which callsites need to be fixed up when we change the function type, it's not obvious anymore once we use a structure. That being said, we only have a handful of sites that actually need to populate this wrapper structure: our ref backends, "refs/iterator.c" as well as very few sites that invoke the iterator callback functions directly. Introduce this wrapper structure so that we can adapt the iterator interfaces more readily. [1]: <ZmarVcF5JjsZx0dl@tanuki> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Oct 23, 2025 at 09:16 UTC bdbebe5714b25dc9d215b48efbb80f410925d7dd
49 files changed +392 -462
bisect.c
+10 -14
@@ -450,21 +450,20 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
450 clear_commit_weight(&commit_weight);
451 }
452
453 -static int register_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
454 - int flags UNUSED, void *cb_data UNUSED)
453 +static int register_ref(const struct reference *ref, void *cb_data UNUSED)
454 {
455 struct strbuf good_prefix = STRBUF_INIT;
456 strbuf_addstr(&good_prefix, term_good);
457 strbuf_addstr(&good_prefix, "-");
458
460 - if (!strcmp(refname, term_bad)) {
459 + if (!strcmp(ref->name, term_bad)) {
460 free(current_bad_oid);
461 current_bad_oid = xmalloc(sizeof(*current_bad_oid));
463 - oidcpy(current_bad_oid, oid);
464 - } else if (starts_with(refname, good_prefix.buf)) {
465 - oid_array_append(&good_revs, oid);
466 - } else if (starts_with(refname, "skip-")) {
467 - oid_array_append(&skipped_revs, oid);
462 + oidcpy(current_bad_oid, ref->oid);
463 + } else if (starts_with(ref->name, good_prefix.buf)) {
464 + oid_array_append(&good_revs, ref->oid);
465 + } else if (starts_with(ref->name, "skip-")) {
466 + oid_array_append(&skipped_revs, ref->oid);
467 }
468
469 strbuf_release(&good_prefix);
@@ -1178,14 +1177,11 @@ int estimate_bisect_steps(int all)
1177 return (e < 3 * x) ? n : n - 1;
1178 }
1179
1181 -static int mark_for_removal(const char *refname,
1182 - const char *referent UNUSED,
1183 - const struct object_id *oid UNUSED,
1184 - int flag UNUSED, void *cb_data)
1180 +static int mark_for_removal(const struct reference *ref, void *cb_data)
1181 {
1182 struct string_list *refs = cb_data;
1187 - char *ref = xstrfmt("refs/bisect%s", refname);
1188 - string_list_append(refs, ref);
1183 + char *bisect_ref = xstrfmt("refs/bisect%s", ref->name);
1184 + string_list_append(refs, bisect_ref);
1185 return 0;
1186 }
1187
builtin/bisect.c
+5 -12
@@ -358,10 +358,7 @@ static int check_and_set_terms(struct bisect_terms *terms, const char *cmd)
358 return 0;
359 }
360
361 -static int inc_nr(const char *refname UNUSED,
362 - const char *referent UNUSED,
363 - const struct object_id *oid UNUSED,
364 - int flag UNUSED, void *cb_data)
361 +static int inc_nr(const struct reference *ref UNUSED, void *cb_data)
362 {
363 unsigned int *nr = (unsigned int *)cb_data;
364 (*nr)++;
@@ -549,12 +546,11 @@ finish:
546 return res;
547 }
548
552 -static int add_bisect_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
553 - int flags UNUSED, void *cb)
549 +static int add_bisect_ref(const struct reference *ref, void *cb)
550 {
551 struct add_bisect_ref_data *data = cb;
552
557 - add_pending_oid(data->revs, refname, oid, data->object_flags);
553 + add_pending_oid(data->revs, ref->name, ref->oid, data->object_flags);
554
555 return 0;
556 }
@@ -1165,12 +1161,9 @@ static int bisect_visualize(struct bisect_terms *terms, int argc,
1161 return run_command(&cmd);
1162 }
1163
1168 -static int get_first_good(const char *refname UNUSED,
1169 - const char *referent UNUSED,
1170 - const struct object_id *oid,
1171 - int flag UNUSED, void *cb_data)
1164 +static int get_first_good(const struct reference *ref, void *cb_data)
1165 {
1173 - oidcpy(cb_data, oid);
1166 + oidcpy(cb_data, ref->oid);
1167 return 1;
1168 }
1169
builtin/checkout.c
+2 -4
@@ -1063,11 +1063,9 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
1063 report_tracking(new_branch_info);
1064 }
1065
1066 -static int add_pending_uninteresting_ref(const char *refname, const char *referent UNUSED,
1067 - const struct object_id *oid,
1068 - int flags UNUSED, void *cb_data)
1066 +static int add_pending_uninteresting_ref(const struct reference *ref, void *cb_data)
1067 {
1070 - add_pending_oid(cb_data, refname, oid, UNINTERESTING);
1068 + add_pending_oid(cb_data, ref->name, ref->oid, UNINTERESTING);
1069 return 0;
1070 }
1071
builtin/describe.c
+9 -9
@@ -154,20 +154,19 @@ static void add_to_known_names(const char *path,
154 }
155 }
156
157 -static int get_name(const char *path, const char *referent UNUSED, const struct object_id *oid,
158 - int flag UNUSED, void *cb_data UNUSED)
157 +static int get_name(const struct reference *ref, void *cb_data UNUSED)
158 {
159 int is_tag = 0;
160 struct object_id peeled;
161 int is_annotated, prio;
162 const char *path_to_match = NULL;
163
165 - if (skip_prefix(path, "refs/tags/", &path_to_match)) {
164 + if (skip_prefix(ref->name, "refs/tags/", &path_to_match)) {
165 is_tag = 1;
166 } else if (all) {
167 if ((exclude_patterns.nr || patterns.nr) &&
169 - !skip_prefix(path, "refs/heads/", &path_to_match) &&
170 - !skip_prefix(path, "refs/remotes/", &path_to_match)) {
168 + !skip_prefix(ref->name, "refs/heads/", &path_to_match) &&
169 + !skip_prefix(ref->name, "refs/remotes/", &path_to_match)) {
170 /* Only accept reference of known type if there are match/exclude patterns */
171 return 0;
172 }
@@ -209,10 +208,10 @@ static int get_name(const char *path, const char *referent UNUSED, const struct
208 }
209
210 /* Is it annotated? */
212 - if (!peel_iterated_oid(the_repository, oid, &peeled)) {
213 - is_annotated = !oideq(oid, &peeled);
211 + if (!peel_iterated_oid(the_repository, ref->oid, &peeled)) {
212 + is_annotated = !oideq(ref->oid, &peeled);
213 } else {
215 - oidcpy(&peeled, oid);
214 + oidcpy(&peeled, ref->oid);
215 is_annotated = 0;
216 }
217
@@ -229,7 +228,8 @@ static int get_name(const char *path, const char *referent UNUSED, const struct
228 else
229 prio = 0;
230
232 - add_to_known_names(all ? path + 5 : path + 10, &peeled, prio, oid);
231 + add_to_known_names(all ? ref->name + 5 : ref->name + 10,
232 + &peeled, prio, ref->oid);
233 return 0;
234 }
235
builtin/fetch.c
+4 -9
@@ -289,13 +289,11 @@ static struct refname_hash_entry *refname_hash_add(struct hashmap *map,
289 return ent;
290 }
291
292 -static int add_one_refname(const char *refname, const char *referent UNUSED,
293 - const struct object_id *oid,
294 - int flag UNUSED, void *cbdata)
292 +static int add_one_refname(const struct reference *ref, void *cbdata)
293 {
294 struct hashmap *refname_map = cbdata;
295
298 - (void) refname_hash_add(refname_map, refname, oid);
296 + (void) refname_hash_add(refname_map, ref->name, ref->oid);
297 return 0;
298 }
299
@@ -1416,14 +1414,11 @@ static void set_option(struct transport *transport, const char *name, const char
1414 }
1415
1416
1419 -static int add_oid(const char *refname UNUSED,
1420 - const char *referent UNUSED,
1421 - const struct object_id *oid,
1422 - int flags UNUSED, void *cb_data)
1417 +static int add_oid(const struct reference *ref, void *cb_data)
1418 {
1419 struct oid_array *oids = cb_data;
1420
1426 - oid_array_append(oids, oid);
1421 + oid_array_append(oids, ref->oid);
1422 return 0;
1423 }
1424
builtin/fsck.c
+19 -14
@@ -530,14 +530,13 @@ static int fsck_handle_reflog(const char *logname, void *cb_data)
530 return 0;
531 }
532
533 -static int fsck_handle_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
534 - int flag UNUSED, void *cb_data UNUSED)
533 +static int fsck_handle_ref(const struct reference *ref, void *cb_data UNUSED)
534 {
535 struct object *obj;
536
538 - obj = parse_object(the_repository, oid);
537 + obj = parse_object(the_repository, ref->oid);
538 if (!obj) {
540 - if (is_promisor_object(the_repository, oid)) {
539 + if (is_promisor_object(the_repository, ref->oid)) {
540 /*
541 * Increment default_refs anyway, because this is a
542 * valid ref.
@@ -546,19 +545,19 @@ static int fsck_handle_ref(const char *refname, const char *referent UNUSED, con
545 return 0;
546 }
547 error(_("%s: invalid sha1 pointer %s"),
549 - refname, oid_to_hex(oid));
548 + ref->name, oid_to_hex(ref->oid));
549 errors_found |= ERROR_REACHABLE;
550 /* We'll continue with the rest despite the error.. */
551 return 0;
552 }
554 - if (obj->type != OBJ_COMMIT && is_branch(refname)) {
555 - error(_("%s: not a commit"), refname);
553 + if (obj->type != OBJ_COMMIT && is_branch(ref->name)) {
554 + error(_("%s: not a commit"), ref->name);
555 errors_found |= ERROR_REFS;
556 }
557 default_refs++;
558 obj->flags |= USED;
559 fsck_put_object_name(&fsck_walk_options,
561 - oid, "%s", refname);
560 + ref->oid, "%s", ref->name);
561 mark_object_reachable(obj);
562
563 return 0;
@@ -580,13 +579,19 @@ static void get_default_heads(void)
579 worktrees = get_worktrees();
580 for (p = worktrees; *p; p++) {
581 struct worktree *wt = *p;
583 - struct strbuf ref = STRBUF_INIT;
582 + struct strbuf refname = STRBUF_INIT;
583
585 - strbuf_worktree_ref(wt, &ref, "HEAD");
586 - fsck_head_link(ref.buf, &head_points_at, &head_oid);
587 - if (head_points_at && !is_null_oid(&head_oid))
588 - fsck_handle_ref(ref.buf, NULL, &head_oid, 0, NULL);
589 - strbuf_release(&ref);
584 + strbuf_worktree_ref(wt, &refname, "HEAD");
585 + fsck_head_link(refname.buf, &head_points_at, &head_oid);
586 + if (head_points_at && !is_null_oid(&head_oid)) {
587 + struct reference ref = {
588 + .name = refname.buf,
589 + .oid = &head_oid,
590 + };
591 +
592 + fsck_handle_ref(&ref, NULL);
593 + }
594 + strbuf_release(&refname);
595
596 if (include_reflogs)
597 refs_for_each_reflog(get_worktree_ref_store(wt),
builtin/gc.c
+6 -9
@@ -1100,24 +1100,21 @@ struct cg_auto_data {
1100 int limit;
1101 };
1102
1103 -static int dfs_on_ref(const char *refname UNUSED,
1104 - const char *referent UNUSED,
1105 - const struct object_id *oid,
1106 - int flags UNUSED,
1107 - void *cb_data)
1103 +static int dfs_on_ref(const struct reference *ref, void *cb_data)
1104 {
1105 struct cg_auto_data *data = (struct cg_auto_data *)cb_data;
1106 int result = 0;
1107 + const struct object_id *maybe_peeled = ref->oid;
1108 struct object_id peeled;
1109 struct commit_list *stack = NULL;
1110 struct commit *commit;
1111
1115 - if (!peel_iterated_oid(the_repository, oid, &peeled))
1116 - oid = &peeled;
1117 - if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
1112 + if (!peel_iterated_oid(the_repository, ref->oid, &peeled))
1113 + maybe_peeled = &peeled;
1114 + if (odb_read_object_info(the_repository->objects, maybe_peeled, NULL) != OBJ_COMMIT)
1115 return 0;
1116
1120 - commit = lookup_commit(the_repository, oid);
1117 + commit = lookup_commit(the_repository, maybe_peeled);
1118 if (!commit)
1119 return 0;
1120 if (repo_parse_commit(the_repository, commit) ||
builtin/name-rev.c
+8 -9
@@ -339,10 +339,9 @@ static int cmp_by_tag_and_age(const void *a_, const void *b_)
339 return a->taggerdate != b->taggerdate;
340 }
341
342 -static int name_ref(const char *path, const char *referent UNUSED, const struct object_id *oid,
343 - int flags UNUSED, void *cb_data)
342 +static int name_ref(const struct reference *ref, void *cb_data)
343 {
345 - struct object *o = parse_object(the_repository, oid);
344 + struct object *o = parse_object(the_repository, ref->oid);
345 struct name_ref_data *data = cb_data;
346 int can_abbreviate_output = data->tags_only && data->name_only;
347 int deref = 0;
@@ -350,14 +349,14 @@ static int name_ref(const char *path, const char *referent UNUSED, const struct
349 struct commit *commit = NULL;
350 timestamp_t taggerdate = TIME_MAX;
351
353 - if (data->tags_only && !starts_with(path, "refs/tags/"))
352 + if (data->tags_only && !starts_with(ref->name, "refs/tags/"))
353 return 0;
354
355 if (data->exclude_filters.nr) {
356 struct string_list_item *item;
357
358 for_each_string_list_item(item, &data->exclude_filters) {
360 - if (subpath_matches(path, item->string) >= 0)
359 + if (subpath_matches(ref->name, item->string) >= 0)
360 return 0;
361 }
362 }
@@ -378,7 +377,7 @@ static int name_ref(const char *path, const char *referent UNUSED, const struct
377 * shouldn't stop when seeing 'refs/tags/v1.4' matches
378 * 'refs/tags/v*'. We should show it as 'v1.4'.
379 */
381 - switch (subpath_matches(path, item->string)) {
380 + switch (subpath_matches(ref->name, item->string)) {
381 case -1: /* did not match */
382 break;
383 case 0: /* matched fully */
@@ -406,13 +405,13 @@ static int name_ref(const char *path, const char *referent UNUSED, const struct
405 }
406 if (o && o->type == OBJ_COMMIT) {
407 commit = (struct commit *)o;
409 - from_tag = starts_with(path, "refs/tags/");
408 + from_tag = starts_with(ref->name, "refs/tags/");
409 if (taggerdate == TIME_MAX)
410 taggerdate = commit->date;
411 }
412
414 - add_to_tip_table(oid, path, can_abbreviate_output, commit, taggerdate,
415 - from_tag, deref);
413 + add_to_tip_table(ref->oid, ref->name, can_abbreviate_output,
414 + commit, taggerdate, from_tag, deref);
415 return 0;
416 }
417
builtin/pack-objects.c
+11 -16
@@ -831,15 +831,14 @@ static enum write_one_status write_one(struct hashfile *f,
831 return WRITE_ONE_WRITTEN;
832 }
833
834 -static int mark_tagged(const char *path UNUSED, const char *referent UNUSED, const struct object_id *oid,
835 - int flag UNUSED, void *cb_data UNUSED)
834 +static int mark_tagged(const struct reference *ref, void *cb_data UNUSED)
835 {
836 struct object_id peeled;
838 - struct object_entry *entry = packlist_find(&to_pack, oid);
837 + struct object_entry *entry = packlist_find(&to_pack, ref->oid);
838
839 if (entry)
840 entry->tagged = 1;
842 - if (!peel_iterated_oid(the_repository, oid, &peeled)) {
841 + if (!peel_iterated_oid(the_repository, ref->oid, &peeled)) {
842 entry = packlist_find(&to_pack, &peeled);
843 if (entry)
844 entry->tagged = 1;
@@ -3306,13 +3305,12 @@ static void add_tag_chain(const struct object_id *oid)
3305 }
3306 }
3307
3309 -static int add_ref_tag(const char *tag UNUSED, const char *referent UNUSED, const struct object_id *oid,
3310 - int flag UNUSED, void *cb_data UNUSED)
3308 +static int add_ref_tag(const struct reference *ref, void *cb_data UNUSED)
3309 {
3310 struct object_id peeled;
3311
3314 - if (!peel_iterated_oid(the_repository, oid, &peeled) && obj_is_packed(&peeled))
3315 - add_tag_chain(oid);
3312 + if (!peel_iterated_oid(the_repository, ref->oid, &peeled) && obj_is_packed(&peeled))
3313 + add_tag_chain(ref->oid);
3314 return 0;
3315 }
3316
@@ -4533,19 +4531,16 @@ static void record_recent_commit(struct commit *commit, void *data UNUSED)
4531 oid_array_append(&recent_objects, &commit->object.oid);
4532 }
4533
4536 -static int mark_bitmap_preferred_tip(const char *refname,
4537 - const char *referent UNUSED,
4538 - const struct object_id *oid,
4539 - int flags UNUSED,
4540 - void *data UNUSED)
4534 +static int mark_bitmap_preferred_tip(const struct reference *ref, void *data UNUSED)
4535 {
4536 + const struct object_id *maybe_peeled = ref->oid;
4537 struct object_id peeled;
4538 struct object *object;
4539
4545 - if (!peel_iterated_oid(the_repository, oid, &peeled))
4546 - oid = &peeled;
4540 + if (!peel_iterated_oid(the_repository, ref->oid, &peeled))
4541 + maybe_peeled = &peeled;
4542
4548 - object = parse_object_or_die(the_repository, oid, refname);
4543 + object = parse_object_or_die(the_repository, maybe_peeled, ref->name);
4544 if (object->type == OBJ_COMMIT)
4545 object->flags |= NEEDS_BITMAP;
4546
builtin/receive-pack.c
+6 -7
@@ -305,13 +305,12 @@ static void show_ref(const char *path, const struct object_id *oid)
305 }
306 }
307
308 -static int show_ref_cb(const char *path_full, const char *referent UNUSED, const struct object_id *oid,
309 - int flag UNUSED, void *data)
308 +static int show_ref_cb(const struct reference *ref, void *data)
309 {
310 struct oidset *seen = data;
312 - const char *path = strip_namespace(path_full);
311 + const char *path = strip_namespace(ref->name);
312
314 - if (ref_is_hidden(path, path_full, &hidden_refs))
313 + if (ref_is_hidden(path, ref->name, &hidden_refs))
314 return 0;
315
316 /*
@@ -320,13 +319,13 @@ static int show_ref_cb(const char *path_full, const char *referent UNUSED, const
319 * transfer but will otherwise ignore them.
320 */
321 if (!path) {
323 - if (oidset_insert(seen, oid))
322 + if (oidset_insert(seen, ref->oid))
323 return 0;
324 path = ".have";
325 } else {
327 - oidset_insert(seen, oid);
326 + oidset_insert(seen, ref->oid);
327 }
329 - show_ref(path, oid);
328 + show_ref(path, ref->oid);
329 return 0;
330 }
331
builtin/remote.c
+19 -25
@@ -570,17 +570,14 @@ struct branches_for_remote {
570 struct known_remotes *keep;
571 };
572
573 -static int add_branch_for_removal(const char *refname,
574 - const char *referent UNUSED,
575 - const struct object_id *oid UNUSED,
576 - int flags UNUSED, void *cb_data)
573 +static int add_branch_for_removal(const struct reference *ref, void *cb_data)
574 {
575 struct branches_for_remote *branches = cb_data;
576 struct refspec_item refspec;
577 struct known_remote *kr;
578
579 memset(&refspec, 0, sizeof(refspec));
583 - refspec.dst = (char *)refname;
580 + refspec.dst = (char *)ref->name;
581 if (remote_find_tracking(branches->remote, &refspec))
582 return 0;
583 free(refspec.src);
@@ -588,7 +585,7 @@ static int add_branch_for_removal(const char *refname,
585 /* don't delete a branch if another remote also uses it */
586 for (kr = branches->keep->list; kr; kr = kr->next) {
587 memset(&refspec, 0, sizeof(refspec));
591 - refspec.dst = (char *)refname;
588 + refspec.dst = (char *)ref->name;
589 if (!remote_find_tracking(kr->remote, &refspec)) {
590 free(refspec.src);
591 return 0;
@@ -596,16 +593,16 @@ static int add_branch_for_removal(const char *refname,
593 }
594
595 /* don't delete non-remote-tracking refs */
599 - if (!starts_with(refname, "refs/remotes/")) {
596 + if (!starts_with(ref->name, "refs/remotes/")) {
597 /* advise user how to delete local branches */
601 - if (starts_with(refname, "refs/heads/"))
598 + if (starts_with(ref->name, "refs/heads/"))
599 string_list_append(branches->skipped,
603 - abbrev_branch(refname));
600 + abbrev_branch(ref->name));
601 /* silently skip over other non-remote refs */
602 return 0;
603 }
604
608 - string_list_append(branches->branches, refname);
605 + string_list_append(branches->branches, ref->name);
606
607 return 0;
608 }
@@ -713,18 +710,18 @@ out:
710 return error;
711 }
712
716 -static int rename_one_ref(const char *old_refname, const char *referent,
717 - const struct object_id *oid,
718 - int flags, void *cb_data)
713 +static int rename_one_ref(const struct reference *ref, void *cb_data)
714 {
715 struct strbuf new_referent = STRBUF_INIT;
716 struct strbuf new_refname = STRBUF_INIT;
717 struct rename_info *rename = cb_data;
718 + const struct object_id *oid = ref->oid;
719 + const char *referent = ref->target;
720 int error;
721
725 - compute_renamed_ref(rename, old_refname, &new_refname);
722 + compute_renamed_ref(rename, ref->name, &new_refname);
723
727 - if (flags & REF_ISSYMREF) {
724 + if (ref->flags & REF_ISSYMREF) {
725 /*
726 * Stupidly enough `referent` is not pointing to the immediate
727 * target of a symref, but it's the recursively resolved value.
@@ -732,25 +729,25 @@ static int rename_one_ref(const char *old_refname, const char *referent,
729 * unborn symrefs don't have any value for the `referent` at all.
730 */
731 referent = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
735 - old_refname, RESOLVE_REF_NO_RECURSE,
732 + ref->name, RESOLVE_REF_NO_RECURSE,
733 NULL, NULL);
734 compute_renamed_ref(rename, referent, &new_referent);
735 oid = NULL;
736 }
737
741 - error = ref_transaction_delete(rename->transaction, old_refname,
738 + error = ref_transaction_delete(rename->transaction, ref->name,
739 oid, referent, REF_NO_DEREF, NULL, rename->err);
740 if (error < 0)
741 goto out;
742
743 error = ref_transaction_update(rename->transaction, new_refname.buf, oid, null_oid(the_hash_algo),
747 - (flags & REF_ISSYMREF) ? new_referent.buf : NULL, NULL,
744 + (ref->flags & REF_ISSYMREF) ? new_referent.buf : NULL, NULL,
745 REF_SKIP_CREATE_REFLOG | REF_NO_DEREF | REF_SKIP_OID_VERIFICATION,
746 NULL, rename->err);
747 if (error < 0)
748 goto out;
749
753 - error = rename_one_reflog(old_refname, oid, rename);
750 + error = rename_one_reflog(ref->name, oid, rename);
751 if (error < 0)
752 goto out;
753
@@ -1125,19 +1122,16 @@ static void free_remote_ref_states(struct ref_states *states)
1122 string_list_clear_func(&states->push, clear_push_info);
1123 }
1124
1128 -static int append_ref_to_tracked_list(const char *refname,
1129 - const char *referent UNUSED,
1130 - const struct object_id *oid UNUSED,
1131 - int flags, void *cb_data)
1125 +static int append_ref_to_tracked_list(const struct reference *ref, void *cb_data)
1126 {
1127 struct ref_states *states = cb_data;
1128 struct refspec_item refspec;
1129
1136 - if (flags & REF_ISSYMREF)
1130 + if (ref->flags & REF_ISSYMREF)
1131 return 0;
1132
1133 memset(&refspec, 0, sizeof(refspec));
1140 - refspec.dst = (char *)refname;
1134 + refspec.dst = (char *)ref->name;
1135 if (!remote_find_tracking(states->remote, &refspec)) {
1136 string_list_append(&states->tracked, abbrev_branch(refspec.src));
1137 free(refspec.src);
builtin/replace.c
+9 -12
@@ -47,30 +47,27 @@ struct show_data {
47 enum replace_format format;
48 };
49
50 -static int show_reference(const char *refname,
51 - const char *referent UNUSED,
52 - const struct object_id *oid,
53 - int flag UNUSED, void *cb_data)
50 +static int show_reference(const struct reference *ref, void *cb_data)
51 {
52 struct show_data *data = cb_data;
53
57 - if (!wildmatch(data->pattern, refname, 0)) {
54 + if (!wildmatch(data->pattern, ref->name, 0)) {
55 if (data->format == REPLACE_FORMAT_SHORT)
59 - printf("%s\n", refname);
56 + printf("%s\n", ref->name);
57 else if (data->format == REPLACE_FORMAT_MEDIUM)
61 - printf("%s -> %s\n", refname, oid_to_hex(oid));
58 + printf("%s -> %s\n", ref->name, oid_to_hex(ref->oid));
59 else { /* data->format == REPLACE_FORMAT_LONG */
60 struct object_id object;
61 enum object_type obj_type, repl_type;
62
66 - if (repo_get_oid(data->repo, refname, &object))
67 - return error(_("failed to resolve '%s' as a valid ref"), refname);
63 + if (repo_get_oid(data->repo, ref->name, &object))
64 + return error(_("failed to resolve '%s' as a valid ref"), ref->name);
65
66 obj_type = odb_read_object_info(data->repo->objects, &object, NULL);
70 - repl_type = odb_read_object_info(data->repo->objects, oid, NULL);
67 + repl_type = odb_read_object_info(data->repo->objects, ref->oid, NULL);
68
72 - printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type),
73 - oid_to_hex(oid), type_name(repl_type));
69 + printf("%s (%s) -> %s (%s)\n", ref->name, type_name(obj_type),
70 + oid_to_hex(ref->oid), type_name(repl_type));
71 }
72 }
73
builtin/repo.c
+3 -6
@@ -366,16 +366,13 @@ struct count_references_data {
366 struct progress *progress;
367 };
368
369 -static int count_references(const char *refname,
370 - const char *referent UNUSED,
371 - const struct object_id *oid,
372 - int flags UNUSED, void *cb_data)
369 +static int count_references(const struct reference *ref, void *cb_data)
370 {
371 struct count_references_data *data = cb_data;
372 struct ref_stats *stats = data->stats;
373 size_t ref_count;
374
378 - switch (ref_kind_from_refname(refname)) {
375 + switch (ref_kind_from_refname(ref->name)) {
376 case FILTER_REFS_BRANCHES:
377 stats->branches++;
378 break;
@@ -396,7 +393,7 @@ static int count_references(const char *refname,
393 * While iterating through references for counting, also add OIDs in
394 * preparation for the path walk.
395 */
399 - add_pending_oid(data->revs, NULL, oid, 0);
396 + add_pending_oid(data->revs, NULL, ref->oid, 0);
397
398 ref_count = get_total_reference_count(stats);
399 display_progress(data->progress, ref_count);
builtin/rev-parse.c
+5 -7
@@ -217,19 +217,17 @@ static int show_default(void)
217 return 0;
218 }
219
220 -static int show_reference(const char *refname, const char *referent UNUSED, const struct object_id *oid,
221 - int flag UNUSED, void *cb_data UNUSED)
220 +static int show_reference(const struct reference *ref, void *cb_data UNUSED)
221 {
223 - if (ref_excluded(&ref_excludes, refname))
222 + if (ref_excluded(&ref_excludes, ref->name))
223 return 0;
225 - show_rev(NORMAL, oid, refname);
224 + show_rev(NORMAL, ref->oid, ref->name);
225 return 0;
226 }
227
229 -static int anti_reference(const char *refname, const char *referent UNUSED, const struct object_id *oid,
230 - int flag UNUSED, void *cb_data UNUSED)
228 +static int anti_reference(const struct reference *ref, void *cb_data UNUSED)
229 {
232 - show_rev(REVERSED, oid, refname);
230 + show_rev(REVERSED, ref->oid, ref->name);
231 return 0;
232 }
233
builtin/show-branch.c
+16 -19
@@ -413,34 +413,32 @@ static int append_ref(const char *refname, const struct object_id *oid,
413 return 0;
414 }
415
416 -static int append_head_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
417 - int flag UNUSED, void *cb_data UNUSED)
416 +static int append_head_ref(const struct reference *ref, void *cb_data UNUSED)
417 {
418 struct object_id tmp;
419 int ofs = 11;
421 - if (!starts_with(refname, "refs/heads/"))
420 + if (!starts_with(ref->name, "refs/heads/"))
421 return 0;
422 /* If both heads/foo and tags/foo exists, get_sha1 would
423 * get confused.
424 */
426 - if (repo_get_oid(the_repository, refname + ofs, &tmp) || !oideq(&tmp, oid))
425 + if (repo_get_oid(the_repository, ref->name + ofs, &tmp) || !oideq(&tmp, ref->oid))
426 ofs = 5;
428 - return append_ref(refname + ofs, oid, 0);
427 + return append_ref(ref->name + ofs, ref->oid, 0);
428 }
429
431 -static int append_remote_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
432 - int flag UNUSED, void *cb_data UNUSED)
430 +static int append_remote_ref(const struct reference *ref, void *cb_data UNUSED)
431 {
432 struct object_id tmp;
433 int ofs = 13;
436 - if (!starts_with(refname, "refs/remotes/"))
434 + if (!starts_with(ref->name, "refs/remotes/"))
435 return 0;
436 /* If both heads/foo and tags/foo exists, get_sha1 would
437 * get confused.
438 */
441 - if (repo_get_oid(the_repository, refname + ofs, &tmp) || !oideq(&tmp, oid))
439 + if (repo_get_oid(the_repository, ref->name + ofs, &tmp) || !oideq(&tmp, ref->oid))
440 ofs = 5;
443 - return append_ref(refname + ofs, oid, 0);
441 + return append_ref(ref->name + ofs, ref->oid, 0);
442 }
443
444 static int append_tag_ref(const char *refname, const struct object_id *oid,
@@ -454,27 +452,26 @@ static int append_tag_ref(const char *refname, const struct object_id *oid,
452 static const char *match_ref_pattern = NULL;
453 static int match_ref_slash = 0;
454
457 -static int append_matching_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
458 - int flag, void *cb_data)
455 +static int append_matching_ref(const struct reference *ref, void *cb_data)
456 {
457 /* we want to allow pattern hold/<asterisk> to show all
458 * branches under refs/heads/hold/, and v0.99.9? to show
459 * refs/tags/v0.99.9a and friends.
460 */
461 const char *tail;
465 - int slash = count_slashes(refname);
466 - for (tail = refname; *tail && match_ref_slash < slash; )
462 + int slash = count_slashes(ref->name);
463 + for (tail = ref->name; *tail && match_ref_slash < slash; )
464 if (*tail++ == '/')
465 slash--;
466 if (!*tail)
467 return 0;
468 if (wildmatch(match_ref_pattern, tail, 0))
469 return 0;
473 - if (starts_with(refname, "refs/heads/"))
474 - return append_head_ref(refname, NULL, oid, flag, cb_data);
475 - if (starts_with(refname, "refs/tags/"))
476 - return append_tag_ref(refname, oid, flag, cb_data);
477 - return append_ref(refname, oid, 0);
470 + if (starts_with(ref->name, "refs/heads/"))
471 + return append_head_ref(ref, cb_data);
472 + if (starts_with(ref->name, "refs/tags/"))
473 + return append_tag_ref(ref->name, ref->oid, ref->flags, cb_data);
474 + return append_ref(ref->name, ref->oid, 0);
475 }
476
477 static void snarf_refs(int head, int remotes)
builtin/show-ref.c
+8 -12
@@ -66,26 +66,25 @@ struct show_ref_data {
66 int show_head;
67 };
68
69 -static int show_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
70 - int flag UNUSED, void *cbdata)
69 +static int show_ref(const struct reference *ref, void *cbdata)
70 {
71 struct show_ref_data *data = cbdata;
72
74 - if (data->show_head && !strcmp(refname, "HEAD"))
73 + if (data->show_head && !strcmp(ref->name, "HEAD"))
74 goto match;
75
76 if (data->patterns) {
78 - int reflen = strlen(refname);
77 + int reflen = strlen(ref->name);
78 const char **p = data->patterns, *m;
79 while ((m = *p++) != NULL) {
80 int len = strlen(m);
81 if (len > reflen)
82 continue;
84 - if (memcmp(m, refname + reflen - len, len))
83 + if (memcmp(m, ref->name + reflen - len, len))
84 continue;
85 if (len == reflen)
86 goto match;
88 - if (refname[reflen - len - 1] == '/')
87 + if (ref->name[reflen - len - 1] == '/')
88 goto match;
89 }
90 return 0;
@@ -94,18 +93,15 @@ static int show_ref(const char *refname, const char *referent UNUSED, const stru
93 match:
94 data->found_match++;
95
97 - show_one(data->show_one_opts, refname, oid);
96 + show_one(data->show_one_opts, ref->name, ref->oid);
97
98 return 0;
99 }
100
102 -static int add_existing(const char *refname,
103 - const char *referent UNUSED,
104 - const struct object_id *oid UNUSED,
105 - int flag UNUSED, void *cbdata)
101 +static int add_existing(const struct reference *ref, void *cbdata)
102 {
103 struct string_list *list = (struct string_list *)cbdata;
108 - string_list_insert(list, refname);
104 + string_list_insert(list, ref->name);
105 return 0;
106 }
107
builtin/submodule--helper.c
+3 -7
@@ -593,16 +593,12 @@ static void print_status(unsigned int flags, char state, const char *path,
593 printf("\n");
594 }
595
596 -static int handle_submodule_head_ref(const char *refname UNUSED,
597 - const char *referent UNUSED,
598 - const struct object_id *oid,
599 - int flags UNUSED,
600 - void *cb_data)
596 +static int handle_submodule_head_ref(const struct reference *ref, void *cb_data)
597 {
598 struct object_id *output = cb_data;
599
604 - if (oid)
605 - oidcpy(output, oid);
600 + if (ref->oid)
601 + oidcpy(output, ref->oid);
602
603 return 0;
604 }
builtin/worktree.c
+1 -5
@@ -635,11 +635,7 @@ static void print_preparing_worktree_line(int detach,
635 *
636 * Returns 0 on failure and non-zero on success.
637 */
638 -static int first_valid_ref(const char *refname UNUSED,
639 - const char *referent UNUSED,
640 - const struct object_id *oid UNUSED,
641 - int flags UNUSED,
642 - void *cb_data UNUSED)
638 +static int first_valid_ref(const struct reference *ref UNUSED, void *cb_data UNUSED)
639 {
640 return 1;
641 }
commit-graph.c
+6 -8
@@ -1851,18 +1851,16 @@ struct refs_cb_data {
1851 struct progress *progress;
1852 };
1853
1854 -static int add_ref_to_set(const char *refname UNUSED,
1855 - const char *referent UNUSED,
1856 - const struct object_id *oid,
1857 - int flags UNUSED, void *cb_data)
1854 +static int add_ref_to_set(const struct reference *ref, void *cb_data)
1855 {
1856 + const struct object_id *maybe_peeled = ref->oid;
1857 struct object_id peeled;
1858 struct refs_cb_data *data = (struct refs_cb_data *)cb_data;
1859
1862 - if (!peel_iterated_oid(data->repo, oid, &peeled))
1863 - oid = &peeled;
1864 - if (odb_read_object_info(data->repo->objects, oid, NULL) == OBJ_COMMIT)
1865 - oidset_insert(data->commits, oid);
1860 + if (!peel_iterated_oid(data->repo, ref->oid, &peeled))
1861 + maybe_peeled = &peeled;
1862 + if (odb_read_object_info(data->repo->objects, maybe_peeled, NULL) == OBJ_COMMIT)
1863 + oidset_insert(data->commits, maybe_peeled);
1864
1865 display_progress(data->progress, oidset_size(data->commits));
1866
delta-islands.c
+4 -5
@@ -390,8 +390,7 @@ static void add_ref_to_island(kh_str_t *remote_islands, const char *island_name,
390 rl->hash += sha_core;
391 }
392
393 -static int find_island_for_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
394 - int flags UNUSED, void *cb)
393 +static int find_island_for_ref(const struct reference *ref, void *cb)
394 {
395 struct island_load_data *ild = cb;
396
@@ -406,7 +405,7 @@ static int find_island_for_ref(const char *refname, const char *referent UNUSED,
405
406 /* walk backwards to get last-one-wins ordering */
407 for (i = ild->nr - 1; i >= 0; i--) {
409 - if (!regexec(&ild->rx[i], refname,
408 + if (!regexec(&ild->rx[i], ref->name,
409 ARRAY_SIZE(matches), matches, 0))
410 break;
411 }
@@ -428,10 +427,10 @@ static int find_island_for_ref(const char *refname, const char *referent UNUSED,
427 if (island_name.len)
428 strbuf_addch(&island_name, '-');
429
431 - strbuf_add(&island_name, refname + match->rm_so, match->rm_eo - match->rm_so);
430 + strbuf_add(&island_name, ref->name + match->rm_so, match->rm_eo - match->rm_so);
431 }
432
434 - add_ref_to_island(ild->remote_islands, island_name.buf, oid);
433 + add_ref_to_island(ild->remote_islands, island_name.buf, ref->oid);
434 strbuf_release(&island_name);
435 return 0;
436 }
fetch-pack.c
+4 -12
@@ -188,13 +188,9 @@ static int rev_list_insert_ref(struct fetch_negotiator *negotiator,
188 return 0;
189 }
190
191 -static int rev_list_insert_ref_oid(const char *refname UNUSED,
192 - const char *referent UNUSED,
193 - const struct object_id *oid,
194 - int flag UNUSED,
195 - void *cb_data)
191 +static int rev_list_insert_ref_oid(const struct reference *ref, void *cb_data)
192 {
197 - return rev_list_insert_ref(cb_data, oid);
193 + return rev_list_insert_ref(cb_data, ref->oid);
194 }
195
196 enum ack_type {
@@ -616,13 +612,9 @@ static int mark_complete(const struct object_id *oid)
612 return 0;
613 }
614
619 -static int mark_complete_oid(const char *refname UNUSED,
620 - const char *referent UNUSED,
621 - const struct object_id *oid,
622 - int flag UNUSED,
623 - void *cb_data UNUSED)
615 +static int mark_complete_oid(const struct reference *ref, void *cb_data UNUSED)
616 {
625 - return mark_complete(oid);
617 + return mark_complete(ref->oid);
618 }
619
620 static void mark_recent_complete_commits(struct fetch_pack_args *args,
help.c
+4 -6
@@ -851,18 +851,16 @@ struct similar_ref_cb {
851 struct string_list *similar_refs;
852 };
853
854 -static int append_similar_ref(const char *refname, const char *referent UNUSED,
855 - const struct object_id *oid UNUSED,
856 - int flags UNUSED, void *cb_data)
854 +static int append_similar_ref(const struct reference *ref, void *cb_data)
855 {
856 struct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data);
859 - char *branch = strrchr(refname, '/') + 1;
857 + char *branch = strrchr(ref->name, '/') + 1;
858
859 /* A remote branch of the same name is deemed similar */
862 - if (starts_with(refname, "refs/remotes/") &&
860 + if (starts_with(ref->name, "refs/remotes/") &&
861 !strcmp(branch, cb->base_ref))
862 string_list_append_nodup(cb->similar_refs,
865 - refs_shorten_unambiguous_ref(get_main_ref_store(the_repository), refname, 1));
863 + refs_shorten_unambiguous_ref(get_main_ref_store(the_repository), ref->name, 1));
864 return 0;
865 }
866
http-backend.c
+9 -11
@@ -513,18 +513,17 @@ static void run_service(const char **argv, int buffer_input)
513 exit(1);
514 }
515
516 -static int show_text_ref(const char *name, const char *referent UNUSED, const struct object_id *oid,
517 - int flag UNUSED, void *cb_data)
516 +static int show_text_ref(const struct reference *ref, void *cb_data)
517 {
519 - const char *name_nons = strip_namespace(name);
518 + const char *name_nons = strip_namespace(ref->name);
519 struct strbuf *buf = cb_data;
521 - struct object *o = parse_object(the_repository, oid);
520 + struct object *o = parse_object(the_repository, ref->oid);
521 if (!o)
522 return 0;
523
525 - strbuf_addf(buf, "%s\t%s\n", oid_to_hex(oid), name_nons);
524 + strbuf_addf(buf, "%s\t%s\n", oid_to_hex(ref->oid), name_nons);
525 if (o->type == OBJ_TAG) {
527 - o = deref_tag(the_repository, o, name, 0);
526 + o = deref_tag(the_repository, o, ref->name, 0);
527 if (!o)
528 return 0;
529 strbuf_addf(buf, "%s\t%s^{}\n", oid_to_hex(&o->oid),
@@ -569,21 +568,20 @@ static void get_info_refs(struct strbuf *hdr, char *arg UNUSED)
568 strbuf_release(&buf);
569 }
570
572 -static int show_head_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
573 - int flag, void *cb_data)
571 +static int show_head_ref(const struct reference *ref, void *cb_data)
572 {
573 struct strbuf *buf = cb_data;
574
577 - if (flag & REF_ISSYMREF) {
575 + if (ref->flags & REF_ISSYMREF) {
576 const char *target = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
579 - refname,
577 + ref->name,
578 RESOLVE_REF_READING,
579 NULL, NULL);
580
581 if (target)
582 strbuf_addf(buf, "ref: %s\n", strip_namespace(target));
583 } else {
586 - strbuf_addf(buf, "%s\n", oid_to_hex(oid));
584 + strbuf_addf(buf, "%s\n", oid_to_hex(ref->oid));
585 }
586
587 return 0;
log-tree.c
+11 -13
@@ -147,9 +147,7 @@ static int ref_filter_match(const char *refname,
147 return 1;
148 }
149
150 -static int add_ref_decoration(const char *refname, const char *referent UNUSED, const struct object_id *oid,
151 - int flags UNUSED,
152 - void *cb_data)
150 +static int add_ref_decoration(const struct reference *ref, void *cb_data)
151 {
152 int i;
153 struct object *obj;
@@ -158,16 +156,16 @@ static int add_ref_decoration(const char *refname, const char *referent UNUSED,
156 struct decoration_filter *filter = (struct decoration_filter *)cb_data;
157 const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;
158
161 - if (filter && !ref_filter_match(refname, filter))
159 + if (filter && !ref_filter_match(ref->name, filter))
160 return 0;
161
164 - if (starts_with(refname, git_replace_ref_base)) {
162 + if (starts_with(ref->name, git_replace_ref_base)) {
163 struct object_id original_oid;
164 if (!replace_refs_enabled(the_repository))
165 return 0;
168 - if (get_oid_hex(refname + strlen(git_replace_ref_base),
166 + if (get_oid_hex(ref->name + strlen(git_replace_ref_base),
167 &original_oid)) {
170 - warning("invalid replace ref %s", refname);
168 + warning("invalid replace ref %s", ref->name);
169 return 0;
170 }
171 obj = parse_object(the_repository, &original_oid);
@@ -176,10 +174,10 @@ static int add_ref_decoration(const char *refname, const char *referent UNUSED,
174 return 0;
175 }
176
179 - objtype = odb_read_object_info(the_repository->objects, oid, NULL);
177 + objtype = odb_read_object_info(the_repository->objects, ref->oid, NULL);
178 if (objtype < 0)
179 return 0;
182 - obj = lookup_object_by_type(the_repository, oid, objtype);
180 + obj = lookup_object_by_type(the_repository, ref->oid, objtype);
181
182 for (i = 0; i < ARRAY_SIZE(ref_namespace); i++) {
183 struct ref_namespace_info *info = &ref_namespace[i];
@@ -187,24 +185,24 @@ static int add_ref_decoration(const char *refname, const char *referent UNUSED,
185 if (!info->decoration)
186 continue;
187 if (info->exact) {
190 - if (!strcmp(refname, info->ref)) {
188 + if (!strcmp(ref->name, info->ref)) {
189 deco_type = info->decoration;
190 break;
191 }
194 - } else if (starts_with(refname, info->ref)) {
192 + } else if (starts_with(ref->name, info->ref)) {
193 deco_type = info->decoration;
194 break;
195 }
196 }
197
200 - add_name_decoration(deco_type, refname, obj);
198 + add_name_decoration(deco_type, ref->name, obj);
199 while (obj->type == OBJ_TAG) {
200 if (!obj->parsed)
201 parse_object(the_repository, &obj->oid);
202 obj = ((struct tag *)obj)->tagged;
203 if (!obj)
204 break;
207 - add_name_decoration(DECORATION_REF_TAG, refname, obj);
205 + add_name_decoration(DECORATION_REF_TAG, ref->name, obj);
206 }
207 return 0;
208 }
ls-refs.c
+22 -14
@@ -75,42 +75,42 @@ struct ls_refs_data {
75 unsigned unborn : 1;
76 };
77
78 -static int send_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
79 - int flag, void *cb_data)
78 +static int send_ref(const struct reference *ref, void *cb_data)
79 {
80 struct ls_refs_data *data = cb_data;
82 - const char *refname_nons = strip_namespace(refname);
81 + const char *refname_nons = strip_namespace(ref->name);
82
83 strbuf_reset(&data->buf);
84
86 - if (ref_is_hidden(refname_nons, refname, &data->hidden_refs))
85 + if (ref_is_hidden(refname_nons, ref->name, &data->hidden_refs))
86 return 0;
87
88 if (!ref_match(&data->prefixes, refname_nons))
89 return 0;
90
92 - if (oid)
93 - strbuf_addf(&data->buf, "%s %s", oid_to_hex(oid), refname_nons);
91 + if (ref->oid)
92 + strbuf_addf(&data->buf, "%s %s", oid_to_hex(ref->oid), refname_nons);
93 else
94 strbuf_addf(&data->buf, "unborn %s", refname_nons);
96 - if (data->symrefs && flag & REF_ISSYMREF) {
95 + if (data->symrefs && ref->flags & REF_ISSYMREF) {
96 + int unused_flag;
97 struct object_id unused;
98 const char *symref_target = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
99 - refname,
99 + ref->name,
100 0,
101 &unused,
102 - &flag);
102 + &unused_flag);
103
104 if (!symref_target)
105 - die("'%s' is a symref but it is not?", refname);
105 + die("'%s' is a symref but it is not?", ref->name);
106
107 strbuf_addf(&data->buf, " symref-target:%s",
108 strip_namespace(symref_target));
109 }
110
111 - if (data->peel && oid) {
111 + if (data->peel && ref->oid) {
112 struct object_id peeled;
113 - if (!peel_iterated_oid(the_repository, oid, &peeled))
113 + if (!peel_iterated_oid(the_repository, ref->oid, &peeled))
114 strbuf_addf(&data->buf, " peeled:%s", oid_to_hex(&peeled));
115 }
116
@@ -131,9 +131,17 @@ static void send_possibly_unborn_head(struct ls_refs_data *data)
131 if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), namespaced.buf, 0, &oid, &flag))
132 return; /* bad ref */
133 oid_is_null = is_null_oid(&oid);
134 +
135 if (!oid_is_null ||
135 - (data->unborn && data->symrefs && (flag & REF_ISSYMREF)))
136 - send_ref(namespaced.buf, NULL, oid_is_null ? NULL : &oid, flag, data);
136 + (data->unborn && data->symrefs && (flag & REF_ISSYMREF))) {
137 + struct reference ref = {
138 + .name = namespaced.buf,
139 + .oid = oid_is_null ? NULL : &oid,
140 + .flags = flag,
141 + };
142 +
143 + send_ref(&ref, data);
144 + }
145 strbuf_release(&namespaced);
146 }
147
midx-write.c
+8 -9
@@ -697,28 +697,27 @@ static void prepare_midx_packing_data(struct packing_data *pdata,
697 trace2_region_leave("midx", "prepare_midx_packing_data", ctx->repo);
698 }
699
700 -static int add_ref_to_pending(const char *refname, const char *referent UNUSED,
701 - const struct object_id *oid,
702 - int flag, void *cb_data)
700 +static int add_ref_to_pending(const struct reference *ref, void *cb_data)
701 {
702 struct rev_info *revs = (struct rev_info*)cb_data;
703 + const struct object_id *maybe_peeled = ref->oid;
704 struct object_id peeled;
705 struct object *object;
706
708 - if ((flag & REF_ISSYMREF) && (flag & REF_ISBROKEN)) {
709 - warning("symbolic ref is dangling: %s", refname);
707 + if ((ref->flags & REF_ISSYMREF) && (ref->flags & REF_ISBROKEN)) {
708 + warning("symbolic ref is dangling: %s", ref->name);
709 return 0;
710 }
711
713 - if (!peel_iterated_oid(revs->repo, oid, &peeled))
714 - oid = &peeled;
712 + if (!peel_iterated_oid(revs->repo, ref->oid, &peeled))
713 + maybe_peeled = &peeled;
714
716 - object = parse_object_or_die(revs->repo, oid, refname);
715 + object = parse_object_or_die(revs->repo, maybe_peeled, ref->name);
716 if (object->type != OBJ_COMMIT)
717 return 0;
718
719 add_pending_object(revs, object, "");
721 - if (bitmap_is_preferred_refname(revs->repo, refname))
720 + if (bitmap_is_preferred_refname(revs->repo, ref->name))
721 object->flags |= NEEDS_BITMAP;
722 return 0;
723 }
negotiator/default.c
+3 -4
@@ -38,11 +38,10 @@ static void rev_list_push(struct negotiation_state *ns,
38 }
39 }
40
41 -static int clear_marks(const char *refname, const char *referent UNUSED, const struct object_id *oid,
42 - int flag UNUSED,
43 - void *cb_data UNUSED)
41 +static int clear_marks(const struct reference *ref, void *cb_data UNUSED)
42 {
45 - struct object *o = deref_tag(the_repository, parse_object(the_repository, oid), refname, 0);
43 + struct object *o = deref_tag(the_repository, parse_object(the_repository, ref->oid),
44 + ref->name, 0);
45
46 if (o && o->type == OBJ_COMMIT)
47 clear_commit_marks((struct commit *)o,
negotiator/skipping.c
+3 -4
@@ -75,11 +75,10 @@ static struct entry *rev_list_push(struct data *data, struct commit *commit, int
75 return entry;
76 }
77
78 -static int clear_marks(const char *refname, const char *referent UNUSED, const struct object_id *oid,
79 - int flag UNUSED,
80 - void *cb_data UNUSED)
78 +static int clear_marks(const struct reference *ref, void *cb_data UNUSED)
79 {
82 - struct object *o = deref_tag(the_repository, parse_object(the_repository, oid), refname, 0);
80 + struct object *o = deref_tag(the_repository, parse_object(the_repository, ref->oid),
81 + ref->name, 0);
82
83 if (o && o->type == OBJ_COMMIT)
84 clear_commit_marks((struct commit *)o,
notes.c
+3 -5
@@ -938,13 +938,11 @@ out:
938 return ret;
939 }
940
941 -static int string_list_add_one_ref(const char *refname, const char *referent UNUSED,
942 - const struct object_id *oid UNUSED,
943 - int flag UNUSED, void *cb)
941 +static int string_list_add_one_ref(const struct reference *ref, void *cb)
942 {
943 struct string_list *refs = cb;
946 - if (!unsorted_string_list_has_string(refs, refname))
947 - string_list_append(refs, refname);
944 + if (!unsorted_string_list_has_string(refs, ref->name))
945 + string_list_append(refs, ref->name);
946 return 0;
947 }
948
object-name.c
+4 -6
@@ -1444,18 +1444,16 @@ struct handle_one_ref_cb {
1444 struct commit_list **list;
1445 };
1446
1447 -static int handle_one_ref(const char *path, const char *referent UNUSED, const struct object_id *oid,
1448 - int flag UNUSED,
1449 - void *cb_data)
1447 +static int handle_one_ref(const struct reference *ref, void *cb_data)
1448 {
1449 struct handle_one_ref_cb *cb = cb_data;
1450 struct commit_list **list = cb->list;
1453 - struct object *object = parse_object(cb->repo, oid);
1451 + struct object *object = parse_object(cb->repo, ref->oid);
1452 if (!object)
1453 return 0;
1454 if (object->type == OBJ_TAG) {
1457 - object = deref_tag(cb->repo, object, path,
1458 - strlen(path));
1455 + object = deref_tag(cb->repo, object, ref->name,
1456 + strlen(ref->name));
1457 if (!object)
1458 return 0;
1459 }
pseudo-merge.c
+9 -12
@@ -221,28 +221,25 @@ void load_pseudo_merges_from_config(struct repository *r,
221 }
222 }
223
224 -static int find_pseudo_merge_group_for_ref(const char *refname,
225 - const char *referent UNUSED,
226 - const struct object_id *oid,
227 - int flags UNUSED,
228 - void *_data)
224 +static int find_pseudo_merge_group_for_ref(const struct reference *ref, void *_data)
225 {
226 struct bitmap_writer *writer = _data;
227 + const struct object_id *maybe_peeled = ref->oid;
228 struct object_id peeled;
229 struct commit *c;
230 uint32_t i;
231 int has_bitmap;
232
236 - if (!peel_iterated_oid(the_repository, oid, &peeled))
237 - oid = &peeled;
233 + if (!peel_iterated_oid(the_repository, ref->oid, &peeled))
234 + maybe_peeled = &peeled;
235
239 - c = lookup_commit(the_repository, oid);
236 + c = lookup_commit(the_repository, maybe_peeled);
237 if (!c)
238 return 0;
242 - if (!packlist_find(writer->to_pack, oid))
239 + if (!packlist_find(writer->to_pack, maybe_peeled))
240 return 0;
241
245 - has_bitmap = bitmap_writer_has_bitmapped_object_id(writer, oid);
242 + has_bitmap = bitmap_writer_has_bitmapped_object_id(writer, maybe_peeled);
243
244 for (i = 0; i < writer->pseudo_merge_groups.nr; i++) {
245 struct pseudo_merge_group *group;
@@ -252,7 +249,7 @@ static int find_pseudo_merge_group_for_ref(const char *refname,
249 size_t j;
250
251 group = writer->pseudo_merge_groups.items[i].util;
255 - if (regexec(group->pattern, refname, ARRAY_SIZE(captures),
252 + if (regexec(group->pattern, ref->name, ARRAY_SIZE(captures),
253 captures, 0))
254 continue;
255
@@ -269,7 +266,7 @@ static int find_pseudo_merge_group_for_ref(const char *refname,
266 if (group_name.len)
267 strbuf_addch(&group_name, '-');
268
272 - strbuf_add(&group_name, refname + match->rm_so,
269 + strbuf_add(&group_name, ref->name + match->rm_so,
270 match->rm_eo - match->rm_so);
271 }
272
reachable.c
+4 -5
@@ -83,18 +83,17 @@ static void add_rebase_files(struct rev_info *revs)
83 free_worktrees(worktrees);
84 }
85
86 -static int add_one_ref(const char *path, const char *referent UNUSED, const struct object_id *oid,
87 - int flag, void *cb_data)
86 +static int add_one_ref(const struct reference *ref, void *cb_data)
87 {
88 struct rev_info *revs = (struct rev_info *)cb_data;
89 struct object *object;
90
92 - if ((flag & REF_ISSYMREF) && (flag & REF_ISBROKEN)) {
93 - warning("symbolic ref is dangling: %s", path);
91 + if ((ref->flags & REF_ISSYMREF) && (ref->flags & REF_ISBROKEN)) {
92 + warning("symbolic ref is dangling: %s", ref->name);
93 return 0;
94 }
95
97 - object = parse_object_or_die(the_repository, oid, path);
96 + object = parse_object_or_die(the_repository, ref->oid, ref->name);
97 add_pending_object(revs, object, "");
98
99 return 0;
ref-filter.c
+13 -11
@@ -2954,14 +2954,15 @@ struct ref_filter_cbdata {
2954 * A call-back given to for_each_ref(). Filter refs and keep them for
2955 * later object processing.
2956 */
2957 -static int filter_one(const char *refname, const char *referent, const struct object_id *oid, int flag, void *cb_data)
2957 +static int filter_one(const struct reference *ref, void *cb_data)
2958 {
2959 struct ref_filter_cbdata *ref_cbdata = cb_data;
2960 - struct ref_array_item *ref;
2960 + struct ref_array_item *item;
2961
2962 - ref = apply_ref_filter(refname, referent, oid, flag, ref_cbdata->filter);
2963 - if (ref)
2964 - ref_array_append(ref_cbdata->array, ref);
2962 + item = apply_ref_filter(ref->name, ref->target, ref->oid,
2963 + ref->flags, ref_cbdata->filter);
2964 + if (item)
2965 + ref_array_append(ref_cbdata->array, item);
2966
2967 return 0;
2968 }
@@ -2990,17 +2991,18 @@ struct ref_filter_and_format_cbdata {
2991 } internal;
2992 };
2993
2993 -static int filter_and_format_one(const char *refname, const char *referent, const struct object_id *oid, int flag, void *cb_data)
2994 +static int filter_and_format_one(const struct reference *ref, void *cb_data)
2995 {
2996 struct ref_filter_and_format_cbdata *ref_cbdata = cb_data;
2996 - struct ref_array_item *ref;
2997 + struct ref_array_item *item;
2998 struct strbuf output = STRBUF_INIT, err = STRBUF_INIT;
2999
2999 - ref = apply_ref_filter(refname, referent, oid, flag, ref_cbdata->filter);
3000 - if (!ref)
3000 + item = apply_ref_filter(ref->name, ref->target, ref->oid,
3001 + ref->flags, ref_cbdata->filter);
3002 + if (!item)
3003 return 0;
3004
3003 - if (format_ref_array_item(ref, ref_cbdata->format, &output, &err))
3005 + if (format_ref_array_item(item, ref_cbdata->format, &output, &err))
3006 die("%s", err.buf);
3007
3008 if (output.len || !ref_cbdata->format->array_opts.omit_empty) {
@@ -3010,7 +3012,7 @@ static int filter_and_format_one(const char *refname, const char *referent, cons
3012
3013 strbuf_release(&output);
3014 strbuf_release(&err);
3013 - free_array_item(ref);
3015 + free_array_item(item);
3016
3017 /*
3018 * Increment the running count of refs that match the filter. If
reflog.c
+3 -6
@@ -423,16 +423,13 @@ int should_expire_reflog_ent_verbose(struct object_id *ooid,
423 return expire;
424 }
425
426 -static int push_tip_to_list(const char *refname UNUSED,
427 - const char *referent UNUSED,
428 - const struct object_id *oid,
429 - int flags, void *cb_data)
426 +static int push_tip_to_list(const struct reference *ref, void *cb_data)
427 {
428 struct commit_list **list = cb_data;
429 struct commit *tip_commit;
433 - if (flags & REF_ISSYMREF)
430 + if (ref->flags & REF_ISSYMREF)
431 return 0;
435 - tip_commit = lookup_commit_reference_gently(the_repository, oid, 1);
432 + tip_commit = lookup_commit_reference_gently(the_repository, ref->oid, 1);
433 if (!tip_commit)
434 return 0;
435 commit_list_insert(tip_commit, list);
refs.c
+38 -29
@@ -426,17 +426,19 @@ int refs_ref_exists(struct ref_store *refs, const char *refname)
426 NULL, NULL);
427 }
428
429 -static int for_each_filter_refs(const char *refname, const char *referent,
430 - const struct object_id *oid,
431 - int flags, void *data)
429 +static int for_each_filter_refs(const struct reference *ref, void *data)
430 {
431 struct for_each_ref_filter *filter = data;
432
435 - if (wildmatch(filter->pattern, refname, 0))
433 + if (wildmatch(filter->pattern, ref->name, 0))
434 return 0;
437 - if (filter->prefix)
438 - skip_prefix(refname, filter->prefix, &refname);
439 - return filter->fn(refname, referent, oid, flags, filter->cb_data);
435 + if (filter->prefix) {
436 + struct reference skipped = *ref;
437 + skip_prefix(skipped.name, filter->prefix, &skipped.name);
438 + return filter->fn(&skipped, filter->cb_data);
439 + } else {
440 + return filter->fn(ref, filter->cb_data);
441 + }
442 }
443
444 struct warn_if_dangling_data {
@@ -447,17 +449,15 @@ struct warn_if_dangling_data {
449 int dry_run;
450 };
451
450 -static int warn_if_dangling_symref(const char *refname, const char *referent UNUSED,
451 - const struct object_id *oid UNUSED,
452 - int flags, void *cb_data)
452 +static int warn_if_dangling_symref(const struct reference *ref, void *cb_data)
453 {
454 struct warn_if_dangling_data *d = cb_data;
455 const char *resolves_to, *msg;
456
457 - if (!(flags & REF_ISSYMREF))
457 + if (!(ref->flags & REF_ISSYMREF))
458 return 0;
459
460 - resolves_to = refs_resolve_ref_unsafe(d->refs, refname, 0, NULL, NULL);
460 + resolves_to = refs_resolve_ref_unsafe(d->refs, ref->name, 0, NULL, NULL);
461 if (!resolves_to
462 || !string_list_has_string(d->refnames, resolves_to)) {
463 return 0;
@@ -466,7 +466,7 @@ static int warn_if_dangling_symref(const char *refname, const char *referent UNU
466 msg = d->dry_run
467 ? _("%s%s will become dangling after %s is deleted\n")
468 : _("%s%s has become dangling after %s was deleted\n");
469 - fprintf(d->fp, msg, d->indent, refname, resolves_to);
469 + fprintf(d->fp, msg, d->indent, ref->name, resolves_to);
470 return 0;
471 }
472
@@ -507,8 +507,15 @@ int refs_head_ref_namespaced(struct ref_store *refs, each_ref_fn fn, void *cb_da
507 int flag;
508
509 strbuf_addf(&buf, "%sHEAD", get_git_namespace());
510 - if (!refs_read_ref_full(refs, buf.buf, RESOLVE_REF_READING, &oid, &flag))
511 - ret = fn(buf.buf, NULL, &oid, flag, cb_data);
510 + if (!refs_read_ref_full(refs, buf.buf, RESOLVE_REF_READING, &oid, &flag)) {
511 + struct reference ref = {
512 + .name = buf.buf,
513 + .oid = &oid,
514 + .flags = flag,
515 + };
516 +
517 + ret = fn(&ref, cb_data);
518 + }
519 strbuf_release(&buf);
520
521 return ret;
@@ -1741,8 +1748,15 @@ int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
1748 int flag;
1749
1750 if (refs_resolve_ref_unsafe(refs, "HEAD", RESOLVE_REF_READING,
1744 - &oid, &flag))
1745 - return fn("HEAD", NULL, &oid, flag, cb_data);
1751 + &oid, &flag)) {
1752 + struct reference ref = {
1753 + .name = "HEAD",
1754 + .oid = &oid,
1755 + .flags = flag,
1756 + };
1757 +
1758 + return fn(&ref, cb_data);
1759 + }
1760
1761 return 0;
1762 }
@@ -2753,14 +2767,10 @@ struct do_for_each_reflog_help {
2767 void *cb_data;
2768 };
2769
2756 -static int do_for_each_reflog_helper(const char *refname,
2757 - const char *referent UNUSED,
2758 - const struct object_id *oid UNUSED,
2759 - int flags UNUSED,
2760 - void *cb_data)
2770 +static int do_for_each_reflog_helper(const struct reference *ref, void *cb_data)
2771 {
2772 struct do_for_each_reflog_help *hp = cb_data;
2763 - return hp->fn(refname, hp->cb_data);
2773 + return hp->fn(ref->name, hp->cb_data);
2774 }
2775
2776 int refs_for_each_reflog(struct ref_store *refs, each_reflog_fn fn, void *cb_data)
@@ -2976,25 +2986,24 @@ struct migration_data {
2986 uint64_t index;
2987 };
2988
2979 -static int migrate_one_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
2980 - int flags, void *cb_data)
2989 +static int migrate_one_ref(const struct reference *ref, void *cb_data)
2990 {
2991 struct migration_data *data = cb_data;
2992 struct strbuf symref_target = STRBUF_INIT;
2993 int ret;
2994
2986 - if (flags & REF_ISSYMREF) {
2987 - ret = refs_read_symbolic_ref(data->old_refs, refname, &symref_target);
2995 + if (ref->flags & REF_ISSYMREF) {
2996 + ret = refs_read_symbolic_ref(data->old_refs, ref->name, &symref_target);
2997 if (ret < 0)
2998 goto done;
2999
2991 - ret = ref_transaction_update(data->transaction, refname, NULL, null_oid(the_hash_algo),
3000 + ret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(the_hash_algo),
3001 symref_target.buf, NULL,
3002 REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);
3003 if (ret < 0)
3004 goto done;
3005 } else {
2997 - ret = ref_transaction_create(data->transaction, refname, oid, NULL,
3006 + ret = ref_transaction_create(data->transaction, ref->name, ref->oid, NULL,
3007 REF_SKIP_CREATE_REFLOG | REF_SKIP_OID_VERIFICATION,
3008 NULL, data->errbuf);
3009 if (ret < 0)
refs.h
+22 -4
@@ -355,14 +355,32 @@ struct ref_transaction;
355 */
356 #define REF_BAD_NAME 0x08
357
358 +/* A reference passed to `for_each_ref()`-style callbacks. */
359 +struct reference {
360 + /* The fully-qualified name of the reference. */
361 + const char *name;
362 +
363 + /* The target of a symbolic ref. `NULL` for direct references. */
364 + const char *target;
365 +
366 + /*
367 + * The object ID of a reference. Either the direct object ID or the
368 + * resolved object ID in the case of a symbolic ref. May be the zero
369 + * object ID in case the symbolic ref cannot be resolved.
370 + */
371 + const struct object_id *oid;
372 +
373 + /* A bitfield of `REF_` flags. */
374 + int flags;
375 +};
376 +
377 /*
378 * The signature for the callback function for the for_each_*()
360 - * functions below. The memory pointed to by the refname and oid
361 - * arguments is only guaranteed to be valid for the duration of a
379 + * functions below. The memory pointed to by the `struct reference`
380 + * argument is only guaranteed to be valid for the duration of a
381 * single callback invocation.
382 */
364 -typedef int each_ref_fn(const char *refname, const char *referent,
365 - const struct object_id *oid, int flags, void *cb_data);
383 +typedef int each_ref_fn(const struct reference *ref, void *cb_data);
384
385 /*
386 * The following functions invoke the specified callback function for
refs/files-backend.c
+2 -5
@@ -3150,14 +3150,11 @@ static int parse_and_write_reflog(struct files_ref_store *refs,
3150 return 0;
3151 }
3152
3153 -static int ref_present(const char *refname, const char *referent UNUSED,
3154 - const struct object_id *oid UNUSED,
3155 - int flags UNUSED,
3156 - void *cb_data)
3153 +static int ref_present(const struct reference *ref, void *cb_data)
3154 {
3155 struct string_list *affected_refnames = cb_data;
3156
3160 - return string_list_has_string(affected_refnames, refname);
3157 + return string_list_has_string(affected_refnames, ref->name);
3158 }
3159
3160 static int files_transaction_finish_initial(struct files_ref_store *refs,
refs/iterator.c
+8 -1
@@ -476,7 +476,14 @@ int do_for_each_ref_iterator(struct ref_iterator *iter,
476
477 current_ref_iter = iter;
478 while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
479 - retval = fn(iter->refname, iter->referent, iter->oid, iter->flags, cb_data);
479 + struct reference ref = {
480 + .name = iter->refname,
481 + .target = iter->referent,
482 + .oid = iter->oid,
483 + .flags = iter->flags,
484 + };
485 +
486 + retval = fn(&ref, cb_data);
487 if (retval)
488 goto out;
489 }
remote.c
+12 -15
@@ -2315,21 +2315,19 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
2315 return 1;
2316 }
2317
2318 -static int one_local_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
2319 - int flag UNUSED,
2320 - void *cb_data)
2318 +static int one_local_ref(const struct reference *ref, void *cb_data)
2319 {
2320 struct ref ***local_tail = cb_data;
2323 - struct ref *ref;
2321 + struct ref *local_ref;
2322
2323 /* we already know it starts with refs/ to get here */
2326 - if (check_refname_format(refname + 5, 0))
2324 + if (check_refname_format(ref->name + 5, 0))
2325 return 0;
2326
2329 - ref = alloc_ref(refname);
2330 - oidcpy(&ref->new_oid, oid);
2331 - **local_tail = ref;
2332 - *local_tail = &ref->next;
2327 + local_ref = alloc_ref(ref->name);
2328 + oidcpy(&local_ref->new_oid, ref->oid);
2329 + **local_tail = local_ref;
2330 + *local_tail = &local_ref->next;
2331 return 0;
2332 }
2333
@@ -2402,15 +2400,14 @@ struct stale_heads_info {
2400 struct refspec *rs;
2401 };
2402
2405 -static int get_stale_heads_cb(const char *refname, const char *referent UNUSED, const struct object_id *oid,
2406 - int flags, void *cb_data)
2403 +static int get_stale_heads_cb(const struct reference *ref, void *cb_data)
2404 {
2405 struct stale_heads_info *info = cb_data;
2406 struct string_list matches = STRING_LIST_INIT_DUP;
2407 struct refspec_item query;
2408 int i, stale = 1;
2409 memset(&query, 0, sizeof(struct refspec_item));
2413 - query.dst = (char *)refname;
2410 + query.dst = (char *)ref->name;
2411
2412 refspec_find_all_matches(info->rs, &query, &matches);
2413 if (matches.nr == 0)
@@ -2423,7 +2420,7 @@ static int get_stale_heads_cb(const char *refname, const char *referent UNUSED,
2420 * overlapping refspecs, we need to go over all of the
2421 * matching refs.
2422 */
2426 - if (flags & REF_ISSYMREF)
2423 + if (ref->flags & REF_ISSYMREF)
2424 goto clean_exit;
2425
2426 for (i = 0; stale && i < matches.nr; i++)
@@ -2431,8 +2428,8 @@ static int get_stale_heads_cb(const char *refname, const char *referent UNUSED,
2428 stale = 0;
2429
2430 if (stale) {
2434 - struct ref *ref = make_linked_ref(refname, &info->stale_refs_tail);
2435 - oidcpy(&ref->new_oid, oid);
2431 + struct ref *linked_ref = make_linked_ref(ref->name, &info->stale_refs_tail);
2432 + oidcpy(&linked_ref->new_oid, ref->oid);
2433 }
2434
2435 clean_exit:
repack-midx.c
+7 -9
@@ -16,25 +16,23 @@ struct midx_snapshot_ref_data {
16 int preferred;
17 };
18
19 -static int midx_snapshot_ref_one(const char *refname UNUSED,
20 - const char *referent UNUSED,
21 - const struct object_id *oid,
22 - int flag UNUSED, void *_data)
19 +static int midx_snapshot_ref_one(const struct reference *ref, void *_data)
20 {
21 struct midx_snapshot_ref_data *data = _data;
22 + const struct object_id *maybe_peeled = ref->oid;
23 struct object_id peeled;
24
27 - if (!peel_iterated_oid(data->repo, oid, &peeled))
28 - oid = &peeled;
25 + if (!peel_iterated_oid(data->repo, ref->oid, &peeled))
26 + maybe_peeled = &peeled;
27
30 - if (oidset_insert(&data->seen, oid))
28 + if (oidset_insert(&data->seen, maybe_peeled))
29 return 0; /* already seen */
30
33 - if (odb_read_object_info(data->repo->objects, oid, NULL) != OBJ_COMMIT)
31 + if (odb_read_object_info(data->repo->objects, maybe_peeled, NULL) != OBJ_COMMIT)
32 return 0;
33
34 fprintf(data->f->fp, "%s%s\n", data->preferred ? "+" : "",
37 - oid_to_hex(oid));
35 + oid_to_hex(maybe_peeled));
36
37 return 0;
38 }
replace-object.c
+6 -10
@@ -8,31 +8,27 @@
8 #include "repository.h"
9 #include "commit.h"
10
11 -static int register_replace_ref(const char *refname,
12 - const char *referent UNUSED,
13 - const struct object_id *oid,
14 - int flag UNUSED,
15 - void *cb_data)
11 +static int register_replace_ref(const struct reference *ref, void *cb_data)
12 {
13 struct repository *r = cb_data;
14
15 /* Get sha1 from refname */
20 - const char *slash = strrchr(refname, '/');
21 - const char *hash = slash ? slash + 1 : refname;
16 + const char *slash = strrchr(ref->name, '/');
17 + const char *hash = slash ? slash + 1 : ref->name;
18 struct replace_object *repl_obj = xmalloc(sizeof(*repl_obj));
19
20 if (get_oid_hex_algop(hash, &repl_obj->original.oid, r->hash_algo)) {
21 free(repl_obj);
26 - warning(_("bad replace ref name: %s"), refname);
22 + warning(_("bad replace ref name: %s"), ref->name);
23 return 0;
24 }
25
26 /* Copy sha1 from the read ref */
31 - oidcpy(&repl_obj->replacement, oid);
27 + oidcpy(&repl_obj->replacement, ref->oid);
28
29 /* Register new object */
30 if (oidmap_put(&r->objects->replace_map, repl_obj))
35 - die(_("duplicate replace ref: %s"), refname);
31 + die(_("duplicate replace ref: %s"), ref->name);
32
33 return 0;
34 }
revision.c
+5 -7
@@ -1644,19 +1644,17 @@ struct all_refs_cb {
1644 struct worktree *wt;
1645 };
1646
1647 -static int handle_one_ref(const char *path, const char *referent UNUSED, const struct object_id *oid,
1648 - int flag UNUSED,
1649 - void *cb_data)
1647 +static int handle_one_ref(const struct reference *ref, void *cb_data)
1648 {
1649 struct all_refs_cb *cb = cb_data;
1650 struct object *object;
1651
1654 - if (ref_excluded(&cb->all_revs->ref_excludes, path))
1652 + if (ref_excluded(&cb->all_revs->ref_excludes, ref->name))
1653 return 0;
1654
1657 - object = get_reference(cb->all_revs, path, oid, cb->all_flags);
1658 - add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags);
1659 - add_pending_object(cb->all_revs, object, path);
1655 + object = get_reference(cb->all_revs, ref->name, ref->oid, cb->all_flags);
1656 + add_rev_cmdline(cb->all_revs, object, ref->name, REV_CMD_REF, cb->all_flags);
1657 + add_pending_object(cb->all_revs, object, ref->name);
1658 return 0;
1659 }
1660
server-info.c
+5 -7
@@ -148,23 +148,21 @@ out:
148 return ret;
149 }
150
151 -static int add_info_ref(const char *path, const char *referent UNUSED, const struct object_id *oid,
152 - int flag UNUSED,
153 - void *cb_data)
151 +static int add_info_ref(const struct reference *ref, void *cb_data)
152 {
153 struct update_info_ctx *uic = cb_data;
156 - struct object *o = parse_object(uic->repo, oid);
154 + struct object *o = parse_object(uic->repo, ref->oid);
155 if (!o)
156 return -1;
157
160 - if (uic_printf(uic, "%s %s\n", oid_to_hex(oid), path) < 0)
158 + if (uic_printf(uic, "%s %s\n", oid_to_hex(ref->oid), ref->name) < 0)
159 return -1;
160
161 if (o->type == OBJ_TAG) {
164 - o = deref_tag(uic->repo, o, path, 0);
162 + o = deref_tag(uic->repo, o, ref->name, 0);
163 if (o)
164 if (uic_printf(uic, "%s %s^{}\n",
167 - oid_to_hex(&o->oid), path) < 0)
165 + oid_to_hex(&o->oid), ref->name) < 0)
166 return -1;
167 }
168 return 0;
shallow.c
+4 -12
@@ -626,14 +626,10 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,
626 free(tmp);
627 }
628
629 -static int mark_uninteresting(const char *refname UNUSED,
630 - const char *referent UNUSED,
631 - const struct object_id *oid,
632 - int flags UNUSED,
633 - void *cb_data UNUSED)
629 +static int mark_uninteresting(const struct reference *ref, void *cb_data UNUSED)
630 {
631 struct commit *commit = lookup_commit_reference_gently(the_repository,
636 - oid, 1);
632 + ref->oid, 1);
633 if (!commit)
634 return 0;
635 commit->object.flags |= UNINTERESTING;
@@ -742,16 +738,12 @@ struct commit_array {
738 size_t nr, alloc;
739 };
740
745 -static int add_ref(const char *refname UNUSED,
746 - const char *referent UNUSED,
747 - const struct object_id *oid,
748 - int flags UNUSED,
749 - void *cb_data)
741 +static int add_ref(const struct reference *ref, void *cb_data)
742 {
743 struct commit_array *ca = cb_data;
744 ALLOC_GROW(ca->commits, ca->nr + 1, ca->alloc);
745 ca->commits[ca->nr] = lookup_commit_reference_gently(the_repository,
754 - oid, 1);
746 + ref->oid, 1);
747 if (ca->commits[ca->nr])
748 ca->nr++;
749 return 0;
submodule.c
+3 -9
@@ -934,10 +934,7 @@ static void free_submodules_data(struct string_list *submodules)
934 string_list_clear(submodules, 1);
935 }
936
937 -static int has_remote(const char *refname UNUSED,
938 - const char *referent UNUSED,
939 - const struct object_id *oid UNUSED,
940 - int flags UNUSED, void *cb_data UNUSED)
937 +static int has_remote(const struct reference *ref UNUSED, void *cb_data UNUSED)
938 {
939 return 1;
940 }
@@ -1255,13 +1252,10 @@ int push_unpushed_submodules(struct repository *r,
1252 return ret;
1253 }
1254
1258 -static int append_oid_to_array(const char *ref UNUSED,
1259 - const char *referent UNUSED,
1260 - const struct object_id *oid,
1261 - int flags UNUSED, void *data)
1255 +static int append_oid_to_array(const struct reference *ref, void *data)
1256 {
1257 struct oid_array *array = data;
1264 - oid_array_append(array, oid);
1258 + oid_array_append(array, ref->oid);
1259 return 0;
1260 }
1261
t/helper/test-ref-store.c
+2 -3
@@ -154,10 +154,9 @@ static int cmd_rename_ref(struct ref_store *refs, const char **argv)
154 return refs_rename_ref(refs, oldref, newref, logmsg);
155 }
156
157 -static int each_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
158 - int flags, void *cb_data UNUSED)
157 +static int each_ref(const struct reference *ref, void *cb_data UNUSED)
158 {
160 - printf("%s %s 0x%x\n", oid_to_hex(oid), refname, flags);
159 + printf("%s %s 0x%x\n", oid_to_hex(ref->oid), ref->name, ref->flags);
160 return 0;
161 }
162
upload-pack.c
+13 -16
@@ -870,8 +870,8 @@ static void send_unshallow(struct upload_pack_data *data)
870 }
871 }
872
873 -static int check_ref(const char *refname_full, const char *referent UNUSED, const struct object_id *oid,
874 - int flag, void *cb_data);
873 +static int check_ref(const struct reference *ref, void *cb_data);
874 +
875 static void deepen(struct upload_pack_data *data, int depth)
876 {
877 if (depth == INFINITE_DEPTH && !is_repository_shallow(the_repository)) {
@@ -1224,13 +1224,12 @@ static int mark_our_ref(const char *refname, const char *refname_full,
1224 return 0;
1225 }
1226
1227 -static int check_ref(const char *refname_full, const char *referent UNUSED,const struct object_id *oid,
1228 - int flag UNUSED, void *cb_data)
1227 +static int check_ref(const struct reference *ref, void *cb_data)
1228 {
1230 - const char *refname = strip_namespace(refname_full);
1229 + const char *refname = strip_namespace(ref->name);
1230 struct upload_pack_data *data = cb_data;
1231
1233 - mark_our_ref(refname, refname_full, oid, &data->hidden_refs);
1232 + mark_our_ref(refname, ref->name, ref->oid, &data->hidden_refs);
1233 return 0;
1234 }
1235
@@ -1292,27 +1291,25 @@ static void write_v0_ref(struct upload_pack_data *data,
1291 return;
1292 }
1293
1295 -static int send_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
1296 - int flag UNUSED, void *cb_data)
1294 +static int send_ref(const struct reference *ref, void *cb_data)
1295 {
1298 - write_v0_ref(cb_data, refname, strip_namespace(refname), oid);
1296 + write_v0_ref(cb_data, ref->name, strip_namespace(ref->name), ref->oid);
1297 return 0;
1298 }
1299
1302 -static int find_symref(const char *refname, const char *referent UNUSED,
1303 - const struct object_id *oid UNUSED,
1304 - int flag, void *cb_data)
1300 +static int find_symref(const struct reference *ref, void *cb_data)
1301 {
1302 const char *symref_target;
1303 struct string_list_item *item;
1304 + int flag;
1305
1309 - if ((flag & REF_ISSYMREF) == 0)
1306 + if ((ref->flags & REF_ISSYMREF) == 0)
1307 return 0;
1308 symref_target = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
1312 - refname, 0, NULL, &flag);
1309 + ref->name, 0, NULL, &flag);
1310 if (!symref_target || (flag & REF_ISSYMREF) == 0)
1314 - die("'%s' is a symref but it is not?", refname);
1315 - item = string_list_append(cb_data, strip_namespace(refname));
1311 + die("'%s' is a symref but it is not?", ref->name);
1312 + item = string_list_append(cb_data, strip_namespace(ref->name));
1313 item->util = xstrdup(strip_namespace(symref_target));
1314 return 0;
1315 }
walker.c
+2 -6
@@ -226,14 +226,10 @@ static int interpret_target(struct walker *walker, char *target, struct object_i
226 return -1;
227 }
228
229 -static int mark_complete(const char *path UNUSED,
230 - const char *referent UNUSED,
231 - const struct object_id *oid,
232 - int flag UNUSED,
233 - void *cb_data UNUSED)
229 +static int mark_complete(const struct reference *ref, void *cb_data UNUSED)
230 {
231 struct commit *commit = lookup_commit_reference_gently(the_repository,
236 - oid, 1);
232 + ref->oid, 1);
233
234 if (commit) {
235 commit->object.flags |= COMPLETE;
worktree.c
+9 -2
@@ -595,8 +595,15 @@ int other_head_refs(each_ref_fn fn, void *cb_data)
595 if (refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
596 refname.buf,
597 RESOLVE_REF_READING,
598 - &oid, &flag))
599 - ret = fn(refname.buf, NULL, &oid, flag, cb_data);
598 + &oid, &flag)) {
599 + struct reference ref = {
600 + .name = refname.buf,
601 + .oid = &oid,
602 + .flags = flag,
603 + };
604 +
605 + ret = fn(&ref, cb_data);
606 + }
607 if (ret)
608 break;
609 }