Message ID | 20241213-320-git-refs-migrate-reflogs-v2-5-f28312cdb6c0@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | refs: add reflog support to `git refs migrate` | expand |
On Fri, Dec 13, 2024 at 11:36:50AM +0100, Karthik Nayak wrote: > The `ref_transaction_add_update()` creates the `ref_update` struct. To > facilitate addition of reflogs in the next commit, the function needs to > accommodate setting the `committer_info` field in the struct. So modify > the function to also take `committer_info` as an argument and set it > accordingly. I was wondering a bit whether we could instead pull out a `add_update_internal()` function so that we don't need to modify all callers of `ref_transaction_add_update()`. Because ultimately, we don't use the field anywhere except from `ref_transaction_add_reflog_update()` as far as I can see. This is more of a thought than a strong opinion, so feel free to ignore. > @@ -1190,8 +1191,12 @@ struct ref_update *ref_transaction_add_update( > oidcpy(&update->new_oid, new_oid); > if ((flags & REF_HAVE_OLD) && old_oid) > oidcpy(&update->old_oid, old_oid); > - if (!(flags & REF_SKIP_CREATE_REFLOG)) > + if (!(flags & REF_SKIP_CREATE_REFLOG)) { > + if (committer_info) > + update->committer_info = xstrdup(committer_info); > + > update->msg = normalize_reflog_message(msg); > + } > > return update; > } This can use `xstrdup_or_null()` and then drop the condition. Patrick
Patrick Steinhardt <ps@pks.im> writes: > On Fri, Dec 13, 2024 at 11:36:50AM +0100, Karthik Nayak wrote: >> The `ref_transaction_add_update()` creates the `ref_update` struct. To >> facilitate addition of reflogs in the next commit, the function needs to >> accommodate setting the `committer_info` field in the struct. So modify >> the function to also take `committer_info` as an argument and set it >> accordingly. > > I was wondering a bit whether we could instead pull out a > `add_update_internal()` function so that we don't need to modify all > callers of `ref_transaction_add_update()`. Because ultimately, we don't > use the field anywhere except from `ref_transaction_add_reflog_update()` > as far as I can see. > > This is more of a thought than a strong opinion, so feel free to ignore. > Yes, that is a possible change, but the number of code changes are relatively low and I didn't think it made so much difference. Also because we'd now have one more function. But I don't mind doing it either, if anyone feels strongly about it, I'll happily make that change. >> @@ -1190,8 +1191,12 @@ struct ref_update *ref_transaction_add_update( >> oidcpy(&update->new_oid, new_oid); >> if ((flags & REF_HAVE_OLD) && old_oid) >> oidcpy(&update->old_oid, old_oid); >> - if (!(flags & REF_SKIP_CREATE_REFLOG)) >> + if (!(flags & REF_SKIP_CREATE_REFLOG)) { >> + if (committer_info) >> + update->committer_info = xstrdup(committer_info); >> + >> update->msg = normalize_reflog_message(msg); >> + } >> >> return update; >> } > > This can use `xstrdup_or_null()` and then drop the condition. > > Patrick That is good improvement, will add. Thanks!
diff --git a/refs.c b/refs.c index 9c9f4940c60d3cdd34ce8f1e668d17b9da3cd801..428ca256f3e5860554e9a7fa42a8368bb2689b31 100644 --- a/refs.c +++ b/refs.c @@ -1166,6 +1166,7 @@ struct ref_update *ref_transaction_add_update( const struct object_id *new_oid, const struct object_id *old_oid, const char *new_target, const char *old_target, + const char *committer_info, const char *msg) { struct ref_update *update; @@ -1190,8 +1191,12 @@ struct ref_update *ref_transaction_add_update( oidcpy(&update->new_oid, new_oid); if ((flags & REF_HAVE_OLD) && old_oid) oidcpy(&update->old_oid, old_oid); - if (!(flags & REF_SKIP_CREATE_REFLOG)) + if (!(flags & REF_SKIP_CREATE_REFLOG)) { + if (committer_info) + update->committer_info = xstrdup(committer_info); + update->msg = normalize_reflog_message(msg); + } return update; } @@ -1253,7 +1258,7 @@ int ref_transaction_update(struct ref_transaction *transaction, ref_transaction_add_update(transaction, refname, flags, new_oid, old_oid, new_target, - old_target, msg); + old_target, NULL, msg); return 0; } diff --git a/refs/files-backend.c b/refs/files-backend.c index 02cb4907d8659e87a227fed4f60a5f6606be8764..255fed8354cae982f785b1b85340e2a1eeecf2a6 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1270,7 +1270,7 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r) ref_transaction_add_update( transaction, r->name, REF_NO_DEREF | REF_HAVE_NEW | REF_HAVE_OLD | REF_IS_PRUNING, - null_oid(), &r->oid, NULL, NULL, NULL); + null_oid(), &r->oid, NULL, NULL, NULL, NULL); if (ref_transaction_commit(transaction, &err)) goto cleanup; @@ -2417,7 +2417,7 @@ static int split_head_update(struct ref_update *update, transaction, "HEAD", update->flags | REF_LOG_ONLY | REF_NO_DEREF, &update->new_oid, &update->old_oid, - NULL, NULL, update->msg); + NULL, NULL, update->committer_info, update->msg); /* * Add "HEAD". This insertion is O(N) in the transaction @@ -2481,7 +2481,8 @@ static int split_symref_update(struct ref_update *update, transaction, referent, new_flags, update->new_target ? NULL : &update->new_oid, update->old_target ? NULL : &update->old_oid, - update->new_target, update->old_target, update->msg); + update->new_target, update->old_target, NULL, + update->msg); new_update->parent_update = update; @@ -2914,7 +2915,7 @@ static int files_transaction_prepare(struct ref_store *ref_store, packed_transaction, update->refname, REF_HAVE_NEW | REF_NO_DEREF, &update->new_oid, NULL, - NULL, NULL, NULL); + NULL, NULL, NULL, NULL); } } @@ -3094,12 +3095,13 @@ static int files_transaction_finish_initial(struct files_ref_store *refs, ref_transaction_add_update(loose_transaction, update->refname, update->flags & ~REF_HAVE_OLD, update->new_target ? NULL : &update->new_oid, NULL, - update->new_target, NULL, NULL); + update->new_target, NULL, update->committer_info, + NULL); } else { ref_transaction_add_update(packed_transaction, update->refname, update->flags & ~REF_HAVE_OLD, &update->new_oid, &update->old_oid, - NULL, NULL, NULL); + NULL, NULL, update->committer_info, NULL); } } diff --git a/refs/refs-internal.h b/refs/refs-internal.h index f5c733d099f0c6f1076a25f4f77d9d5eb345ec87..79b287c5ec5c7d8f759869cf93cda405640186dc 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -162,6 +162,7 @@ struct ref_update *ref_transaction_add_update( const struct object_id *new_oid, const struct object_id *old_oid, const char *new_target, const char *old_target, + const char *committer_info, const char *msg); /* diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index c008f20be719fec3af6a8f81c821cb9c263764d7..b2e3ba877de9e59fea5a4d066eb13e60ef22a32b 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -1078,7 +1078,8 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, new_update = ref_transaction_add_update( transaction, "HEAD", u->flags | REF_LOG_ONLY | REF_NO_DEREF, - &u->new_oid, &u->old_oid, NULL, NULL, u->msg); + &u->new_oid, &u->old_oid, NULL, NULL, NULL, + u->msg); string_list_insert(&affected_refnames, new_update->refname); } @@ -1161,7 +1162,8 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, transaction, referent.buf, new_flags, u->new_target ? NULL : &u->new_oid, u->old_target ? NULL : &u->old_oid, - u->new_target, u->old_target, u->msg); + u->new_target, u->old_target, + u->committer_info, u->msg); new_update->parent_update = u;
The `ref_transaction_add_update()` creates the `ref_update` struct. To facilitate addition of reflogs in the next commit, the function needs to accommodate setting the `committer_info` field in the struct. So modify the function to also take `committer_info` as an argument and set it accordingly. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> --- refs.c | 9 +++++++-- refs/files-backend.c | 14 ++++++++------ refs/refs-internal.h | 1 + refs/reftable-backend.c | 6 ++++-- 4 files changed, 20 insertions(+), 10 deletions(-)