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