refs: add `committer_info` to `ref_transaction_add_update()`

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karthik Nayak committed Dec 16, 2024 at 17:44 UTC 4483be36f4477252f785df0c8c40677df8c18828
4 files changed +18 -10
refs.c
+5 -2
@@ -1166,6 +1166,7 @@ struct ref_update *ref_transaction_add_update(
1166 const struct object_id *new_oid,
1167 const struct object_id *old_oid,
1168 const char *new_target, const char *old_target,
1169 + const char *committer_info,
1170 const char *msg)
1171 {
1172 struct ref_update *update;
@@ -1190,8 +1191,10 @@ struct ref_update *ref_transaction_add_update(
1191 oidcpy(&update->new_oid, new_oid);
1192 if ((flags & REF_HAVE_OLD) && old_oid)
1193 oidcpy(&update->old_oid, old_oid);
1193 - if (!(flags & REF_SKIP_CREATE_REFLOG))
1194 + if (!(flags & REF_SKIP_CREATE_REFLOG)) {
1195 + update->committer_info = xstrdup_or_null(committer_info);
1196 update->msg = normalize_reflog_message(msg);
1197 + }
1198
1199 return update;
1200 }
@@ -1253,7 +1256,7 @@ int ref_transaction_update(struct ref_transaction *transaction,
1256
1257 ref_transaction_add_update(transaction, refname, flags,
1258 new_oid, old_oid, new_target,
1256 - old_target, msg);
1259 + old_target, NULL, msg);
1260 return 0;
1261 }
1262
refs/files-backend.c
+8 -6
@@ -1270,7 +1270,7 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
1270 ref_transaction_add_update(
1271 transaction, r->name,
1272 REF_NO_DEREF | REF_HAVE_NEW | REF_HAVE_OLD | REF_IS_PRUNING,
1273 - null_oid(), &r->oid, NULL, NULL, NULL);
1273 + null_oid(), &r->oid, NULL, NULL, NULL, NULL);
1274 if (ref_transaction_commit(transaction, &err))
1275 goto cleanup;
1276
@@ -2417,7 +2417,7 @@ static int split_head_update(struct ref_update *update,
2417 transaction, "HEAD",
2418 update->flags | REF_LOG_ONLY | REF_NO_DEREF,
2419 &update->new_oid, &update->old_oid,
2420 - NULL, NULL, update->msg);
2420 + NULL, NULL, update->committer_info, update->msg);
2421
2422 /*
2423 * Add "HEAD". This insertion is O(N) in the transaction
@@ -2481,7 +2481,8 @@ static int split_symref_update(struct ref_update *update,
2481 transaction, referent, new_flags,
2482 update->new_target ? NULL : &update->new_oid,
2483 update->old_target ? NULL : &update->old_oid,
2484 - update->new_target, update->old_target, update->msg);
2484 + update->new_target, update->old_target, NULL,
2485 + update->msg);
2486
2487 new_update->parent_update = update;
2488
@@ -2914,7 +2915,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,
2915 packed_transaction, update->refname,
2916 REF_HAVE_NEW | REF_NO_DEREF,
2917 &update->new_oid, NULL,
2917 - NULL, NULL, NULL);
2918 + NULL, NULL, NULL, NULL);
2919 }
2920 }
2921
@@ -3094,12 +3095,13 @@ static int files_transaction_finish_initial(struct files_ref_store *refs,
3095 ref_transaction_add_update(loose_transaction, update->refname,
3096 update->flags & ~REF_HAVE_OLD,
3097 update->new_target ? NULL : &update->new_oid, NULL,
3097 - update->new_target, NULL, NULL);
3098 + update->new_target, NULL, update->committer_info,
3099 + NULL);
3100 } else {
3101 ref_transaction_add_update(packed_transaction, update->refname,
3102 update->flags & ~REF_HAVE_OLD,
3103 &update->new_oid, &update->old_oid,
3102 - NULL, NULL, NULL);
3104 + NULL, NULL, update->committer_info, NULL);
3105 }
3106 }
3107
refs/refs-internal.h
+1
@@ -162,6 +162,7 @@ struct ref_update *ref_transaction_add_update(
162 const struct object_id *new_oid,
163 const struct object_id *old_oid,
164 const char *new_target, const char *old_target,
165 + const char *committer_info,
166 const char *msg);
167
168 /*
refs/reftable-backend.c
+4 -2
@@ -1078,7 +1078,8 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
1078 new_update = ref_transaction_add_update(
1079 transaction, "HEAD",
1080 u->flags | REF_LOG_ONLY | REF_NO_DEREF,
1081 - &u->new_oid, &u->old_oid, NULL, NULL, u->msg);
1081 + &u->new_oid, &u->old_oid, NULL, NULL, NULL,
1082 + u->msg);
1083 string_list_insert(&affected_refnames, new_update->refname);
1084 }
1085
@@ -1161,7 +1162,8 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
1162 transaction, referent.buf, new_flags,
1163 u->new_target ? NULL : &u->new_oid,
1164 u->old_target ? NULL : &u->old_oid,
1164 - u->new_target, u->old_target, u->msg);
1165 + u->new_target, u->old_target,
1166 + u->committer_info, u->msg);
1167
1168 new_update->parent_update = u;
1169