diff mbox series

[v9,22/37] read-cache: convert post-index-change hook to use config

Message ID 20210527000856.695702-23-emilyshaffer@google.com (mailing list archive)
State New, archived
Headers show
Series propose config-based hooks | expand

Commit Message

Emily Shaffer May 27, 2021, 12:08 a.m. UTC
By using hook.h instead of run-command.h to run, post-index-change hooks
can now be specified in the config in addition to the hookdir.
post-index-change is not run anywhere besides in read-cache.c.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
 Documentation/githooks.txt |  3 +++
 read-cache.c               | 14 +++++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

Comments

Ævar Arnfjörð Bjarmason May 27, 2021, 11:04 p.m. UTC | #1
On Wed, May 26 2021, Emily Shaffer wrote:

>  Part of the linkgit:git[1] suite
> diff --git a/read-cache.c b/read-cache.c
> index 1b3c2eb408..6a5c9403f4 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -26,6 +26,8 @@
>  #include "thread-utils.h"
>  #include "progress.h"
>  #include "sparse-index.h"
> +#include "hook.h"
> +>>>>>>> 9524a9d29d (read-cache: convert post-index-change hook to use config)

This adds a conflict marker, which is removed later in the series.

Obviously a trivial mistake, but it's a good idea to use git rebase -i
-x 'make test' or equivalent for such a large series, perhaps there are
other inter-patch issues lurking here...
Taylor Blau May 28, 2021, 1:09 a.m. UTC | #2
On Fri, May 28, 2021 at 01:04:40AM +0200, Ævar Arnfjörð Bjarmason wrote:
> Obviously a trivial mistake, but it's a good idea to use git rebase -i
> -x 'make test' or equivalent for such a large series, perhaps there are
> other inter-patch issues lurking here...

This is tangential to this series, but I would add that `git rebase -x
'make DEVELOPER=1 git' @{u}` can be useful to run often while developing
the series and reorganizing patches to make sure that everything
compiles.

The benefit of `make git` is that it ensures everything still compiles
while avoiding having to link everything together. This ends up being
quick enough that I find myself running it often while developing a
series.

I do `s/git/test` before submitting, though.

Thanks,
Taylor
Felipe Contreras May 31, 2021, 7:21 p.m. UTC | #3
Ævar Arnfjörð Bjarmason wrote:
> 
> On Wed, May 26 2021, Emily Shaffer wrote:
> 
> >  Part of the linkgit:git[1] suite
> > diff --git a/read-cache.c b/read-cache.c
> > index 1b3c2eb408..6a5c9403f4 100644
> > --- a/read-cache.c
> > +++ b/read-cache.c
> > @@ -26,6 +26,8 @@
> >  #include "thread-utils.h"
> >  #include "progress.h"
> >  #include "sparse-index.h"
> > +#include "hook.h"
> > +>>>>>>> 9524a9d29d (read-cache: convert post-index-change hook to use config)
> 
> This adds a conflict marker, which is removed later in the series.
> 
> Obviously a trivial mistake, but it's a good idea to use git rebase -i
> -x 'make test' or equivalent for such a large series, perhaps there are
> other inter-patch issues lurking here...

Ahh, thanks so much for this. I've often wanted to do this and sometimes
wrote simple scripts. It's good to know there a straightforward way from
standard commands.

That way I have less excuse not to do the check... and I just found a
couple of transitory issues on my latest patch series.

Cheers.
diff mbox series

Patch

diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
index 7ae24d65ec..5efa25a44a 100644
--- a/Documentation/githooks.txt
+++ b/Documentation/githooks.txt
@@ -729,6 +729,9 @@  and "0" meaning they were not.
 Only one parameter should be set to "1" when the hook runs.  The hook
 running passing "1", "1" should not be possible.
 
+Hooks run during 'post-index-change' will be run in parallel, unless hook.jobs
+is configured to 1.
+
 GIT
 ---
 Part of the linkgit:git[1] suite
diff --git a/read-cache.c b/read-cache.c
index 1b3c2eb408..6a5c9403f4 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -26,6 +26,8 @@ 
 #include "thread-utils.h"
 #include "progress.h"
 #include "sparse-index.h"
+#include "hook.h"
+>>>>>>> 9524a9d29d (read-cache: convert post-index-change hook to use config)
 
 /* Mask for the name length in ce_flags in the on-disk index */
 
@@ -3131,6 +3133,7 @@  static int do_write_locked_index(struct index_state *istate, struct lock_file *l
 {
 	int ret;
 	int was_full = !istate->sparse_index;
+	struct run_hooks_opt hook_opt;
 
 	ret = convert_to_sparse(istate);
 
@@ -3159,9 +3162,14 @@  static int do_write_locked_index(struct index_state *istate, struct lock_file *l
 	else
 		ret = close_lock_file_gently(lock);
 
-	run_hook_le(NULL, "post-index-change",
-			istate->updated_workdir ? "1" : "0",
-			istate->updated_skipworktree ? "1" : "0", NULL);
+	run_hooks_opt_init_async(&hook_opt);
+	strvec_pushl(&hook_opt.args,
+		     istate->updated_workdir ? "1" : "0",
+		     istate->updated_skipworktree ? "1" : "0",
+		     NULL);
+	run_hooks("post-index-change", &hook_opt);
+	run_hooks_opt_clear(&hook_opt);
+
 	istate->updated_workdir = 0;
 	istate->updated_skipworktree = 0;