{"thread":{"id":"27461","subject":"[PATCH v2 1/3] setup: Provide GIT_PREFIX to built-ins","startedAt":"2011-05-26T03:37:12Z","lastAt":"2011-05-26T21:49:34Z","messageCount":8,"participants":["David Aguilar","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":3},"messages":[{"id":"168743","messageId":"1306381034-44190-1-git-send-email-davvid@gmail.com","threadId":"27461","inReplyTo":null,"subject":"[PATCH v2 1/3] setup: Provide GIT_PREFIX to built-ins","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2011-05-26T03:37:12Z","receivedAt":"2011-05-26T03:37:12Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"GIT_PREFIX was added in 7cf16a14f5c070f7b14cf28023769450133172ae so that\naliases can know the directory from which a !alias was called.\n\nKnowing the prefix relative to the root is helpful in other programs\nso export it to built-ins as well.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n\nThe original version of this patch did not set GIT_PREFIX\nto an empty string when prefix returns NULL.\nNow we do.\n\n setup.c                 |    5 +++++\n t/t1020-subdirectory.sh |   16 ++++++++++++++++\n 2 files changed, 21 insertions(+), 0 deletions(-)\n\ndiff --git a/setup.c b/setup.c\nindex 013ad11..4569974 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -710,6 +710,11 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \tconst char *prefix;\n \n \tprefix = setup_git_directory_gently_1(nongit_ok);\n+\tif (prefix)\n+\t\tsetenv(\"GIT_PREFIX\", prefix, 1);\n+\telse\n+\t\tsetenv(\"GIT_PREFIX\", \"\", 1);\n+\n \tif (startup_info) {\n \t\tstartup_info->have_repository = !nongit_ok || !*nongit_ok;\n \t\tstartup_info->prefix = prefix;\ndiff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh\nindex ddc3921..3c74480 100755\n--- a/t/t1020-subdirectory.sh\n+++ b/t/t1020-subdirectory.sh\n@@ -139,6 +139,22 @@ test_expect_success 'GIT_PREFIX for !alias' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'GIT_PREFIX for built-ins' '\n+\t# Use GIT_EXTERNAL_DIFF to test that the \"diff\" built-in\n+\t# receives the GIT_PREFIX variable.\n+\tprintf \"dir/\" >expect &&\n+\tprintf \"#!/bin/sh\\n\" >diff &&\n+\tprintf \"printf \\\"\\$GIT_PREFIX\\\"\" >>diff &&\n+\tchmod +x diff &&\n+\t(\n+\t\tcd dir &&\n+\t\tprintf \"change\" >two &&\n+\t\tenv GIT_EXTERNAL_DIFF=./diff git diff >../actual\n+\t\tgit checkout -- two\n+\t) &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'no file/rev ambiguity check inside .git' '\n \tgit commit -a -m 1 &&\n \t(\n-- \n1.7.5.2.660.g9f46\n"},{"id":"168745","messageId":"1306381034-44190-2-git-send-email-davvid@gmail.com","threadId":"27461","inReplyTo":"1306381034-44190-1-git-send-email-davvid@gmail.com","subject":"[PATCH v2 2/3] git: Remove handling for GIT_PREFIX","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2011-05-26T03:37:13Z","receivedAt":"2011-05-26T03:37:13Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"handle_alias() no longer needs to set GIT_PREFIX since it is defined\nin setup_git_directory_gently().  Remove the duplicated effort and use\nrun_command_v_opt() since there is no need to setup the environment.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n\nThis patch is unchanged.\n\n git.c |   10 +---------\n 1 files changed, 1 insertions(+), 9 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex 89721d4..8828c18 100644\n--- a/git.c\n+++ b/git.c\n@@ -183,8 +183,6 @@ static int handle_alias(int *argcp, const char ***argv)\n \t\tif (alias_string[0] == '!') {\n \t\t\tconst char **alias_argv;\n \t\t\tint argc = *argcp, i;\n-\t\t\tstruct strbuf sb = STRBUF_INIT;\n-\t\t\tconst char *env[2];\n \n \t\t\tcommit_pager_choice();\n \n@@ -195,13 +193,7 @@ static int handle_alias(int *argcp, const char ***argv)\n \t\t\t\talias_argv[i] = (*argv)[i];\n \t\t\talias_argv[argc] = NULL;\n \n-\t\t\tstrbuf_addstr(&sb, \"GIT_PREFIX=\");\n-\t\t\tif (subdir)\n-\t\t\t\tstrbuf_addstr(&sb, subdir);\n-\t\t\tenv[0] = sb.buf;\n-\t\t\tenv[1] = NULL;\n-\t\t\tret = run_command_v_opt_cd_env(alias_argv, RUN_USING_SHELL, NULL, env);\n-\t\t\tstrbuf_release(&sb);\n+\t\t\tret = run_command_v_opt(alias_argv, RUN_USING_SHELL);\n \t\t\tif (ret >= 0)   /* normal exit */\n \t\t\t\texit(ret);\n \n-- \n1.7.5.2.660.g9f46\n"},{"id":"168744","messageId":"1306381034-44190-3-git-send-email-davvid@gmail.com","threadId":"27461","inReplyTo":"1306381034-44190-1-git-send-email-davvid@gmail.com","subject":"[PATCH v2 3/3] git-mergetool--lib: Make vimdiff retain the current directory","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2011-05-26T03:37:14Z","receivedAt":"2011-05-26T03:37:14Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"When using difftool with vimdiff it can be unexpected that\nthe current directory changes to the root of the project.\nTell vim to chdir to the value of $GIT_PREFIX to fix this.\n\nCare is taken to quote the variable so that vim expands it.\nThis avoids problems when directory names contain spaces.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\nReported-by: Frédéric Heitzmann <frederic.heitzmann@gmail.com>\n---\n\nThis version of the patch resolves GIT_PREFIX unconditionally.\nWe did not do so before.\n\n git-mergetool--lib.sh |   12 ++++++++++++\n 1 files changed, 12 insertions(+), 0 deletions(-)\n\ndiff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\nindex 4db9212..2cef8a2 100644\n--- a/git-mergetool--lib.sh\n+++ b/git-mergetool--lib.sh\n@@ -89,6 +89,7 @@ run_merge_tool () {\n \tmerge_tool_path=\"$(get_merge_tool_path \"$1\")\" || exit\n \tbase_present=\"$2\"\n \tstatus=0\n+\tresolve_git_prefix\n \n \tcase \"$1\" in\n \taraxis)\n@@ -188,6 +189,7 @@ run_merge_tool () {\n \t\t\tcheck_unchanged\n \t\telse\n \t\t\t\"$merge_tool_path\" -R -f -d -c \"wincmd l\" \\\n+\t\t\t\t-c 'cd $GIT_PREFIX' \\\n \t\t\t\t\"$LOCAL\" \"$REMOTE\"\n \t\tfi\n \t\t;;\n@@ -199,6 +201,7 @@ run_merge_tool () {\n \t\t\tcheck_unchanged\n \t\telse\n \t\t\t\"$merge_tool_path\" -R -f -d -c \"wincmd l\" \\\n+\t\t\t\t-c 'cd $GIT_PREFIX' \\\n \t\t\t\t\"$LOCAL\" \"$REMOTE\"\n \t\tfi\n \t\t;;\n@@ -437,3 +440,12 @@ get_merge_tool () {\n \tfi\n \techo \"$merge_tool\"\n }\n+\n+resolve_git_prefix() {\n+\t# If GIT_PREFIX is empty then we cannot use it in tools\n+\t# that expect to be able to chdir() to its value.\n+\tif test -z \"$GIT_PREFIX\"; then\n+\t\tGIT_PREFIX=.\n+\t\texport GIT_PREFIX\n+\tfi\n+}\n-- \n1.7.5.2.660.g9f46\n"},{"id":"168748","messageId":"BANLkTinWUK8NDDd3i7fRRTEXjSmTtMwL_Q@mail.gmail.com","threadId":"27461","inReplyTo":"1306381034-44190-3-git-send-email-davvid@gmail.com","subject":"Re: [PATCH v2 3/3] git-mergetool--lib: Make vimdiff retain the current directory","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2011-05-26T05:05:32Z","receivedAt":"2011-05-26T05:05:32Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"On Wed, May 25, 2011 at 8:37 PM, David Aguilar <davvid@gmail.com> wrote:\n> +\n> +resolve_git_prefix() {\n> +       # If GIT_PREFIX is empty then we cannot use it in tools\n> +       # that expect to be able to chdir() to its value.\n> +       if test -z \"$GIT_PREFIX\"; then\n> +               GIT_PREFIX=.\n> +               export GIT_PREFIX\n> +       fi\n> +}\n\nOops, I forgot to replace the function call with : GIT_PREFIX=${GIT_PREFIX:-.}\n-- \n    David\n"},{"id":"168749","messageId":"1306387776-14593-1-git-send-email-davvid@gmail.com","threadId":"27461","inReplyTo":"1306381034-44190-3-git-send-email-davvid@gmail.com","subject":"[PATCH] git-mergetool--lib: Make vimdiff retain the current directory","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2011-05-26T05:29:36Z","receivedAt":"2011-05-26T05:29:36Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"When using difftool with vimdiff it can be unexpected that\nthe current directory changes to the root of the project.\nTell vim to chdir to the value of $GIT_PREFIX to fix this.\n\nCare is taken to quote the variable so that vim expands it.\nThis avoids problems when directory names contain spaces.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\nReported-by: Frédéric Heitzmann <frederic.heitzmann@gmail.com>\n---\nReplacement for the last patch: uses ${GIT_PREFIX:-.}\n\n git-mergetool--lib.sh |    6 ++++++\n 1 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\nindex 4db9212..43a9a28 100644\n--- a/git-mergetool--lib.sh\n+++ b/git-mergetool--lib.sh\n@@ -86,6 +86,10 @@ get_merge_tool_cmd () {\n }\n \n run_merge_tool () {\n+\t# If GIT_PREFIX is empty then we cannot use it in tools\n+\t# that expect to be able to chdir() to its value.\n+\t: GIT_PREFIX=${GIT_PREFIX:-.}\n+\n \tmerge_tool_path=\"$(get_merge_tool_path \"$1\")\" || exit\n \tbase_present=\"$2\"\n \tstatus=0\n@@ -188,6 +192,7 @@ run_merge_tool () {\n \t\t\tcheck_unchanged\n \t\telse\n \t\t\t\"$merge_tool_path\" -R -f -d -c \"wincmd l\" \\\n+\t\t\t\t-c 'cd $GIT_PREFIX' \\\n \t\t\t\t\"$LOCAL\" \"$REMOTE\"\n \t\tfi\n \t\t;;\n@@ -199,6 +204,7 @@ run_merge_tool () {\n \t\t\tcheck_unchanged\n \t\telse\n \t\t\t\"$merge_tool_path\" -R -f -d -c \"wincmd l\" \\\n+\t\t\t\t-c 'cd $GIT_PREFIX' \\\n \t\t\t\t\"$LOCAL\" \"$REMOTE\"\n \t\tfi\n \t\t;;\n-- \n1.7.5.2.660.g9f46c\n"},{"id":"168751","messageId":"1306390861-57054-1-git-send-email-davvid@gmail.com","threadId":"27461","inReplyTo":"1306387776-14593-1-git-send-email-davvid@gmail.com","subject":"[PATCH v4 3/3] git-mergetool--lib: Make vimdiff retain the current directory","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2011-05-26T06:21:01Z","receivedAt":"2011-05-26T06:21:01Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"When using difftool with vimdiff it can be unexpected that\nthe current directory changes to the root of the project.\nTell vim to chdir to the value of $GIT_PREFIX to fix this.\n\nCare is taken to quote the variable so that vim expands it.\nThis avoids problems when directory names contain spaces.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\nReported-by: Frédéric Heitzmann <frederic.heitzmann@gmail.com>\n---\nHow embarassing.  I'm going to bed now.  This one works.\n\n git-mergetool--lib.sh |    7 +++++++\n 1 files changed, 7 insertions(+), 0 deletions(-)\n\ndiff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\nindex 4db9212..91f90ac 100644\n--- a/git-mergetool--lib.sh\n+++ b/git-mergetool--lib.sh\n@@ -86,6 +86,11 @@ get_merge_tool_cmd () {\n }\n \n run_merge_tool () {\n+\t# If GIT_PREFIX is empty then we cannot use it in tools\n+\t# that expect to be able to chdir() to its value.\n+\tGIT_PREFIX=${GIT_PREFIX:-.}\n+\texport GIT_PREFIX\n+\n \tmerge_tool_path=\"$(get_merge_tool_path \"$1\")\" || exit\n \tbase_present=\"$2\"\n \tstatus=0\n@@ -188,6 +193,7 @@ run_merge_tool () {\n \t\t\tcheck_unchanged\n \t\telse\n \t\t\t\"$merge_tool_path\" -R -f -d -c \"wincmd l\" \\\n+\t\t\t\t-c 'cd $GIT_PREFIX' \\\n \t\t\t\t\"$LOCAL\" \"$REMOTE\"\n \t\tfi\n \t\t;;\n@@ -199,6 +205,7 @@ run_merge_tool () {\n \t\t\tcheck_unchanged\n \t\telse\n \t\t\t\"$merge_tool_path\" -R -f -d -c \"wincmd l\" \\\n+\t\t\t\t-c 'cd $GIT_PREFIX' \\\n \t\t\t\t\"$LOCAL\" \"$REMOTE\"\n \t\tfi\n \t\t;;\n-- \n1.7.5.2.663.gfcb11.dirty\n"},{"id":"168806","messageId":"7vfwo1xsn4.fsf@alter.siamese.dyndns.org","threadId":"27461","inReplyTo":"1306381034-44190-1-git-send-email-davvid@gmail.com","subject":"Re: [PATCH v2 1/3] setup: Provide GIT_PREFIX to built-ins","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-05-26T17:45:35Z","receivedAt":"2011-05-26T17:45:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Aguilar <davvid@gmail.com> writes:\n\n> GIT_PREFIX was added in 7cf16a14f5c070f7b14cf28023769450133172ae so that\n> aliases can know the directory from which a !alias was called.\n>\n> Knowing the prefix relative to the root is helpful in other programs\n> so export it to built-ins as well.\n>\n> Signed-off-by: David Aguilar <davvid@gmail.com>\n> ---\n>\n> The original version of this patch did not set GIT_PREFIX\n> to an empty string when prefix returns NULL.\n> Now we do.\n\nThanks.  Should I add \"Helped-by: MJG\"?\n"},{"id":"168833","messageId":"20110526214918.GA22623@gmail.com","threadId":"27461","inReplyTo":"7vfwo1xsn4.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2 1/3] setup: Provide GIT_PREFIX to built-ins","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2011-05-26T21:49:34Z","receivedAt":"2011-05-26T21:49:34Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"On Thu, May 26, 2011 at 10:45:35AM -0700, Junio C Hamano wrote:\n> David Aguilar <davvid@gmail.com> writes:\n> \n> > GIT_PREFIX was added in 7cf16a14f5c070f7b14cf28023769450133172ae so that\n> > aliases can know the directory from which a !alias was called.\n> >\n> > Knowing the prefix relative to the root is helpful in other programs\n> > so export it to built-ins as well.\n> >\n> > Signed-off-by: David Aguilar <davvid@gmail.com>\n> > ---\n> >\n> > The original version of this patch did not set GIT_PREFIX\n> > to an empty string when prefix returns NULL.\n> > Now we do.\n> \n> Thanks.  Should I add \"Helped-by: MJG\"?\n\nYes, that'd be great.\n-- \n\t\t\t\t\tDavid\n"}]}