-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ab/config-based-hooks-1' into jch
Mostly preliminary clean-up in the hook API. * ab/config-based-hooks-1: hook-list.h: add a generated list of hooks, like config-list.h hook.c users: use "hook_exists()" instead of "find_hook()" hook.c: add a hook_exists() wrapper and use it in bugreport.c hook.[ch]: move find_hook() from run-command.c to hook.c Makefile: remove an out-of-date comment Makefile: don't perform "mv $@+ $@" dance for $(GENERATED_H) Makefile: stop hardcoding {command,config}-list.h Makefile: mark "check" target as .PHONY
- Loading branch information
Showing
19 changed files
with
127 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,7 @@ | |
/gitweb/static/gitweb.min.* | ||
/config-list.h | ||
/command-list.h | ||
/hook-list.h | ||
*.tar.gz | ||
*.dsc | ||
*.deb | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
# | ||
# Usage: ./generate-hooklist.sh >hook-list.h | ||
|
||
cat <<EOF | ||
/* Automatically generated by generate-hooklist.sh */ | ||
static const char *hook_name_list[] = { | ||
EOF | ||
|
||
sed -n \ | ||
-e '/^~~~~*$/ {x; s/^.*$/ "&",/; p;}' \ | ||
-e 'x' \ | ||
<Documentation/githooks.txt | | ||
LC_ALL=C sort | ||
|
||
cat <<EOF | ||
NULL, | ||
}; | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "cache.h" | ||
#include "hook.h" | ||
#include "run-command.h" | ||
|
||
const char *find_hook(const char *name) | ||
{ | ||
static struct strbuf path = STRBUF_INIT; | ||
|
||
strbuf_reset(&path); | ||
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; | ||
if (errno == EACCES) | ||
err = errno; | ||
#endif | ||
|
||
if (err == EACCES && advice_enabled(ADVICE_IGNORED_HOOK)) { | ||
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; | ||
} | ||
return path.buf; | ||
} | ||
|
||
int hook_exists(const char *name) | ||
{ | ||
return !!find_hook(name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef HOOK_H | ||
#define HOOK_H | ||
|
||
/* | ||
* Returns the path to the hook file, or NULL if the hook is missing | ||
* or disabled. Note that this points to static storage that will be | ||
* overwritten by further calls to find_hook and run_hook_*. | ||
*/ | ||
const char *find_hook(const char *name); | ||
|
||
/** | ||
* A boolean version of find_hook() | ||
*/ | ||
int hook_exists(const char *hookname); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.