{"thread":{"id":"21648","subject":"[PATCH 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable","startedAt":"2009-11-17T05:11:23Z","lastAt":"2009-11-18T06:49:47Z","messageCount":5,"participants":["Christian Couder","Johannes Sixt","Michael J Gruber"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"127731","messageId":"20091117051125.3588.91072.chriscool@tuxfamily.org","threadId":"21648","inReplyTo":null,"subject":"[PATCH 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-11-17T05:11:23Z","receivedAt":"2009-11-17T05:11:23Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This environment variable is set when the --no-replace-objects\nflag is passed to git, and it is read when other environment\nvariables are read.\n\nIt is useful for example for scripts, as the git commands used in\nthem can now be aware that they must not read replace refs.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n cache.h            |    1 +\n environment.c      |    2 ++\n git.c              |    3 +++\n t/t6050-replace.sh |   17 +++++++++++++++++\n 4 files changed, 23 insertions(+), 0 deletions(-)\n\n\tMichael J Gruber wrote:\n\t>\n\t> [ The example also shows that we need a way to specify\n\t> --no-replace-objects for gitk. Would easier if gitk really\n\t> where git something. ]\n\n\tThese 2 patches should fix that for gitk and many other scripted\n\tcommands. But if it doesn't for some, please tell me.\n\n\tThanks,\n\tChristian.\n\ndiff --git a/cache.h b/cache.h\nindex 71a731d..bc77909 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -369,6 +369,7 @@ static inline enum object_type object_type(unsigned int mode)\n #define CONFIG_ENVIRONMENT \"GIT_CONFIG\"\n #define EXEC_PATH_ENVIRONMENT \"GIT_EXEC_PATH\"\n #define CEILING_DIRECTORIES_ENVIRONMENT \"GIT_CEILING_DIRECTORIES\"\n+#define NO_REPLACE_OBJECTS_ENVIRONMENT \"GIT_NO_REPLACE_OBJECTS\"\n #define GITATTRIBUTES_FILE \".gitattributes\"\n #define INFOATTRIBUTES_FILE \"info/attributes\"\n #define ATTRIBUTE_MACRO_PREFIX \"[attr]\"\ndiff --git a/environment.c b/environment.c\nindex 5de6837..279a38a 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -83,6 +83,8 @@ static void setup_git_env(void)\n \tgit_graft_file = getenv(GRAFT_ENVIRONMENT);\n \tif (!git_graft_file)\n \t\tgit_graft_file = git_pathdup(\"info/grafts\");\n+\tif (read_replace_refs && getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))\n+\t\tread_replace_refs = 0;\n }\n \n int is_bare_repository(void)\ndiff --git a/git.c b/git.c\nindex bd2c5fe..7f7d73d 100644\n--- a/git.c\n+++ b/git.c\n@@ -89,6 +89,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n \t\t\t\t*envchanged = 1;\n \t\t} else if (!strcmp(cmd, \"--no-replace-objects\")) {\n \t\t\tread_replace_refs = 0;\n+\t\t\tsetenv(NO_REPLACE_OBJECTS_ENVIRONMENT, \"\", 1);\n+\t\t\tif (envchanged)\n+\t\t\t\t*envchanged = 1;\n \t\t} else if (!strcmp(cmd, \"--git-dir\")) {\n \t\t\tif (*argc < 2) {\n \t\t\t\tfprintf(stderr, \"No directory given for --git-dir.\\n\" );\ndiff --git a/t/t6050-replace.sh b/t/t6050-replace.sh\nindex d4818b4..82cf2ec 100755\n--- a/t/t6050-replace.sh\n+++ b/t/t6050-replace.sh\n@@ -77,6 +77,11 @@ test_expect_success 'test --no-replace-objects option' '\n      git --no-replace-objects show $HASH2 | grep \"A U Thor\"\n '\n \n+test_expect_success 'test GIT_NO_REPLACE_OBJECTS env variable' '\n+     GIT_NO_REPLACE_OBJECTS= git cat-file commit $HASH2 | grep \"author A U Thor\" &&\n+     GIT_NO_REPLACE_OBJECTS= git show $HASH2 | grep \"A U Thor\"\n+'\n+\n cat >tag.sig <<EOF\n object $HASH2\n type commit\n@@ -202,6 +207,18 @@ test_expect_success 'fetch branch with replacement' '\n      cd ..\n '\n \n+test_expect_success 'bisect and replacements' '\n+     git bisect start $HASH7 $HASH1 &&\n+     test \"$S\" = \"$(git rev-parse --verify HEAD)\" &&\n+     git bisect reset &&\n+     GIT_NO_REPLACE_OBJECTS= git bisect start $HASH7 $HASH1 &&\n+     test \"$HASH4\" = \"$(git rev-parse --verify HEAD)\" &&\n+     git bisect reset &&\n+     git --no-replace-objects bisect start $HASH7 $HASH1 &&\n+     test \"$HASH4\" = \"$(git rev-parse --verify HEAD)\" &&\n+     git bisect reset\n+'\n+\n #\n #\n test_done\n-- \n1.6.5.1.gaf97d\n"},{"id":"127746","messageId":"4B0253DA.1090003@viscovery.net","threadId":"21648","inReplyTo":"20091117051125.3588.91072.chriscool@tuxfamily.org","subject":"Re: [PATCH 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-11-17T07:42:18Z","receivedAt":"2009-11-17T07:42:18Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Christian Couder schrieb:\n> diff --git a/git.c b/git.c\n> index bd2c5fe..7f7d73d 100644\n> --- a/git.c\n> +++ b/git.c\n> @@ -89,6 +89,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n>  \t\t\t\t*envchanged = 1;\n>  \t\t} else if (!strcmp(cmd, \"--no-replace-objects\")) {\n>  \t\t\tread_replace_refs = 0;\n> +\t\t\tsetenv(NO_REPLACE_OBJECTS_ENVIRONMENT, \"\", 1);\n\nIt is safer to set to a non-empty string, e.g., \"1\".\n\nI think this variable should be added to the list in connect.c around line\n630 so that it does not propagate to the remote end.\n\n-- Hannes\n"},{"id":"127757","messageId":"4B026DE8.9070905@drmicha.warpmail.net","threadId":"21648","inReplyTo":"20091117051125.3588.91072.chriscool@tuxfamily.org","subject":"Re: [PATCH 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-11-17T09:33:28Z","receivedAt":"2009-11-17T09:33:28Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Christian Couder venit, vidit, dixit 17.11.2009 06:11:\n> This environment variable is set when the --no-replace-objects\n> flag is passed to git, and it is read when other environment\n> variables are read.\n> \n> It is useful for example for scripts, as the git commands used in\n> them can now be aware that they must not read replace refs.\n> \n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n\nTested-by: Michael J Gruber <git@drmicha.warpmail.net>\n\n:) This works, thanks, as well as the gitk patch 2/2, which is difficult\nto cover by test scripts. Some OSes (or rather certain setenv/putenv\nvariants) have problems distinguishing an unset variable from an empty\none. I think we've worked around this, but avoiding it is safer, as J6t\npointed out.\n\nThanks!\nMichael\n"},{"id":"127818","messageId":"200911180748.42061.chriscool@tuxfamily.org","threadId":"21648","inReplyTo":"4B0253DA.1090003@viscovery.net","subject":"Re: [PATCH 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-11-18T06:48:41Z","receivedAt":"2009-11-18T06:48:41Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On mardi 17 novembre 2009, Johannes Sixt wrote:\n> Christian Couder schrieb:\n> > diff --git a/git.c b/git.c\n> > index bd2c5fe..7f7d73d 100644\n> > --- a/git.c\n> > +++ b/git.c\n> > @@ -89,6 +89,9 @@ static int handle_options(const char ***argv, int\n> > *argc, int *envchanged) *envchanged = 1;\n> >  \t\t} else if (!strcmp(cmd, \"--no-replace-objects\")) {\n> >  \t\t\tread_replace_refs = 0;\n> > +\t\t\tsetenv(NO_REPLACE_OBJECTS_ENVIRONMENT, \"\", 1);\n>\n> It is safer to set to a non-empty string, e.g., \"1\".\n\nOk, I will use a non empty string.\n\n> I think this variable should be added to the list in connect.c around\n> line 630 so that it does not propagate to the remote end.\n\nOk, I have done that in the version I will send.\n\nThanks,\nChristian.\n"},{"id":"127819","messageId":"200911180749.47243.chriscool@tuxfamily.org","threadId":"21648","inReplyTo":"4B026DE8.9070905@drmicha.warpmail.net","subject":"Re: [PATCH 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-11-18T06:49:47Z","receivedAt":"2009-11-18T06:49:47Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On mardi 17 novembre 2009, Michael J Gruber wrote:\n> Christian Couder venit, vidit, dixit 17.11.2009 06:11:\n> > This environment variable is set when the --no-replace-objects\n> > flag is passed to git, and it is read when other environment\n> > variables are read.\n> >\n> > It is useful for example for scripts, as the git commands used in\n> > them can now be aware that they must not read replace refs.\n> >\n> > Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n>\n> Tested-by: Michael J Gruber <git@drmicha.warpmail.net>\n>\n> :) This works, thanks, as well as the gitk patch 2/2, which is difficult\n> to cover by test scripts. Some OSes (or rather certain setenv/putenv\n> variants) have problems distinguishing an unset variable from an empty\n> one. I think we've worked around this, but avoiding it is safer, as J6t\n> pointed out.\n\nOk.\n\nThanks for testing,\nChristian.\n"}]}