[v2,0/6] sequencer: start running post-commit hook again
mbox series

Message ID pull.388.v2.git.1571135132.gitgitgadget@gmail.com
Headers show
Series
  • sequencer: start running post-commit hook again
Related show

Message

ryenus via GitGitGadget Oct. 15, 2019, 10:25 a.m. UTC
When I converted the sequencer to avoid forking git commit i forgot about
the post-commit hook. These patches are based on
pw/rebase-i-show-HEAD-to-reword, otherwise the new test fails as that branch
changes the number of commits we make.

Thanks to Dscho & Junio for their comments on V1. I've made the following
changes:

Patches 1-3 These are new patches in response to Dscho's request to set
$EDITOR in a subshell. There were ~80 other tests that weren't doing that
and they are fixed in these patches. Patch 2 contains the main action,
unfortunately due to a combination of having to remove the trailing ' &&'
from the last line moved into the subshell and re-wrapping some lines due to
the increased indentation --color-moved and --color-moved-ws are of limited
use when viewing this patch.

Patch 4 (was 1) Unchanged

Patch 5 (was 2) I've moved the function definition to commit.c rather than
sequencer.c as suggested. I've also removed an unused struct argv_array from
run_prepare_commit_msg_hook() (There wasn't a compiler warning as it was
still calling argv_array_clear() at the end of the function) and reworded
the commit message.

Patch 6 (was 3) I've tided up the test and removed the wrapper function for
running the post-commit hook as suggested.

Phillip Wood (6):
  t3404: remove unnecessary subshell
  t3404: set $EDITOR in subshell
  t3404: remove uneeded calls to set_fake_editor
  sequencer.h fix placement of #endif
  move run_commit_hook() to libgit and use it there
  sequencer: run post-commit hook

 builtin/commit.c              |  22 --
 commit.c                      |  24 ++
 sequencer.c                   |  24 +-
 sequencer.h                   |   3 +-
 t/lib-rebase.sh               |  28 ++
 t/t3404-rebase-interactive.sh | 596 +++++++++++++++++++++-------------
 6 files changed, 432 insertions(+), 265 deletions(-)


base-commit: b0a3186140dbc7bd64cbc6ef733386a0f1eb6a4d
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-388%2Fphillipwood%2Fwip%2Frebase-commit-hooks-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-388/phillipwood/wip/rebase-commit-hooks-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/388

Range-diff vs v1:

 -:  ---------- > 1:  b9689e85e5 t3404: remove unnecessary subshell
 -:  ---------- > 2:  96432cd0f0 t3404: set $EDITOR in subshell
 -:  ---------- > 3:  09857dee78 t3404: remove uneeded calls to set_fake_editor
 1:  7305f8d8e8 = 4:  0eac3ede02 sequencer.h fix placement of #endif
 2:  420ecf442c ! 5:  f394a0e163 sequencer: use run_commit_hook()
     @@ -1,9 +1,11 @@
      Author: Phillip Wood <phillip.wood@dunelm.org.uk>
      
     -    sequencer: use run_commit_hook()
     +    move run_commit_hook() to libgit and use it there
      
     -    This simplifies the implementation of run_prepare_commit_msg_hook() and
     -    will be used in the next commit.
     +    This function was declared in commit.h but was implemented in
     +    builtin/commit.c so was not part of libgit. Move it to libgit so we can
     +    use it in the sequencer. This simplifies the implementation of
     +    run_prepare_commit_msg_hook() and will be used in the next commit.
      
          Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
      
     @@ -40,25 +42,22 @@
       {
       	const char *argv_gc_auto[] = {"gc", "--auto", NULL};
      
     - diff --git a/commit.h b/commit.h
     - --- a/commit.h
     - +++ b/commit.h
     + diff --git a/commit.c b/commit.c
     + --- a/commit.c
     + +++ b/commit.c
      @@
     - int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused);
     - int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused);
     + #include "advice.h"
     + #include "refs.h"
     + #include "commit-reach.h"
     ++#include "run-command.h"
     + 
     + static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
       
     --LAST_ARG_MUST_BE_NULL
     --int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...);
     --
     - #endif /* COMMIT_H */
     -
     - diff --git a/sequencer.c b/sequencer.c
     - --- a/sequencer.c
     - +++ b/sequencer.c
      @@
     - 	run_rewrite_hook(&old_head->object.oid, new_head);
     + 	}
     + 	return boc ? len - boc : len - cutoff;
       }
     - 
     ++
      +int run_commit_hook(int editor_is_used, const char *index_file,
      +		    const char *name, ...)
      +{
     @@ -81,12 +80,15 @@
      +
      +	return ret;
      +}
     -+
     - static int run_prepare_commit_msg_hook(struct repository *r,
     +
     + diff --git a/sequencer.c b/sequencer.c
     + --- a/sequencer.c
     + +++ b/sequencer.c
     +@@
       				       struct strbuf *msg,
       				       const char *commit)
       {
     - 	struct argv_array hook_env = ARGV_ARRAY_INIT;
     +-	struct argv_array hook_env = ARGV_ARRAY_INIT;
      -	int ret;
      -	const char *name;
      +	int ret = 0;
     @@ -114,18 +116,7 @@
      +	if (run_commit_hook(0, r->index_file, "prepare-commit-msg", name,
      +			    arg1, arg2, NULL))
       		ret = error(_("'prepare-commit-msg' hook failed"));
     -+
     - 	argv_array_clear(&hook_env);
     +-	argv_array_clear(&hook_env);
       
       	return ret;
     -
     - diff --git a/sequencer.h b/sequencer.h
     - --- a/sequencer.h
     - +++ b/sequencer.h
     -@@
     - void sequencer_post_commit_cleanup(struct repository *r);
     - int sequencer_get_last_command(struct repository* r,
     - 			       enum replay_action *action);
     -+LAST_ARG_MUST_BE_NULL
     -+int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...);
     - #endif /* SEQUENCER_H */
     + }
 3:  acaa086a48 ! 6:  67a711754e sequencer: run post-commit hook
     @@ -10,52 +10,18 @@
      
          Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
      
     - diff --git a/builtin/commit.c b/builtin/commit.c
     - --- a/builtin/commit.c
     - +++ b/builtin/commit.c
     -@@
     - 
     - 	repo_rerere(the_repository, 0);
     - 	run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
     --	run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
     -+	run_post_commit_hook(use_editor, get_index_file());
     - 	if (amend && !no_post_rewrite) {
     - 		commit_post_rewrite(the_repository, current_head, &oid);
     - 	}
     -
       diff --git a/sequencer.c b/sequencer.c
       --- a/sequencer.c
       +++ b/sequencer.c
     -@@
     - 	return ret;
     - }
     - 
     -+void run_post_commit_hook(int editor_is_used, const char *index_file) {
     -+	run_commit_hook(editor_is_used, index_file, "post-commit", NULL);
     -+}
     -+
     - static const char implicit_ident_advice_noconfig[] =
     - N_("Your name and email address were configured automatically based\n"
     - "on your username and hostname. Please check that they are accurate.\n"
      @@
       		goto out;
       	}
       
     -+	run_post_commit_hook(0, r->index_file);
     ++	run_commit_hook(0, r->index_file, "post-commit", NULL);
       	if (flags & AMEND_MSG)
       		commit_post_rewrite(r, current_head, oid);
       
      
     - diff --git a/sequencer.h b/sequencer.h
     - --- a/sequencer.h
     - +++ b/sequencer.h
     -@@
     - 			       enum replay_action *action);
     - LAST_ARG_MUST_BE_NULL
     - int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...);
     -+void run_post_commit_hook(int editor_is_used, const char *index_file);
     - #endif /* SEQUENCER_H */
     -
       diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
       --- a/t/t3404-rebase-interactive.sh
       +++ b/t/t3404-rebase-interactive.sh
     @@ -64,20 +30,24 @@
       '
       
      +test_expect_success 'post-commit hook is called' '
     -+	test_when_finished "rm -f .git/hooks/post-commit commits" &&
     ++	test_when_finished "rm -f .git/hooks/post-commit" &&
     ++	>actual &&
      +	mkdir -p .git/hooks &&
      +	write_script .git/hooks/post-commit <<-\EOS &&
     -+	git rev-parse HEAD >>commits
     ++	git rev-parse HEAD >>actual
      +	EOS
     -+	set_fake_editor &&
     -+	FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E &&
     -+	echo x>file3 &&
     -+	git add file3 &&
     -+	FAKE_COMMIT_MESSAGE=edited git rebase --continue &&
     -+	# rev-list does not support -g --reverse
     -+	git rev-list --no-walk=unsorted HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} \
     -+		HEAD@{1} HEAD >expected &&
     -+	test_cmp expected commits
     ++	(
     ++		set_fake_editor &&
     ++		FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E &&
     ++		echo x>file3 &&
     ++		git add file3 &&
     ++		FAKE_COMMIT_MESSAGE=edited git rebase --continue
     ++	) &&
     ++	git rev-parse HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} HEAD@{1} HEAD \
     ++		>expect &&
     ++	test_cmp expect actual
      +'
      +
     - test_done
     + # This must be the last test in this file
     + test_expect_success '$EDITOR and friends are unchanged' '
     + 	test_editor_unchanged

Comments

Johannes Schindelin Oct. 15, 2019, 2:26 p.m. UTC | #1
Hi Phillip,

On Tue, 15 Oct 2019, Phillip Wood via GitGitGadget wrote:

> When I converted the sequencer to avoid forking git commit i forgot about
> the post-commit hook. These patches are based on
> pw/rebase-i-show-HEAD-to-reword, otherwise the new test fails as that branch
> changes the number of commits we make.
>
> Thanks to Dscho & Junio for their comments on V1. I've made the following
> changes:
>
> Patches 1-3 These are new patches in response to Dscho's request to set
> $EDITOR in a subshell. There were ~80 other tests that weren't doing that
> and they are fixed in these patches. Patch 2 contains the main action,
> unfortunately due to a combination of having to remove the trailing ' &&'
> from the last line moved into the subshell and re-wrapping some lines due to
> the increased indentation --color-moved and --color-moved-ws are of limited
> use when viewing this patch.
>
> Patch 4 (was 1) Unchanged
>
> Patch 5 (was 2) I've moved the function definition to commit.c rather than
> sequencer.c as suggested. I've also removed an unused struct argv_array from
> run_prepare_commit_msg_hook() (There wasn't a compiler warning as it was
> still calling argv_array_clear() at the end of the function) and reworded
> the commit message.
>
> Patch 6 (was 3) I've tided up the test and removed the wrapper function for
> running the post-commit hook as suggested.

I had a look over the patches, too, and all looks good to me.

Thank you so much!
Dscho

>
> Phillip Wood (6):
>   t3404: remove unnecessary subshell
>   t3404: set $EDITOR in subshell
>   t3404: remove uneeded calls to set_fake_editor
>   sequencer.h fix placement of #endif
>   move run_commit_hook() to libgit and use it there
>   sequencer: run post-commit hook
>
>  builtin/commit.c              |  22 --
>  commit.c                      |  24 ++
>  sequencer.c                   |  24 +-
>  sequencer.h                   |   3 +-
>  t/lib-rebase.sh               |  28 ++
>  t/t3404-rebase-interactive.sh | 596 +++++++++++++++++++++-------------
>  6 files changed, 432 insertions(+), 265 deletions(-)
>
>
> base-commit: b0a3186140dbc7bd64cbc6ef733386a0f1eb6a4d
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-388%2Fphillipwood%2Fwip%2Frebase-commit-hooks-v2
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-388/phillipwood/wip/rebase-commit-hooks-v2
> Pull-Request: https://github.com/gitgitgadget/git/pull/388
>
> Range-diff vs v1:
>
>  -:  ---------- > 1:  b9689e85e5 t3404: remove unnecessary subshell
>  -:  ---------- > 2:  96432cd0f0 t3404: set $EDITOR in subshell
>  -:  ---------- > 3:  09857dee78 t3404: remove uneeded calls to set_fake_editor
>  1:  7305f8d8e8 = 4:  0eac3ede02 sequencer.h fix placement of #endif
>  2:  420ecf442c ! 5:  f394a0e163 sequencer: use run_commit_hook()
>      @@ -1,9 +1,11 @@
>       Author: Phillip Wood <phillip.wood@dunelm.org.uk>
>
>      -    sequencer: use run_commit_hook()
>      +    move run_commit_hook() to libgit and use it there
>
>      -    This simplifies the implementation of run_prepare_commit_msg_hook() and
>      -    will be used in the next commit.
>      +    This function was declared in commit.h but was implemented in
>      +    builtin/commit.c so was not part of libgit. Move it to libgit so we can
>      +    use it in the sequencer. This simplifies the implementation of
>      +    run_prepare_commit_msg_hook() and will be used in the next commit.
>
>           Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
>
>      @@ -40,25 +42,22 @@
>        {
>        	const char *argv_gc_auto[] = {"gc", "--auto", NULL};
>
>      - diff --git a/commit.h b/commit.h
>      - --- a/commit.h
>      - +++ b/commit.h
>      + diff --git a/commit.c b/commit.c
>      + --- a/commit.c
>      + +++ b/commit.c
>       @@
>      - int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused);
>      - int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused);
>      + #include "advice.h"
>      + #include "refs.h"
>      + #include "commit-reach.h"
>      ++#include "run-command.h"
>      +
>      + static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
>
>      --LAST_ARG_MUST_BE_NULL
>      --int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...);
>      --
>      - #endif /* COMMIT_H */
>      -
>      - diff --git a/sequencer.c b/sequencer.c
>      - --- a/sequencer.c
>      - +++ b/sequencer.c
>       @@
>      - 	run_rewrite_hook(&old_head->object.oid, new_head);
>      + 	}
>      + 	return boc ? len - boc : len - cutoff;
>        }
>      -
>      ++
>       +int run_commit_hook(int editor_is_used, const char *index_file,
>       +		    const char *name, ...)
>       +{
>      @@ -81,12 +80,15 @@
>       +
>       +	return ret;
>       +}
>      -+
>      - static int run_prepare_commit_msg_hook(struct repository *r,
>      +
>      + diff --git a/sequencer.c b/sequencer.c
>      + --- a/sequencer.c
>      + +++ b/sequencer.c
>      +@@
>        				       struct strbuf *msg,
>        				       const char *commit)
>        {
>      - 	struct argv_array hook_env = ARGV_ARRAY_INIT;
>      +-	struct argv_array hook_env = ARGV_ARRAY_INIT;
>       -	int ret;
>       -	const char *name;
>       +	int ret = 0;
>      @@ -114,18 +116,7 @@
>       +	if (run_commit_hook(0, r->index_file, "prepare-commit-msg", name,
>       +			    arg1, arg2, NULL))
>        		ret = error(_("'prepare-commit-msg' hook failed"));
>      -+
>      - 	argv_array_clear(&hook_env);
>      +-	argv_array_clear(&hook_env);
>
>        	return ret;
>      -
>      - diff --git a/sequencer.h b/sequencer.h
>      - --- a/sequencer.h
>      - +++ b/sequencer.h
>      -@@
>      - void sequencer_post_commit_cleanup(struct repository *r);
>      - int sequencer_get_last_command(struct repository* r,
>      - 			       enum replay_action *action);
>      -+LAST_ARG_MUST_BE_NULL
>      -+int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...);
>      - #endif /* SEQUENCER_H */
>      + }
>  3:  acaa086a48 ! 6:  67a711754e sequencer: run post-commit hook
>      @@ -10,52 +10,18 @@
>
>           Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
>
>      - diff --git a/builtin/commit.c b/builtin/commit.c
>      - --- a/builtin/commit.c
>      - +++ b/builtin/commit.c
>      -@@
>      -
>      - 	repo_rerere(the_repository, 0);
>      - 	run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
>      --	run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
>      -+	run_post_commit_hook(use_editor, get_index_file());
>      - 	if (amend && !no_post_rewrite) {
>      - 		commit_post_rewrite(the_repository, current_head, &oid);
>      - 	}
>      -
>        diff --git a/sequencer.c b/sequencer.c
>        --- a/sequencer.c
>        +++ b/sequencer.c
>      -@@
>      - 	return ret;
>      - }
>      -
>      -+void run_post_commit_hook(int editor_is_used, const char *index_file) {
>      -+	run_commit_hook(editor_is_used, index_file, "post-commit", NULL);
>      -+}
>      -+
>      - static const char implicit_ident_advice_noconfig[] =
>      - N_("Your name and email address were configured automatically based\n"
>      - "on your username and hostname. Please check that they are accurate.\n"
>       @@
>        		goto out;
>        	}
>
>      -+	run_post_commit_hook(0, r->index_file);
>      ++	run_commit_hook(0, r->index_file, "post-commit", NULL);
>        	if (flags & AMEND_MSG)
>        		commit_post_rewrite(r, current_head, oid);
>
>
>      - diff --git a/sequencer.h b/sequencer.h
>      - --- a/sequencer.h
>      - +++ b/sequencer.h
>      -@@
>      - 			       enum replay_action *action);
>      - LAST_ARG_MUST_BE_NULL
>      - int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...);
>      -+void run_post_commit_hook(int editor_is_used, const char *index_file);
>      - #endif /* SEQUENCER_H */
>      -
>        diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
>        --- a/t/t3404-rebase-interactive.sh
>        +++ b/t/t3404-rebase-interactive.sh
>      @@ -64,20 +30,24 @@
>        '
>
>       +test_expect_success 'post-commit hook is called' '
>      -+	test_when_finished "rm -f .git/hooks/post-commit commits" &&
>      ++	test_when_finished "rm -f .git/hooks/post-commit" &&
>      ++	>actual &&
>       +	mkdir -p .git/hooks &&
>       +	write_script .git/hooks/post-commit <<-\EOS &&
>      -+	git rev-parse HEAD >>commits
>      ++	git rev-parse HEAD >>actual
>       +	EOS
>      -+	set_fake_editor &&
>      -+	FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E &&
>      -+	echo x>file3 &&
>      -+	git add file3 &&
>      -+	FAKE_COMMIT_MESSAGE=edited git rebase --continue &&
>      -+	# rev-list does not support -g --reverse
>      -+	git rev-list --no-walk=unsorted HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} \
>      -+		HEAD@{1} HEAD >expected &&
>      -+	test_cmp expected commits
>      ++	(
>      ++		set_fake_editor &&
>      ++		FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E &&
>      ++		echo x>file3 &&
>      ++		git add file3 &&
>      ++		FAKE_COMMIT_MESSAGE=edited git rebase --continue
>      ++	) &&
>      ++	git rev-parse HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} HEAD@{1} HEAD \
>      ++		>expect &&
>      ++	test_cmp expect actual
>       +'
>       +
>      - test_done
>      + # This must be the last test in this file
>      + test_expect_success '$EDITOR and friends are unchanged' '
>      + 	test_editor_unchanged
>
> --
> gitgitgadget
>
Junio C Hamano Oct. 16, 2019, 1:32 a.m. UTC | #2
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> Hi Phillip,
>
> On Tue, 15 Oct 2019, Phillip Wood via GitGitGadget wrote:
>
>> When I converted the sequencer to avoid forking git commit i forgot about
>> the post-commit hook. These patches are based on
>> pw/rebase-i-show-HEAD-to-reword, otherwise the new test fails as that branch
>> changes the number of commits we make.
>> ...
>
> I had a look over the patches, too, and all looks good to me.

Me three; thanks, both.