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

Re: [PATCH v2 8/8] refs: add support for migrating reflogs

From
karthik nayak <karthik.188@gmail.com>
Date
Dec 15, 2024, 11:09 UTC
Message-ID
<CAOLa=ZQ9SHD3gzTVaznGhkCBjrrJbHm1fDyi1F-h6VZvtdpxgw@mail.gmail.com>
In-Reply-To
<Z1wngv1Kox_QQcwK@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 49 quoted lines
> On Fri, Dec 13, 2024 at 11:36:53AM +0100, Karthik Nayak wrote:
>> diff --git a/refs.c b/refs.c
>> index 9f539369bc94a25594adc3e95847f2fe72f58a08..f19292d50f0003881220e8f7cfcf6c7eb4b2e749 100644
>> --- a/refs.c
>> +++ b/refs.c
>> @@ -2708,6 +2710,53 @@ static int migrate_one_ref(const char *refname, const char *referent UNUSED, con
>>  	return ret;
>>  }
>>
>> +struct reflog_migration_data {
>> +	unsigned int *index;
>> +	const char *refname;
>> +	struct ref_store *old_refs;
>> +	struct ref_transaction *transaction;
>> +	struct strbuf *errbuf;
>> +};
>> +
>> +static int migrate_one_reflog_entry(struct object_id *old_oid,
>> +				    struct object_id *new_oid,
>> +				    const char *committer,
>> +				    timestamp_t timestamp, int tz,
>> +				    const char *msg, void *cb_data)
>> +{
>> +	struct reflog_migration_data *data = cb_data;
>> +	struct strbuf sb = STRBUF_INIT;
>> +	const char *date;
>> +	int ret;
>> +
>> +	date = show_date(timestamp, tz, DATE_MODE(NORMAL));
>> +	/* committer contains name and email */
>> +	strbuf_addstr(&sb, fmt_ident("", committer, WANT_BLANK_IDENT, date, 0));
>> +
>> +	ret = ref_transaction_update_reflog(data->transaction, data->refname,
>> +					    new_oid, old_oid, sb.buf,
>> +					    REF_HAVE_NEW | REF_HAVE_OLD, msg,
>> +					    (*data->index)++, data->errbuf);
>
> This is where we now increment the reflog index to ensure a proper
> ordering.
>
>> +	strbuf_release(&sb);
>> +
>> +	return ret;
>> +}
>
> We're now allocating one buffer per reflog entry. We may want to
> optimize this by having a scratch buffer in `migration_data`, which we
> could then pass on via `reflog_migration_data`.
>
That makes sense, let me do that.
Show 10 quoted lines
>> @@ -2910,6 +2940,11 @@ int repo_migrate_ref_storage_format(struct repository *repo,
>>  	if (ret < 0)
>>  		goto done;
>>
>> +	data.reflog_index = 1;
>
> I'm a bit surprised that we initialize the relfog entry here, because
> that means we now have a globally increasing counter across all reflogs.
> Couldn't we initialize the index per reflog instead? It ultimately does
> not really matter, but feels like the more obvious design to me

Yes, this was needed cause I initially didn't understand how the udpate_index worked and assumed two logs couldn't have the same update_index. I missed changing it, like you said, it works, but I'll fix it.

> Also, is there any specific reason why we start at 1 and not 0? Just curious.

Not really, I wanted to distinguish between index entries vs non-indexed entries. But logically, no, I'll remove it, to remove any confusion.

> Patrick
Thanks
Previous: Patrick SteinhardtNext: Karthik Nayak
Message 20 of 63 in “refs: add reflog support to `git refs migrate`”
  1. 0/8 refs: add reflog support to `git refs migrate`Karthik Nayak, Dec 13, 2024
  2. 1/8 refs: include committer info in `ref_update` structKarthik Nayak, Dec 13, 2024
  3. 2/8 refs: add `index` field to `struct ref_udpate`Karthik Nayak, Dec 13, 2024
  4. 3/8 refs/files: add count field to ref_lockKarthik Nayak, Dec 13, 2024
  5. 4/8 refs: extract out refname verification in transactionsKarthik Nayak, Dec 13, 2024
  6. 5/8 refs: add `committer_info` to `ref_transaction_add_update()`Karthik Nayak, Dec 13, 2024
  7. Patrick SteinhardtDec 13, 2024
  8. karthik nayakDec 13, 2024
  9. Toon ClaesDec 19, 2024
  10. karthik nayakDec 20, 2024
  11. 6/8 refs: introduce the `ref_transaction_update_reflog` functionKarthik Nayak, Dec 13, 2024
  12. Christian CouderDec 13, 2024
  13. karthik nayakDec 13, 2024
  14. Patrick SteinhardtDec 13, 2024
  15. 7/8 refs: allow multiple reflog entries for the same refnameKarthik Nayak, Dec 13, 2024
  16. Patrick SteinhardtDec 13, 2024
  17. karthik nayakDec 13, 2024
  18. 8/8 refs: add support for migrating reflogsKarthik Nayak, Dec 13, 2024
  19. Patrick SteinhardtDec 13, 2024
  20. karthik nayakDec 15, 2024
  21. 0/8 refs: add reflog support to `git refs migrate`Karthik Nayak, Dec 15, 2024
  22. 1/8 refs: include committer info in `ref_update` structKarthik Nayak, Dec 15, 2024
  23. 2/8 refs: add `index` field to `struct ref_udpate`Karthik Nayak, Dec 15, 2024
  24. 3/8 refs/files: add count field to ref_lockKarthik Nayak, Dec 15, 2024
  25. 4/8 refs: extract out refname verification in transactionsKarthik Nayak, Dec 15, 2024
  26. 5/8 refs: add `committer_info` to `ref_transaction_add_update()`Karthik Nayak, Dec 15, 2024
  27. 6/8 refs: introduce the `ref_transaction_update_reflog` functionKarthik Nayak, Dec 15, 2024
  28. 7/8 refs: allow multiple reflog entries for the same refnameKarthik Nayak, Dec 15, 2024
  29. 8/8 refs: add support for migrating reflogsKarthik Nayak, Dec 15, 2024
  30. Patrick SteinhardtDec 16, 2024
  31. Junio C HamanoDec 16, 2024
  32. karthik nayakDec 16, 2024
  33. Junio C HamanoDec 15, 2024
  34. karthik nayakDec 16, 2024
  35. Junio C HamanoDec 16, 2024
  36. 0/8 refs: add reflog support to `git refs migrate`Karthik Nayak, Dec 16, 2024
  37. 1/8 refs: include committer info in `ref_update` structKarthik Nayak, Dec 16, 2024
  38. 2/8 refs: add `index` field to `struct ref_udpate`Karthik Nayak, Dec 16, 2024
  39. Toon ClaesDec 19, 2024
  40. karthik nayakDec 20, 2024
  41. 3/8 refs/files: add count field to ref_lockKarthik Nayak, Dec 16, 2024
  42. 4/8 refs: extract out refname verification in transactionsKarthik Nayak, Dec 16, 2024
  43. Toon ClaesDec 19, 2024
  44. karthik nayakDec 20, 2024
  45. 5/8 refs: add `committer_info` to `ref_transaction_add_update()`Karthik Nayak, Dec 16, 2024
  46. Toon ClaesDec 19, 2024
  47. karthik nayakDec 20, 2024
  48. 6/8 refs: introduce the `ref_transaction_update_reflog` functionKarthik Nayak, Dec 16, 2024
  49. Toon ClaesDec 19, 2024
  50. Junio C HamanoDec 19, 2024
  51. karthik nayakDec 20, 2024
  52. refs: mark invalid refname message for translationKarthik Nayak, Dec 20, 2024
  53. Junio C HamanoDec 20, 2024
  54. Toon ClaesDec 24, 2024
  55. 7/8 refs: allow multiple reflog entries for the same refnameKarthik Nayak, Dec 16, 2024
  56. Toon ClaesDec 19, 2024
  57. karthik nayakDec 20, 2024
  58. 8/8 refs: add support for migrating reflogsKarthik Nayak, Dec 16, 2024
  59. Patrick SteinhardtDec 17, 2024
  60. karthik nayakDec 17, 2024
  61. Junio C HamanoDec 17, 2024
  62. Toon ClaesDec 19, 2024
  63. karthik nayakDec 20, 2024

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.