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

Re: [PATCH v2] run-command: add hint when a hook is ignored

From
Damien <damien@dam.io>
Date
Oct 6, 2017, 08:04 UTC
Message-ID
<CAAQ5yihg2+BNVG-Dpvq8-qV21uX8xLsDmQpvhUzD5nSvMRFyyQ@mail.gmail.com>
In-Reply-To
<xmqqh8vcx1nh.fsf@gitster.mtv.corp.google.com>
Thanks for the help, a new patch is coming with those fixes applied.
On Fri, Oct 6, 2017 at 7:53 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 66 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> I think it is easier to reason about if this were not "else if", but
>> just a simple "if".
>
> And here are two small suggested changes to the code portion of your
> patch.
>
>  - break if / else if cascade into two independent if / if
>    statements for clarity.
>
>  - give the "ignored hook" advice only once per <process,hook>
>    pair.
>
>
>
>  run-command.c | 19 +++++++++++++------
>  1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/run-command.c b/run-command.c
> index 0f8a5f7fa2..0e60dd2075 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -5,6 +5,7 @@
>  #include "argv-array.h"
>  #include "thread-utils.h"
>  #include "strbuf.h"
> +#include "string-list.h"
>
>  void child_process_init(struct child_process *child)
>  {
> @@ -1170,19 +1171,25 @@ const char *find_hook(const char *name)
>         strbuf_git_path(&path, "hooks/%s", name);
>         if (access(path.buf, X_OK) < 0) {
>                 int err = errno;
> +
>  #ifdef STRIP_EXTENSION
>                 strbuf_addstr(&path, STRIP_EXTENSION);
>                 if (access(path.buf, X_OK) >= 0)
>                         return path.buf;
> -               else if (errno == EACCES)
> +               if (errno == EACCES)
>                         err = errno;
>  #endif
>                 if (err == EACCES && advice_ignored_hook) {
> -                       advise(_(
> -                               "The '%s' hook was ignored because "
> -                               "it's not set as executable.\n"
> -                               "You can disable this warning with "
> -                               "`git config advice.ignoredHook false`."), path.buf);
> +                       static struct string_list advise_given = STRING_LIST_INIT_DUP;
> +
> +                       if (!string_list_lookup(&advise_given, name)) {
> +                               string_list_insert(&advise_given, name);
> +                               advise(_("The '%s' hook was ignored because "
> +                                        "it's not set as executable.\n"
> +                                        "You can disable this warning with "
> +                                        "`git config advice.ignoredHook false`."),
> +                                      path.buf);
> +                       }
>                 }
>                 return NULL;
>         }
> --
> 2.15.0-rc0-155-g07e9c1a78d
>
Previous: Junio C HamanoNext: Damien Marié
Message 9 of 16 in “run-command.c: add hint when hook is not executable”
  1. run-command.c: add hint when hook is not executableDamien, Oct 3, 2017
  2. Junio C HamanoOct 4, 2017
  3. DamienOct 5, 2017
  4. run-command: add hint when a hook is ignoredDamien Marié, Oct 5, 2017
  5. Junio C HamanoOct 6, 2017
  6. Junio C HamanoOct 6, 2017
  7. Junio C HamanoOct 6, 2017
  8. Junio C HamanoOct 6, 2017
  9. DamienOct 6, 2017
  10. run-command: add hint when a hook is ignoredDamien Marié, Oct 6, 2017
  11. Junio C HamanoOct 10, 2017
  12. Junio C HamanoOct 11, 2017
  13. Jeff KingJan 3, 2018
  14. Junio C HamanoJan 5, 2018
  15. Jeff KingMar 3, 2018
  16. Junio C HamanoMar 5, 2018

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.