{"thread":{"id":"15056","subject":"[PATCH 3/7] Refactor git_set_argv0_path() to git_extract_argv0_path()","startedAt":"2008-08-17T12:44:36Z","lastAt":"2008-09-21T07:48:27Z","messageCount":16,"participants":["Steffen Prohaska","Junio C Hamano","Johannes Sixt","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"87437","messageId":"1218977083-14526-1-git-send-email-prohaska@zib.de","threadId":"15056","inReplyTo":null,"subject":"[PATCH 0/7] prefix discovery at runtime (on Windows)","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-08-17T12:44:36Z","receivedAt":"2008-08-17T12:44:36Z","isPatch":true,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"Hi,\nThis patch series fixes discovery of the installation prefix at runtime on\nWindows.  It introduces a compile flag RUNTIME_PREFIX, which can be set to\nexplicitly request prefix computation at runtime.\n\nApologies for proposing such large changes that late in the release cycle.\nMaybe we want to postpone the series until 1.6.0.1 or even 1.6.1.  Note however\nthat in this case we should consider not releasing 1.6.0 on Windows because the\ncurrent solution in master does not reliably read the system wide configuration\non Windows.\n\nWe probably won't see a Windows installer before mid of September anyway,\nunless someone temporarily takes over the position of the msysgit maintainer\nuntil I return from holidays.  I'll be completely offline from August 25\nuntil September 13.\n\n        Steffen\n\n Makefile       |   21 +++++++++++------\n daemon.c       |    3 ++\n exec_cmd.c     |   67 ++++++++++++++++++++++++++++++++++++++++++++++++-------\n exec_cmd.h     |    2 +-\n fast-import.c  |    4 +++\n git.c          |   20 ++++------------\n hash-object.c  |    4 +++\n index-pack.c   |    4 +++\n receive-pack.c |    3 ++\n unpack-file.c  |    4 +++\n upload-pack.c  |    3 ++\n var.c          |    4 +++\n 12 files changed, 107 insertions(+), 32 deletions(-)\n\n [PATCH 1/7] Windows: Add workaround for MSYS' path conversion\n [PATCH 2/7] system_path(): Add prefix computation at runtime if RUNTIME_PREFIX set\n [PATCH 3/7] Refactor git_set_argv0_path() to git_extract_argv0_path()\n [PATCH 4/7] Glean libexec path from argv[0] for git-upload-pack and git-receive-pack.\n [PATCH 5/7] Add calls to git_extract_argv0_path() in programs that call git_config_*\n [PATCH 6/7] Modify setup_path() to only add git_exec_path() to PATH\n [PATCH 7/7] Windows: Revert to default paths and convert them by RUNTIME_PREFIX\n"},{"id":"87435","messageId":"1218977083-14526-2-git-send-email-prohaska@zib.de","threadId":"15056","inReplyTo":"1218977083-14526-1-git-send-email-prohaska@zib.de","subject":"[PATCH 1/7] Windows: Add workaround for MSYS' path conversion","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-08-17T12:44:37Z","receivedAt":"2008-08-17T12:44:37Z","isPatch":true,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"MSYS' automatic path conversion causes problems when passing paths as '-D'\narguments to the compiler.  MSYS tries to be smart and converts absolute\npaths to native Windows paths.  But we want the paths as we compute them in\nthe Makefile.\n\nThis commit adds a workaround by replacing \"/\" with its octal\nrepresentation \"\\057\", effectively hiding the path from MSYS.  MSYS does no\nlonger see the absolute path and therefore leaves it alone.\n\nSigned-off-by: Steffen Prohaska <prohaska@zib.de>\n---\n Makefile |   14 ++++++++++----\n 1 files changed, 10 insertions(+), 4 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 53ab4b5..9df5a9d 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1042,6 +1042,12 @@ template_dir_SQ = $(subst ','\\'',$(template_dir))\n htmldir_SQ = $(subst ','\\'',$(htmldir))\n prefix_SQ = $(subst ','\\'',$(prefix))\n \n+ETC_GITCONFIG_SQ_C = $(subst /,\\057,$(ETC_GITCONFIG_SQ))\n+bindir_SQ_C = $(subst /,\\057,$(bindir_SQ))\n+gitexecdir_SQ_C = $(subst /,\\057,$(gitexecdir_SQ))\n+htmldir_SQ_C = $(subst /,\\057,$(htmldir_SQ))\n+template_dir_SQ_C = $(subst /,\\057,$(template_dir_SQ))\n+\n SHELL_PATH_SQ = $(subst ','\\'',$(SHELL_PATH))\n PERL_PATH_SQ = $(subst ','\\'',$(PERL_PATH))\n TCLTK_PATH_SQ = $(subst ','\\'',$(TCLTK_PATH))\n@@ -1093,7 +1099,7 @@ git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)\n \n help.o: help.c common-cmds.h GIT-CFLAGS\n \t$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \\\n-\t\t'-DGIT_HTML_PATH=\"$(htmldir_SQ)\"' \\\n+\t\t'-DGIT_HTML_PATH=\"$(htmldir_SQ_C)\"' \\\n \t\t'-DGIT_MAN_PATH=\"$(mandir_SQ)\"' \\\n \t\t'-DGIT_INFO_PATH=\"$(infodir_SQ)\"' $<\n \n@@ -1197,12 +1203,12 @@ git.o git.spec \\\n \t$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<\n \n exec_cmd.o: exec_cmd.c GIT-CFLAGS\n-\t$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) '-DGIT_EXEC_PATH=\"$(gitexecdir_SQ)\"' $<\n+\t$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) '-DGIT_EXEC_PATH=\"$(gitexecdir_SQ_C)\"' -DBINDIR='\"$(bindir_SQ_C)\"' $<\n builtin-init-db.o: builtin-init-db.c GIT-CFLAGS\n-\t$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='\"$(template_dir_SQ)\"' $<\n+\t$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='\"$(template_dir_SQ_C)\"' $<\n \n config.o: config.c GIT-CFLAGS\n-\t$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DETC_GITCONFIG='\"$(ETC_GITCONFIG_SQ)\"' $<\n+\t$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DETC_GITCONFIG='\"$(ETC_GITCONFIG_SQ_C)\"' $<\n \n http.o: http.c GIT-CFLAGS\n \t$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DGIT_USER_AGENT='\"git/$(GIT_VERSION)\"' $<\n-- \n1.6.0.rc3.22.g053fd\n"},{"id":"87436","messageId":"1218977083-14526-3-git-send-email-prohaska@zib.de","threadId":"15056","inReplyTo":"1218977083-14526-2-git-send-email-prohaska@zib.de","subject":"[PATCH 2/7] system_path(): Add prefix computation at runtime if RUNTIME_PREFIX set","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-08-17T12:44:38Z","receivedAt":"2008-08-17T12:44:38Z","isPatch":true,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"This commit modifies system_path() to compute the prefix at runtime\nif explicitly requested to do so.  If RUNTIME_PREFIX is defined,\nsystem_path() tries to strip known directories that executables can\nbe located in from the path of the executable.  If the path is\nsuccessfully stripped it is used as the prefix.\n\nWe print errors if the runtime prefix computation fails.  The user\nneeds to know that the global configuration are not picked up,\nbecause this can cause unexpected behavior.  If a user explicitly\nwants to ignore system wide paths, he can set GIT_CONFIG_NOSYSTEM,\nas our tests do.\n\nSigned-off-by: Steffen Prohaska <prohaska@zib.de>\n---\n Makefile   |    3 +++\n exec_cmd.c |   48 ++++++++++++++++++++++++++++++++++++++++++++----\n 2 files changed, 47 insertions(+), 4 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 9df5a9d..8341558 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -982,6 +982,9 @@ ifdef INTERNAL_QSORT\n \tCOMPAT_CFLAGS += -DINTERNAL_QSORT\n \tCOMPAT_OBJS += compat/qsort.o\n endif\n+ifdef RUNTIME_PREFIX\n+\tCOMPAT_CFLAGS += -DRUNTIME_PREFIX\n+endif\n \n ifdef THREADED_DELTA_SEARCH\n \tBASIC_CFLAGS += -DTHREADED_DELTA_SEARCH\ndiff --git a/exec_cmd.c b/exec_cmd.c\nindex ce6741e..1622481 100644\n--- a/exec_cmd.c\n+++ b/exec_cmd.c\n@@ -9,11 +9,51 @@ static const char *argv0_path;\n \n const char *system_path(const char *path)\n {\n-\tif (!is_absolute_path(path) && argv0_path) {\n-\t\tstruct strbuf d = STRBUF_INIT;\n-\t\tstrbuf_addf(&d, \"%s/%s\", argv0_path, path);\n-\t\tpath = strbuf_detach(&d, NULL);\n+#ifdef RUNTIME_PREFIX\n+\tstatic const char *prefix;\n+\n+\tif (!argv0_path) {\n+\t\tfprintf(stderr, \"RUNTIME_PREFIX requested for path '%s', \"\n+\t\t\t\t\"but argv0_path not set.\\n\", path);\n+\t\treturn path;\n+\t}\n+\n+\tif (!prefix) {\n+\t\tconst char *strip[] = {\n+\t\t\tGIT_EXEC_PATH,\n+\t\t\tBINDIR,\n+\t\t\t0\n+\t\t};\n+\t\tconst char **s;\n+\n+\t\tfor (s = strip; *s; s++) {\n+\t\t\tconst char *sargv = argv0_path + strlen(argv0_path);\n+\t\t\tconst char *ss = *s + strlen(*s);\n+\t\t\twhile (argv0_path < sargv && *s < ss\n+\t\t\t\t&& (*sargv == *ss ||\n+\t\t\t\t    (is_dir_sep(*sargv) && is_dir_sep(*ss)))) {\n+\t\t\t\tsargv--;\n+\t\t\t\tss--;\n+\t\t\t}\n+\t\t\tif (*s == ss) {\n+\t\t\t\tstruct strbuf d = STRBUF_INIT;\n+\t\t\t\tstrbuf_add(&d, argv0_path, sargv - argv0_path);\n+\t\t\t\tprefix = strbuf_detach(&d, NULL);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n \t}\n+\n+\tif (!prefix) {\n+\t\tfprintf(stderr, \"RUNTIME_PREFIX requested for path '%s', \"\n+\t\t\t\t\"but prefix computation failed.\\n\", path);\n+\t\treturn path;\n+\t}\n+\n+\tstruct strbuf d = STRBUF_INIT;\n+\tstrbuf_addf(&d, \"%s/%s\", prefix, path);\n+\tpath = strbuf_detach(&d, NULL);\n+#endif\n \treturn path;\n }\n \n-- \n1.6.0.rc3.22.g053fd\n"},{"id":"87434","messageId":"1218977083-14526-4-git-send-email-prohaska@zib.de","threadId":"15056","inReplyTo":"1218977083-14526-3-git-send-email-prohaska@zib.de","subject":"[PATCH 3/7] Refactor git_set_argv0_path() to git_extract_argv0_path()","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-08-17T12:44:39Z","receivedAt":"2008-08-17T12:44:39Z","isPatch":true,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"From: Steve Haslam <shaslam@lastminute.com>\n\nThis commit moves the code that computes the dirname of argv[0]\nfrom git.c's main() to git_set_argv0_path() and renames the function\nto git_extract_argv0_path().  This makes the code in git.c's main\nless cluttered, and we can use the direname computation from other\nmain() functions too.\n\n[spr: split Steve's original commit and wrote new commit message. ]\n\nSigned-off-by: Steve Haslam <shaslam@lastminute.com>\nSigned-off-by: Steffen Prohaska <prohaska@zib.de>\n---\n exec_cmd.c |   15 +++++++++++++--\n exec_cmd.h |    2 +-\n git.c      |   20 +++++---------------\n 3 files changed, 19 insertions(+), 18 deletions(-)\n\ndiff --git a/exec_cmd.c b/exec_cmd.c\nindex 1622481..d84e9e9 100644\n--- a/exec_cmd.c\n+++ b/exec_cmd.c\n@@ -57,9 +57,20 @@ const char *system_path(const char *path)\n \treturn path;\n }\n \n-void git_set_argv0_path(const char *path)\n+const char *git_extract_argv0_path(const char *argv0)\n {\n-\targv0_path = path;\n+\tconst char *slash = argv0 + strlen(argv0);\n+\n+\tdo\n+\t\t--slash;\n+\twhile (slash >= argv0 && !is_dir_sep(*slash));\n+\n+\tif (slash >= argv0) {\n+\t\targv0_path = xstrndup(argv0, slash - argv0);\n+\t\treturn slash + 1;\n+\t}\n+\n+\treturn argv0;\n }\n \n void git_set_argv_exec_path(const char *exec_path)\ndiff --git a/exec_cmd.h b/exec_cmd.h\nindex 594f961..392e903 100644\n--- a/exec_cmd.h\n+++ b/exec_cmd.h\n@@ -2,7 +2,7 @@\n #define GIT_EXEC_CMD_H\n \n extern void git_set_argv_exec_path(const char *exec_path);\n-extern void git_set_argv0_path(const char *path);\n+extern const char* git_extract_argv0_path(const char *path);\n extern const char* git_exec_path(void);\n extern void setup_path(void);\n extern const char **prepare_git_cmd(const char **argv);\ndiff --git a/git.c b/git.c\nindex 37b1d76..b1eff4a 100644\n--- a/git.c\n+++ b/git.c\n@@ -416,23 +416,13 @@ static void execv_dashed_external(const char **argv)\n \n int main(int argc, const char **argv)\n {\n-\tconst char *cmd = argv[0] && *argv[0] ? argv[0] : \"git-help\";\n-\tchar *slash = (char *)cmd + strlen(cmd);\n+\tconst char *cmd;\n \tint done_alias = 0;\n \n-\t/*\n-\t * Take the basename of argv[0] as the command\n-\t * name, and the dirname as the default exec_path\n-\t * if we don't have anything better.\n-\t */\n-\tdo\n-\t\t--slash;\n-\twhile (cmd <= slash && !is_dir_sep(*slash));\n-\tif (cmd <= slash) {\n-\t\t*slash++ = 0;\n-\t\tgit_set_argv0_path(cmd);\n-\t\tcmd = slash;\n-\t}\n+\tif (argv[0] && *argv[0])\n+\t\tcmd = git_extract_argv0_path(argv[0]);\n+\telse\n+\t\tcmd = \"git-help\";\n \n \t/*\n \t * \"git-xxxx\" is the same as \"git xxxx\", but we obviously:\n-- \n1.6.0.rc3.22.g053fd\n"},{"id":"87440","messageId":"1218977083-14526-5-git-send-email-prohaska@zib.de","threadId":"15056","inReplyTo":"1218977083-14526-4-git-send-email-prohaska@zib.de","subject":"[PATCH 4/7] Glean libexec path from argv[0] for git-upload-pack and git-receive-pack.","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-08-17T12:44:40Z","receivedAt":"2008-08-17T12:44:40Z","isPatch":true,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"From: Steve Haslam <shaslam@lastminute.com>\n\nIf the user specified the full path to git-upload-pack as the -u option to\n\"git clone\" when cloning a remote repository, and git was not on the default\nPATH on the remote machine, git-upload-pack was failing to exec\ngit-pack-objects.\n\nBy making the argv[0] path (if any) available to setup_path(), this will\nallow finding the \"git\" executable in the same directory as\n\"git-upload-pack\". The default built in to exec_cmd.c is to look for \"git\"\nin the \".../libexec/git-core\" directory, but it is not installed there (any\nlonger).\n\nMuch the same applies to invoking git-receive-pack from a non-PATH location\nusing the \"--exec\" argument to \"git push\".\n\n[ spr: split Steve's original commit into two commits. ]\n\nSigned-off-by: Steve Haslam <shaslam@lastminute.com>\nSigned-off-by: Steffen Prohaska <prohaska@zib.de>\n---\n receive-pack.c |    3 +++\n upload-pack.c  |    3 +++\n 2 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/receive-pack.c b/receive-pack.c\nindex d44c19e..3699b16 100644\n--- a/receive-pack.c\n+++ b/receive-pack.c\n@@ -467,6 +467,9 @@ int main(int argc, char **argv)\n \tint i;\n \tchar *dir = NULL;\n \n+\tif (argv[0] && *argv[0])\n+\t\tgit_extract_argv0_path(argv[0]);\n+\n \targv++;\n \tfor (i = 1; i < argc; i++) {\n \t\tchar *arg = *argv++;\ndiff --git a/upload-pack.c b/upload-pack.c\nindex c911e70..086eff6 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -616,6 +616,9 @@ int main(int argc, char **argv)\n \tint i;\n \tint strict = 0;\n \n+\tif (argv[0] && *argv[0])\n+\t\tgit_extract_argv0_path(argv[0]);\n+\n \tfor (i = 1; i < argc; i++) {\n \t\tchar *arg = argv[i];\n \n-- \n1.6.0.rc3.22.g053fd\n"},{"id":"87439","messageId":"1218977083-14526-6-git-send-email-prohaska@zib.de","threadId":"15056","inReplyTo":"1218977083-14526-5-git-send-email-prohaska@zib.de","subject":"[PATCH 5/7] Add calls to git_extract_argv0_path() in programs that call git_config_*","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-08-17T12:44:41Z","receivedAt":"2008-08-17T12:44:41Z","isPatch":true,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"Programs that use git_config need to find the global\nconfiguration.  When runtime prefix computation is enabled, this\nrequires that git_extract_argv0_path() is called early in the\nprogram's main().\n\nThis commit adds the necessary calls in the programs that use\ngit_config.\n\nSigned-off-by: Steffen Prohaska <prohaska@zib.de>\n---\n daemon.c      |    3 +++\n fast-import.c |    4 ++++\n hash-object.c |    4 ++++\n index-pack.c  |    4 ++++\n unpack-file.c |    4 ++++\n var.c         |    4 ++++\n 6 files changed, 23 insertions(+), 0 deletions(-)\n\ndiff --git a/daemon.c b/daemon.c\nindex 8dcde73..172854e 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -1055,6 +1055,9 @@ int main(int argc, char **argv)\n \tgid_t gid = 0;\n \tint i;\n \n+\tif (argv[0] && *argv[0])\n+\t\tgit_extract_argv0_path(argv[0]);\n+\n \t/* Without this we cannot rely on waitpid() to tell\n \t * what happened to our children.\n \t */\ndiff --git a/fast-import.c b/fast-import.c\nindex 7089e6f..7789d60 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -150,6 +150,7 @@ Format of STDIN stream:\n #include \"refs.h\"\n #include \"csum-file.h\"\n #include \"quote.h\"\n+#include \"exec_cmd.h\"\n \n #define PACK_ID_BITS 16\n #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)\n@@ -2394,6 +2395,9 @@ int main(int argc, const char **argv)\n {\n \tunsigned int i, show_stats = 1;\n \n+\tif (argv[0] && *argv[0])\n+\t\tgit_extract_argv0_path(argv[0]);\n+\n \tsetup_git_directory();\n \tgit_config(git_pack_config, NULL);\n \tif (!pack_compression_seen && core_compression_seen)\ndiff --git a/hash-object.c b/hash-object.c\nindex 46c06a9..0f77a46 100644\n--- a/hash-object.c\n+++ b/hash-object.c\n@@ -7,6 +7,7 @@\n #include \"cache.h\"\n #include \"blob.h\"\n #include \"quote.h\"\n+#include \"exec_cmd.h\"\n \n static void hash_object(const char *path, enum object_type type, int write_object)\n {\n@@ -65,6 +66,9 @@ int main(int argc, char **argv)\n \tint hashstdin = 0;\n \tint stdin_paths = 0;\n \n+\tif (argv[0] && *argv[0])\n+\t\tgit_extract_argv0_path(argv[0]);\n+\n \tgit_config(git_default_config, NULL);\n \n \tfor (i = 1 ; i < argc; i++) {\ndiff --git a/index-pack.c b/index-pack.c\nindex 52064be..bd5983b 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -8,6 +8,7 @@\n #include \"tree.h\"\n #include \"progress.h\"\n #include \"fsck.h\"\n+#include \"exec_cmd.h\"\n \n static const char index_pack_usage[] =\n \"git index-pack [-v] [-o <index-file>] [{ ---keep | --keep=<msg> }] [--strict] { <pack-file> | --stdin [--fix-thin] [<pack-file>] }\";\n@@ -877,6 +878,9 @@ int main(int argc, char **argv)\n \tstruct pack_idx_entry **idx_objects;\n \tunsigned char sha1[20];\n \n+\tif (argv[0] && *argv[0])\n+\t\tgit_extract_argv0_path(argv[0]);\n+\n \tgit_config(git_index_pack_config, NULL);\n \n \tfor (i = 1; i < argc; i++) {\ndiff --git a/unpack-file.c b/unpack-file.c\nindex bcdc8bb..f8bfda7 100644\n--- a/unpack-file.c\n+++ b/unpack-file.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"blob.h\"\n+#include \"exec_cmd.h\"\n \n static char *create_temp_file(unsigned char *sha1)\n {\n@@ -25,6 +26,9 @@ int main(int argc, char **argv)\n {\n \tunsigned char sha1[20];\n \n+\tif (argv[0] && *argv[0])\n+\t\tgit_extract_argv0_path(argv[0]);\n+\n \tif (argc != 2)\n \t\tusage(\"git-unpack-file <sha1>\");\n \tif (get_sha1(argv[1], sha1))\ndiff --git a/var.c b/var.c\nindex f1eb314..33457dc 100644\n--- a/var.c\n+++ b/var.c\n@@ -4,6 +4,7 @@\n  * Copyright (C) Eric Biederman, 2005\n  */\n #include \"cache.h\"\n+#include \"exec_cmd.h\"\n \n static const char var_usage[] = \"git var [-l | <variable>]\";\n \n@@ -56,6 +57,9 @@ int main(int argc, char **argv)\n \t\tusage(var_usage);\n \t}\n \n+\tif (argv[0] && *argv[0])\n+\t\tgit_extract_argv0_path(argv[0]);\n+\n \tsetup_git_directory_gently(&nongit);\n \tval = NULL;\n \n-- \n1.6.0.rc3.22.g053fd\n"},{"id":"87441","messageId":"1218977083-14526-7-git-send-email-prohaska@zib.de","threadId":"15056","inReplyTo":"1218977083-14526-6-git-send-email-prohaska@zib.de","subject":"[PATCH 6/7] Modify setup_path() to only add git_exec_path() to PATH","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-08-17T12:44:42Z","receivedAt":"2008-08-17T12:44:42Z","isPatch":true,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"Searching git programs only in the highest-priority location is\nsufficient.  If the user explicitly overrides the default location\n(by --exec-path or GIT_EXEC_PATH), we can safely expect that the\nrequired programs are there.\n\nThis change allows testing of executables built with RUNTIME_PREFIX.\nCalling system_path(GIT_EXEC_PATH) is avoided if a higher-priority\nlocation is provided, which is the case for the tests.\n\nSigned-off-by: Steffen Prohaska <prohaska@zib.de>\n---\n exec_cmd.c |    4 +---\n 1 files changed, 1 insertions(+), 3 deletions(-)\n\ndiff --git a/exec_cmd.c b/exec_cmd.c\nindex d84e9e9..63efe23 100644\n--- a/exec_cmd.c\n+++ b/exec_cmd.c\n@@ -114,9 +114,7 @@ void setup_path(void)\n \n \tstrbuf_init(&new_path, 0);\n \n-\tadd_path(&new_path, argv_exec_path);\n-\tadd_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));\n-\tadd_path(&new_path, system_path(GIT_EXEC_PATH));\n+\tadd_path(&new_path, git_exec_path());\n \tadd_path(&new_path, argv0_path);\n \n \tif (old_path)\n-- \n1.6.0.rc3.22.g053fd\n"},{"id":"87438","messageId":"1218977083-14526-8-git-send-email-prohaska@zib.de","threadId":"15056","inReplyTo":"1218977083-14526-7-git-send-email-prohaska@zib.de","subject":"[PATCH 7/7] Windows: Revert to default paths and convert them by RUNTIME_PREFIX","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-08-17T12:44:43Z","receivedAt":"2008-08-17T12:44:43Z","isPatch":true,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"The RUNTIME_PREFIX mechanism allows us to use the default (absolute) paths\non Windows too.  Defining RUNTIME_PREFIX explicitly requests for\ntranslation of paths during runtime, depending on the path to the\nexecutable.\n\nSigned-off-by: Steffen Prohaska <prohaska@zib.de>\n---\n Makefile |    4 +---\n 1 files changed, 1 insertions(+), 3 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 8341558..8d57557 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -748,6 +748,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))\n \tSNPRINTF_RETURNS_BOGUS = YesPlease\n \tNO_SVN_TESTS = YesPlease\n \tNO_PERL_MAKEMAKER = YesPlease\n+\tRUNTIME_PREFIX = YesPlease\n \tNO_POSIX_ONLY_PROGRAMS = YesPlease\n \tCOMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat\n \tCOMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1\n@@ -755,9 +756,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))\n \tCOMPAT_OBJS += compat/mingw.o compat/fnmatch.o compat/regex.o compat/winansi.o\n \tEXTLIBS += -lws2_32\n \tX = .exe\n-\tgitexecdir = ../libexec/git-core\n-\ttemplate_dir = ../share/git-core/templates/\n-\tETC_GITCONFIG = ../etc/gitconfig\n endif\n ifneq (,$(findstring arm,$(uname_M)))\n \tARM_SHA1 = YesPlease\n-- \n1.6.0.rc3.22.g053fd\n"},{"id":"87449","messageId":"7v3al35xmy.fsf@gitster.siamese.dyndns.org","threadId":"15056","inReplyTo":"1218977083-14526-1-git-send-email-prohaska@zib.de","subject":"Re: [PATCH 0/7] prefix discovery at runtime (on Windows)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-17T18:01:25Z","receivedAt":"2008-08-17T18:01:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Steffen Prohaska <prohaska@zib.de> writes:\n\n> Apologies for proposing such large changes that late in the release cycle.\n> Maybe we want to postpone the series until 1.6.0.1 or even 1.6.1.\n\nWell, from the cursory look, it does not seem to be 1.6.0.1 material, even\nthough it is possible to fork a topic at 1.6.0 and use the changes in\n'next', then 'master', and eventually to 'maint' to produce 1.6.0.X, if\nall of this hapapens before 1.6.1.\n\nI wouldn't mind at all if the binary distribution on Windows is based on\n\"git.git plus port specific patchset that will eventually be sent\nupstream\" like it used to be.  In fact it might even be preferrable, as I\nwon't be testing ports to that platform myself anyway.\n"},{"id":"87458","messageId":"200808172228.14424.johannes.sixt@telecom.at","threadId":"15056","inReplyTo":"1218977083-14526-7-git-send-email-prohaska@zib.de","subject":"Re: [PATCH 6/7] Modify setup_path() to only add git_exec_path() to PATH","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2008-08-17T20:28:14Z","receivedAt":"2008-08-17T20:28:14Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"On Sonntag, 17. August 2008, Steffen Prohaska wrote:\n> Searching git programs only in the highest-priority location is\n> sufficient.  If the user explicitly overrides the default location\n> (by --exec-path or GIT_EXEC_PATH), we can safely expect that the\n> required programs are there.\n...\n> --- a/exec_cmd.c\n> +++ b/exec_cmd.c\n> @@ -114,9 +114,7 @@ void setup_path(void)\n>\n>  \tstrbuf_init(&new_path, 0);\n>\n> -\tadd_path(&new_path, argv_exec_path);\n> -\tadd_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));\n> -\tadd_path(&new_path, system_path(GIT_EXEC_PATH));\n> +\tadd_path(&new_path, git_exec_path());\n>  \tadd_path(&new_path, argv0_path);\n>\n>  \tif (old_path)\n\nI thought about a change like this, too. But I recall that this area has been \nchanged several times. One thread I found here:\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/62472\n\nSee also the commit message of 77cb17e940, which introduces exec_cmd.*.\n\nBut probably the points raised there are already moot, and your change is \ngood.\n\n-- Hannes\n"},{"id":"87461","messageId":"200808172235.48321.johannes.sixt@telecom.at","threadId":"15056","inReplyTo":"1218977083-14526-2-git-send-email-prohaska@zib.de","subject":"Re: [PATCH 1/7] Windows: Add workaround for MSYS' path conversion","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2008-08-17T20:35:48Z","receivedAt":"2008-08-17T20:35:48Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"On Sonntag, 17. August 2008, Steffen Prohaska wrote:\n> MSYS' automatic path conversion causes problems when passing paths as '-D'\n> arguments to the compiler.  MSYS tries to be smart and converts absolute\n> paths to native Windows paths.  But we want the paths as we compute them in\n> the Makefile.\n\nHuh? Doesn't the Makefile compute paths like \"/c/path/to/git\"? We certainly \ndon't want to compile such paths into git that in Windows speak actually \nmean \"c:/path/to/git\" - git is not an MSYS program and wouldn't understand \nthe former. Which form of conversion are you refering to?\n\n-- Hannes\n"},{"id":"87462","messageId":"200808172243.09129.johannes.sixt@telecom.at","threadId":"15056","inReplyTo":"1218977083-14526-3-git-send-email-prohaska@zib.de","subject":"Re: [PATCH 2/7] system_path(): Add prefix computation at runtime if RUNTIME_PREFIX set","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2008-08-17T20:43:09Z","receivedAt":"2008-08-17T20:43:09Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"On Sonntag, 17. August 2008, Steffen Prohaska wrote:\n> This commit modifies system_path() to compute the prefix at runtime\n> if explicitly requested to do so.  If RUNTIME_PREFIX is defined,\n> system_path() tries to strip known directories that executables can\n> be located in from the path of the executable.  If the path is\n> successfully stripped it is used as the prefix.\n\nAn example would be helpful. From your description it is difficult to \nunderstand what is stripped from where.\n\n> diff --git a/exec_cmd.c b/exec_cmd.c\n> index ce6741e..1622481 100644\n> --- a/exec_cmd.c\n> +++ b/exec_cmd.c\n> @@ -9,11 +9,51 @@ static const char *argv0_path;\n>\n>  const char *system_path(const char *path)\n>  {\n> -\tif (!is_absolute_path(path) && argv0_path) {\n> -\t\tstruct strbuf d = STRBUF_INIT;\n> -\t\tstrbuf_addf(&d, \"%s/%s\", argv0_path, path);\n> -\t\tpath = strbuf_detach(&d, NULL);\n> +#ifdef RUNTIME_PREFIX\n> +\tstatic const char *prefix;\n> +\n> +\tif (!argv0_path) {\n> +\t\tfprintf(stderr, \"RUNTIME_PREFIX requested for path '%s', \"\n> +\t\t\t\t\"but argv0_path not set.\\n\", path);\n\nIf this happens, isn't this a logic error: assert(argv0_path)?\n\n> +\t\treturn path;\n> +\t}\n> +\n> +\tif (!prefix) {\n> +\t\tconst char *strip[] = {\n> +\t\t\tGIT_EXEC_PATH,\n> +\t\t\tBINDIR,\n> +\t\t\t0\n> +\t\t};\n> +\t\tconst char **s;\n> +\n> +\t\tfor (s = strip; *s; s++) {\n> +\t\t\tconst char *sargv = argv0_path + strlen(argv0_path);\n> +\t\t\tconst char *ss = *s + strlen(*s);\n> +\t\t\twhile (argv0_path < sargv && *s < ss\n> +\t\t\t\t&& (*sargv == *ss ||\n> +\t\t\t\t    (is_dir_sep(*sargv) && is_dir_sep(*ss)))) {\n> +\t\t\t\tsargv--;\n> +\t\t\t\tss--;\n> +\t\t\t}\n> +\t\t\tif (*s == ss) {\n> +\t\t\t\tstruct strbuf d = STRBUF_INIT;\n> +\t\t\t\tstrbuf_add(&d, argv0_path, sargv - argv0_path);\n> +\t\t\t\tprefix = strbuf_detach(&d, NULL);\n> +\t\t\t\tbreak;\n> +\t\t\t}\n> +\t\t}\n\nDoesn't this do a thing very similar to longest_ancestor_length() (which still \ndoes not work for Windows paths, yet)?\n\n>  \t}\n> +\n> +\tif (!prefix) {\n> +\t\tfprintf(stderr, \"RUNTIME_PREFIX requested for path '%s', \"\n> +\t\t\t\t\"but prefix computation failed.\\n\", path);\n\nAgain a logic error?\n\n> +\t\treturn path;\n> +\t}\n> +\n> +\tstruct strbuf d = STRBUF_INIT;\n> +\tstrbuf_addf(&d, \"%s/%s\", prefix, path);\n> +\tpath = strbuf_detach(&d, NULL);\n> +#endif\n>  \treturn path;\n>  }\n"},{"id":"87511","messageId":"6E4B0DFF-DD1D-450D-B02A-9A89E260DBCB@zib.de","threadId":"15056","inReplyTo":"200808172243.09129.johannes.sixt@telecom.at","subject":"Re: [PATCH 2/7] system_path(): Add prefix computation at runtime if RUNTIME_PREFIX set","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-08-18T05:28:56Z","receivedAt":"2008-08-18T05:28:56Z","isPatch":true,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"\nOn Aug 17, 2008, at 10:43 PM, Johannes Sixt wrote:\n\n> On Sonntag, 17. August 2008, Steffen Prohaska wrote:\n>>\n>> diff --git a/exec_cmd.c b/exec_cmd.c\n>> index ce6741e..1622481 100644\n>> --- a/exec_cmd.c\n>> +++ b/exec_cmd.c\n>> @@ -9,11 +9,51 @@ static const char *argv0_path;\n>>\n>> const char *system_path(const char *path)\n>> {\n>> -\tif (!is_absolute_path(path) && argv0_path) {\n>> -\t\tstruct strbuf d = STRBUF_INIT;\n>> -\t\tstrbuf_addf(&d, \"%s/%s\", argv0_path, path);\n>> -\t\tpath = strbuf_detach(&d, NULL);\n>> +#ifdef RUNTIME_PREFIX\n>> +\tstatic const char *prefix;\n>> +\n>> +\tif (!argv0_path) {\n>> +\t\tfprintf(stderr, \"RUNTIME_PREFIX requested for path '%s', \"\n>> +\t\t\t\t\"but argv0_path not set.\\n\", path);\n>\n> If this happens, isn't this a logic error: assert(argv0_path)?\n\nWe could consider this a logic error.\n\n\n>> \t}\n>> +\n>> +\tif (!prefix) {\n>> +\t\tfprintf(stderr, \"RUNTIME_PREFIX requested for path '%s', \"\n>> +\t\t\t\t\"but prefix computation failed.\\n\", path);\n>\n> Again a logic error?\n\nThe user can move the executable, so it's not a logic error.\n\n\tSteffen\n"},{"id":"90144","messageId":"7vprnedzgc.fsf@gitster.siamese.dyndns.org","threadId":"15056","inReplyTo":"7v3al35xmy.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 0/7] prefix discovery at runtime (on Windows)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-09-08T22:50:43Z","receivedAt":"2008-09-08T22:50:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Steffen Prohaska <prohaska@zib.de> writes:\n>\n>> Apologies for proposing such large changes that late in the release cycle.\n>> Maybe we want to postpone the series until 1.6.0.1 or even 1.6.1.\n>\n> Well, from the cursory look, it does not seem to be 1.6.0.1 material, even\n> though it is possible to fork a topic at 1.6.0 and use the changes in\n> 'next', then 'master', and eventually to 'maint' to produce 1.6.0.X, if\n> all of this hapapens before 1.6.1.\n>\n> I wouldn't mind at all if the binary distribution on Windows is based on\n> \"git.git plus port specific patchset that will eventually be sent\n> upstream\" like it used to be.  In fact it might even be preferrable, as I\n> won't be testing ports to that platform myself anyway.\n\nIf the depth difference between /usr/libexec/git-cat-file and /bin/git is\nthe major source of this headache, I do not think it is unreasonable for\nthe mingw git port to use \"gitexecdir=$(bindir)\" layout by default.  After\nall, Windows users do not really care where bulk of things are, as long as\nthey see one single clickable icon on the desktop, don't they?\n"},{"id":"90220","messageId":"alpine.DEB.1.00.0809091648130.13830@pacific.mpi-cbg.de.mpi-cbg.de","threadId":"15056","inReplyTo":"7vprnedzgc.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 0/7] prefix discovery at runtime (on Windows)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-09-09T14:49:19Z","receivedAt":"2008-09-09T14:49:19Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 8 Sep 2008, Junio C Hamano wrote:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n> \n> > Steffen Prohaska <prohaska@zib.de> writes:\n> >\n> >> Apologies for proposing such large changes that late in the release \n> >> cycle. Maybe we want to postpone the series until 1.6.0.1 or even \n> >> 1.6.1.\n> >\n> > Well, from the cursory look, it does not seem to be 1.6.0.1 material, \n> > even though it is possible to fork a topic at 1.6.0 and use the \n> > changes in 'next', then 'master', and eventually to 'maint' to produce \n> > 1.6.0.X, if all of this hapapens before 1.6.1.\n> >\n> > I wouldn't mind at all if the binary distribution on Windows is based \n> > on \"git.git plus port specific patchset that will eventually be sent \n> > upstream\" like it used to be.  In fact it might even be preferrable, \n> > as I won't be testing ports to that platform myself anyway.\n> \n> If the depth difference between /usr/libexec/git-cat-file and /bin/git \n> is the major source of this headache, I do not think it is unreasonable \n> for the mingw git port to use \"gitexecdir=$(bindir)\" layout by default.  \n> After all, Windows users do not really care where bulk of things are, as \n> long as they see one single clickable icon on the desktop, don't they?\n\nI think the main point is that we could (finally!) adopt a saner default \non Unix: instead of hardcoding an absolute exec path, a relative would do.  \nSo I'd like to see this supported for Linux...\n\nCiao,\nDscho\n"},{"id":"91214","messageId":"C76DB1B2-D9AB-4BA1-A983-E39D156F56A6@zib.de","threadId":"15056","inReplyTo":"200808172235.48321.johannes.sixt@telecom.at","subject":"Re: [PATCH 1/7] Windows: Add workaround for MSYS' path conversion","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2008-09-21T07:48:27Z","receivedAt":"2008-09-21T07:48:27Z","isPatch":true,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"\nOn Aug 17, 2008, at 10:35 PM, Johannes Sixt wrote:\n\n> On Sonntag, 17. August 2008, Steffen Prohaska wrote:\n>> MSYS' automatic path conversion causes problems when passing paths  \n>> as '-D'\n>> arguments to the compiler.  MSYS tries to be smart and converts  \n>> absolute\n>> paths to native Windows paths.  But we want the paths as we compute  \n>> them in\n>> the Makefile.\n>\n> Huh? Doesn't the Makefile compute paths like \"/c/path/to/git\"? We  \n> certainly\n> don't want to compile such paths into git that in Windows speak  \n> actually\n> mean \"c:/path/to/git\" - git is not an MSYS program and wouldn't  \n> understand\n> the former. Which form of conversion are you refering to?\n\n\nMSYS' automatic path conversion causes problems when passing paths as\ndefines ('-D' arguments to the compiler).  MSYS tries to be smart and\nconverts absolute paths to native Windows paths, e.g. if MSYS sees\n\"/bin\" it converts it to \"c:/msysgit/bin\".  But we want completely\nunmodified paths; e.g. if we set bindir in the Makefile to \"/bin\", the\ndefine BINDIR shall expand to \"/bin\".  Conversion to absolute Windows\npath will takes place later, during runtime.\n\nI'll update the commit message.\n\n\tSteffen\n"}]}