All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable
@ 2009-11-17  5:11 Christian Couder
  2009-11-17  7:42 ` Johannes Sixt
  2009-11-17  9:33 ` Michael J Gruber
  0 siblings, 2 replies; 5+ messages in thread
From: Christian Couder @ 2009-11-17  5:11 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Michael J Gruber, Jakub Narebski, Johannes Sixt, bill lam,
	Andreas Schwab, Paul Mackerras

This environment variable is set when the --no-replace-objects
flag is passed to git, and it is read when other environment
variables are read.

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.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 cache.h            |    1 +
 environment.c      |    2 ++
 git.c              |    3 +++
 t/t6050-replace.sh |   17 +++++++++++++++++
 4 files changed, 23 insertions(+), 0 deletions(-)

	Michael J Gruber wrote:
	>
	> [ The example also shows that we need a way to specify
	> --no-replace-objects for gitk. Would easier if gitk really
	> where git something. ]

	These 2 patches should fix that for gitk and many other scripted
	commands. But if it doesn't for some, please tell me.

	Thanks,
	Christian.

diff --git a/cache.h b/cache.h
index 71a731d..bc77909 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/environment.c b/environment.c
index 5de6837..279a38a 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 (read_replace_refs && getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
+		read_replace_refs = 0;
 }
 
 int is_bare_repository(void)
diff --git a/git.c b/git.c
index bd2c5fe..7f7d73d 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);
+			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 d4818b4..82cf2ec 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= git cat-file commit $HASH2 | grep "author A U Thor" &&
+     GIT_NO_REPLACE_OBJECTS= git show $HASH2 | grep "A U Thor"
+'
+
 cat >tag.sig <<EOF
 object $HASH2
 type commit
@@ -202,6 +207,18 @@ test_expect_success 'fetch branch with replacement' '
      cd ..
 '
 
+test_expect_success 'bisect and replacements' '
+     git bisect start $HASH7 $HASH1 &&
+     test "$S" = "$(git rev-parse --verify HEAD)" &&
+     git bisect reset &&
+     GIT_NO_REPLACE_OBJECTS= git bisect start $HASH7 $HASH1 &&
+     test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
+     git bisect reset &&
+     git --no-replace-objects bisect start $HASH7 $HASH1 &&
+     test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
+     git bisect reset
+'
+
 #
 #
 test_done
-- 
1.6.5.1.gaf97d

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable
  2009-11-17  5:11 [PATCH 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable Christian Couder
@ 2009-11-17  7:42 ` Johannes Sixt
  2009-11-18  6:48   ` Christian Couder
  2009-11-17  9:33 ` Michael J Gruber
  1 sibling, 1 reply; 5+ messages in thread
From: Johannes Sixt @ 2009-11-17  7:42 UTC (permalink / raw)
  To: Christian Couder
  Cc: Junio C Hamano, git, Michael J Gruber, Jakub Narebski, bill lam,
	Andreas Schwab, Paul Mackerras

Christian Couder schrieb:
> diff --git a/git.c b/git.c
> index bd2c5fe..7f7d73d 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);

It is safer to set to a non-empty string, e.g., "1".

I think this variable should be added to the list in connect.c around line
630 so that it does not propagate to the remote end.

-- Hannes

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable
  2009-11-17  5:11 [PATCH 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable Christian Couder
  2009-11-17  7:42 ` Johannes Sixt
@ 2009-11-17  9:33 ` Michael J Gruber
  2009-11-18  6:49   ` Christian Couder
  1 sibling, 1 reply; 5+ messages in thread
From: Michael J Gruber @ 2009-11-17  9:33 UTC (permalink / raw)
  To: Christian Couder
  Cc: Junio C Hamano, git, Jakub Narebski, Johannes Sixt, bill lam,
	Andreas Schwab, Paul Mackerras

Christian Couder venit, vidit, dixit 17.11.2009 06:11:
> This environment variable is set when the --no-replace-objects
> flag is passed to git, and it is read when other environment
> variables are read.
> 
> 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.
> 
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>

Tested-by: Michael J Gruber <git@drmicha.warpmail.net>

:) This works, thanks, as well as the gitk patch 2/2, which is difficult
to cover by test scripts. Some OSes (or rather certain setenv/putenv
variants) have problems distinguishing an unset variable from an empty
one. I think we've worked around this, but avoiding it is safer, as J6t
pointed out.

Thanks!
Michael

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable
  2009-11-17  7:42 ` Johannes Sixt
@ 2009-11-18  6:48   ` Christian Couder
  0 siblings, 0 replies; 5+ messages in thread
From: Christian Couder @ 2009-11-18  6:48 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: Junio C Hamano, git, Michael J Gruber, Jakub Narebski, bill lam,
	Andreas Schwab, Paul Mackerras

On mardi 17 novembre 2009, Johannes Sixt wrote:
> Christian Couder schrieb:
> > diff --git a/git.c b/git.c
> > index bd2c5fe..7f7d73d 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);
>
> It is safer to set to a non-empty string, e.g., "1".

Ok, I will use a non empty string.

> I think this variable should be added to the list in connect.c around
> line 630 so that it does not propagate to the remote end.

Ok, I have done that in the version I will send.

Thanks,
Christian.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable
  2009-11-17  9:33 ` Michael J Gruber
@ 2009-11-18  6:49   ` Christian Couder
  0 siblings, 0 replies; 5+ messages in thread
From: Christian Couder @ 2009-11-18  6:49 UTC (permalink / raw)
  To: Michael J Gruber
  Cc: Junio C Hamano, git, Jakub Narebski, Johannes Sixt, bill lam,
	Andreas Schwab, Paul Mackerras

On mardi 17 novembre 2009, Michael J Gruber wrote:
> Christian Couder venit, vidit, dixit 17.11.2009 06:11:
> > This environment variable is set when the --no-replace-objects
> > flag is passed to git, and it is read when other environment
> > variables are read.
> >
> > 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.
> >
> > Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
>
> Tested-by: Michael J Gruber <git@drmicha.warpmail.net>
>
> :) This works, thanks, as well as the gitk patch 2/2, which is difficult
> to cover by test scripts. Some OSes (or rather certain setenv/putenv
> variants) have problems distinguishing an unset variable from an empty
> one. I think we've worked around this, but avoiding it is safer, as J6t
> pointed out.

Ok.

Thanks for testing,
Christian.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-11-18  6:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-17  5:11 [PATCH 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable Christian Couder
2009-11-17  7:42 ` Johannes Sixt
2009-11-18  6:48   ` Christian Couder
2009-11-17  9:33 ` Michael J Gruber
2009-11-18  6:49   ` Christian Couder

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.