From: Junio C Hamano Date: Wed, 10 Jun 2026 16:25:41 GMT Subject: Re: [PATCH v4 09/10] builtin/history: split handling of ref updates into two phases Message-ID: In-Reply-To: <20260610-b4-pks-history-drop-v4-9-70d5f0ae8c25@pks.im> Patrick Steinhardt writes: > The function `handle_reference_updates()` is used by git-history(1) to > update all references that refer to commits that have been rewritten. As > such, it performs two steps: > > - It gathers the references that need to be updated in the first > place. > > - It prepares and commits the reference transaction. > > In a subsequent commit we'll want to handle those two steps separately. > Prepare for this by splitting up the function into two. OK. I can sees how this will help doing a dry-run mode. > +static int apply_pending_ref_updates(struct repository *repo, > + const struct replay_result *result, > + const char *reflog_msg, > + int dry_run) > +{ > + struct ref_transaction *transaction = NULL; > + struct strbuf err = STRBUF_INIT; > + int ret; > + > + if (!dry_run) { > + transaction = ref_store_transaction_begin(get_main_ref_store(repo), > + 0, &err); > + if (!transaction) { > + ret = error(_("failed to begin ref transaction: %s"), err.buf); > + goto out; > + } > + } > + > + for (size_t i = 0; i < result->updates_nr; i++) { > ret = handle_ref_update(transaction, > - decoration->name, > - &rewritten->object.oid, > - &original->object.oid, > + result->updates[i].refname, > + &result->updates[i].new_oid, > + &result->updates[i].old_oid, > reflog_msg, &err); Cute. handle_ref_update() uses transaction==NULL not as a signal to update each ref as request comes (i.e., non-transactional updates) but as a singal to perform a dry-run, which was unexpected to my taste but it has been that way since at least February this year ;-) Looking good. Thanks.