Skip to content

Commit 2f530e5

Browse files
pks-tgitster
authored andcommitted
refs: simplify logic when migrating reflog entries
When migrating reflog entries between two storage formats we have to do so via two callback-driven functions: - `migrate_one_reflog()` gets invoked via `refs_for_each_reflog()` to first list all available reflogs. - `migrate_one_reflog_entry()` gets invoked via `refs_for_each_reflog_ent()` in `migrate_one_reflog()`. Before the preceding commit we didn't have the refname available in `migrate_one_reflog_entry()`, which made it necessary to have a separate structure that we pass to the second callback so that we can propagate the refname. Now that `refs_for_each_reflog_ent()` knows to pass the refname to the callback though that indirection isn't necessary anymore. There's one catch though: we do have an update index that is also stored in the entry-specific callback data. This update index is required so that we can tell the ref backend in which order it should persist the reflog entries to disk. But that purpose can be trivially achieved by just converting it into a global counter that is used for all reflog entries, regardless of which reference they are for. The ordering will remain the same as both the update index and the refname is considered when sorting the entries. Move the index into `struct migration_data` and drop the now-unused `struct reflog_migration_data` to simplify the code a bit. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b9fd73a commit 2f530e5

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

refs.c

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,6 +2941,7 @@ struct migration_data {
29412941
struct ref_transaction *transaction;
29422942
struct strbuf *errbuf;
29432943
struct strbuf sb, name, mail;
2944+
uint64_t index;
29442945
};
29452946

29462947
static int migrate_one_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
@@ -2973,58 +2974,41 @@ static int migrate_one_ref(const char *refname, const char *referent UNUSED, con
29732974
return ret;
29742975
}
29752976

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-
29842977
static int migrate_one_reflog_entry(const char *refname,
29852978
struct object_id *old_oid,
29862979
struct object_id *new_oid,
29872980
const char *committer,
29882981
timestamp_t timestamp, int tz,
29892982
const char *msg, void *cb_data)
29902983
{
2991-
struct reflog_migration_data *data = cb_data;
2984+
struct migration_data *data = cb_data;
29922985
struct ident_split ident;
29932986
const char *date;
29942987
int ret;
29952988

29962989
if (split_ident_line(&ident, committer, strlen(committer)) < 0)
29972990
return -1;
29982991

2999-
strbuf_reset(data->name);
3000-
strbuf_add(data->name, ident.name_begin, ident.name_end - ident.name_begin);
3001-
strbuf_reset(data->mail);
3002-
strbuf_add(data->mail, ident.mail_begin, ident.mail_end - ident.mail_begin);
2992+
strbuf_reset(&data->name);
2993+
strbuf_add(&data->name, ident.name_begin, ident.name_end - ident.name_begin);
2994+
strbuf_reset(&data->mail);
2995+
strbuf_add(&data->mail, ident.mail_begin, ident.mail_end - ident.mail_begin);
30032996

30042997
date = show_date(timestamp, tz, DATE_MODE(NORMAL));
3005-
strbuf_reset(data->sb);
3006-
strbuf_addstr(data->sb, fmt_ident(data->name->buf, data->mail->buf, WANT_BLANK_IDENT, date, 0));
2998+
strbuf_reset(&data->sb);
2999+
strbuf_addstr(&data->sb, fmt_ident(data->name.buf, data->mail.buf, WANT_BLANK_IDENT, date, 0));
30073000

30083001
ret = ref_transaction_update_reflog(data->transaction, refname,
3009-
new_oid, old_oid, data->sb->buf,
3002+
new_oid, old_oid, data->sb.buf,
30103003
msg, data->index++, data->errbuf);
30113004
return ret;
30123005
}
30133006

30143007
static int migrate_one_reflog(const char *refname, void *cb_data)
30153008
{
30163009
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,
3021-
.sb = &migration_data->sb,
3022-
.name = &migration_data->name,
3023-
.mail = &migration_data->mail,
3024-
};
3025-
30263010
return refs_for_each_reflog_ent(migration_data->old_refs, refname,
3027-
migrate_one_reflog_entry, &data);
3011+
migrate_one_reflog_entry, migration_data);
30283012
}
30293013

30303014
static int move_files(const char *from_path, const char *to_path, struct strbuf *errbuf)

0 commit comments

Comments
 (0)