git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/5] sequencer: add support for multiple hooks

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Apr 24, 2019, 22:46 UTC
Message-ID
<20190424224626.GJ6316@genre.crustytoothpaste.net>
In-Reply-To
<ed0312f5-d174-76e0-fea7-5de93f5840b8@gmail.com>
On Wed, Apr 24, 2019 at 10:51:56AM +0100, Phillip Wood wrote:
Show 12 quoted lines
> On 24/04/2019 01:49, brian m. carlson wrote:
> > Add support for multiple post-rewrite hooks, both for "git commit
> > --amend" and "git rebase".
> > 
> > Additionally add support for multiple prepare-commit-msg hooks.
> > 
> > Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> > ---
> >  builtin/am.c                       | 28 ++++++---
> 
> Having read the patch subject I was surprised to see this touching
> bulitin/am.c

I can rewrite the subject. Unfortunately, the same hook for rebase goes through two wildly different modules, so in order to completely convert the post-rewrite hook, I have to update both at the same time.

Show 29 quoted lines
> > +static void run_interactive_rewrite_hook(void)
> > +{
> > +	struct string_list *hooks;
> > +	struct string_list_item *p;
> > +	struct child_process child;
> > +
> > +	hooks = find_hooks("post-rewrite");
> > +	if (!hooks)
> > +		return;
> > +
> > +	for_each_string_list_item(p, hooks) {
> > +		child_process_init(&child);
> > +
> > +		child.in = open(rebase_path_rewritten_list(),
> > +			O_RDONLY);
> > +		child.stdout_to_stderr = 1;
> > +		child.trace2_hook_name = "post-rewrite";
> > +		argv_array_push(&child.args, p->string);
> > +		argv_array_push(&child.args, "rebase");
> > +		if (run_command(&child))
> > +			break;
> > +	}
> > +	free_hooks(hooks);
> >  }
> 
> If you're adding a function to do this it would be nice to use it from
> am.c as well rather than duplicating essentially the same code. Is there
> any way to use a helper to run all the hooks, rather than introducing a
> similar loop everywhere where we call a hook?

It's becoming clear to me that a helper is probably going to be cleaner, so I'll add one in for v2.

Show 21 quoted lines
> >  void commit_post_rewrite(struct repository *r,
> > @@ -1326,6 +1362,7 @@ static int try_to_commit(struct repository *r,
> >  	char *amend_author = NULL;
> >  	const char *hook_commit = NULL;
> >  	enum commit_msg_cleanup_mode cleanup;
> > +	struct string_list *hooks;
> >  	int res = 0;
> >  
> >  	if (parse_head(r, &current_head))
> > @@ -1369,7 +1406,10 @@ static int try_to_commit(struct repository *r,
> >  		goto out;
> >  	}
> >  
> > -	if (find_hook("prepare-commit-msg")) {
> > +	hooks = find_hooks("prepare-commit-msg");
> > +	if (hooks) {
> > +		free_hooks(hooks);
> 
> I think you forgot to update run_prepare_commit_msg_hook(), it should
> probably be passed this list now. It might be outside the scope of this
> series but unifying this with builtin/commit.c

run_prepare_commit_msg_hook calls run_hook_le, which looks up that value itself. It's unfortunate that we have to do it twice, but we need to know whether we need to re-read the commit msg or not. I can explain this further in the commit message.

Show 25 quoted lines
> > diff --git a/t/t7505-prepare-commit-msg-hook.sh b/t/t7505-prepare-commit-msg-hook.sh
> > index ba8bd1b514..5b83f037b5 100755
> > --- a/t/t7505-prepare-commit-msg-hook.sh
> > +++ b/t/t7505-prepare-commit-msg-hook.sh
> > @@ -3,6 +3,7 @@
> >  test_description='prepare-commit-msg hook'
> >  
> >  . ./test-lib.sh
> > +. "$TEST_DIRECTORY/lib-hooks.sh"
> >  
> >  test_expect_success 'set up commits for rebasing' '
> >  	test_commit root &&
> > @@ -317,4 +318,12 @@ test_expect_success C_LOCALE_OUTPUT 'with failing hook (cherry-pick)' '
> >  	test $(grep -c prepare-commit-msg actual) = 1
> >  '
> >  
> > +commit_command () {
> > +	echo "$1" >>file &&
> > +	git add file &&
> > +	git commit -m "$1"
> > +}
> > +
> > +test_multiple_hooks prepare-commit-msg commit_command
> 
> It's not clear to me that this is testing the sequencer
You're right. I need to adopt a different approach here.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Previous: Phillip WoodNext: Phillip Wood
Message 15 of 51 in “Multiple hook support”
  1. 0/5 Multiple hook supportbrian m. carlson, Apr 24, 2019
  2. 1/5 run-command: add preliminary support for multiple hooksbrian m. carlson, Apr 24, 2019
  3. Junio C HamanoApr 24, 2019
  4. Johannes SixtApr 24, 2019
  5. Junio C HamanoApr 25, 2019
  6. Ævar Arnfjörð BjarmasonApr 25, 2019
  7. Junio C HamanoApr 25, 2019
  8. Johannes SixtApr 25, 2019
  9. brian m. carlsonApr 26, 2019
  10. Johannes SixtApr 26, 2019
  11. brian m. carlsonApr 24, 2019
  12. 2/5 builtin/receive-pack: add support for multiple hooksbrian m. carlson, Apr 24, 2019
  13. 3/5 sequencer: add support for multiple hooksbrian m. carlson, Apr 24, 2019
  14. Phillip WoodApr 24, 2019
  15. brian m. carlsonApr 24, 2019
  16. Phillip WoodApr 25, 2019
  17. 5/5 transport: add support for multiple pre-push hooksbrian m. carlson, Apr 24, 2019
  18. 4/5 builtin/worktree: add support for multiple post-checkout hooksbrian m. carlson, Apr 24, 2019
  19. Junio C HamanoApr 24, 2019
  20. brian m. carlsonApr 24, 2019
  21. Junio C HamanoApr 24, 2019
  22. Ævar Arnfjörð BjarmasonApr 24, 2019
  23. Jonathan NiederApr 24, 2019
  24. Ævar Arnfjörð BjarmasonApr 24, 2019
  25. Ævar Arnfjörð BjarmasonApr 24, 2019
  26. brian m. carlsonApr 24, 2019
  27. Jonathan NiederApr 24, 2019
  28. How to undo previously set configuration? (again)Ævar Arnfjörð Bjarmason, Apr 25, 2019
  29. Duy NguyenApr 25, 2019
  30. Ævar Arnfjörð BjarmasonApr 25, 2019
  31. Ævar Arnfjörð BjarmasonApr 26, 2019
  32. Jonathan NiederApr 25, 2019
  33. Barret RhodenApr 25, 2019
  34. Ævar Arnfjörð BjarmasonApr 25, 2019
  35. Ævar Arnfjörð BjarmasonApr 25, 2019
  36. Junio C HamanoApr 26, 2019
  37. Duy NguyenApr 26, 2019
  38. Jeff KingApr 30, 2019
  39. Duy NguyenMay 1, 2019
  40. Ævar Arnfjörð BjarmasonMay 1, 2019
  41. Duy NguyenMay 1, 2019
  42. Jeff KingMay 1, 2019
  43. Jeff KingMay 1, 2019
  44. Ævar Arnfjörð BjarmasonApr 24, 2019
  45. Phillip WoodApr 24, 2019
  46. Bryan TurnerApr 24, 2019
  47. Duy NguyenApr 24, 2019
  48. brian m. carlsonApr 24, 2019
  49. brian m. carlsonApr 24, 2019
  50. Duy NguyenApr 25, 2019
  51. Jeff KingApr 30, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.