From 6476b38b1f3d258006566c3c9c6c80cc07fda354 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Wed, 18 Nov 2009 07:50:58 +0100 Subject: [PATCH 1/3] replace: use a GIT_NO_REPLACE_OBJECTS env variable This has the same effect as --no-replace-objects option; git ignores the replace refs. When --no-replace-objects option is passed to git, this environment variable is set to "1" and exported to subprocesses in order to propagate the same setting. It is useful for example for scripts, as the git commands used in them can now be aware that they must not read replace refs. Tested-by: Michael J Gruber Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- cache.h | 1 + connect.c | 1 + environment.c | 2 ++ git.c | 3 +++ t/t6050-replace.sh | 17 +++++++++++++++++ 5 files changed, 24 insertions(+) diff --git a/cache.h b/cache.h index 71a731dbc988a8..bc7790924f6378 100644 --- a/cache.h +++ b/cache.h @@ -369,6 +369,7 @@ static inline enum object_type object_type(unsigned int mode) #define CONFIG_ENVIRONMENT "GIT_CONFIG" #define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH" #define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES" +#define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS" #define GITATTRIBUTES_FILE ".gitattributes" #define INFOATTRIBUTES_FILE "info/attributes" #define ATTRIBUTE_MACRO_PREFIX "[attr]" diff --git a/connect.c b/connect.c index 7945e38ac1c99c..c4f134f07aa44d 100644 --- a/connect.c +++ b/connect.c @@ -630,6 +630,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig, GIT_WORK_TREE_ENVIRONMENT, GRAFT_ENVIRONMENT, INDEX_ENVIRONMENT, + NO_REPLACE_OBJECTS_ENVIRONMENT, NULL }; conn->env = env; diff --git a/environment.c b/environment.c index 5de683784039f2..5946f385f57d4b 100644 --- a/environment.c +++ b/environment.c @@ -83,6 +83,8 @@ static void setup_git_env(void) git_graft_file = getenv(GRAFT_ENVIRONMENT); if (!git_graft_file) git_graft_file = git_pathdup("info/grafts"); + if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT)) + read_replace_refs = 0; } int is_bare_repository(void) diff --git a/git.c b/git.c index bd2c5fe77b41f3..d50bbc3e43694e 100644 --- a/git.c +++ b/git.c @@ -89,6 +89,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) *envchanged = 1; } else if (!strcmp(cmd, "--no-replace-objects")) { read_replace_refs = 0; + setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1); + if (envchanged) + *envchanged = 1; } else if (!strcmp(cmd, "--git-dir")) { if (*argc < 2) { fprintf(stderr, "No directory given for --git-dir.\n" ); diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index d4818b430aad55..203ffdb17a9146 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -77,6 +77,11 @@ test_expect_success 'test --no-replace-objects option' ' git --no-replace-objects show $HASH2 | grep "A U Thor" ' +test_expect_success 'test GIT_NO_REPLACE_OBJECTS env variable' ' + GIT_NO_REPLACE_OBJECTS=1 git cat-file commit $HASH2 | grep "author A U Thor" && + GIT_NO_REPLACE_OBJECTS=1 git show $HASH2 | grep "A U Thor" +' + cat >tag.sig < Date: Thu, 19 Nov 2009 07:13:15 +0100 Subject: [PATCH 2/3] Documentation: fix typos and spelling in replace documentation This patch fix a missing "s" at the end of an occurence of "--no-replace-objects" and, while at it, it also improves spelling and rendering. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Documentation/git-replace.txt | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt index 8adc1ef55c620d..69f704faf8e36c 100644 --- a/Documentation/git-replace.txt +++ b/Documentation/git-replace.txt @@ -17,31 +17,32 @@ DESCRIPTION Adds a 'replace' reference in `.git/refs/replace/` The name of the 'replace' reference is the SHA1 of the object that is -replaced. The content of the replace reference is the SHA1 of the +replaced. The content of the 'replace' reference is the SHA1 of the replacement object. -Unless `-f` is given, the replace reference must not yet exist in +Unless `-f` is given, the 'replace' reference must not yet exist in `.git/refs/replace/` directory. -Replace references will be used by default by all git commands except -those doing reachability traversal (prune, pack transfer and fsck). +Replacement references will be used by default by all git commands +except those doing reachability traversal (prune, pack transfer and +fsck). -It is possible to disable use of replacement refs for any command -using the --no-replace-objects option just after "git". +It is possible to disable use of replacement references for any +command using the `--no-replace-objects` option just after 'git'. -For example if commit "foo" has been replaced by commit "bar": +For example if commit 'foo' has been replaced by commit 'bar': ------------------------------------------------ -$ git --no-replace-object cat-file commit foo +$ git --no-replace-objects cat-file commit foo ------------------------------------------------ -show information about commit "foo", while: +shows information about commit 'foo', while: ------------------------------------------------ $ git cat-file commit foo ------------------------------------------------ -show information about commit "bar". +shows information about commit 'bar'. OPTIONS ------- From 0de8b94720501e869a05c52a691985fa4ce69803 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Thu, 19 Nov 2009 07:13:16 +0100 Subject: [PATCH 3/3] Documentation: talk a little bit about GIT_NO_REPLACE_OBJECTS Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Documentation/git-replace.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt index 69f704faf8e36c..65a0da508a6be0 100644 --- a/Documentation/git-replace.txt +++ b/Documentation/git-replace.txt @@ -44,6 +44,9 @@ $ git cat-file commit foo shows information about commit 'bar'. +The 'GIT_NO_REPLACE_OBJECTS' environment variable can be set to +achieve the same effect as the `--no-replace-objects` option. + OPTIONS ------- -f::