Skip to content

Commit 39b2f6a

Browse files
peffgitster
authored andcommitted
system_path: move RUNTIME_PREFIX to a sub-function
The system_path() function has an #ifdef in the middle of it. Let's move the conditional logic into a sub-function. This isolates it more, which will make it easier to change and add to. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3d9c5b5 commit 39b2f6a

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

exec_cmd.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,12 @@
77
static const char *argv_exec_path;
88
static const char *argv0_path;
99

10-
char *system_path(const char *path)
11-
{
1210
#ifdef RUNTIME_PREFIX
13-
static const char *prefix;
14-
#else
15-
static const char *prefix = PREFIX;
16-
#endif
17-
struct strbuf d = STRBUF_INIT;
1811

19-
if (is_absolute_path(path))
20-
return xstrdup(path);
12+
static const char *system_prefix(void)
13+
{
14+
static const char *prefix;
2115

22-
#ifdef RUNTIME_PREFIX
2316
assert(argv0_path);
2417
assert(is_absolute_path(argv0_path));
2518

@@ -32,9 +25,25 @@ char *system_path(const char *path)
3225
"but prefix computation failed. "
3326
"Using static fallback '%s'.\n", prefix);
3427
}
35-
#endif
28+
return prefix;
29+
}
30+
#else
31+
32+
static const char *system_prefix(void)
33+
{
34+
return PREFIX;
35+
}
36+
37+
#endif /* RUNTIME_PREFIX */
38+
39+
char *system_path(const char *path)
40+
{
41+
struct strbuf d = STRBUF_INIT;
42+
43+
if (is_absolute_path(path))
44+
return xstrdup(path);
3645

37-
strbuf_addf(&d, "%s/%s", prefix, path);
46+
strbuf_addf(&d, "%s/%s", system_prefix(), path);
3847
return strbuf_detach(&d, NULL);
3948
}
4049

0 commit comments

Comments
 (0)