Skip to content

Commit ec922e0

Browse files
pks-tgitster
authored andcommitted
refs: fix identity for migrated reflogs
When migrating reflog entries between different storage formats we must reconstruct the identity of reflog entries. This is done by passing the committer passed to the `migrate_one_reflog_entry()` callback function to `fmt_ident()`. This results in an invalid identity though: `fmt_ident()` expects the caller to provide both name and mail of the author, but we pass the full identity as mail. This leads to an identity like: pks <Patrick Steinhardt [email protected]> Fix the bug by splitting the identity line first. This allows us to extract both the name and mail so that we can pass them to `fmt_ident()` separately. This commit does not yet add any tests as there is another bug in the reflog migration that will be fixed in a subsequent commit. Once that bug is fixed we'll make the reflog verification in t1450 stricter, and that will catch both this bug here and the other bug. Note that we also add two new `name` and `mail` string buffers to the callback structures and splice them through to the callbacks. This is done so that we can avoid allocating a new buffer every time we compute the committer information. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9fdbba8 commit ec922e0

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

refs.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2954,7 +2954,7 @@ struct migration_data {
29542954
struct ref_store *old_refs;
29552955
struct ref_transaction *transaction;
29562956
struct strbuf *errbuf;
2957-
struct strbuf sb;
2957+
struct strbuf sb, name, mail;
29582958
};
29592959

29602960
static int migrate_one_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
@@ -2993,7 +2993,7 @@ struct reflog_migration_data {
29932993
struct ref_store *old_refs;
29942994
struct ref_transaction *transaction;
29952995
struct strbuf *errbuf;
2996-
struct strbuf *sb;
2996+
struct strbuf *sb, *name, *mail;
29972997
};
29982998

29992999
static int migrate_one_reflog_entry(struct object_id *old_oid,
@@ -3003,13 +3003,21 @@ static int migrate_one_reflog_entry(struct object_id *old_oid,
30033003
const char *msg, void *cb_data)
30043004
{
30053005
struct reflog_migration_data *data = cb_data;
3006+
struct ident_split ident;
30063007
const char *date;
30073008
int ret;
30083009

3010+
if (split_ident_line(&ident, committer, strlen(committer)) < 0)
3011+
return -1;
3012+
3013+
strbuf_reset(data->name);
3014+
strbuf_add(data->name, ident.name_begin, ident.name_end - ident.name_begin);
3015+
strbuf_reset(data->mail);
3016+
strbuf_add(data->mail, ident.mail_begin, ident.mail_end - ident.mail_begin);
3017+
30093018
date = show_date(timestamp, tz, DATE_MODE(NORMAL));
30103019
strbuf_reset(data->sb);
3011-
/* committer contains name and email */
3012-
strbuf_addstr(data->sb, fmt_ident("", committer, WANT_BLANK_IDENT, date, 0));
3020+
strbuf_addstr(data->sb, fmt_ident(data->name->buf, data->mail->buf, WANT_BLANK_IDENT, date, 0));
30133021

30143022
ret = ref_transaction_update_reflog(data->transaction, data->refname,
30153023
new_oid, old_oid, data->sb->buf,
@@ -3026,6 +3034,8 @@ static int migrate_one_reflog(const char *refname, void *cb_data)
30263034
.transaction = migration_data->transaction,
30273035
.errbuf = migration_data->errbuf,
30283036
.sb = &migration_data->sb,
3037+
.name = &migration_data->name,
3038+
.mail = &migration_data->mail,
30293039
};
30303040

30313041
return refs_for_each_reflog_ent(migration_data->old_refs, refname,
@@ -3124,6 +3134,8 @@ int repo_migrate_ref_storage_format(struct repository *repo,
31243134
struct strbuf new_gitdir = STRBUF_INIT;
31253135
struct migration_data data = {
31263136
.sb = STRBUF_INIT,
3137+
.name = STRBUF_INIT,
3138+
.mail = STRBUF_INIT,
31273139
};
31283140
int did_migrate_refs = 0;
31293141
int ret;
@@ -3299,6 +3311,8 @@ int repo_migrate_ref_storage_format(struct repository *repo,
32993311
ref_transaction_free(transaction);
33003312
strbuf_release(&new_gitdir);
33013313
strbuf_release(&data.sb);
3314+
strbuf_release(&data.name);
3315+
strbuf_release(&data.mail);
33023316
return ret;
33033317
}
33043318

0 commit comments

Comments
 (0)