Skip to content

Commit 650c449

Browse files
peffgitster
authored andcommitted
common-main: call git_extract_argv0_path()
Every program which links against libgit.a must call this function, or risk hitting an assert() in system_path() that checks whether we have configured argv0_path (though only when RUNTIME_PREFIX is defined, so essentially only on Windows). Looking at the diff, you can see that putting it into the common main() saves us having to do it individually in each of the external commands. But what you can't see are the cases where we _should_ have been doing so, but weren't (e.g., git-credential-store, and all of the t/helper test programs). This has been an accident-waiting-to-happen for a long time, but wasn't triggered until recently because it involves one of those programs actually calling system_path(). That happened with git-credential-store in v2.8.0 with ae5f677 (lazily load core.sharedrepository, 2016-03-11). The program: - takes a lock file, which... - opens a tempfile, which... - calls adjust_shared_perm to fix permissions, which... - lazy-loads the config (as of ae5f677), which... - calls system_path() to find the location of /etc/gitconfig On systems with RUNTIME_PREFIX, this means credential-store reliably hits that assert() and cannot be used. We never noticed in the test suite, because we set GIT_CONFIG_NOSYSTEM there, which skips the system_path() lookup entirely. But if we were to tweak git_config() to find /etc/gitconfig even when we aren't going to open it, then the test suite shows multiple failures (for credential-store, and for some other test helpers). I didn't include that tweak here because it's way too specific to this particular call to be worth carrying around what is essentially dead code. The implementation is fairly straightforward, with one exception: there is exactly one caller (git.c) that actually cares about the result of the function, and not the side-effect of setting up argv0_path. We can accommodate that by simply replacing the value of argv[0] in the array we hand down to cmd_main(). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3f2e229 commit 650c449

12 files changed

+4
-19
lines changed

common-main.c

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "git-compat-util.h"
2+
#include "exec_cmd.h"
23

34
int main(int argc, char **av)
45
{
@@ -8,5 +9,7 @@ int main(int argc, char **av)
89
*/
910
const char **argv = (const char **)av;
1011

12+
argv[0] = git_extract_argv0_path(argv[0]);
13+
1114
return cmd_main(argc, argv);
1215
}

daemon.c

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "cache.h"
22
#include "pkt-line.h"
3-
#include "exec_cmd.h"
43
#include "run-command.h"
54
#include "strbuf.h"
65
#include "string-list.h"
@@ -1190,8 +1189,6 @@ int cmd_main(int argc, const char **argv)
11901189

11911190
git_setup_gettext();
11921191

1193-
git_extract_argv0_path(argv[0]);
1194-
11951192
for (i = 1; i < argc; i++) {
11961193
const char *arg = argv[i];
11971194
const char *v;

fast-import.c

-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ Format of STDIN stream:
164164
#include "refs.h"
165165
#include "csum-file.h"
166166
#include "quote.h"
167-
#include "exec_cmd.h"
168167
#include "dir.h"
169168

170169
#define PACK_ID_BITS 16
@@ -3385,8 +3384,6 @@ int cmd_main(int argc, const char **argv)
33853384
{
33863385
unsigned int i;
33873386

3388-
git_extract_argv0_path(argv[0]);
3389-
33903387
git_setup_gettext();
33913388

33923389
if (argc == 2 && !strcmp(argv[1], "-h"))

git.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ int cmd_main(int argc, const char **argv)
635635
const char *cmd;
636636
int done_help = 0;
637637

638-
cmd = git_extract_argv0_path(argv[0]);
638+
cmd = argv[0];
639639
if (!cmd)
640640
cmd = "git-help";
641641

http-backend.c

-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,6 @@ int cmd_main(int argc, const char **argv)
642642

643643
git_setup_gettext();
644644

645-
git_extract_argv0_path(argv[0]);
646645
set_die_routine(die_webcgi);
647646
set_die_is_recursing_routine(die_webcgi_recursing);
648647

http-fetch.c

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ int cmd_main(int argc, const char **argv)
2424

2525
git_setup_gettext();
2626

27-
git_extract_argv0_path(argv[0]);
28-
2927
while (arg < argc && argv[arg][0] == '-') {
3028
if (argv[arg][1] == 't') {
3129
get_tree = 1;

http-push.c

-2
Original file line numberDiff line numberDiff line change
@@ -1711,8 +1711,6 @@ int cmd_main(int argc, const char **argv)
17111711

17121712
git_setup_gettext();
17131713

1714-
git_extract_argv0_path(argv[0]);
1715-
17161714
repo = xcalloc(1, sizeof(*repo));
17171715

17181716
argv++;

imap-send.c

-2
Original file line numberDiff line numberDiff line change
@@ -1500,8 +1500,6 @@ int cmd_main(int argc, const char **argv)
15001500
int total;
15011501
int nongit_ok;
15021502

1503-
git_extract_argv0_path(argv[0]);
1504-
15051503
git_setup_gettext();
15061504

15071505
setup_git_directory_gently(&nongit_ok);

remote-curl.c

-1
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,6 @@ int cmd_main(int argc, const char **argv)
991991

992992
git_setup_gettext();
993993

994-
git_extract_argv0_path(argv[0]);
995994
setup_git_directory_gently(&nongit);
996995
if (argc < 2) {
997996
error("remote-curl: usage: git remote-curl <remote> [<url>]");

remote-testsvn.c

-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ int cmd_main(int argc, const char **argv)
292292
static struct remote *remote;
293293
const char *url_in;
294294

295-
git_extract_argv0_path(argv[0]);
296295
setup_git_directory();
297296
if (argc < 2 || argc > 3) {
298297
usage("git-remote-svn <remote-name> [<url>]");

shell.c

-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ int cmd_main(int argc, const char **argv)
147147

148148
git_setup_gettext();
149149

150-
git_extract_argv0_path(argv[0]);
151-
152150
/*
153151
* Always open file descriptors 0/1/2 to avoid clobbering files
154152
* in die(). It also avoids messing up when the pipes are dup'ed

upload-pack.c

-1
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,6 @@ int cmd_main(int argc, const char **argv)
826826
git_setup_gettext();
827827

828828
packet_trace_identity("upload-pack");
829-
git_extract_argv0_path(argv[0]);
830829
check_replace_refs = 0;
831830

832831
for (i = 1; i < argc; i++) {

0 commit comments

Comments
 (0)