diff mbox series

[RFC,1/2] hook: move list of hooks

Message ID 74ed668e9bbf56bb7898bcdfaaf77db4f3205fe5.1623881977.git.jonathantanmy@google.com (mailing list archive)
State Superseded
Headers show
Series MVP implementation of remote-suggested hooks | expand

Commit Message

Jonathan Tan June 16, 2021, 11:31 p.m. UTC
The list of hooks will need to be used outside bugreport, so move it to
a central location.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
 builtin/bugreport.c | 38 +++-----------------------------------
 hook.c              | 34 ++++++++++++++++++++++++++++++++++
 hook.h              |  3 +++
 3 files changed, 40 insertions(+), 35 deletions(-)

Comments

Emily Shaffer June 18, 2021, 8:59 p.m. UTC | #1
On Wed, Jun 16, 2021 at 04:31:48PM -0700, Jonathan Tan wrote:
> 
> The list of hooks will need to be used outside bugreport, so move it to
> a central location.

Hm, does this fight with
https://lore.kernel.org/git/cover-0.3-0000000000-20210617T100239Z-avarab@gmail.com
?

This patch itself looks pretty straightforward, but I think it is a good
idea to take a look at avarab's change first.

 - Emily

> 
> Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
> ---
>  builtin/bugreport.c | 38 +++-----------------------------------
>  hook.c              | 34 ++++++++++++++++++++++++++++++++++
>  hook.h              |  3 +++
>  3 files changed, 40 insertions(+), 35 deletions(-)
> 
> diff --git a/builtin/bugreport.c b/builtin/bugreport.c
> index 190272ba70..4e0806dff3 100644
> --- a/builtin/bugreport.c
> +++ b/builtin/bugreport.c
> @@ -41,38 +41,6 @@ static void get_system_info(struct strbuf *sys_info)
>  
>  static void get_populated_hooks(struct strbuf *hook_info, int nongit)
>  {
> -	/*
> -	 * NEEDSWORK: Doesn't look like there is a list of all possible hooks;
> -	 * so below is a transcription of `git help hooks`. Later, this should
> -	 * be replaced with some programmatically generated list (generated from
> -	 * doc or else taken from some library which tells us about all the
> -	 * hooks)
> -	 */
> -	static const char *hook[] = {
> -		"applypatch-msg",
> -		"pre-applypatch",
> -		"post-applypatch",
> -		"pre-commit",
> -		"pre-merge-commit",
> -		"prepare-commit-msg",
> -		"commit-msg",
> -		"post-commit",
> -		"pre-rebase",
> -		"post-checkout",
> -		"post-merge",
> -		"pre-push",
> -		"pre-receive",
> -		"update",
> -		"post-receive",
> -		"post-update",
> -		"push-to-checkout",
> -		"pre-auto-gc",
> -		"post-rewrite",
> -		"sendemail-validate",
> -		"fsmonitor-watchman",
> -		"p4-pre-submit",
> -		"post-index-change",
> -	};
>  	int i;
>  
>  	if (nongit) {
> @@ -81,9 +49,9 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit)
>  		return;
>  	}
>  
> -	for (i = 0; i < ARRAY_SIZE(hook); i++)
> -		if (hook_exists(hook[i], HOOKDIR_USE_CONFIG))
> -			strbuf_addf(hook_info, "%s\n", hook[i]);
> +	for (i = 0; i < hook_name_count; i++)
> +		if (hook_exists(hook_name[i], HOOKDIR_USE_CONFIG))
> +			strbuf_addf(hook_info, "%s\n", hook_name[i]);
>  }
>  
>  static const char * const bugreport_usage[] = {
> diff --git a/hook.c b/hook.c
> index ff80e52edd..3ccacb72fa 100644
> --- a/hook.c
> +++ b/hook.c
> @@ -5,6 +5,40 @@
>  #include "run-command.h"
>  #include "prompt.h"
>  
> +/*
> + * NEEDSWORK: Doesn't look like there is a list of all possible hooks;
> + * so below is a transcription of `git help hooks`. Later, this should
> + * be replaced with some programmatically generated list (generated from
> + * doc or else taken from some library which tells us about all the
> + * hooks)
> + */
> +const char *hook_name[] = {
> +	"applypatch-msg",
> +	"pre-applypatch",
> +	"post-applypatch",
> +	"pre-commit",
> +	"pre-merge-commit",
> +	"prepare-commit-msg",
> +	"commit-msg",
> +	"post-commit",
> +	"pre-rebase",
> +	"post-checkout",
> +	"post-merge",
> +	"pre-push",
> +	"pre-receive",
> +	"update",
> +	"post-receive",
> +	"post-update",
> +	"push-to-checkout",
> +	"pre-auto-gc",
> +	"post-rewrite",
> +	"sendemail-validate",
> +	"fsmonitor-watchman",
> +	"p4-pre-submit",
> +	"post-index-change",
> +};
> +int hook_name_count = ARRAY_SIZE(hook_name);
> +
>  void free_hook(struct hook *ptr)
>  {
>  	if (ptr) {
> diff --git a/hook.h b/hook.h
> index f32189380a..d902166408 100644
> --- a/hook.h
> +++ b/hook.h
> @@ -4,6 +4,9 @@
>  #include "strvec.h"
>  #include "run-command.h"
>  
> +extern const char *hook_name[];
> +extern int hook_name_count;
> +
>  struct hook {
>  	struct list_head list;
>  	/*
> -- 
> 2.32.0.272.g935e593368-goog
>
Jonathan Tan June 18, 2021, 9:48 p.m. UTC | #2
> On Wed, Jun 16, 2021 at 04:31:48PM -0700, Jonathan Tan wrote:
> > 
> > The list of hooks will need to be used outside bugreport, so move it to
> > a central location.
> 
> Hm, does this fight with
> https://lore.kernel.org/git/cover-0.3-0000000000-20210617T100239Z-avarab@gmail.com
> ?
> 
> This patch itself looks pretty straightforward, but I think it is a good
> idea to take a look at avarab's change first.
> 
>  - Emily

Hmm...you might be right. In any case, this is just an RFC patch set so
I presume avarab's will be merged first (and then I can use his hook
list in a subsequent version of my patch set).
diff mbox series

Patch

diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index 190272ba70..4e0806dff3 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -41,38 +41,6 @@  static void get_system_info(struct strbuf *sys_info)
 
 static void get_populated_hooks(struct strbuf *hook_info, int nongit)
 {
-	/*
-	 * NEEDSWORK: Doesn't look like there is a list of all possible hooks;
-	 * so below is a transcription of `git help hooks`. Later, this should
-	 * be replaced with some programmatically generated list (generated from
-	 * doc or else taken from some library which tells us about all the
-	 * hooks)
-	 */
-	static const char *hook[] = {
-		"applypatch-msg",
-		"pre-applypatch",
-		"post-applypatch",
-		"pre-commit",
-		"pre-merge-commit",
-		"prepare-commit-msg",
-		"commit-msg",
-		"post-commit",
-		"pre-rebase",
-		"post-checkout",
-		"post-merge",
-		"pre-push",
-		"pre-receive",
-		"update",
-		"post-receive",
-		"post-update",
-		"push-to-checkout",
-		"pre-auto-gc",
-		"post-rewrite",
-		"sendemail-validate",
-		"fsmonitor-watchman",
-		"p4-pre-submit",
-		"post-index-change",
-	};
 	int i;
 
 	if (nongit) {
@@ -81,9 +49,9 @@  static void get_populated_hooks(struct strbuf *hook_info, int nongit)
 		return;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(hook); i++)
-		if (hook_exists(hook[i], HOOKDIR_USE_CONFIG))
-			strbuf_addf(hook_info, "%s\n", hook[i]);
+	for (i = 0; i < hook_name_count; i++)
+		if (hook_exists(hook_name[i], HOOKDIR_USE_CONFIG))
+			strbuf_addf(hook_info, "%s\n", hook_name[i]);
 }
 
 static const char * const bugreport_usage[] = {
diff --git a/hook.c b/hook.c
index ff80e52edd..3ccacb72fa 100644
--- a/hook.c
+++ b/hook.c
@@ -5,6 +5,40 @@ 
 #include "run-command.h"
 #include "prompt.h"
 
+/*
+ * NEEDSWORK: Doesn't look like there is a list of all possible hooks;
+ * so below is a transcription of `git help hooks`. Later, this should
+ * be replaced with some programmatically generated list (generated from
+ * doc or else taken from some library which tells us about all the
+ * hooks)
+ */
+const char *hook_name[] = {
+	"applypatch-msg",
+	"pre-applypatch",
+	"post-applypatch",
+	"pre-commit",
+	"pre-merge-commit",
+	"prepare-commit-msg",
+	"commit-msg",
+	"post-commit",
+	"pre-rebase",
+	"post-checkout",
+	"post-merge",
+	"pre-push",
+	"pre-receive",
+	"update",
+	"post-receive",
+	"post-update",
+	"push-to-checkout",
+	"pre-auto-gc",
+	"post-rewrite",
+	"sendemail-validate",
+	"fsmonitor-watchman",
+	"p4-pre-submit",
+	"post-index-change",
+};
+int hook_name_count = ARRAY_SIZE(hook_name);
+
 void free_hook(struct hook *ptr)
 {
 	if (ptr) {
diff --git a/hook.h b/hook.h
index f32189380a..d902166408 100644
--- a/hook.h
+++ b/hook.h
@@ -4,6 +4,9 @@ 
 #include "strvec.h"
 #include "run-command.h"
 
+extern const char *hook_name[];
+extern int hook_name_count;
+
 struct hook {
 	struct list_head list;
 	/*