update-ref: read commands in a line-wise fashion
commit94fd491a54b955990146f63e7283e9813dc85fef
authorPatrick Steinhardt <ps@pks.im>
Thu, 2 Apr 2020 07:09:57 +0000 (2 09:09 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Apr 2020 18:09:49 +0000 (2 11:09 -0700)
tree031acd3d064226897ed11ebeacf4615cdccdf10d
parentde0e0d650a1c2afc81a4c5e8d37d266ffa2b8ccf
update-ref: read commands in a line-wise fashion

The git-update-ref(1) supports a `--stdin` mode that allows it to read
all reference updates from standard input. This is mainly used to allow
for atomic reference updates that are all or nothing, so that either all
references will get updated or none.

Currently, git-update-ref(1) reads all commands as a single block of up
to 1000 characters and only starts processing after stdin gets closed.
This is less flexible than one might wish for, as it doesn't really
allow for longer-lived transactions and doesn't allow any verification
without committing everything. E.g. one may imagine the following
exchange:

    > start
    < start: ok
    > update refs/heads/master $NEWOID1 $OLDOID1
    > update refs/heads/branch $NEWOID2 $OLDOID2
    > prepare
    < prepare: ok
    > commit
    < commit: ok

When reading all input as a whole block, the above interactive protocol
is obviously impossible to achieve. But by converting the command to
read commands linewise, we can make it more interactive than before.

Obviously, the linewise interface is only a first step in making
git-update-ref(1) work in a more transaction-oriented way. Missing is
most importantly support for transactional commands that manage the
current transaction.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/update-ref.c