Hi, inspired by recent discussions about handling transactions in git-update-refs(1), this series implements proper transaction support in `git update-refs --stdin`. The goal is to have an all-or-nothing transaction where a user can queue multiple updates, verify that they can be committed, and then finally either commits or aborts the transaction. A typical session would look like the following: # Start the transaction > start < start: ok # Queue updates > delete refs/heads/branch > create refs/heads/another $OID1 # Prepare the transaction. git-update-ref will now try to allocate # all locks and verify that references are at their expected values. > prepare < prepare: ok # Commit the transaction. The user could also have said "abort" to # roll back everything. > commit < commit: ok The series builds on the already existing transaction support in refs.c and exposes it to the user. The most important change that was required to support this was to convert `git-update-ref --stdin` to handle input linewise instead of trying to read it in full and only acting after stdin was closed. The series is structured as follows: Patches 1-2: Preparatory patches which make sense as standalone patches. Patches 3-7: Preparatory patches that make it easier to convert to reading commands in a line-wise fashion. No functional changes are expected. Patch 8: Conversion to read commands line-wise. No functional changes are expected, except that Git builds up the transaction while reading stdin instead of waiting for stdin to be closed first. Patch 9: Implementation of transactional commands. All in all, the new transactional support will only be enabled if the user invokes any the new commands "start", "prepare", "commit" or "abort". In case he doesn't, no functional changes are expected. Patrick Patrick Steinhardt (9): refs: fix segfault when aborting empty transaction git-update-ref.txt: add missing word strbuf: provide function to append whole lines update-ref: organize commands in an array update-ref: drop unused argument for `parse_refname` update-ref: pass end pointer instead of strbuf update-ref: move transaction handling into `update_refs_stdin()` update-ref: read commands in a line-wise fashion update-ref: implement interactive transaction handling Documentation/git-update-ref.txt | 28 +++- builtin/update-ref.c | 255 ++++++++++++++++++++++--------- refs/files-backend.c | 20 +-- strbuf.c | 10 ++ strbuf.h | 6 + t/t1400-update-ref.sh | 131 ++++++++++++++++ 6 files changed, 370 insertions(+), 80 deletions(-) -- 2.26.0
Attachment:
signature.asc
Description: PGP signature