Git fork

refs: pass refname when invoking reflog entry callback

With `refs_for_each_reflog_ent()` callers can iterate through all the
reflog entries for a given reference. The callback that is being invoked
for each such entry does not receive the name of the reference that we
are currently iterating through. This isn't really a limiting factor, as
callers can simply pass the name via the callback data.

But this layout sometimes does make for a bit of an awkward calling
pattern. One example: when iterating through all reflogs, and for each
reflog we iterate through all refnames, we have to do some extra book
keeping to track which reference name we are currently yielding reflog
entries for.

Change the signature of the callback function so that the reference name
of the reflog gets passed through to it. Adapt callers accordingly and
start using the new parameter in trivial cases. The next commit will
refactor the reference migration logic to make use of this parameter so
that we can simplify its logic a bit.

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

authored by

Patrick Steinhardt and committed by
Junio C Hamano
b9fd73a2 cf038155

+63 -45
+4 -5
builtin/fsck.c
··· 502 502 } 503 503 } 504 504 505 - static int fsck_handle_reflog_ent(struct object_id *ooid, struct object_id *noid, 505 + static int fsck_handle_reflog_ent(const char *refname, 506 + struct object_id *ooid, struct object_id *noid, 506 507 const char *email UNUSED, 507 508 timestamp_t timestamp, int tz UNUSED, 508 - const char *message UNUSED, void *cb_data) 509 + const char *message UNUSED, void *cb_data UNUSED) 509 510 { 510 - const char *refname = cb_data; 511 - 512 511 if (verbose) 513 512 fprintf_ln(stderr, _("Checking reflog %s->%s"), 514 513 oid_to_hex(ooid), oid_to_hex(noid)); ··· 525 524 strbuf_worktree_ref(cb_data, &refname, logname); 526 525 refs_for_each_reflog_ent(get_main_ref_store(the_repository), 527 526 refname.buf, fsck_handle_reflog_ent, 528 - refname.buf); 527 + NULL); 529 528 strbuf_release(&refname); 530 529 return 0; 531 530 }
+2 -1
builtin/gc.c
··· 312 312 size_t limit; 313 313 }; 314 314 315 - static int count_reflog_entries(struct object_id *old_oid, struct object_id *new_oid, 315 + static int count_reflog_entries(const char *refname UNUSED, 316 + struct object_id *old_oid, struct object_id *new_oid, 316 317 const char *committer, timestamp_t timestamp, 317 318 int tz, const char *msg, void *cb_data) 318 319 {
+4 -2
builtin/stash.c
··· 738 738 return ret; 739 739 } 740 740 741 - static int reject_reflog_ent(struct object_id *ooid UNUSED, 741 + static int reject_reflog_ent(const char *refname UNUSED, 742 + struct object_id *ooid UNUSED, 742 743 struct object_id *noid UNUSED, 743 744 const char *email UNUSED, 744 745 timestamp_t timestamp UNUSED, ··· 2173 2174 size_t count; 2174 2175 }; 2175 2176 2176 - static int collect_stash_entries(struct object_id *old_oid UNUSED, 2177 + static int collect_stash_entries(const char *refname UNUSED, 2178 + struct object_id *old_oid UNUSED, 2177 2179 struct object_id *new_oid, 2178 2180 const char *committer UNUSED, 2179 2181 timestamp_t timestamp UNUSED,
+2 -1
commit.c
··· 1031 1031 commit->object.flags |= TMP_MARK; 1032 1032 } 1033 1033 1034 - static int collect_one_reflog_ent(struct object_id *ooid, struct object_id *noid, 1034 + static int collect_one_reflog_ent(const char *refname UNUSED, 1035 + struct object_id *ooid, struct object_id *noid, 1035 1036 const char *ident UNUSED, 1036 1037 timestamp_t timestamp UNUSED, int tz UNUSED, 1037 1038 const char *message UNUSED, void *cbdata)
+2 -1
object-name.c
··· 1516 1516 struct strbuf *sb; 1517 1517 }; 1518 1518 1519 - static int grab_nth_branch_switch(struct object_id *ooid UNUSED, 1519 + static int grab_nth_branch_switch(const char *refname UNUSED, 1520 + struct object_id *ooid UNUSED, 1520 1521 struct object_id *noid UNUSED, 1521 1522 const char *email UNUSED, 1522 1523 timestamp_t timestamp UNUSED,
+4 -3
reflog-walk.c
··· 22 22 int nr, alloc; 23 23 }; 24 24 25 - static int read_one_reflog(struct object_id *ooid, struct object_id *noid, 26 - const char *email, timestamp_t timestamp, int tz, 27 - const char *message, void *cb_data) 25 + static int read_one_reflog(const char *refname UNUSED, 26 + struct object_id *ooid, struct object_id *noid, 27 + const char *email, timestamp_t timestamp, int tz, 28 + const char *message, void *cb_data) 28 29 { 29 30 struct complete_reflogs *array = cb_data; 30 31 struct reflog_info *item;
+2 -1
reflog.c
··· 492 492 free_commit_list(cb->mark_list); 493 493 } 494 494 495 - int count_reflog_ent(struct object_id *ooid UNUSED, 495 + int count_reflog_ent(const char *refname UNUSED, 496 + struct object_id *ooid UNUSED, 496 497 struct object_id *noid UNUSED, 497 498 const char *email UNUSED, 498 499 timestamp_t timestamp, int tz UNUSED,
+2 -1
reflog.h
··· 63 63 int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid, 64 64 const char *email, timestamp_t timestamp, int tz, 65 65 const char *message, void *cb_data); 66 - int count_reflog_ent(struct object_id *ooid, struct object_id *noid, 66 + int count_reflog_ent(const char *refname, 67 + struct object_id *ooid, struct object_id *noid, 67 68 const char *email, timestamp_t timestamp, int tz, 68 69 const char *message, void *cb_data); 69 70 int should_expire_reflog_ent_verbose(struct object_id *ooid,
+9 -11
refs.c
··· 1022 1022 } 1023 1023 1024 1024 struct read_ref_at_cb { 1025 - const char *refname; 1026 1025 timestamp_t at_time; 1027 1026 int cnt; 1028 1027 int reccnt; ··· 1052 1051 *cb->cutoff_cnt = cb->reccnt; 1053 1052 } 1054 1053 1055 - static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid, 1054 + static int read_ref_at_ent(const char *refname, 1055 + struct object_id *ooid, struct object_id *noid, 1056 1056 const char *email UNUSED, 1057 1057 timestamp_t timestamp, int tz, 1058 1058 const char *message, void *cb_data) ··· 1072 1072 oidcpy(cb->oid, noid); 1073 1073 if (!oideq(&cb->ooid, noid)) 1074 1074 warning(_("log for ref %s has gap after %s"), 1075 - cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822))); 1075 + refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822))); 1076 1076 } 1077 1077 else if (cb->date == cb->at_time) 1078 1078 oidcpy(cb->oid, noid); 1079 1079 else if (!oideq(noid, cb->oid)) 1080 1080 warning(_("log for ref %s unexpectedly ended on %s"), 1081 - cb->refname, show_date(cb->date, cb->tz, 1082 - DATE_MODE(RFC2822))); 1081 + refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822))); 1083 1082 cb->reccnt++; 1084 1083 oidcpy(&cb->ooid, ooid); 1085 1084 oidcpy(&cb->noid, noid); ··· 1094 1093 return 0; 1095 1094 } 1096 1095 1097 - static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid, 1096 + static int read_ref_at_ent_oldest(const char *refname UNUSED, 1097 + struct object_id *ooid, struct object_id *noid, 1098 1098 const char *email UNUSED, 1099 1099 timestamp_t timestamp, int tz, 1100 1100 const char *message, void *cb_data) ··· 1117 1117 struct read_ref_at_cb cb; 1118 1118 1119 1119 memset(&cb, 0, sizeof(cb)); 1120 - cb.refname = refname; 1121 1120 cb.at_time = at_time; 1122 1121 cb.cnt = cnt; 1123 1122 cb.msg = msg; ··· 2976 2975 2977 2976 struct reflog_migration_data { 2978 2977 uint64_t index; 2979 - const char *refname; 2980 2978 struct ref_store *old_refs; 2981 2979 struct ref_transaction *transaction; 2982 2980 struct strbuf *errbuf; 2983 2981 struct strbuf *sb, *name, *mail; 2984 2982 }; 2985 2983 2986 - static int migrate_one_reflog_entry(struct object_id *old_oid, 2984 + static int migrate_one_reflog_entry(const char *refname, 2985 + struct object_id *old_oid, 2987 2986 struct object_id *new_oid, 2988 2987 const char *committer, 2989 2988 timestamp_t timestamp, int tz, ··· 3006 3005 strbuf_reset(data->sb); 3007 3006 strbuf_addstr(data->sb, fmt_ident(data->name->buf, data->mail->buf, WANT_BLANK_IDENT, date, 0)); 3008 3007 3009 - ret = ref_transaction_update_reflog(data->transaction, data->refname, 3008 + ret = ref_transaction_update_reflog(data->transaction, refname, 3010 3009 new_oid, old_oid, data->sb->buf, 3011 3010 msg, data->index++, data->errbuf); 3012 3011 return ret; ··· 3016 3015 { 3017 3016 struct migration_data *migration_data = cb_data; 3018 3017 struct reflog_migration_data data = { 3019 - .refname = refname, 3020 3018 .old_refs = migration_data->old_refs, 3021 3019 .transaction = migration_data->transaction, 3022 3020 .errbuf = migration_data->errbuf,
+7 -4
refs.h
··· 558 558 * The cb_data is a caller-supplied pointer given to the iterator 559 559 * functions. 560 560 */ 561 - typedef int each_reflog_ent_fn( 562 - struct object_id *old_oid, struct object_id *new_oid, 563 - const char *committer, timestamp_t timestamp, 564 - int tz, const char *msg, void *cb_data); 561 + typedef int each_reflog_ent_fn(const char *refname, 562 + struct object_id *old_oid, 563 + struct object_id *new_oid, 564 + const char *committer, 565 + timestamp_t timestamp, 566 + int tz, const char *msg, 567 + void *cb_data); 565 568 566 569 /* Iterate over reflog entries in the log for `refname`. */ 567 570
+3 -2
refs/debug.c
··· 276 276 void *cb_data; 277 277 }; 278 278 279 - static int debug_print_reflog_ent(struct object_id *old_oid, 279 + static int debug_print_reflog_ent(const char *refname, 280 + struct object_id *old_oid, 280 281 struct object_id *new_oid, 281 282 const char *committer, timestamp_t timestamp, 282 283 int tz, const char *msg, void *cb_data) ··· 291 292 if (new_oid) 292 293 oid_to_hex_r(n, new_oid); 293 294 294 - ret = dbg->fn(old_oid, new_oid, committer, timestamp, tz, msg, 295 + ret = dbg->fn(refname, old_oid, new_oid, committer, timestamp, tz, msg, 295 296 dbg->cb_data); 296 297 trace_printf_key(&trace_refs, 297 298 "reflog_ent %s (ret %d): %s -> %s, %s %ld \"%.*s\"\n",
+9 -6
refs/files-backend.c
··· 2115 2115 return ret; 2116 2116 } 2117 2117 2118 - static int show_one_reflog_ent(struct files_ref_store *refs, struct strbuf *sb, 2118 + static int show_one_reflog_ent(struct files_ref_store *refs, 2119 + const char *refname, 2120 + struct strbuf *sb, 2119 2121 each_reflog_ent_fn fn, void *cb_data) 2120 2122 { 2121 2123 struct object_id ooid, noid; ··· 2142 2144 message += 6; 2143 2145 else 2144 2146 message += 7; 2145 - return fn(&ooid, &noid, p, timestamp, tz, message, cb_data); 2147 + return fn(refname, &ooid, &noid, p, timestamp, tz, message, cb_data); 2146 2148 } 2147 2149 2148 2150 static char *find_beginning_of_line(char *bob, char *scan) ··· 2226 2228 strbuf_splice(&sb, 0, 0, bp + 1, endp - (bp + 1)); 2227 2229 scanp = bp; 2228 2230 endp = bp + 1; 2229 - ret = show_one_reflog_ent(refs, &sb, fn, cb_data); 2231 + ret = show_one_reflog_ent(refs, refname, &sb, fn, cb_data); 2230 2232 strbuf_reset(&sb); 2231 2233 if (ret) 2232 2234 break; ··· 2238 2240 * Process it, and we can end the loop. 2239 2241 */ 2240 2242 strbuf_splice(&sb, 0, 0, buf, endp - buf); 2241 - ret = show_one_reflog_ent(refs, &sb, fn, cb_data); 2243 + ret = show_one_reflog_ent(refs, refname, &sb, fn, cb_data); 2242 2244 strbuf_reset(&sb); 2243 2245 break; 2244 2246 } ··· 2288 2290 return -1; 2289 2291 2290 2292 while (!ret && !strbuf_getwholeline(&sb, logfp, '\n')) 2291 - ret = show_one_reflog_ent(refs, &sb, fn, cb_data); 2293 + ret = show_one_reflog_ent(refs, refname, &sb, fn, cb_data); 2292 2294 fclose(logfp); 2293 2295 strbuf_release(&sb); 2294 2296 return ret; ··· 3359 3361 dry_run:1; 3360 3362 }; 3361 3363 3362 - static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid, 3364 + static int expire_reflog_ent(const char *refname UNUSED, 3365 + struct object_id *ooid, struct object_id *noid, 3363 3366 const char *email, timestamp_t timestamp, int tz, 3364 3367 const char *message, void *cb_data) 3365 3368 {
+1 -1
refs/reftable-backend.c
··· 2148 2148 2149 2149 full_committer = fmt_ident(log->value.update.name, log->value.update.email, 2150 2150 WANT_COMMITTER_IDENT, NULL, IDENT_NO_DATE); 2151 - return fn(&old_oid, &new_oid, full_committer, 2151 + return fn(log->refname, &old_oid, &new_oid, full_committer, 2152 2152 log->value.update.time, log->value.update.tz_offset, 2153 2153 log->value.update.message, cb_data); 2154 2154 }
+4 -2
remote.c
··· 2578 2578 }; 2579 2579 2580 2580 /* Get the timestamp of the latest entry. */ 2581 - static int peek_reflog(struct object_id *o_oid UNUSED, 2581 + static int peek_reflog(const char *refname UNUSED, 2582 + struct object_id *o_oid UNUSED, 2582 2583 struct object_id *n_oid UNUSED, 2583 2584 const char *ident UNUSED, 2584 2585 timestamp_t timestamp, int tz UNUSED, ··· 2589 2590 return 1; 2590 2591 } 2591 2592 2592 - static int check_and_collect_until(struct object_id *o_oid UNUSED, 2593 + static int check_and_collect_until(const char *refname UNUSED, 2594 + struct object_id *o_oid UNUSED, 2593 2595 struct object_id *n_oid, 2594 2596 const char *ident UNUSED, 2595 2597 timestamp_t timestamp, int tz UNUSED,
+2 -1
revision.c
··· 1699 1699 } 1700 1700 } 1701 1701 1702 - static int handle_one_reflog_ent(struct object_id *ooid, struct object_id *noid, 1702 + static int handle_one_reflog_ent(const char *refname UNUSED, 1703 + struct object_id *ooid, struct object_id *noid, 1703 1704 const char *email UNUSED, 1704 1705 timestamp_t timestamp UNUSED, 1705 1706 int tz UNUSED,
+2 -1
t/helper/test-ref-store.c
··· 215 215 return refs_for_each_reflog(refs, each_reflog, NULL); 216 216 } 217 217 218 - static int each_reflog_ent(struct object_id *old_oid, struct object_id *new_oid, 218 + static int each_reflog_ent(const char *refname UNUSED, 219 + struct object_id *old_oid, struct object_id *new_oid, 219 220 const char *committer, timestamp_t timestamp, 220 221 int tz, const char *msg, void *cb_data UNUSED) 221 222 {
+4 -2
wt-status.c
··· 972 972 wt_longstatus_print_trailer(s); 973 973 } 974 974 975 - static int stash_count_refs(struct object_id *ooid UNUSED, 975 + static int stash_count_refs(const char *refname UNUSED, 976 + struct object_id *ooid UNUSED, 976 977 struct object_id *noid UNUSED, 977 978 const char *email UNUSED, 978 979 timestamp_t timestamp UNUSED, int tz UNUSED, ··· 1664 1665 struct object_id noid; 1665 1666 }; 1666 1667 1667 - static int grab_1st_switch(struct object_id *ooid UNUSED, 1668 + static int grab_1st_switch(const char *refname UNUSED, 1669 + struct object_id *ooid UNUSED, 1668 1670 struct object_id *noid, 1669 1671 const char *email UNUSED, 1670 1672 timestamp_t timestamp UNUSED, int tz UNUSED,