git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Added hook in git-receive-pack
Date: Sun, 31 Jul 2005 13:15:53 -0700	[thread overview]
Message-ID: <7v3bpuenpi.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: 200507312117.43957.Josef.Weidendorfer@gmx.de

Josef Weidendorfer <Josef.Weidendorfer@gmx.de> writes:

> +It is assured that sha1-old is an ancestor of sha1-new (otherwise,
> +the update would have not been allowed). refname is relative to
> +$GIT_DIR; e.g. for the master head this is "refs/heads/master".

I think this description is inaccurate; the send-pack can be run
with the --force flag and it is my understanding that receiver
would happily rewind the branch.  One possibility, if we wanted
to enforce it on the receiver end, would be to add another hook
that is called before the rename happens and tell the
receive-pack to refuse that update, but that should be done with
a separate patch, I suppose.

> +Using this hook, it is easy to generate mails on updates to
> +the local repository. This example script sends a mail with
> +the commits pushed to the repository:
> +
> +       #!/bin/sh
> +       git-rev-list --pretty "$3" "^$2" |
> +        mail -r $USER -s "New commits on $1" commit-list@mydomain

What is the environment the hook runs in?  For example, who
defines $USER used here?

We might want to describe the environment a bit more tightly
than the current patch does.  This includes not just the
environment variables, but $cwd and the set of open file
descriptors among other things.

I am not saying this from the security standpoint (the fact that
you can invoke receive-pack and that you can write into the
update hooks means you already have control over that
repository), but to help hook writers to avoid making mistakes.
For example, I offhand cannot tell what happens if the hook
tries to read from its standard input.  Also what happens if the
hook does not return but sleeps forever in a loop?  Do we want
to somehow time it out?  I think "It is hooks' responsibility to
time itself out" is an acceptable answer here, but if that is
the case it had better be documented.

> +static void updatehook(const char *name, unsigned char *old_sha1, unsigned char *new_sha1)
> +{
> +        if (access(update_hook, X_OK) < 0) return;
> +       fprintf(stderr, "executing update hook for %s\n", name);
> +...
> +}

I think I've seen this "fork -- exec -- for loop with waitpid"
pattern repeated number of times in the code.  Would it be
feasible to make them into a single library-ish function and
call it from here and other existing places?

Another thing you may want to consider is to do this hook
processing before and/or after processing all the refs.  A hook
might want to know what the entire set of refs are that are
being updated, and may not have enough information if it is
invoked once per ref.

Thanks for the patch; I agree with what the patch tries to
achieve in general.

-jc

  parent reply	other threads:[~2005-07-31 20:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-31 19:17 [PATCH] Added hook in git-receive-pack Josef Weidendorfer
2005-07-31 20:11 ` Linus Torvalds
2005-07-31 20:33   ` Junio C Hamano
2005-07-31 22:50     ` Linus Torvalds
2005-07-31 23:24       ` Junio C Hamano
2005-07-31 23:31         ` Johannes Schindelin
2005-07-31 23:33         ` Linus Torvalds
2005-08-01  0:11           ` Junio C Hamano
2005-08-01  0:25             ` Linus Torvalds
2005-07-31 20:15 ` Junio C Hamano [this message]
2005-07-31 23:17   ` Josef Weidendorfer
2005-08-01  8:14     ` Junio C Hamano
2005-08-13 18:31 ` Josef Weidendorfer
2005-08-13 19:27   ` Junio C Hamano
2005-08-13 20:39     ` Josef Weidendorfer

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v3bpuenpi.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=Josef.Weidendorfer@gmx.de \
    --cc=git@vger.kernel.org \
    /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.
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 NNTP newsgroup(s).