git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 0/6] sequencer: start running post-commit hook again
Date: Tue, 15 Oct 2019 10:25:26 +0000	[thread overview]
Message-ID: <pull.388.v2.git.1571135132.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.388.git.gitgitgadget@gmail.com>

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

-- 
gitgitgadget

  parent reply	other threads:[~2019-10-15 10:25 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10 18:36 [PATCH 0/3] sequencer: start running post-commit hook again Phillip Wood via GitGitGadget
2019-10-10 18:36 ` [PATCH 1/3] sequencer.h fix placement of #endif Phillip Wood via GitGitGadget
2019-10-10 18:36 ` [PATCH 2/3] sequencer: use run_commit_hook() Phillip Wood via GitGitGadget
2019-10-10 21:15   ` Johannes Schindelin
2019-10-11  4:24     ` Junio C Hamano
2019-10-14 13:26       ` Phillip Wood
2019-10-14 22:14         ` Johannes Schindelin
2019-10-10 18:36 ` [PATCH 3/3] sequencer: run post-commit hook Phillip Wood via GitGitGadget
2019-10-10 21:31   ` Johannes Schindelin
2019-10-11  4:27     ` Junio C Hamano
2019-10-11 15:39     ` Phillip Wood
2019-10-15 10:25 ` Phillip Wood via GitGitGadget [this message]
2019-10-15 10:25   ` [PATCH v2 1/6] t3404: remove unnecessary subshell Phillip Wood via GitGitGadget
2019-10-15 10:25   ` [PATCH v2 2/6] t3404: set $EDITOR in subshell Phillip Wood via GitGitGadget
2019-10-15 10:25   ` [PATCH v2 3/6] t3404: remove uneeded calls to set_fake_editor Phillip Wood via GitGitGadget
2019-10-15 10:25   ` [PATCH v2 4/6] sequencer.h fix placement of #endif Phillip Wood via GitGitGadget
2019-10-15 10:25   ` [PATCH v2 5/6] move run_commit_hook() to libgit and use it there Phillip Wood via GitGitGadget
2019-10-15 10:25   ` [PATCH v2 6/6] sequencer: run post-commit hook Phillip Wood via GitGitGadget
2019-10-15 14:26   ` [PATCH v2 0/6] sequencer: start running post-commit hook again Johannes Schindelin
2019-10-16  1:32     ` Junio C Hamano

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=pull.388.v2.git.1571135132.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).