{"thread":{"id":"42230","subject":"[PATCH] exec_cmd.c, sideband.c, Makefile: avoid multiple PREFIX definitions","startedAt":"2016-05-05T21:28:52Z","lastAt":"2016-05-06T16:55:11Z","messageCount":7,"participants":["Philip Oakley","Junio C Hamano","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"285604","messageId":"1462483733-3496-1-git-send-email-philipoakley@iee.org","threadId":"42230","inReplyTo":null,"subject":"[PATCH] Conflicting PREFIX usage","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.org","sentAt":"2016-05-05T21:28:52Z","receivedAt":"2016-05-05T21:28:52Z","isPatch":true,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"While trying to resurrect the MSVC/Visual Studio capability for Git\nfor Windows I noticed this little nuance.\n\nThe PREFIX in Windows was introduced in 35fb0e8 (Compute prefix at runtime\nif RUNTIME_PREFIX is set, 2009-01-18) and in sideband.c at ebe8fa7\n(fix display overlap between remote and local progress, 2007-11-04) though\nclash has not been noticed before.\n\nThe attached patch simply gives the two PREFIXs more purposeful names of\nEXEC_PREFIX and DISPLAY_PREFIX.\n\nPhilip Oakley (1):\n  exec_cmd.c, sideband.c, Makefile: avoid multiple PREFIX definitions\n\n Makefile   | 2 +-\n exec_cmd.c | 4 ++--\n sideband.c | 6 +++---\n 3 files changed, 6 insertions(+), 6 deletions(-)\n\n-- \n2.8.1.windows.1\n"},{"id":"285603","messageId":"1462483733-3496-2-git-send-email-philipoakley@iee.org","threadId":"42230","inReplyTo":"1462483733-3496-1-git-send-email-philipoakley@iee.org","subject":"[PATCH] exec_cmd.c, sideband.c, Makefile: avoid multiple PREFIX definitions","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.org","sentAt":"2016-05-05T21:28:53Z","receivedAt":"2016-05-05T21:28:53Z","isPatch":true,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"The short and sweet PREFIX can be confused when used in many places.\n\nRename both usages to better describe their purpose.\n\nNoticed when compiling Git for Windows using MSVC/Visual Studio which\nreports the conflict beteeen the command line definition and the\ndefinition in sideband.c\n\nSigned-off-by: Philip Oakley <philipoakley@iee.org>\n---\n Makefile   | 2 +-\n exec_cmd.c | 4 ++--\n sideband.c | 6 +++---\n 3 files changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 33b0f76..bcdd3ec 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1973,7 +1973,7 @@ exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX\n exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \\\n \t'-DGIT_EXEC_PATH=\"$(gitexecdir_SQ)\"' \\\n \t'-DBINDIR=\"$(bindir_relative_SQ)\"' \\\n-\t'-DPREFIX=\"$(prefix_SQ)\"'\n+\t'-DEXEC_PREFIX=\"$(prefix_SQ)\"'\n \n builtin/init-db.sp builtin/init-db.s builtin/init-db.o: GIT-PREFIX\n builtin/init-db.sp builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \\\ndiff --git a/exec_cmd.c b/exec_cmd.c\nindex 9d5703a..2a79781 100644\n--- a/exec_cmd.c\n+++ b/exec_cmd.c\n@@ -12,7 +12,7 @@ char *system_path(const char *path)\n #ifdef RUNTIME_PREFIX\n \tstatic const char *prefix;\n #else\n-\tstatic const char *prefix = PREFIX;\n+\tstatic const char *prefix = EXEC_PREFIX;\n #endif\n \tstruct strbuf d = STRBUF_INIT;\n \n@@ -27,7 +27,7 @@ char *system_path(const char *path)\n \t    !(prefix = strip_path_suffix(argv0_path, GIT_EXEC_PATH)) &&\n \t    !(prefix = strip_path_suffix(argv0_path, BINDIR)) &&\n \t    !(prefix = strip_path_suffix(argv0_path, \"git\"))) {\n-\t\tprefix = PREFIX;\n+\t\tprefix = EXEC_PREFIX;\n \t\ttrace_printf(\"RUNTIME_PREFIX requested, \"\n \t\t\t\t\"but prefix computation failed.  \"\n \t\t\t\t\"Using static fallback '%s'.\\n\", prefix);\ndiff --git a/sideband.c b/sideband.c\nindex fde8adc..d448ba7 100644\n--- a/sideband.c\n+++ b/sideband.c\n@@ -13,7 +13,7 @@\n  * the remote died unexpectedly.  A flush() concludes the stream.\n  */\n \n-#define PREFIX \"remote:\"\n+#define DISPLAY_PREFIX \"remote:\"\n \n #define ANSI_SUFFIX \"\\033[K\"\n #define DUMB_SUFFIX \"        \"\n@@ -22,13 +22,13 @@\n \n int recv_sideband(const char *me, int in_stream, int out)\n {\n-\tunsigned pf = strlen(PREFIX);\n+\tunsigned pf = strlen(DISPLAY_PREFIX);\n \tunsigned sf;\n \tchar buf[LARGE_PACKET_MAX + 2*FIX_SIZE];\n \tchar *suffix, *term;\n \tint skip_pf = 0;\n \n-\tmemcpy(buf, PREFIX, pf);\n+\tmemcpy(buf, DISPLAY_PREFIX, pf);\n \tterm = getenv(\"TERM\");\n \tif (isatty(2) && term && strcmp(term, \"dumb\"))\n \t\tsuffix = ANSI_SUFFIX;\n-- \n2.8.1.windows.1\n"},{"id":"285633","messageId":"xmqqk2j89n9y.fsf@gitster.mtv.corp.google.com","threadId":"42230","inReplyTo":"1462483733-3496-2-git-send-email-philipoakley@iee.org","subject":"Re: [PATCH] exec_cmd.c, sideband.c, Makefile: avoid multiple PREFIX definitions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-05T22:02:17Z","receivedAt":"2016-05-05T22:02:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Philip Oakley <philipoakley@iee.org> writes:\n\n> The short and sweet PREFIX can be confused when used in many places.\n>\n> Rename both usages to better describe their purpose.\n>\n> Noticed when compiling Git for Windows using MSVC/Visual Studio which\n> reports the conflict beteeen the command line definition and the\n> definition in sideband.c\n\nGood eyes.\n\n>\n> Signed-off-by: Philip Oakley <philipoakley@iee.org>\n> ---\n>  Makefile   | 2 +-\n>  exec_cmd.c | 4 ++--\n>  sideband.c | 6 +++---\n>  3 files changed, 6 insertions(+), 6 deletions(-)\n>\n> diff --git a/Makefile b/Makefile\n> index 33b0f76..bcdd3ec 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -1973,7 +1973,7 @@ exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX\n>  exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \\\n>  \t'-DGIT_EXEC_PATH=\"$(gitexecdir_SQ)\"' \\\n>  \t'-DBINDIR=\"$(bindir_relative_SQ)\"' \\\n> -\t'-DPREFIX=\"$(prefix_SQ)\"'\n> +\t'-DEXEC_PREFIX=\"$(prefix_SQ)\"'\n\nI am not entirely happy with this name as the name can be easily\nconfused with GIT_EXEC_PATH.\n\nThis is a fallback used under RUNTIME_PREFIX option, if I am reading\nthe code correctly, so the name should hint the linkage between the\n\"runtime prefix\" mechanism and this variable.\n\nPerhaps RUNTIME_PREFIX_FALLBACK?  Used at only two places, that\nshould not be an overlong name.\n\nDISPLAY_PREFIX is OK, as it is an entirely a local thing to\nsideband.c, but with the externally visible PREFIX fixed to be a\nmore appropriate name that hints its relation with the \"runtime\nprefix\" mechanism, it may be better not to even touch it.\n\n>  builtin/init-db.sp builtin/init-db.s builtin/init-db.o: GIT-PREFIX\n>  builtin/init-db.sp builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \\\n> diff --git a/exec_cmd.c b/exec_cmd.c\n> index 9d5703a..2a79781 100644\n> --- a/exec_cmd.c\n> +++ b/exec_cmd.c\n> @@ -12,7 +12,7 @@ char *system_path(const char *path)\n>  #ifdef RUNTIME_PREFIX\n>  \tstatic const char *prefix;\n>  #else\n> -\tstatic const char *prefix = PREFIX;\n> +\tstatic const char *prefix = EXEC_PREFIX;\n>  #endif\n>  \tstruct strbuf d = STRBUF_INIT;\n>  \n> @@ -27,7 +27,7 @@ char *system_path(const char *path)\n>  \t    !(prefix = strip_path_suffix(argv0_path, GIT_EXEC_PATH)) &&\n>  \t    !(prefix = strip_path_suffix(argv0_path, BINDIR)) &&\n>  \t    !(prefix = strip_path_suffix(argv0_path, \"git\"))) {\n> -\t\tprefix = PREFIX;\n> +\t\tprefix = EXEC_PREFIX;\n>  \t\ttrace_printf(\"RUNTIME_PREFIX requested, \"\n>  \t\t\t\t\"but prefix computation failed.  \"\n>  \t\t\t\t\"Using static fallback '%s'.\\n\", prefix);\n"},{"id":"285666","messageId":"572C3723.8010508@kdbg.org","threadId":"42230","inReplyTo":"1462483733-3496-2-git-send-email-philipoakley@iee.org","subject":"Re: [git-for-windows] [PATCH] exec_cmd.c, sideband.c, Makefile: avoid multiple PREFIX definitions","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2016-05-06T06:18:11Z","receivedAt":"2016-05-06T06:18:11Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 05.05.2016 um 23:28 schrieb Philip Oakley:\n> The short and sweet PREFIX can be confused when used in many places.\n>\n> Rename both usages to better describe their purpose.\n>\n> Noticed when compiling Git for Windows using MSVC/Visual Studio which\n> reports the conflict beteeen the command line definition and the\n> definition in sideband.c\n\nYou should describe the circumstances better under which you notice a \nconflict, because there is no conflict when Git is built with the \nMakefile and 'make':\n\n> diff --git a/Makefile b/Makefile\n> index 33b0f76..bcdd3ec 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -1973,7 +1973,7 @@ exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX\n>   exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \\\n>   \t'-DGIT_EXEC_PATH=\"$(gitexecdir_SQ)\"' \\\n>   \t'-DBINDIR=\"$(bindir_relative_SQ)\"' \\\n> -\t'-DPREFIX=\"$(prefix_SQ)\"'\n> +\t'-DEXEC_PREFIX=\"$(prefix_SQ)\"'\n\nNotice that PREFIX is set only for a small subset of .c files. \nsideband.c is not among them.\n\n-- Hannes\n"},{"id":"285672","messageId":"1C7D96C1B53D45CCAA8658C9DBB1AAB5@PhilipOakley","threadId":"42230","inReplyTo":"xmqqk2j89n9y.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] exec_cmd.c, sideband.c, Makefile: avoid multiple PREFIX definitions","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.org","sentAt":"2016-05-06T07:23:23Z","receivedAt":"2016-05-06T07:23:23Z","isPatch":true,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"From: \"Junio C Hamano\" <gitster@pobox.com>\n> Philip Oakley <philipoakley@iee.org> writes:\n>\n>> The short and sweet PREFIX can be confused when used in many places.\n>>\n>> Rename both usages to better describe their purpose.\n>>\n>> Noticed when compiling Git for Windows using MSVC/Visual Studio which\n>> reports the conflict beteeen the command line definition and the\n>> definition in sideband.c\n>\n> Good eyes.\n>\n>>\n>> Signed-off-by: Philip Oakley <philipoakley@iee.org>\n>> ---\n>>  Makefile   | 2 +-\n>>  exec_cmd.c | 4 ++--\n>>  sideband.c | 6 +++---\n>>  3 files changed, 6 insertions(+), 6 deletions(-)\n>>\n>> diff --git a/Makefile b/Makefile\n>> index 33b0f76..bcdd3ec 100644\n>> --- a/Makefile\n>> +++ b/Makefile\n>> @@ -1973,7 +1973,7 @@ exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX\n>>  exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \\\n>>  '-DGIT_EXEC_PATH=\"$(gitexecdir_SQ)\"' \\\n>>  '-DBINDIR=\"$(bindir_relative_SQ)\"' \\\n>> - '-DPREFIX=\"$(prefix_SQ)\"'\n>> + '-DEXEC_PREFIX=\"$(prefix_SQ)\"'\n>\n> I am not entirely happy with this name as the name can be easily\n> confused with GIT_EXEC_PATH.\n>\n> This is a fallback used under RUNTIME_PREFIX option, if I am reading\n> the code correctly, so the name should hint the linkage between the\n> \"runtime prefix\" mechanism and this variable.\n>\n> Perhaps RUNTIME_PREFIX_FALLBACK?  Used at only two places, that\n> should not be an overlong name.\n\nPerhaps EXEC_CMD_PREFIX, for that is what it is? And it's got a 2-way \ndifference from the GIT_EXEC_PATH. I wasn't seeing it as a fallback, rather \njust a different way the OS uses to get to the path. If anything \nRUNTIME_PREFIX feels a bit long for a flag.\n\n>\n> DISPLAY_PREFIX is OK, as it is an entirely a local thing to\n> sideband.c, but with the externally visible PREFIX fixed to be a\n> more appropriate name that hints its relation with the \"runtime\n> prefix\" mechanism, it may be better not to even touch it.\n>\n>>  builtin/init-db.sp builtin/init-db.s builtin/init-db.o: GIT-PREFIX\n>>  builtin/init-db.sp builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \n>> \\\n>> diff --git a/exec_cmd.c b/exec_cmd.c\n>> index 9d5703a..2a79781 100644\n>> --- a/exec_cmd.c\n>> +++ b/exec_cmd.c\n>> @@ -12,7 +12,7 @@ char *system_path(const char *path)\n>>  #ifdef RUNTIME_PREFIX\n>>  static const char *prefix;\n>>  #else\n>> - static const char *prefix = PREFIX;\n>> + static const char *prefix = EXEC_PREFIX;\n>>  #endif\n>>  struct strbuf d = STRBUF_INIT;\n>>\n>> @@ -27,7 +27,7 @@ char *system_path(const char *path)\n>>      !(prefix = strip_path_suffix(argv0_path, GIT_EXEC_PATH)) &&\n>>      !(prefix = strip_path_suffix(argv0_path, BINDIR)) &&\n>>      !(prefix = strip_path_suffix(argv0_path, \"git\"))) {\n>> - prefix = PREFIX;\n>> + prefix = EXEC_PREFIX;\n>>  trace_printf(\"RUNTIME_PREFIX requested, \"\n>>  \"but prefix computation failed.  \"\n>>  \"Using static fallback '%s'.\\n\", prefix);\n> \n"},{"id":"285673","messageId":"1F2FA999624B417EB2EC2FF7F2EA3828@PhilipOakley","threadId":"42230","inReplyTo":"572C3723.8010508@kdbg.org","subject":"Re: [git-for-windows] [PATCH] exec_cmd.c, sideband.c, Makefile: avoid multiple PREFIX definitions","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.org","sentAt":"2016-05-06T07:31:17Z","receivedAt":"2016-05-06T07:31:17Z","isPatch":true,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"From: \"Johannes Sixt\" <j6t@kdbg.org>\n> Am 05.05.2016 um 23:28 schrieb Philip Oakley:\n>> The short and sweet PREFIX can be confused when used in many places.\n>>\n>> Rename both usages to better describe their purpose.\n>>\n>> Noticed when compiling Git for Windows using MSVC/Visual Studio which\n>> reports the conflict beteeen the command line definition and the\n>> definition in sideband.c\n>\n> You should describe the circumstances better under which you notice a \n> conflict, because there is no conflict when Git is built with the Makefile \n> and 'make':\n\nI haven't dug deep into the G4W make results so I can't say either way \nregarding the make on G4W, but it does show when creating the Git.sln \nproject via the contrib process. It is specific to the Windows OS and how it \ngenerates the path to the exe (You will know far more than me).\n\nsee below regarding commit message\n\n>\n>> diff --git a/Makefile b/Makefile\n>> index 33b0f76..bcdd3ec 100644\n>> --- a/Makefile\n>> +++ b/Makefile\n>> @@ -1973,7 +1973,7 @@ exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX\n>>   exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \\\n>>   '-DGIT_EXEC_PATH=\"$(gitexecdir_SQ)\"' \\\n>>   '-DBINDIR=\"$(bindir_relative_SQ)\"' \\\n>> - '-DPREFIX=\"$(prefix_SQ)\"'\n>> + '-DEXEC_PREFIX=\"$(prefix_SQ)\"'\n>\n> Notice that PREFIX is set only for a small subset of .c files. sideband.c \n> is not among them.\n\nThe issue is in the libgit sub-project, where both reside side by side, and \nwhen sideband.c is being compiled, the PREFIX has also been declared on the \ncommand line, thus giving the unexpected conflict.\n\nI'll bring more of the explanation into the commit message.\n\n--\nPhilip \n"},{"id":"285753","messageId":"xmqqd1oz5dow.fsf@gitster.mtv.corp.google.com","threadId":"42230","inReplyTo":"1C7D96C1B53D45CCAA8658C9DBB1AAB5@PhilipOakley","subject":"Re: [PATCH] exec_cmd.c, sideband.c, Makefile: avoid multiple PREFIX definitions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-06T16:55:11Z","receivedAt":"2016-05-06T16:55:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dropped \"git-for-windows\" <git-for-windows@googlegroups.com> from\nthe Cc: list, as I seem to be getting bounces from it due to its\nmoderation policy.\n\n\"Philip Oakley\" <philipoakley@iee.org> writes:\n\n> Perhaps EXEC_CMD_PREFIX, for that is what it is?\n\nThat name is doubly wrong, I have to say.\n\nThis is used only after RUNTIME_PREFIX heuristics to learn the\nbinary location from argv[0] fails, or the result of it does not\nhave expected suffix string (i.e. GIT_EXEC_PATH . BINDIR . \"git\").\nThe code even says this:\n\n\tif (!prefix &&\n\t    !(prefix = strip_path_suffix(argv0_path, GIT_EXEC_PATH)) &&\n\t    !(prefix = strip_path_suffix(argv0_path, BINDIR)) &&\n\t    !(prefix = strip_path_suffix(argv0_path, \"git\"))) {\n\t\tprefix = PREFIX;\n\t\ttrace_printf(\"RUNTIME_PREFIX requested, \"\n\t\t\t\t\"but prefix computation failed.  \"\n\t\t\t\t\"Using static fallback '%s'.\\n\", prefix);\n\t}\n\nNotice \"static fallback\" there?\n\nI have a very strong preference for the name to reflect that fact.\nI.e.  send a signal to those who do not use RUNTIME_PREFIX\nconfiguration that they do not have to care.\n\nAlso \"EXEC\" is wrong, too.  The way the 'prefix' variable we see\nabove is used is that system_path() takes a directory path to\nvarious installed component of the Git package, e.g. GIT_MAN_PATH\nis the location for manual pages, as its \"path\" parameter, and\nthen \n\n\tstrbuf_addf(&d, \"%s/%s\", prefix, path);\n\nis used to formulate the absolute path for it.  A name with \"EXEC\"\nin it would incorrectly hint that it points at a rough equivalent to\n/usr/local/bin/ or /usr/local/libexec/git/, but PREFIX corresponds\nmore to /usr/local/.\n\nEven if J6t's point about these two separate PREFIXes should never\nexist at the same time is correct, I think it is a good change to\nuse a more explicit name for this variable that is used to\ncommunicate between Makefile and the *.c source.\n\nAs to your \"RUNTIME_PREFIX_FALLBACK is very long\" objection, I do\nnot care ;-) More seriously, this is not something typed very often.\nIt appears only twice in this codepath and having clear names to\ntell readers what it is about is much more important.\n\nI do agree the most logical name, after understanding all of the\nabove, which is RUNTIME_PREFIX_STATIC_FALLBACK, may be a bit too\nlong, though.\n"}]}