summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2013-12-05 20:02:45 +0700
committerJunio C Hamano <gitster@pobox.com>2013-12-10 16:14:17 -0800
commit069c053222bfc62a6522430a137e9b2c7ff36e4c (patch)
tree6c86c32582176d17f7ddd31ff24f7ced1f890dc0
parent5dbd767601812209273ae007a97b7c9305dc6cfd (diff)
downloadgit-069c053222bfc62a6522430a137e9b2c7ff36e4c.tar.gz
add GIT_SHALLOW_FILE to propagate --shallow-file to subprocesses
This may be needed when a hook is run after a new shallow pack is received, but .git/shallow is not settled yet. A temporary shallow file to plug all loose ends should be used instead. GIT_SHALLOW_FILE is overriden by --shallow-file. --shallow-file does not work in this case because the hook may spawn many git subprocesses and the launch commands do not have --shallow-file as it's a recent addition. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--cache.h1
-rw-r--r--commit.h2
-rw-r--r--environment.c6
-rw-r--r--git.c2
-rw-r--r--shallow.c4
5 files changed, 12 insertions, 3 deletions
diff --git a/cache.h b/cache.h
index 55dd4e3c8e..8b132878ce 100644
--- a/cache.h
+++ b/cache.h
@@ -354,6 +354,7 @@ static inline enum object_type object_type(unsigned int mode)
#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
+#define GIT_SHALLOW_FILE_ENVIRONMENT "GIT_SHALLOW_FILE"
#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR"
#define CONFIG_ENVIRONMENT "GIT_CONFIG"
#define CONFIG_DATA_ENVIRONMENT "GIT_CONFIG_PARAMETERS"
diff --git a/commit.h b/commit.h
index 69bca3e4be..79649efc7c 100644
--- a/commit.h
+++ b/commit.h
@@ -202,7 +202,7 @@ extern int is_repository_shallow(void);
extern struct commit_list *get_shallow_commits(struct object_array *heads,
int depth, int shallow_flag, int not_shallow_flag);
extern void check_shallow_file_for_update(void);
-extern void set_alternate_shallow_file(const char *path);
+extern void set_alternate_shallow_file(const char *path, int override);
extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
const struct sha1_array *extra);
extern void setup_alternate_shallow(struct lock_file *shallow_lock,
diff --git a/environment.c b/environment.c
index 0a15349cfe..b73b39d72f 100644
--- a/environment.c
+++ b/environment.c
@@ -10,6 +10,7 @@
#include "cache.h"
#include "refs.h"
#include "fmt-merge-msg.h"
+#include "commit.h"
int trust_executable_bit = 1;
int trust_ctime = 1;
@@ -97,6 +98,7 @@ const char * const local_repo_env[] = {
INDEX_ENVIRONMENT,
NO_REPLACE_OBJECTS_ENVIRONMENT,
GIT_PREFIX_ENVIRONMENT,
+ GIT_SHALLOW_FILE_ENVIRONMENT,
NULL
};
@@ -124,6 +126,7 @@ static char *expand_namespace(const char *raw_namespace)
static void setup_git_env(void)
{
const char *gitfile;
+ const char *shallow_file;
git_dir = getenv(GIT_DIR_ENVIRONMENT);
if (!git_dir)
@@ -147,6 +150,9 @@ static void setup_git_env(void)
read_replace_refs = 0;
namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));
namespace_len = strlen(namespace);
+ shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);
+ if (shallow_file)
+ set_alternate_shallow_file(shallow_file, 0);
}
int is_bare_repository(void)
diff --git a/git.c b/git.c
index cb5208de6a..179c4f6ff8 100644
--- a/git.c
+++ b/git.c
@@ -162,7 +162,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
} else if (!strcmp(cmd, "--shallow-file")) {
(*argv)++;
(*argc)--;
- set_alternate_shallow_file((*argv)[0]);
+ set_alternate_shallow_file((*argv)[0], 1);
if (envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "-C")) {
diff --git a/shallow.c b/shallow.c
index 52268544fd..ec9179480f 100644
--- a/shallow.c
+++ b/shallow.c
@@ -13,10 +13,12 @@ static int is_shallow = -1;
static struct stat shallow_stat;
static char *alternate_shallow_file;
-void set_alternate_shallow_file(const char *path)
+void set_alternate_shallow_file(const char *path, int override)
{
if (is_shallow != -1)
die("BUG: is_repository_shallow must not be called before set_alternate_shallow_file");
+ if (alternate_shallow_file && !override)
+ return;
free(alternate_shallow_file);
alternate_shallow_file = path ? xstrdup(path) : NULL;
}