From: Patrick Steinhardt <ps@pks.im>
To: "SZEDER Gábor" <szeder.dev@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH] refs: implement reference transaction hooks
Date: Mon, 8 Jun 2020 07:36:05 +0200 [thread overview]
Message-ID: <20200608053605.GA851@tanuki> (raw)
In-Reply-To: <20200607201233.GB8232@szeder.dev>
[-- Attachment #1: Type: text/plain, Size: 4210 bytes --]
On Sun, Jun 07, 2020 at 10:12:33PM +0200, SZEDER Gábor wrote:
> On Wed, Jun 03, 2020 at 01:26:04PM +0200, Patrick Steinhardt wrote:
> > On Tue, Jun 02, 2020 at 10:47:55AM -0700, Junio C Hamano wrote:
> > > Patrick Steinhardt <ps@pks.im> writes:
> > >
> > > > The above scenario is the motivation for a set of three new hooks that
> > > > reach directly into Git's reference transaction. Each of the following
> > > > new hooks (currently) doesn't accept any parameters and receives the set
> > > > of queued reference updates via stdin:
> > >
> > > Do we have something (e.g. performance measurement) to convince
> > > ourselves that this won't incur unacceptable levels of overhead in
> > > null cases where there is no hook installed in the repository?
> >
> > Not yet, but I'll try to come up with a benchmark in the next iteration.
> > I guess the best way to test is to directly exercise git-update-refs, as
> > it's nearly a direct wrapper around reference transactions.
> >
> > > > + proc.in = -1;
> > > > + proc.stdout_to_stderr = 1;
> > > > + proc.trace2_hook_name = hook_name;
> > > > +
> > > > + code = start_command(&proc);
> > > > + if (code)
> > > > + return code;
> > > > +
> > > > + sigchain_push(SIGPIPE, SIG_IGN);
> > > > +
> > > > + for (i = 0; i < transaction->nr; i++) {
> > > > + struct ref_update *update = transaction->updates[i];
> > > > +
> > > > + strbuf_reset(&buf);
> > > > + strbuf_addf(&buf, "%s %s %s\n",
> > > > + oid_to_hex(&update->old_oid),
> > > > + oid_to_hex(&update->new_oid),
> > > > + update->refname);
> > > > +
> > > > + if (write_in_full(proc.in, buf.buf, buf.len) < 0)
> > > > + break;
> > >
> > > We leave the loop early when we detect a write failure here...
> > >
> > > > + }
> > > > +
> > > > + close(proc.in);
> > > > + sigchain_pop(SIGPIPE);
> > > > +
> > > > + strbuf_release(&buf);
> > > > + return finish_command(&proc);
> > >
> > > ... but the caller does not get notified. Intended?
> >
> > This is semi-intended. In case the hook doesn't fully consume stdin and
> > exits early, writing to its stdin would fail as we ignore SIGPIPE. We
> > don't want to force the hook to care about consuming all of stdin,
> > though.
>
> Why? How could the prepared hook properly initialize the voting
> mechanism for the transaction without reading all the refs to be
> updated?
Because the hook might not want to implement a voting mechanism after
all but something entirely different which we're currently not
foreseeing as a valid usecase. We don't enforce this anywhere else
either, like e.g. for the pre-receive hook. If that one exits early
without consuming its stdin then that's totally fine.
> > We could improve error handling here by ignoring EPIPE, but making every
> > other write error fatal. If there's any other abnormal error condition
> > then we certainly don't want the hook to act on incomplete data and
> > pretend everything's fine.
>
> As I read v2 of this patch, a prepared hook can exit(0) early without
> reading all the refs to be updated, cause EPIPE in the git process
> invoking the hook, and that process would interpret that as success.
> I haven't though it through how such a voting mechanism would work,
> but I have a gut feeling that this can't be good.
As said, I lean towards allowing more flexibility for the hook
implementation to also cater for other usecases. But I agree that in a
voting implementation, not reading all of stdin is a bad thing and may
point to a buggy hook implementation. Aborting the transaction if the
hook didn't read all of stdin would be a nice safeguard in that case.
With the current implementation of using a single hook for "prepared",
"committed" and "aborted", it'd also force the hook implementation to do
something in cases it doesn't care about. E.g.
#!/bin/sh
case "$1" in
prepared)
VOTE=$(sha1sum <&0)
cast $VOTE
;;
aborted|committed)
cat <&0 >/dev/null
;;
esac
That being said, I'm not opposed to enforce this and not treat EPIPE
differently.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2020-06-08 5:35 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-02 8:25 [PATCH] refs: implement reference transaction hooks Patrick Steinhardt
2020-06-02 17:47 ` Junio C Hamano
2020-06-03 11:26 ` Patrick Steinhardt
2020-06-07 20:12 ` SZEDER Gábor
2020-06-08 5:36 ` Patrick Steinhardt [this message]
2020-06-02 18:09 ` SZEDER Gábor
2020-06-03 9:46 ` Patrick Steinhardt
2020-06-03 12:27 ` [PATCH v2] refs: implement reference transaction hook Patrick Steinhardt
2020-06-03 16:51 ` Taylor Blau
2020-06-04 7:36 ` Patrick Steinhardt
2020-06-15 16:46 ` Taylor Blau
2020-06-16 5:45 ` Patrick Steinhardt
2020-06-03 17:44 ` Han-Wen Nienhuys
2020-06-03 18:03 ` Junio C Hamano
2020-06-18 10:27 ` [PATCH v3] " Patrick Steinhardt
2020-06-18 22:23 ` Junio C Hamano
2020-06-19 6:56 ` [PATCH v4] " Patrick Steinhardt
2020-10-23 1:03 ` Jeff King
2020-10-23 3:59 ` Junio C Hamano
2020-10-23 19:57 ` Taylor Blau
2020-10-23 22:07 ` Taylor Blau
2020-10-26 7:43 ` Patrick Steinhardt
2020-10-26 23:52 ` Taylor Blau
2020-10-27 5:37 ` Jeff King
2020-10-28 18:22 ` Patrick Steinhardt
2020-10-23 20:00 ` Taylor Blau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200608053605.GA851@tanuki \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=szeder.dev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).