{"thread":{"id":"22783","subject":"[PATCHv3 1/5] cache: static list of repo-local env vars","startedAt":"2010-02-23T23:35:31Z","lastAt":"2010-02-24T07:33:15Z","messageCount":8,"participants":["Giuseppe Bilotta","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"135497","messageId":"1266968136-11129-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22783","inReplyTo":null,"subject":"[PATCHv3 0/5] repo-local env vars handling","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-23T23:35:31Z","receivedAt":"2010-02-23T23:35:31Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Ok, the Git GUI + submodule fix is shaping up in a pretty much more\ngeneral thing. In this third iteration, the patch has been augmented by\ntwo important patches:\n\n* the first patch defines a static list (const char *const []) holding\n  all the repo-local environment variables. The list is not used yet,\n  just defined\n* the third patch adds a rev-parse (I couldn't think of a better place)\n  option to list these variables (just the names, not the values)\n\nThe connect and sh-setup patches have obviously been adapted to use\nthe new provided features. The last patch didn't change, which in\nparticular means that Jens Lehmann's C-side submodule fix is still\nvalid, although it might benefit from being reworked to exploit the\nstatic list exposed by this patchset.\n\nGiuseppe Bilotta (5):\n  cache: static list of repo-local env vars\n  connect: use static list of repo-local env vars\n  rev-parse: --local-env-vars option\n  shell setup: clear_local_git_env() function\n  submodules: ensure clean environment when operating in a submodule\n\n Documentation/git-rev-parse.txt |    6 ++++++\n Makefile                        |    1 +\n builtin-rev-parse.c             |    8 ++++++++\n cache.c                         |   13 +++++++++++++\n cache.h                         |    2 ++\n connect.c                       |   13 +------------\n git-sh-setup.sh                 |    7 +++++++\n git-submodule.sh                |   20 ++++++++++----------\n 8 files changed, 48 insertions(+), 22 deletions(-)\n create mode 100644 cache.c\n"},{"id":"135496","messageId":"1266968136-11129-2-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22783","inReplyTo":"1266968136-11129-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 1/5] cache: static list of repo-local env vars","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-23T23:35:32Z","receivedAt":"2010-02-23T23:35:32Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n Makefile |    1 +\n cache.c  |   13 +++++++++++++\n cache.h  |    2 ++\n 3 files changed, 16 insertions(+), 0 deletions(-)\n create mode 100644 cache.c\n\ndiff --git a/Makefile b/Makefile\nindex 36611f4..9e9a858 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -524,6 +524,7 @@ LIB_OBJS += bisect.o\n LIB_OBJS += blob.o\n LIB_OBJS += branch.o\n LIB_OBJS += bundle.o\n+LIB_OBJS += cache.o\n LIB_OBJS += cache-tree.o\n LIB_OBJS += color.o\n LIB_OBJS += combine-diff.o\ndiff --git a/cache.c b/cache.c\nnew file mode 100644\nindex 0000000..961ea56\n--- /dev/null\n+++ b/cache.c\n@@ -0,0 +1,13 @@\n+#include \"cache.h\"\n+\n+const char *const local_repo_env[] = {\n+\tALTERNATE_DB_ENVIRONMENT,\n+\tCONFIG_ENVIRONMENT,\n+\tDB_ENVIRONMENT,\n+\tGIT_DIR_ENVIRONMENT,\n+\tGIT_WORK_TREE_ENVIRONMENT,\n+\tGRAFT_ENVIRONMENT,\n+\tINDEX_ENVIRONMENT,\n+\tNO_REPLACE_OBJECTS_ENVIRONMENT,\n+\tNULL\n+};\ndiff --git a/cache.h b/cache.h\nindex c863085..7648a61 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -388,6 +388,8 @@ static inline enum object_type object_type(unsigned int mode)\n #define GIT_NOTES_REF_ENVIRONMENT \"GIT_NOTES_REF\"\n #define GIT_NOTES_DEFAULT_REF \"refs/notes/commits\"\n \n+extern const char *const local_repo_env[];\n+\n extern int is_bare_repository_cfg;\n extern int is_bare_repository(void);\n extern int is_inside_git_dir(void);\n-- \n1.7.0.200.g5ba36.dirty\n"},{"id":"135500","messageId":"1266968136-11129-3-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22783","inReplyTo":"1266968136-11129-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 2/5] connect: use static list of repo-local env vars","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-23T23:35:33Z","receivedAt":"2010-02-23T23:35:33Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"This adds the missing GIT_CONFIG to the list of env vars that\nshould be cleared.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n connect.c |   13 +------------\n 1 files changed, 1 insertions(+), 12 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex 9f39038..94b3707 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -582,18 +582,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig,\n \t\t*arg++ = host;\n \t}\n \telse {\n-\t\t/* remove these from the environment */\n-\t\tconst char *env[] = {\n-\t\t\tALTERNATE_DB_ENVIRONMENT,\n-\t\t\tDB_ENVIRONMENT,\n-\t\t\tGIT_DIR_ENVIRONMENT,\n-\t\t\tGIT_WORK_TREE_ENVIRONMENT,\n-\t\t\tGRAFT_ENVIRONMENT,\n-\t\t\tINDEX_ENVIRONMENT,\n-\t\t\tNO_REPLACE_OBJECTS_ENVIRONMENT,\n-\t\t\tNULL\n-\t\t};\n-\t\tconn->env = env;\n+\t\tconn->env = local_repo_env;\n \t\tconn->use_shell = 1;\n \t}\n \t*arg++ = cmd.buf;\n-- \n1.7.0.200.g5ba36.dirty\n"},{"id":"135498","messageId":"1266968136-11129-4-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22783","inReplyTo":"1266968136-11129-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 3/5] rev-parse: --local-env-vars option","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-23T23:35:34Z","receivedAt":"2010-02-23T23:35:34Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"This prints the list of repo-local environment variables.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n Documentation/git-rev-parse.txt |    6 ++++++\n builtin-rev-parse.c             |    8 ++++++++\n 2 files changed, 14 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt\nindex 1a613aa..8db600f 100644\n--- a/Documentation/git-rev-parse.txt\n+++ b/Documentation/git-rev-parse.txt\n@@ -148,6 +148,12 @@ shown.  If the pattern does not contain a globbing character (`?`,\n --is-bare-repository::\n \tWhen the repository is bare print \"true\", otherwise \"false\".\n \n+--local-env-vars::\n+\tList the GIT_* environment variables that are local to the\n+\trepository (e.g. GIT_DIR or GIT_WORK_TREE, but not GIT_EDITOR).\n+\tOnly the names of the variables are listed, not their value,\n+\teven if they are set.\n+\n --short::\n --short=number::\n \tInstead of outputting the full SHA1 values of object names try to\ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex a8c5043..ab7b520 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -455,7 +455,15 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \tif (argc > 1 && !strcmp(\"--sq-quote\", argv[1]))\n \t\treturn cmd_sq_quote(argc - 2, argv + 2);\n \n+\tif (argc > 0 && !strcmp(\"--local-env-vars\", argv[1])) {\n+\t\tunsigned int i = 0;\n+\t\tconst char *var;\n+\t\twhile (var = local_repo_env[i++])\n+\t\t\tprintf(\"%s\\n\", var);\n+\t\treturn 0;\n+\t}\n \tif (argc > 1 && !strcmp(\"-h\", argv[1]))\n+\n \t\tusage(builtin_rev_parse_usage);\n \n \tprefix = setup_git_directory();\n-- \n1.7.0.200.g5ba36.dirty\n"},{"id":"135501","messageId":"1266968136-11129-5-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22783","inReplyTo":"1266968136-11129-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 4/5] shell setup: clear_local_git_env() function","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-23T23:35:35Z","receivedAt":"2010-02-23T23:35:35Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Introduce an auxiliary function to clear all repo-local environment\nvariables. This should be invoked by any shell script that switches\nrepository during execution, to ensure that the environment is clean\nand that things such as the git dir and worktree are set up correctly.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-sh-setup.sh |    7 +++++++\n 1 files changed, 7 insertions(+), 0 deletions(-)\n\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex 7a09566..6131670 100644\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -172,6 +172,13 @@ get_author_ident_from_commit () {\n \tLANG=C LC_ALL=C sed -ne \"$pick_author_script\"\n }\n \n+# Clear repo-local GIT_* environment variables. Useful when switching to\n+# another repository (e.g. when entering a submodule). See also the env\n+# list in git_connect()\n+clear_local_git_env() {\n+\tunset $(git rev-parse --local-env-vars)\n+}\n+\n # Make sure we are in a valid repository of a vintage we understand,\n # if we require to be in a git repository.\n if test -z \"$NONGIT_OK\"\n-- \n1.7.0.200.g5ba36.dirty\n"},{"id":"135499","messageId":"1266968136-11129-6-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22783","inReplyTo":"1266968136-11129-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 5/5] submodules: ensure clean environment when operating in a submodule","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-23T23:35:36Z","receivedAt":"2010-02-23T23:35:36Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"git-submodule used to take care of clearing GIT_DIR whenever it operated\non a submodule index or configuration, but forgot to unset GIT_WORK_TREE\nor other repo-local variables. This would lead to failures e.g. when\nGIT_WORK_TREE was set.\n\nThis only happened in very unusual contexts such as operating on the\nmain worktree from outside of it, but since \"git-gui: set GIT_DIR and\nGIT_WORK_TREE after setup\" (a9fa11fe5bd5978bb) such failures could also\nbe provoked by invoking an external tool such as \"git submodule update\"\nfrom the Git Gui in a standard setup.\n\nSolve by using the newly introduced clear_local_git_env() shell function\nto ensure that all repo-local environment variables are unset.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-submodule.sh |   20 ++++++++++----------\n 1 files changed, 10 insertions(+), 10 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 5869c00..1ea4143 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -222,7 +222,7 @@ cmd_add()\n \n \t\tmodule_clone \"$path\" \"$realrepo\" \"$reference\" || exit\n \t\t(\n-\t\t\tunset GIT_DIR\n+\t\t\tclear_local_git_env\n \t\t\tcd \"$path\" &&\n \t\t\t# ash fails to wordsplit ${branch:+-b \"$branch\"...}\n \t\t\tcase \"$branch\" in\n@@ -278,7 +278,7 @@ cmd_foreach()\n \t\t\tname=$(module_name \"$path\")\n \t\t\t(\n \t\t\t\tprefix=\"$prefix$path/\"\n-\t\t\t\tunset GIT_DIR\n+\t\t\t\tclear_local_git_env\n \t\t\t\tcd \"$path\" &&\n \t\t\t\teval \"$@\" &&\n \t\t\t\tif test -n \"$recursive\"\n@@ -434,7 +434,7 @@ cmd_update()\n \t\t\tmodule_clone \"$path\" \"$url\" \"$reference\"|| exit\n \t\t\tsubsha1=\n \t\telse\n-\t\t\tsubsha1=$(unset GIT_DIR; cd \"$path\" &&\n+\t\t\tsubsha1=$(clear_local_git_env; cd \"$path\" &&\n \t\t\t\tgit rev-parse --verify HEAD) ||\n \t\t\tdie \"Unable to find current revision in submodule path '$path'\"\n \t\tfi\n@@ -454,7 +454,7 @@ cmd_update()\n \n \t\t\tif test -z \"$nofetch\"\n \t\t\tthen\n-\t\t\t\t(unset GIT_DIR; cd \"$path\" &&\n+\t\t\t\t(clear_local_git_env; cd \"$path\" &&\n \t\t\t\t\tgit-fetch) ||\n \t\t\t\tdie \"Unable to fetch in submodule path '$path'\"\n \t\t\tfi\n@@ -477,14 +477,14 @@ cmd_update()\n \t\t\t\t;;\n \t\t\tesac\n \n-\t\t\t(unset GIT_DIR; cd \"$path\" && $command \"$sha1\") ||\n+\t\t\t(clear_local_git_env; cd \"$path\" && $command \"$sha1\") ||\n \t\t\tdie \"Unable to $action '$sha1' in submodule path '$path'\"\n \t\t\tsay \"Submodule path '$path': $msg '$sha1'\"\n \t\tfi\n \n \t\tif test -n \"$recursive\"\n \t\tthen\n-\t\t\t(unset GIT_DIR; cd \"$path\" && cmd_update $orig_args) ||\n+\t\t\t(clear_local_git_env; cd \"$path\" && cmd_update $orig_args) ||\n \t\t\tdie \"Failed to recurse into submodule path '$path'\"\n \t\tfi\n \tdone\n@@ -492,7 +492,7 @@ cmd_update()\n \n set_name_rev () {\n \trevname=$( (\n-\t\tunset GIT_DIR\n+\t\tclear_local_git_env\n \t\tcd \"$1\" && {\n \t\t\tgit describe \"$2\" 2>/dev/null ||\n \t\t\tgit describe --tags \"$2\" 2>/dev/null ||\n@@ -760,7 +760,7 @@ cmd_status()\n \t\telse\n \t\t\tif test -z \"$cached\"\n \t\t\tthen\n-\t\t\t\tsha1=$(unset GIT_DIR; cd \"$path\" && git rev-parse --verify HEAD)\n+\t\t\t\tsha1=$(clear_local_git_env; cd \"$path\" && git rev-parse --verify HEAD)\n \t\t\t\tset_name_rev \"$path\" \"$sha1\"\n \t\t\tfi\n \t\t\tsay \"+$sha1 $displaypath$revname\"\n@@ -770,7 +770,7 @@ cmd_status()\n \t\tthen\n \t\t\t(\n \t\t\t\tprefix=\"$displaypath/\"\n-\t\t\t\tunset GIT_DIR\n+\t\t\t\tclear_local_git_env\n \t\t\t\tcd \"$path\" &&\n \t\t\t\tcmd_status $orig_args\n \t\t\t) ||\n@@ -821,7 +821,7 @@ cmd_sync()\n \t\tif test -e \"$path\"/.git\n \t\tthen\n \t\t(\n-\t\t\tunset GIT_DIR\n+\t\t\tclear_local_git_env\n \t\t\tcd \"$path\"\n \t\t\tremote=$(get_default_remote)\n \t\t\tsay \"Synchronizing submodule url for '$name'\"\n-- \n1.7.0.200.g5ba36.dirty\n"},{"id":"135532","messageId":"4B84D1BD.2030908@viscovery.net","threadId":"22783","inReplyTo":"1266968136-11129-3-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCHv3 2/5] connect: use static list of repo-local env vars","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-02-24T07:14:05Z","receivedAt":"2010-02-24T07:14:05Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Giuseppe Bilotta schrieb:\n> -\t\t/* remove these from the environment */\n\nYou shouldn't remove this comment.\n\n> -\t\tconst char *env[] = {\n> -\t\t\tALTERNATE_DB_ENVIRONMENT,\n> -\t\t\tDB_ENVIRONMENT,\n> -\t\t\tGIT_DIR_ENVIRONMENT,\n> -\t\t\tGIT_WORK_TREE_ENVIRONMENT,\n> -\t\t\tGRAFT_ENVIRONMENT,\n> -\t\t\tINDEX_ENVIRONMENT,\n> -\t\t\tNO_REPLACE_OBJECTS_ENVIRONMENT,\n> -\t\t\tNULL\n> -\t\t};\n> -\t\tconn->env = env;\n> +\t\tconn->env = local_repo_env;\n\nIMO, you should squash this patch and the previous one under the subject\n\"Move list of repo-local environment variables to a public place\", and\nthat public place could be environment.c instead of a new file cache.c\n(the name \"cache.c\" is definitely wrong).\n\n-- Hannes\n"},{"id":"135540","messageId":"cb7bb73a1002232333o2470b8d5x3dd9bd22dd30764e@mail.gmail.com","threadId":"22783","inReplyTo":"4B84D1BD.2030908@viscovery.net","subject":"Re: [PATCHv3 2/5] connect: use static list of repo-local env vars","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-02-24T07:33:15Z","receivedAt":"2010-02-24T07:33:15Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Doh. I knew I should have waitied a little more before sending the new\nseries ...\n\nOn Wed, Feb 24, 2010 at 8:14 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n> Giuseppe Bilotta schrieb:\n>> -             /* remove these from the environment */\n>\n> You shouldn't remove this comment.\n\nRight. I should probably rephrase it a little, though.\n\n>> -             const char *env[] = {\n>> -                     ALTERNATE_DB_ENVIRONMENT,\n>> -                     DB_ENVIRONMENT,\n>> -                     GIT_DIR_ENVIRONMENT,\n>> -                     GIT_WORK_TREE_ENVIRONMENT,\n>> -                     GRAFT_ENVIRONMENT,\n>> -                     INDEX_ENVIRONMENT,\n>> -                     NO_REPLACE_OBJECTS_ENVIRONMENT,\n>> -                     NULL\n>> -             };\n>> -             conn->env = env;\n>> +             conn->env = local_repo_env;\n>\n> IMO, you should squash this patch and the previous one under the subject\n> \"Move list of repo-local environment variables to a public place\", and\n> that public place could be environment.c instead of a new file cache.c\n> (the name \"cache.c\" is definitely wrong).\n\nThe list is now the right place (v4). The squashing is most definitely\na good idea, gives a better idea of the code movement.\n\n-- \nGiuseppe \"Oblomov\" Bilotta\n"}]}