Re: [RFC PATCH v3 03/12] commit --amend: invoke post-rewrite hook
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 21, 2010, 03:12 UTC
- Message-ID
- <7vd3zz46zm.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <99b0d5c4ecb129fd663e50fbb46f41ff9f824c34.1266703765.git.trast@student.ethz.ch>
Thomas Rast <trast@student.ethz.ch> writes:
Show 21 quoted lines
> +static const char post_rewrite_hook[] = "hooks/post-rewrite";
> +
> +static int run_rewrite_hook(const unsigned char *oldsha1,
> + const unsigned char *newsha1)
> +{
> +...
> +}
> +
> int cmd_commit(int argc, const char **argv, const char *prefix)
> {
> struct strbuf sb = STRBUF_INIT;
> @@ -1303,6 +1339,13 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>
> rerere(0);
> run_hook(get_index_file(), "post-commit", NULL);
> + if (amend && !no_post_rewrite) {
> + struct commit *commit;
> + commit = lookup_commit(head_sha1);
> + if (!commit || parse_commit(commit))
> + die("HEAD commit disappeared right under my eyes?");
> + run_rewrite_hook(commit->object.sha1, commit_sha1);Why aren't you passing head_sha1 to run_rewrite_hook() in the first place, and instead run lookup_commit() only to get its object.sha1?
This is merely a "post" hook, so failure to run it should not cause the main program to fail. By not looking it up you do not even have to check and call die(). Let the dying be done in the hook instead ;-).