Skip to content

Commit b9fd73a

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cf03815 commit b9fd73a

File tree

17 files changed

+63
-45
lines changed

17 files changed

+63
-45
lines changed

builtin/fsck.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,13 +502,12 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
502502
}
503503
}
504504

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,
506507
const char *email UNUSED,
507508
timestamp_t timestamp, int tz UNUSED,
508-
const char *message UNUSED, void *cb_data)
509+
const char *message UNUSED, void *cb_data UNUSED)
509510
{
510-
const char *refname = cb_data;
511-
512511
if (verbose)
513512
fprintf_ln(stderr, _("Checking reflog %s->%s"),
514513
oid_to_hex(ooid), oid_to_hex(noid));
@@ -525,7 +524,7 @@ static int fsck_handle_reflog(const char *logname, void *cb_data)
525524
strbuf_worktree_ref(cb_data, &refname, logname);
526525
refs_for_each_reflog_ent(get_main_ref_store(the_repository),
527526
refname.buf, fsck_handle_reflog_ent,
528-
refname.buf);
527+
NULL);
529528
strbuf_release(&refname);
530529
return 0;
531530
}

builtin/gc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ struct count_reflog_entries_data {
312312
size_t limit;
313313
};
314314

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,
316317
const char *committer, timestamp_t timestamp,
317318
int tz, const char *msg, void *cb_data)
318319
{

builtin/stash.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,8 @@ static int apply_stash(int argc, const char **argv, const char *prefix,
738738
return ret;
739739
}
740740

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,
742743
struct object_id *noid UNUSED,
743744
const char *email UNUSED,
744745
timestamp_t timestamp UNUSED,
@@ -2173,7 +2174,8 @@ struct stash_entry_data {
21732174
size_t count;
21742175
};
21752176

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,
21772179
struct object_id *new_oid,
21782180
const char *committer UNUSED,
21792181
timestamp_t timestamp UNUSED,

commit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,8 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs)
10311031
commit->object.flags |= TMP_MARK;
10321032
}
10331033

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,
10351036
const char *ident UNUSED,
10361037
timestamp_t timestamp UNUSED, int tz UNUSED,
10371038
const char *message UNUSED, void *cbdata)

object-name.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,8 @@ struct grab_nth_branch_switch_cbdata {
15161516
struct strbuf *sb;
15171517
};
15181518

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,
15201521
struct object_id *noid UNUSED,
15211522
const char *email UNUSED,
15221523
timestamp_t timestamp UNUSED,

reflog-walk.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ struct complete_reflogs {
2222
int nr, alloc;
2323
};
2424

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)
2829
{
2930
struct complete_reflogs *array = cb_data;
3031
struct reflog_info *item;

reflog.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ void reflog_expiry_cleanup(void *cb_data)
492492
free_commit_list(cb->mark_list);
493493
}
494494

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,
496497
struct object_id *noid UNUSED,
497498
const char *email UNUSED,
498499
timestamp_t timestamp, int tz UNUSED,

reflog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ void reflog_expiry_prepare(const char *refname, const struct object_id *oid,
6363
int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
6464
const char *email, timestamp_t timestamp, int tz,
6565
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,
6768
const char *email, timestamp_t timestamp, int tz,
6869
const char *message, void *cb_data);
6970
int should_expire_reflog_ent_verbose(struct object_id *ooid,

refs.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,6 @@ int is_branch(const char *refname)
10221022
}
10231023

10241024
struct read_ref_at_cb {
1025-
const char *refname;
10261025
timestamp_t at_time;
10271026
int cnt;
10281027
int reccnt;
@@ -1052,7 +1051,8 @@ static void set_read_ref_cutoffs(struct read_ref_at_cb *cb,
10521051
*cb->cutoff_cnt = cb->reccnt;
10531052
}
10541053

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,
10561056
const char *email UNUSED,
10571057
timestamp_t timestamp, int tz,
10581058
const char *message, void *cb_data)
@@ -1072,14 +1072,13 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
10721072
oidcpy(cb->oid, noid);
10731073
if (!oideq(&cb->ooid, noid))
10741074
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)));
10761076
}
10771077
else if (cb->date == cb->at_time)
10781078
oidcpy(cb->oid, noid);
10791079
else if (!oideq(noid, cb->oid))
10801080
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)));
10831082
cb->reccnt++;
10841083
oidcpy(&cb->ooid, ooid);
10851084
oidcpy(&cb->noid, noid);
@@ -1094,7 +1093,8 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
10941093
return 0;
10951094
}
10961095

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,
10981098
const char *email UNUSED,
10991099
timestamp_t timestamp, int tz,
11001100
const char *message, void *cb_data)
@@ -1117,7 +1117,6 @@ int read_ref_at(struct ref_store *refs, const char *refname,
11171117
struct read_ref_at_cb cb;
11181118

11191119
memset(&cb, 0, sizeof(cb));
1120-
cb.refname = refname;
11211120
cb.at_time = at_time;
11221121
cb.cnt = cnt;
11231122
cb.msg = msg;
@@ -2976,14 +2975,14 @@ static int migrate_one_ref(const char *refname, const char *referent UNUSED, con
29762975

29772976
struct reflog_migration_data {
29782977
uint64_t index;
2979-
const char *refname;
29802978
struct ref_store *old_refs;
29812979
struct ref_transaction *transaction;
29822980
struct strbuf *errbuf;
29832981
struct strbuf *sb, *name, *mail;
29842982
};
29852983

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,
29872986
struct object_id *new_oid,
29882987
const char *committer,
29892988
timestamp_t timestamp, int tz,
@@ -3006,7 +3005,7 @@ static int migrate_one_reflog_entry(struct object_id *old_oid,
30063005
strbuf_reset(data->sb);
30073006
strbuf_addstr(data->sb, fmt_ident(data->name->buf, data->mail->buf, WANT_BLANK_IDENT, date, 0));
30083007

3009-
ret = ref_transaction_update_reflog(data->transaction, data->refname,
3008+
ret = ref_transaction_update_reflog(data->transaction, refname,
30103009
new_oid, old_oid, data->sb->buf,
30113010
msg, data->index++, data->errbuf);
30123011
return ret;
@@ -3016,7 +3015,6 @@ static int migrate_one_reflog(const char *refname, void *cb_data)
30163015
{
30173016
struct migration_data *migration_data = cb_data;
30183017
struct reflog_migration_data data = {
3019-
.refname = refname,
30203018
.old_refs = migration_data->old_refs,
30213019
.transaction = migration_data->transaction,
30223020
.errbuf = migration_data->errbuf,

refs.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,13 @@ int refs_delete_reflog(struct ref_store *refs, const char *refname);
558558
* The cb_data is a caller-supplied pointer given to the iterator
559559
* functions.
560560
*/
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);
565568

566569
/* Iterate over reflog entries in the log for `refname`. */
567570

0 commit comments

Comments
 (0)