{"thread":{"id":"10388","subject":"[PATCH] If git is ran with a relative path, try building an absolute exec_path from it","startedAt":"2007-10-20T06:46:17Z","lastAt":"2007-10-20T21:25:26Z","messageCount":4,"participants":["Scott R Parish","Johannes Schindelin","David Brown"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"56670","messageId":"20071020064617.GC2237@srparish.net","threadId":"10388","inReplyTo":null,"subject":"[PATCH] If git is ran with a relative path, try building an absolute exec_path from it","fromName":"Scott R Parish","fromEmail":"srp@srparish.net","sentAt":"2007-10-20T06:46:17Z","receivedAt":"2007-10-20T06:46:17Z","isPatch":true,"sender":{"key":"srp@srparish.net","avatar":"https://gravatar.com/avatar/870e5b6fc4f710cf4db5684bd9af7f2cee5734b3dab3209b13e00cf64f6c9f0e?d=mp&s=160"},"body":" Signed-off-by: Scott R Parish <srp@srparish.net>\n\n---\n git.c |   35 +++++++++++++++++++++++++++++++++--\n 1 files changed, 33 insertions(+), 2 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex 9eaca1d..d129ecc 100644\n--- a/git.c\n+++ b/git.c\n@@ -28,6 +28,35 @@ static void prepend_to_path(const char *dir, int len)\n \tfree(path);\n }\n \n+static char *rel_to_abs_exec_path(const char *cmd) {\n+\tint len, rc;\n+\tchar *exec_path = xmalloc(PATH_MAX + 1);\n+\n+\tif (!getcwd(exec_path, PATH_MAX)) {\n+\t\tfprintf(stderr, \"git: cannot determine current directory: %s\\n\",\n+\t\t\tstrerror(errno));\n+\t\tfree(exec_path);\n+\t\treturn NULL;\n+\t}\n+\tlen = strlen(exec_path);\n+\n+\t/* Trivial cleanup */\n+\twhile (!prefixcmp(cmd, \"./\")) {\n+\t\tcmd += 2;\n+\t\twhile (*cmd == '/')\n+\t\t\tcmd++;\n+\t}\n+\n+\trc = snprintf(exec_path + len, PATH_MAX - len, \"/%s\", cmd);\n+\tif (rc < 0 || rc >= PATH_MAX - len) {\n+\t\tfprintf(stderr, \"git: command name given is too long.\\n\");\n+\t\tfree(exec_path);\n+\t\treturn NULL;\n+\t}\n+\n+\treturn exec_path;\n+}\n+\n static int handle_options(const char*** argv, int* argc, int* envchanged)\n {\n \tint handled = 0;\n@@ -409,13 +438,15 @@ int main(int argc, const char **argv)\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 it's an absolute path and we don't have\n-\t * anything better.\n+\t * if we don't have anything better.\n \t */\n \tif (slash) {\n \t\t*slash++ = 0;\n \t\tif (*cmd == '/')\n \t\t\texec_path = cmd;\n+\t\telse\n+\t\t\texec_path = rel_to_abs_exec_path(cmd);\n+\n \t\tcmd = slash;\n \t}\n \n-- \n1.5.3.GIT\n"},{"id":"56673","messageId":"Pine.LNX.4.64.0710200818410.25221@racer.site","threadId":"10388","inReplyTo":"20071020064617.GC2237@srparish.net","subject":"[PATCH] Deduce exec_path also from calls to git with a relative path","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-10-20T07:21:34Z","receivedAt":"2007-10-20T07:21:34Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThere is already logic in the git wrapper to deduce the exec_path from\nargv[0], when the git wrapper was called with an absolute path.  Extend\nthat logic to handle relative paths as well.\n\nFor example, when you call \"../../hello/world/git\", it will not turn\n\"../../hello/world\" into an absolute path, and use that.\n\nInitial implementation by Scott R Parish.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tOn Fri, 19 Oct 2007, Scott R Parish wrote:\n\n\t>  Signed-off-by: Scott R Parish <srp@srparish.net>\n\n\tThat is a little short for a commit message ;-)\n\n\t>  git.c |   35 +++++++++++++++++++++++++++++++++--\n\t>  1 files changed, 33 insertions(+), 2 deletions(-)\n\n\tI had commented on this before.  Probably I did a very bad job \n\tat explaining things, so hopefully this is better:\n\n git.c |    5 +++--\n 1 files changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex d7c6bca..1dad764 100644\n--- a/git.c\n+++ b/git.c\n@@ -414,13 +414,14 @@ int main(int argc, const char **argv)\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 it's an absolute path and we don't have\n-\t * anything better.\n+\t * if we don't have anything better.\n \t */\n \tif (slash) {\n \t\t*slash++ = 0;\n \t\tif (*cmd == '/')\n \t\t\texec_path = cmd;\n+\t\telse\n+\t\t\texec_path = xstrdup(make_absolute_path(cmd));\n \t\tcmd = slash;\n \t}\n \n-- \n1.5.3.4.1287.g8b31e\n"},{"id":"56697","messageId":"20071020122516.GA23190@old.davidb.org","threadId":"10388","inReplyTo":"Pine.LNX.4.64.0710200818410.25221@racer.site","subject":"Re: [PATCH] Deduce exec_path also from calls to git with a relative path","fromName":"David Brown","fromEmail":"git@davidb.org","sentAt":"2007-10-20T12:25:16Z","receivedAt":"2007-10-20T12:25:16Z","isPatch":true,"sender":{"key":"git@davidb.org","avatar":"https://gravatar.com/avatar/94c86a2938470a74c2eac5e2b69afc0871f79a660295c02219597aba8cb101c1?d=mp&s=160"},"body":"On Sat, Oct 20, 2007 at 08:21:34AM +0100, Johannes Schindelin wrote:\n\n>For example, when you call \"../../hello/world/git\", it will not turn\n>\"../../hello/world\" into an absolute path, and use that.\n\nDid you mean \"it will turn...\"?\n\nDavid\n"},{"id":"56737","messageId":"Pine.LNX.4.64.0710202224450.25221@racer.site","threadId":"10388","inReplyTo":"20071020122516.GA23190@old.davidb.org","subject":"Re: [PATCH] Deduce exec_path also from calls to git with a relative path","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-10-20T21:25:26Z","receivedAt":"2007-10-20T21:25:26Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 20 Oct 2007, David Brown wrote:\n\n> On Sat, Oct 20, 2007 at 08:21:34AM +0100, Johannes Schindelin wrote:\n> \n> > For example, when you call \"../../hello/world/git\", it will not turn \n> > \"../../hello/world\" into an absolute path, and use that.\n> \n> Did you mean \"it will turn...\"?\n\nYes, I meant that.  I was in a hurry, since a car was waiting outside the \ndoor, taking me to the highlands.\n\nCiao,\nDscho\n"}]}