From d807c4a01db2b06db047fc6d5d18ac25c8f05bd7 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Tue, 10 Apr 2018 14:26:18 -0700 Subject: exec_cmd: rename to use dash in file name This is more consistent with the project style. The majority of Git's source files use dashes in preference to underscores in their file names. Signed-off-by: Stefan Beller diff --git a/Makefile b/Makefile index f83b796..88730d6 100644 --- a/Makefile +++ b/Makefile @@ -818,7 +818,7 @@ LIB_OBJS += ewah/bitmap.o LIB_OBJS += ewah/ewah_bitmap.o LIB_OBJS += ewah/ewah_io.o LIB_OBJS += ewah/ewah_rlw.o -LIB_OBJS += exec_cmd.o +LIB_OBJS += exec-cmd.o LIB_OBJS += fetch-object.o LIB_OBJS += fetch-pack.o LIB_OBJS += fsck.o @@ -2155,8 +2155,8 @@ else $(OBJECTS): $(LIB_H) endif -exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX -exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \ +exec-cmd.sp exec-cmd.s exec-cmd.o: GIT-PREFIX +exec-cmd.sp exec-cmd.s exec-cmd.o: EXTRA_CPPFLAGS = \ '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \ '-DBINDIR="$(bindir_relative_SQ)"' \ '-DPREFIX="$(prefix_SQ)"' diff --git a/attr.c b/attr.c index dfc3a55..03a678f 100644 --- a/attr.c +++ b/attr.c @@ -10,7 +10,7 @@ #define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "attr.h" #include "dir.h" #include "utf8.h" diff --git a/builtin/add.c b/builtin/add.c index 9ef7fb0..c9e2619 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -9,7 +9,7 @@ #include "lockfile.h" #include "dir.h" #include "pathspec.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "cache-tree.h" #include "run-command.h" #include "parse-options.h" diff --git a/builtin/am.c b/builtin/am.c index 9c82603..d834f9e 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -6,7 +6,7 @@ #include "cache.h" #include "config.h" #include "builtin.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "parse-options.h" #include "dir.h" #include "run-command.h" diff --git a/builtin/describe.c b/builtin/describe.c index de840f9..b5afc45 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -6,7 +6,7 @@ #include "blob.h" #include "refs.h" #include "builtin.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "parse-options.h" #include "revision.h" #include "diff.h" diff --git a/builtin/difftool.c b/builtin/difftool.c index ee8dce0..aad0e07 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -15,7 +15,7 @@ #include "config.h" #include "builtin.h" #include "run-command.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "parse-options.h" #include "argv-array.h" #include "strbuf.h" diff --git a/builtin/hash-object.c b/builtin/hash-object.c index 526da5c..a9a3a19 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -9,7 +9,7 @@ #include "blob.h" #include "quote.h" #include "parse-options.h" -#include "exec_cmd.h" +#include "exec-cmd.h" /* * This is to create corrupt objects for debugging and as such it diff --git a/builtin/help.c b/builtin/help.c index 598867c..2d51071 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -4,7 +4,7 @@ #include "cache.h" #include "config.h" #include "builtin.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "parse-options.h" #include "run-command.h" #include "column.h" diff --git a/builtin/index-pack.c b/builtin/index-pack.c index d81473e..7700907 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -9,7 +9,7 @@ #include "tree.h" #include "progress.h" #include "fsck.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "streaming.h" #include "thread-utils.h" #include "packfile.h" diff --git a/builtin/init-db.c b/builtin/init-db.c index 68ff4ad..2542c52 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -7,7 +7,7 @@ #include "config.h" #include "refs.h" #include "builtin.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "parse-options.h" #ifndef DEFAULT_GIT_TEMPLATE_DIR diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 32736e0..bf01e05 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -2,7 +2,7 @@ #include "tree-walk.h" #include "xdiff-interface.h" #include "blob.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "merge-blobs.h" static const char merge_tree_usage[] = "git merge-tree "; diff --git a/builtin/notes.c b/builtin/notes.c index 921e08d..e5bf80e 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -14,7 +14,7 @@ #include "blob.h" #include "pretty.h" #include "refs.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "run-command.h" #include "parse-options.h" #include "string-list.h" diff --git a/builtin/pull.c b/builtin/pull.c index e32d6cd..71aac50 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -9,7 +9,7 @@ #include "config.h" #include "builtin.h" #include "parse-options.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "run-command.h" #include "sha1-array.h" #include "remote.h" diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index c4272fb..4b68a28 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -7,7 +7,7 @@ #include "pkt-line.h" #include "sideband.h" #include "run-command.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "commit.h" #include "object.h" #include "remote.h" diff --git a/common-main.c b/common-main.c index 7d716d5..b989e13 100644 --- a/common-main.c +++ b/common-main.c @@ -1,5 +1,5 @@ #include "cache.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "attr.h" /* diff --git a/config.c b/config.c index c698988..e2b87b4 100644 --- a/config.c +++ b/config.c @@ -9,7 +9,7 @@ #include "config.h" #include "repository.h" #include "lockfile.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "strbuf.h" #include "quote.h" #include "hashmap.h" diff --git a/exec-cmd.c b/exec-cmd.c new file mode 100644 index 0000000..8a82617 --- /dev/null +++ b/exec-cmd.c @@ -0,0 +1,165 @@ +#include "cache.h" +#include "exec-cmd.h" +#include "quote.h" +#include "argv-array.h" +#define MAX_ARGS 32 + +static const char *argv_exec_path; + +#ifdef RUNTIME_PREFIX +static const char *argv0_path; + +static const char *system_prefix(void) +{ + static const char *prefix; + + assert(argv0_path); + assert(is_absolute_path(argv0_path)); + + if (!prefix && + !(prefix = strip_path_suffix(argv0_path, GIT_EXEC_PATH)) && + !(prefix = strip_path_suffix(argv0_path, BINDIR)) && + !(prefix = strip_path_suffix(argv0_path, "git"))) { + prefix = PREFIX; + trace_printf("RUNTIME_PREFIX requested, " + "but prefix computation failed. " + "Using static fallback '%s'.\n", prefix); + } + return prefix; +} + +void git_extract_argv0_path(const char *argv0) +{ + const char *slash; + + if (!argv0 || !*argv0) + return; + + slash = find_last_dir_sep(argv0); + + if (slash) + argv0_path = xstrndup(argv0, slash - argv0); +} + +#else + +static const char *system_prefix(void) +{ + return PREFIX; +} + +void git_extract_argv0_path(const char *argv0) +{ +} + +#endif /* RUNTIME_PREFIX */ + +char *system_path(const char *path) +{ + struct strbuf d = STRBUF_INIT; + + if (is_absolute_path(path)) + return xstrdup(path); + + strbuf_addf(&d, "%s/%s", system_prefix(), path); + return strbuf_detach(&d, NULL); +} + +void git_set_argv_exec_path(const char *exec_path) +{ + argv_exec_path = exec_path; + /* + * Propagate this setting to external programs. + */ + setenv(EXEC_PATH_ENVIRONMENT, exec_path, 1); +} + + +/* Returns the highest-priority, location to look for git programs. */ +const char *git_exec_path(void) +{ + static char *cached_exec_path; + + if (argv_exec_path) + return argv_exec_path; + + if (!cached_exec_path) { + const char *env = getenv(EXEC_PATH_ENVIRONMENT); + if (env && *env) + cached_exec_path = xstrdup(env); + else + cached_exec_path = system_path(GIT_EXEC_PATH); + } + return cached_exec_path; +} + +static void add_path(struct strbuf *out, const char *path) +{ + if (path && *path) { + strbuf_add_absolute_path(out, path); + strbuf_addch(out, PATH_SEP); + } +} + +void setup_path(void) +{ + const char *old_path = getenv("PATH"); + struct strbuf new_path = STRBUF_INIT; + + add_path(&new_path, git_exec_path()); + + if (old_path) + strbuf_addstr(&new_path, old_path); + else + strbuf_addstr(&new_path, _PATH_DEFPATH); + + setenv("PATH", new_path.buf, 1); + + strbuf_release(&new_path); +} + +const char **prepare_git_cmd(struct argv_array *out, const char **argv) +{ + argv_array_push(out, "git"); + argv_array_pushv(out, argv); + return out->argv; +} + +int execv_git_cmd(const char **argv) { + struct argv_array nargv = ARGV_ARRAY_INIT; + + prepare_git_cmd(&nargv, argv); + trace_argv_printf(nargv.argv, "trace: exec:"); + + /* execvp() can only ever return if it fails */ + sane_execvp("git", (char **)nargv.argv); + + trace_printf("trace: exec failed: %s\n", strerror(errno)); + + argv_array_clear(&nargv); + return -1; +} + + +int execl_git_cmd(const char *cmd,...) +{ + int argc; + const char *argv[MAX_ARGS + 1]; + const char *arg; + va_list param; + + va_start(param, cmd); + argv[0] = cmd; + argc = 1; + while (argc < MAX_ARGS) { + arg = argv[argc++] = va_arg(param, char *); + if (!arg) + break; + } + va_end(param); + if (MAX_ARGS <= argc) + return error("too many args to run %s", cmd); + + argv[argc] = NULL; + return execv_git_cmd(argv); +} diff --git a/exec-cmd.h b/exec-cmd.h new file mode 100644 index 0000000..ff0b480 --- /dev/null +++ b/exec-cmd.h @@ -0,0 +1,16 @@ +#ifndef GIT_EXEC_CMD_H +#define GIT_EXEC_CMD_H + +struct argv_array; + +extern void git_set_argv_exec_path(const char *exec_path); +extern void git_extract_argv0_path(const char *path); +extern const char *git_exec_path(void); +extern void setup_path(void); +extern const char **prepare_git_cmd(struct argv_array *out, const char **argv); +extern int execv_git_cmd(const char **argv); /* NULL terminated */ +LAST_ARG_MUST_BE_NULL +extern int execl_git_cmd(const char *cmd, ...); +extern char *system_path(const char *path); + +#endif /* GIT_EXEC_CMD_H */ diff --git a/exec_cmd.c b/exec_cmd.c deleted file mode 100644 index ce192a2..0000000 --- a/exec_cmd.c +++ /dev/null @@ -1,165 +0,0 @@ -#include "cache.h" -#include "exec_cmd.h" -#include "quote.h" -#include "argv-array.h" -#define MAX_ARGS 32 - -static const char *argv_exec_path; - -#ifdef RUNTIME_PREFIX -static const char *argv0_path; - -static const char *system_prefix(void) -{ - static const char *prefix; - - assert(argv0_path); - assert(is_absolute_path(argv0_path)); - - if (!prefix && - !(prefix = strip_path_suffix(argv0_path, GIT_EXEC_PATH)) && - !(prefix = strip_path_suffix(argv0_path, BINDIR)) && - !(prefix = strip_path_suffix(argv0_path, "git"))) { - prefix = PREFIX; - trace_printf("RUNTIME_PREFIX requested, " - "but prefix computation failed. " - "Using static fallback '%s'.\n", prefix); - } - return prefix; -} - -void git_extract_argv0_path(const char *argv0) -{ - const char *slash; - - if (!argv0 || !*argv0) - return; - - slash = find_last_dir_sep(argv0); - - if (slash) - argv0_path = xstrndup(argv0, slash - argv0); -} - -#else - -static const char *system_prefix(void) -{ - return PREFIX; -} - -void git_extract_argv0_path(const char *argv0) -{ -} - -#endif /* RUNTIME_PREFIX */ - -char *system_path(const char *path) -{ - struct strbuf d = STRBUF_INIT; - - if (is_absolute_path(path)) - return xstrdup(path); - - strbuf_addf(&d, "%s/%s", system_prefix(), path); - return strbuf_detach(&d, NULL); -} - -void git_set_argv_exec_path(const char *exec_path) -{ - argv_exec_path = exec_path; - /* - * Propagate this setting to external programs. - */ - setenv(EXEC_PATH_ENVIRONMENT, exec_path, 1); -} - - -/* Returns the highest-priority, location to look for git programs. */ -const char *git_exec_path(void) -{ - static char *cached_exec_path; - - if (argv_exec_path) - return argv_exec_path; - - if (!cached_exec_path) { - const char *env = getenv(EXEC_PATH_ENVIRONMENT); - if (env && *env) - cached_exec_path = xstrdup(env); - else - cached_exec_path = system_path(GIT_EXEC_PATH); - } - return cached_exec_path; -} - -static void add_path(struct strbuf *out, const char *path) -{ - if (path && *path) { - strbuf_add_absolute_path(out, path); - strbuf_addch(out, PATH_SEP); - } -} - -void setup_path(void) -{ - const char *old_path = getenv("PATH"); - struct strbuf new_path = STRBUF_INIT; - - add_path(&new_path, git_exec_path()); - - if (old_path) - strbuf_addstr(&new_path, old_path); - else - strbuf_addstr(&new_path, _PATH_DEFPATH); - - setenv("PATH", new_path.buf, 1); - - strbuf_release(&new_path); -} - -const char **prepare_git_cmd(struct argv_array *out, const char **argv) -{ - argv_array_push(out, "git"); - argv_array_pushv(out, argv); - return out->argv; -} - -int execv_git_cmd(const char **argv) { - struct argv_array nargv = ARGV_ARRAY_INIT; - - prepare_git_cmd(&nargv, argv); - trace_argv_printf(nargv.argv, "trace: exec:"); - - /* execvp() can only ever return if it fails */ - sane_execvp("git", (char **)nargv.argv); - - trace_printf("trace: exec failed: %s\n", strerror(errno)); - - argv_array_clear(&nargv); - return -1; -} - - -int execl_git_cmd(const char *cmd,...) -{ - int argc; - const char *argv[MAX_ARGS + 1]; - const char *arg; - va_list param; - - va_start(param, cmd); - argv[0] = cmd; - argc = 1; - while (argc < MAX_ARGS) { - arg = argv[argc++] = va_arg(param, char *); - if (!arg) - break; - } - va_end(param); - if (MAX_ARGS <= argc) - return error("too many args to run %s", cmd); - - argv[argc] = NULL; - return execv_git_cmd(argv); -} diff --git a/exec_cmd.h b/exec_cmd.h deleted file mode 100644 index ff0b480..0000000 --- a/exec_cmd.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef GIT_EXEC_CMD_H -#define GIT_EXEC_CMD_H - -struct argv_array; - -extern void git_set_argv_exec_path(const char *exec_path); -extern void git_extract_argv0_path(const char *path); -extern const char *git_exec_path(void); -extern void setup_path(void); -extern const char **prepare_git_cmd(struct argv_array *out, const char **argv); -extern int execv_git_cmd(const char **argv); /* NULL terminated */ -LAST_ARG_MUST_BE_NULL -extern int execl_git_cmd(const char *cmd, ...); -extern char *system_path(const char *path); - -#endif /* GIT_EXEC_CMD_H */ diff --git a/fetch-pack.c b/fetch-pack.c index adc1b68..4a8bad8 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -6,7 +6,7 @@ #include "pkt-line.h" #include "commit.h" #include "tag.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "pack.h" #include "sideband.h" #include "fetch-pack.h" diff --git a/git.c b/git.c index 3a89893..f598fae 100644 --- a/git.c +++ b/git.c @@ -1,6 +1,6 @@ #include "builtin.h" #include "config.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "help.h" #include "run-command.h" diff --git a/help.c b/help.c index 60071a9..a4feef2 100644 --- a/help.c +++ b/help.c @@ -1,7 +1,7 @@ #include "cache.h" #include "config.h" #include "builtin.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "run-command.h" #include "levenshtein.h" #include "help.h" diff --git a/http-backend.c b/http-backend.c index 88d2a9b..cc16cd0 100644 --- a/http-backend.c +++ b/http-backend.c @@ -5,7 +5,7 @@ #include "pkt-line.h" #include "object.h" #include "tag.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "run-command.h" #include "string-list.h" #include "url.h" diff --git a/http-fetch.c b/http-fetch.c index 8af3800..885e471 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -1,6 +1,6 @@ #include "cache.h" #include "config.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "http.h" #include "walker.h" diff --git a/http-push.c b/http-push.c index c0998fd..f308ce0 100644 --- a/http-push.c +++ b/http-push.c @@ -6,7 +6,7 @@ #include "refs.h" #include "diff.h" #include "revision.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "remote.h" #include "list-objects.h" #include "sigchain.h" diff --git a/imap-send.c b/imap-send.c index ffb0a6e..3573cbf 100644 --- a/imap-send.c +++ b/imap-send.c @@ -24,7 +24,7 @@ #include "cache.h" #include "config.h" #include "credential.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "run-command.h" #include "parse-options.h" #ifdef NO_OPENSSL diff --git a/remote-curl.c b/remote-curl.c index a7c4c9b..8d2ffaf 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -4,7 +4,7 @@ #include "strbuf.h" #include "walker.h" #include "http.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "run-command.h" #include "pkt-line.h" #include "string-list.h" diff --git a/remote-testsvn.c b/remote-testsvn.c index c4bb9a8..444d980 100644 --- a/remote-testsvn.c +++ b/remote-testsvn.c @@ -3,7 +3,7 @@ #include "remote.h" #include "strbuf.h" #include "url.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "run-command.h" #include "vcs-svn/svndump.h" #include "notes.h" diff --git a/run-command.c b/run-command.c index 84899e4..12c94c1 100644 --- a/run-command.c +++ b/run-command.c @@ -1,6 +1,6 @@ #include "cache.h" #include "run-command.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "sigchain.h" #include "argv-array.h" #include "thread-utils.h" diff --git a/sequencer.c b/sequencer.c index 667f35e..6d631d2 100644 --- a/sequencer.c +++ b/sequencer.c @@ -7,7 +7,7 @@ #include "sequencer.h" #include "tag.h" #include "run-command.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "utf8.h" #include "cache-tree.h" #include "diff.h" diff --git a/shell.c b/shell.c index 234b2d4..0200d10 100644 --- a/shell.c +++ b/shell.c @@ -1,6 +1,6 @@ #include "cache.h" #include "quote.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "strbuf.h" #include "run-command.h" diff --git a/upload-pack.c b/upload-pack.c index 4a82602..6261d4f 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -6,7 +6,7 @@ #include "tag.h" #include "object.h" #include "commit.h" -#include "exec_cmd.h" +#include "exec-cmd.h" #include "diff.h" #include "revision.h" #include "list-objects.h" -- cgit v0.10.2-6-g49f6