git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 6/9] refs: fix identity for migrated reflogs

From
Patrick Steinhardt <ps@pks.im>
Date
Jul 29, 2025, 08:55 UTC
Message-ID
<20250729-pks-reflog-append-v3-6-9614d310f073@pks.im>
In-Reply-To
<20250729-pks-reflog-append-v3-0-9614d310f073@pks.im>

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 ps@pks.im>

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 <ps@pks.im>
---
 refs.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/refs.c b/refs.c
index 8aa9f7236a3..a5f9ffaa45d 100644
--- a/refs.c
+++ b/refs.c
@@ -2954,7 +2954,7 @@ struct migration_data {
 	struct ref_store *old_refs;
 	struct ref_transaction *transaction;
 	struct strbuf *errbuf;
-	struct strbuf sb;
+	struct strbuf sb, name, mail;
 };
 
 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 {
 	struct ref_store *old_refs;
 	struct ref_transaction *transaction;
 	struct strbuf *errbuf;
-	struct strbuf *sb;
+	struct strbuf *sb, *name, *mail;
 };
 
 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,
 				    const char *msg, void *cb_data)
 {
 	struct reflog_migration_data *data = cb_data;
+	struct ident_split ident;
 	const char *date;
 	int ret;
 
+	if (split_ident_line(&ident, committer, strlen(committer)) < 0)
+		return -1;
+
+	strbuf_reset(data->name);
+	strbuf_add(data->name, ident.name_begin, ident.name_end - ident.name_begin);
+	strbuf_reset(data->mail);
+	strbuf_add(data->mail, ident.mail_begin, ident.mail_end - ident.mail_begin);
+
 	date = show_date(timestamp, tz, DATE_MODE(NORMAL));
 	strbuf_reset(data->sb);
-	/* committer contains name and email */
-	strbuf_addstr(data->sb, fmt_ident("", committer, WANT_BLANK_IDENT, date, 0));
+	strbuf_addstr(data->sb, fmt_ident(data->name->buf, data->mail->buf, WANT_BLANK_IDENT, date, 0));
 
 	ret = ref_transaction_update_reflog(data->transaction, data->refname,
 					    new_oid, old_oid, data->sb->buf,
@@ -3026,6 +3034,8 @@ static int migrate_one_reflog(const char *refname, void *cb_data)
 		.transaction = migration_data->transaction,
 		.errbuf = migration_data->errbuf,
 		.sb = &migration_data->sb,
+		.name = &migration_data->name,
+		.mail = &migration_data->mail,
 	};
 
 	return refs_for_each_reflog_ent(migration_data->old_refs, refname,
@@ -3124,6 +3134,8 @@ int repo_migrate_ref_storage_format(struct repository *repo,
 	struct strbuf new_gitdir = STRBUF_INIT;
 	struct migration_data data = {
 		.sb = STRBUF_INIT,
+		.name = STRBUF_INIT,
+		.mail = STRBUF_INIT,
 	};
 	int did_migrate_refs = 0;
 	int ret;
@@ -3299,6 +3311,8 @@ int repo_migrate_ref_storage_format(struct repository *repo,
 	ref_transaction_free(transaction);
 	strbuf_release(&new_gitdir);
 	strbuf_release(&data.sb);
+	strbuf_release(&data.name);
+	strbuf_release(&data.mail);
 	return ret;
 }
 
-- 
2.50.1.619.g074bbf1d35.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 70 of 114 in “refs: fix migration of reflog entries”
  1. 0/8 refs: fix migration of reflog entriesPatrick Steinhardt, Jul 22, 2025
  2. 1/8 Documentation/git-reflog: convert to use synopsis typePatrick Steinhardt, Jul 22, 2025
  3. Junio C HamanoJul 22, 2025
  4. 2/8 builtin/reflog: improve grouping of subcommandsPatrick Steinhardt, Jul 22, 2025
  5. Justin ToblerJul 23, 2025
  6. Patrick SteinhardtJul 24, 2025
  7. Junio C HamanoJul 24, 2025
  8. 3/8 refs: export `ref_transaction_update_reflog()`Patrick Steinhardt, Jul 22, 2025
  9. Justin ToblerJul 23, 2025
  10. Karthik NayakJul 24, 2025
  11. Toon ClaesJul 24, 2025
  12. 4/8 builtin/reflog: implement subcommand to write new entriesPatrick Steinhardt, Jul 22, 2025
  13. Justin ToblerJul 23, 2025
  14. Patrick SteinhardtJul 24, 2025
  15. Toon ClaesJul 24, 2025
  16. Patrick SteinhardtJul 25, 2025
  17. SZEDER GáborJul 24, 2025
  18. Junio C HamanoJul 24, 2025
  19. Patrick SteinhardtJul 25, 2025
  20. Junio C HamanoJul 25, 2025
  21. 5/8 ident: fix type of string length parameterPatrick Steinhardt, Jul 22, 2025
  22. 6/8 refs: fix identity for migrated reflogsPatrick Steinhardt, Jul 22, 2025
  23. Justin ToblerJul 23, 2025
  24. Patrick SteinhardtJul 24, 2025
  25. Karthik NayakJul 24, 2025
  26. Toon ClaesJul 24, 2025
  27. 7/8 refs: stop unsetting REF_HAVE_OLD for log-only updatesPatrick Steinhardt, Jul 22, 2025
  28. Justin ToblerJul 23, 2025
  29. Patrick SteinhardtJul 24, 2025
  30. Karthik NayakJul 24, 2025
  31. Patrick SteinhardtJul 24, 2025
  32. 8/8 refs: fix invalid old object IDs when migrating reflogsPatrick Steinhardt, Jul 22, 2025
  33. Junio C HamanoJul 22, 2025
  34. Patrick SteinhardtJul 23, 2025
  35. 0/8 refs: fix migration of reflog entriesPatrick Steinhardt, Jul 25, 2025
  36. 1/8 Documentation/git-reflog: convert to use synopsis typePatrick Steinhardt, Jul 25, 2025
  37. 2/8 builtin/reflog: improve grouping of subcommandsPatrick Steinhardt, Jul 25, 2025
  38. 3/8 refs: export `ref_transaction_update_reflog()`Patrick Steinhardt, Jul 25, 2025
  39. 4/8 builtin/reflog: implement subcommand to write new entriesPatrick Steinhardt, Jul 25, 2025
  40. Kristoffer HaugsbakkJul 28, 2025
  41. Junio C HamanoJul 28, 2025
  42. Karthik NayakJul 28, 2025
  43. Junio C HamanoJul 28, 2025
  44. Karthik NayakJul 30, 2025
  45. Ben KnobleJul 29, 2025
  46. Kristoffer HaugsbakkJul 29, 2025
  47. Patrick SteinhardtJul 29, 2025
  48. Junio C HamanoJul 29, 2025
  49. Patrick SteinhardtJul 30, 2025
  50. Patrick SteinhardtJul 30, 2025
  51. 5/8 ident: fix type of string length parameterPatrick Steinhardt, Jul 25, 2025
  52. 6/8 refs: fix identity for migrated reflogsPatrick Steinhardt, Jul 25, 2025
  53. 7/8 refs: stop unsetting REF_HAVE_OLD for log-only updatesPatrick Steinhardt, Jul 25, 2025
  54. Jeff KingJul 25, 2025
  55. Patrick SteinhardtJul 28, 2025
  56. Jeff KingJul 29, 2025
  57. Patrick SteinhardtJul 29, 2025
  58. 8/8 refs: fix invalid old object IDs when migrating reflogsPatrick Steinhardt, Jul 25, 2025
  59. 0/9 refs: fix migration of reflog entriesPatrick Steinhardt, Jul 29, 2025
  60. 1/9 Documentation/git-reflog: convert to use synopsis typePatrick Steinhardt, Jul 29, 2025
  61. 2/9 builtin/reflog: improve grouping of subcommandsPatrick Steinhardt, Jul 29, 2025
  62. 3/9 refs: export `ref_transaction_update_reflog()`Patrick Steinhardt, Jul 29, 2025
  63. Toon ClaesAug 1, 2025
  64. Patrick SteinhardtAug 4, 2025
  65. 4/9 builtin/reflog: implement subcommand to write new entriesPatrick Steinhardt, Jul 29, 2025
  66. Junio C HamanoJul 29, 2025
  67. Toon ClaesAug 1, 2025
  68. Patrick SteinhardtAug 4, 2025
  69. 5/9 ident: fix type of string length parameterPatrick Steinhardt, Jul 29, 2025
  70. 6/9 refs: fix identity for migrated reflogsPatrick Steinhardt, Jul 29, 2025
  71. 7/9 refs/files: detect race when generating reflog entry for HEADPatrick Steinhardt, Jul 29, 2025
  72. Junio C HamanoJul 29, 2025
  73. Toon ClaesAug 1, 2025
  74. Jeff KingAug 2, 2025
  75. Patrick SteinhardtAug 4, 2025
  76. Jeff KingAug 4, 2025
  77. 8/9 refs: stop unsetting REF_HAVE_OLD for log-only updatesPatrick Steinhardt, Jul 29, 2025
  78. 9/9 refs: fix invalid old object IDs when migrating reflogsPatrick Steinhardt, Jul 29, 2025
  79. 0/9 refs: fix migration of reflog entriesPatrick Steinhardt, Aug 4, 2025
  80. 1/9 Documentation/git-reflog: convert to use synopsis typePatrick Steinhardt, Aug 4, 2025
  81. 2/9 builtin/reflog: improve grouping of subcommandsPatrick Steinhardt, Aug 4, 2025
  82. 3/9 refs: export `ref_transaction_update_reflog()`Patrick Steinhardt, Aug 4, 2025
  83. 4/9 builtin/reflog: implement subcommand to write new entriesPatrick Steinhardt, Aug 4, 2025
  84. 5/9 ident: fix type of string length parameterPatrick Steinhardt, Aug 4, 2025
  85. 6/9 refs: fix identity for migrated reflogsPatrick Steinhardt, Aug 4, 2025
  86. 7/9 refs/files: detect race when generating reflog entry for HEADPatrick Steinhardt, Aug 4, 2025
  87. Jeff KingAug 4, 2025
  88. 8/9 refs: stop unsetting REF_HAVE_OLD for log-only updatesPatrick Steinhardt, Aug 4, 2025
  89. 9/9 refs: fix invalid old object IDs when migrating reflogsPatrick Steinhardt, Aug 4, 2025
  90. 0/9 refs: fix migration of reflog entriesPatrick Steinhardt, Aug 5, 2025
  91. 1/9 Documentation/git-reflog: convert to use synopsis typePatrick Steinhardt, Aug 5, 2025
  92. Jean-Noël AVILAAug 5, 2025
  93. Junio C HamanoAug 5, 2025
  94. Patrick SteinhardtAug 6, 2025
  95. 2/9 builtin/reflog: improve grouping of subcommandsPatrick Steinhardt, Aug 5, 2025
  96. 3/9 refs: export `ref_transaction_update_reflog()`Patrick Steinhardt, Aug 5, 2025
  97. 4/9 builtin/reflog: implement subcommand to write new entriesPatrick Steinhardt, Aug 5, 2025
  98. 5/9 ident: fix type of string length parameterPatrick Steinhardt, Aug 5, 2025
  99. 6/9 refs: fix identity for migrated reflogsPatrick Steinhardt, Aug 5, 2025
  100. 7/9 refs/files: detect race when generating reflog entry for HEADPatrick Steinhardt, Aug 5, 2025
  101. 8/9 refs: stop unsetting REF_HAVE_OLD for log-only updatesPatrick Steinhardt, Aug 5, 2025
  102. 9/9 refs: fix invalid old object IDs when migrating reflogsPatrick Steinhardt, Aug 5, 2025
  103. Jeff KingAug 5, 2025
  104. Patrick SteinhardtAug 6, 2025
  105. 0/9 refs: fix migration of reflog entriesPatrick Steinhardt, Aug 6, 2025
  106. 1/9 Documentation/git-reflog: convert to use synopsis typePatrick Steinhardt, Aug 6, 2025
  107. 2/9 builtin/reflog: improve grouping of subcommandsPatrick Steinhardt, Aug 6, 2025
  108. 3/9 refs: export `ref_transaction_update_reflog()`Patrick Steinhardt, Aug 6, 2025
  109. 4/9 builtin/reflog: implement subcommand to write new entriesPatrick Steinhardt, Aug 6, 2025
  110. 5/9 ident: fix type of string length parameterPatrick Steinhardt, Aug 6, 2025
  111. 6/9 refs: fix identity for migrated reflogsPatrick Steinhardt, Aug 6, 2025
  112. 7/9 refs/files: detect race when generating reflog entry for HEADPatrick Steinhardt, Aug 6, 2025
  113. 8/9 refs: stop unsetting REF_HAVE_OLD for log-only updatesPatrick Steinhardt, Aug 6, 2025
  114. 9/9 refs: fix invalid old object IDs when migrating reflogsPatrick Steinhardt, Aug 6, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.