From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Couder Subject: [PATCH v2 1/2] replace: use a GIT_NO_REPLACE_OBJECTS env variable Date: Wed, 18 Nov 2009 07:50:58 +0100 Message-ID: <20091118065100.4206.37331.chriscool@tuxfamily.org> Cc: git@vger.kernel.org, Michael J Gruber , Jakub Narebski , Johannes Sixt , bill lam , Andreas Schwab , Paul Mackerras To: Junio C Hamano X-From: git-owner@vger.kernel.org Wed Nov 18 07:50:14 2009 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1NAeMm-0000qi-Ms for gcvg-git-2@lo.gmane.org; Wed, 18 Nov 2009 07:50:13 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754070AbZKRGt5 (ORCPT ); Wed, 18 Nov 2009 01:49:57 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752871AbZKRGt4 (ORCPT ); Wed, 18 Nov 2009 01:49:56 -0500 Received: from smtp3-g21.free.fr ([212.27.42.3]:59501 "EHLO smtp3-g21.free.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752206AbZKRGt4 (ORCPT ); Wed, 18 Nov 2009 01:49:56 -0500 Received: from smtp3-g21.free.fr (localhost [127.0.0.1]) by smtp3-g21.free.fr (Postfix) with ESMTP id DD61B8180C8; Wed, 18 Nov 2009 07:49:53 +0100 (CET) Received: from bureau.boubyland (gre92-7-82-243-130-161.fbx.proxad.net [82.243.130.161]) by smtp3-g21.free.fr (Postfix) with ESMTP id CCFA981802F; Wed, 18 Nov 2009 07:49:50 +0100 (CET) X-git-sha1: 588b714d7f4262527615993f226efeff3b60be8e X-Mailer: git-mail-commits v0.5.2 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: 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. The GIT_NO_REPLACE_OBJECTS is set to "1" instead of "" as it is safer on some platforms, thanks to Johannes Sixt and Michael J Gruber. Tested-by: Michael J Gruber Signed-off-by: Christian Couder --- cache.h | 1 + connect.c | 1 + environment.c | 2 ++ git.c | 3 +++ t/t6050-replace.sh | 17 +++++++++++++++++ 5 files changed, 24 insertions(+), 0 deletions(-) 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/connect.c b/connect.c index 7945e38..c4f134f 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 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..d50bbc3 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 d4818b4..203ffdb 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 <