Avoid multiple PREFIX definitions

The short and sweet PREFIX can be confused when used in many places. Rename both usages to better describe their purpose. EXEC_CMD_PREFIX is used in full to disambiguate it from the nearby GIT_EXEC_PATH. The PREFIX in sideband.c, while nominally independant of the exec_cmd PREFIX, does reside within libgit[1], so the definitions would clash when taken together with a PREFIX given on the command line for use by exec_cmd.c. Noticed when compiling Git for Windows using MSVC/Visual Studio [1] which reports the conflict beteeen the command line definition and the definition in sideband.c within the libgit project. [1] the libgit functions are brought into a single sub-project within the Visual Studio construction script provided in contrib, and hence uses a single command for both exec_cmd.c and sideband.c. Signed-off-by: Philip Oakley <philipoakley@iee.org> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Philip Oakley committed Apr 21, 2018 at 13:18 UTC 4d5b4c247597a5891beb84d933b8eecb77c76186
3 files changed +8 -8
Makefile
+1 -1
@@ -2261,7 +2261,7 @@ exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
2261 '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
2262 '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
2263 '-DBINDIR="$(bindir_relative_SQ)"' \
2264 - '-DPREFIX="$(prefix_SQ)"'
2264 + '-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"'
2265
2266 builtin/init-db.sp builtin/init-db.s builtin/init-db.o: GIT-PREFIX
2267 builtin/init-db.sp builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
exec_cmd.c
+2 -2
@@ -48,7 +48,7 @@ static const char *system_prefix(void)
48 !(prefix = strip_path_suffix(executable_dirname, GIT_EXEC_PATH)) &&
49 !(prefix = strip_path_suffix(executable_dirname, BINDIR)) &&
50 !(prefix = strip_path_suffix(executable_dirname, "git"))) {
51 - prefix = PREFIX;
51 + prefix = FALLBACK_RUNTIME_PREFIX;
52 trace_printf("RUNTIME_PREFIX requested, "
53 "but prefix computation failed. "
54 "Using static fallback '%s'.\n", prefix);
@@ -243,7 +243,7 @@ void git_resolve_executable_dir(const char *argv0)
243 */
244 static const char *system_prefix(void)
245 {
246 - return PREFIX;
246 + return FALLBACK_RUNTIME_PREFIX;
247 }
248
249 /*
sideband.c
+5 -5
@@ -13,7 +13,7 @@
13 * the remote died unexpectedly. A flush() concludes the stream.
14 */
15
16 -#define PREFIX "remote: "
16 +#define DISPLAY_PREFIX "remote: "
17
18 #define ANSI_SUFFIX "\033[K"
19 #define DUMB_SUFFIX " "
@@ -49,7 +49,7 @@ int recv_sideband(const char *me, int in_stream, int out)
49 switch (band) {
50 case 3:
51 strbuf_addf(&outbuf, "%s%s%s", outbuf.len ? "\n" : "",
52 - PREFIX, buf + 1);
52 + DISPLAY_PREFIX, buf + 1);
53 retval = SIDEBAND_REMOTE_ERROR;
54 break;
55 case 2:
@@ -67,7 +67,7 @@ int recv_sideband(const char *me, int in_stream, int out)
67 int linelen = brk - b;
68
69 if (!outbuf.len)
70 - strbuf_addstr(&outbuf, PREFIX);
70 + strbuf_addstr(&outbuf, DISPLAY_PREFIX);
71 if (linelen > 0) {
72 strbuf_addf(&outbuf, "%.*s%s%c",
73 linelen, b, suffix, *brk);
@@ -81,8 +81,8 @@ int recv_sideband(const char *me, int in_stream, int out)
81 }
82
83 if (*b)
84 - strbuf_addf(&outbuf, "%s%s",
85 - outbuf.len ? "" : PREFIX, b);
84 + strbuf_addf(&outbuf, "%s%s", outbuf.len ?
85 + "" : DISPLAY_PREFIX, b);
86 break;
87 case 1:
88 write_or_die(out, buf + 1, len);