On Tue, May 14, 2019 at 07:46:17PM +0700, Duy Nguyen wrote: > On Tue, May 14, 2019 at 7:24 AM brian m. carlson > <sandals@xxxxxxxxxxxxxxxxxxxx> wrote: > > - argv_array_push(&hook.args, p); > > - while ((p = va_arg(args, const char *))) > > - argv_array_push(&hook.args, p); > > - hook.env = env; > > + strbuf_reset(&path); > > + strbuf_git_path(&path, "hooks/%s.d", name); > > + d = opendir(path.buf); > > + if (!d) { > > + if (list) > > + string_list_clear(list, 0); > > + return 0; > > + } > > + while ((de = readdir(d))) { > > + if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) > > + continue; > > + strbuf_reset(&path); > > + strbuf_git_path(&path, "hooks/%s.d/%s", name, de->d_name); > > + if (has_hook(&path, 0, X_OK)) { > > Do we want to support hooks in subdirectories as well (if so, using > dir-iterator.h might be more appropriate) No, I don't think so. That's not what most other software does, and I don't really think recursive behavior provides a lot of value. > If not, what happens when "path" is a directory. X_OK could be set > (and often are) on them too. We get an exec failure when trying to run it, just like if you create a directory in place of the existing hook now. I think that's a fine behavior. > > + if (list) > > + string_list_append(list, path.buf); > > + else > > + return 1; > > + } > > + } > > + closedir(d); > > + strbuf_reset(&path); > > + if (!list->nr) { > > + return 0; > > + } > > + > > + string_list_sort(list); > > This is going to be interesting on case-insensitive filesystems > because we do strcmp by default, not the friendlier fspathcmp. And the > ".exe" suffix might affect sort order too. > > But I suppose we just need to be clear here (in documentation). They > can always prefix with a number to keep hook files in expected order. Numbering is definitely the way I'd go on a case-insensitive file system. Also, I don't think the ".exe" will be a problem in practice, since generally you'd have to have a mix of binary and non-binary hooks, which is unlikely to be super common. > > diff --git a/run-command.h b/run-command.h > > index a6950691c0..1b3677fcac 100644 > > --- a/run-command.h > > +++ b/run-command.h > > @@ -4,6 +4,7 @@ > > #include "thread-utils.h" > > > > #include "argv-array.h" > > +#include "string-list.h" > > 'struct string_list;' should be enough (and a bit lighter) although I > don't suppose it really matters. I can make that change. -- brian m. carlson: Houston, Texas, US OpenPGP: https://keybase.io/bk2204
Attachment:
signature.asc
Description: PGP signature