remote-helpers: export GIT_DIR variable to helpers
The gitdir capability is recognized by git and can be used to tell the helper where the .git directory is. But it is not mentioned in the documentation and considered worse than if gitdir was passed via GIT_DIR environment variable. Remove support for the gitdir capability and export GIT_DIR instead. Teach testgit to use env instead of the now-removed gitdir command. [sr: fixed up documentation] Signed-off-by: Dmitry Ivankov <divanorama@gmail.com> Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Dmitry Ivankov committed
Jul 16, 2011 at 15:03 UTC
e173587252ea0db16efc5c64c2cb165ccb406495
3 files changed
+14
-18
Documentation/git-remote-helpers.txt
+3
@@ -47,6 +47,9 @@ arguments. The first argument specifies a remote repository as in git;
47
it is either the name of a configured remote or a URL. The second
48
argument specifies a URL; it is usually of the form
49
'<transport>://<address>', but any arbitrary string is possible.
50
+The 'GIT_DIR' environment variable is set up for the remote helper
51
+and can be used to determine where to store additional data or from
52
+which directory to invoke auxiliary git commands.
53
54
When git encounters a URL of the form '<transport>://<address>', where
55
'<transport>' is a protocol that it cannot handle natively, it
git-remote-testgit.py
+1
-13
@@ -35,7 +35,7 @@ def get_repo(alias, url):
35
prefix = 'refs/testgit/%s/' % alias
36
debug("prefix: '%s'", prefix)
37
38
- repo.gitdir = ""
38
+ repo.gitdir = os.environ["GIT_DIR"]
39
repo.alias = alias
40
repo.prefix = prefix
41
@@ -70,7 +70,6 @@ def do_capabilities(repo, args):
70
71
print "import"
72
print "export"
73
- print "gitdir"
73
print "refspec refs/heads/*:%s*" % repo.prefix
74
75
print # end capabilities
@@ -150,22 +149,11 @@ def do_export(repo, args):
149
repo.non_local.push(repo.gitdir)
150
151
153
-def do_gitdir(repo, args):
154
- """Stores the location of the gitdir.
155
- """
156
-
157
- if not args:
158
- die("gitdir needs an argument")
159
-
160
- repo.gitdir = ' '.join(args)
161
-
162
-
152
COMMANDS = {
153
'capabilities': do_capabilities,
154
'list': do_list,
155
'import': do_import,
156
'export': do_export,
168
- 'gitdir': do_gitdir,
157
}
158
159
transport-helper.c
+10
-5
@@ -105,6 +105,12 @@ static struct child_process *get_helper(struct transport *transport)
105
int refspec_alloc = 0;
106
int duped;
107
int code;
108
+ char git_dir_buf[sizeof(GIT_DIR_ENVIRONMENT) + PATH_MAX + 1];
109
+ const char *helper_env[] = {
110
+ git_dir_buf,
111
+ NULL
112
+ };
113
+
114
115
if (data->helper)
116
return data->helper;
@@ -120,6 +126,10 @@ static struct child_process *get_helper(struct transport *transport)
126
helper->argv[2] = remove_ext_force(transport->url);
127
helper->git_cmd = 0;
128
helper->silent_exec_failure = 1;
129
+
130
+ snprintf(git_dir_buf, sizeof(git_dir_buf), "%s=%s", GIT_DIR_ENVIRONMENT, get_git_dir());
131
+ helper->env = helper_env;
132
+
133
code = start_command(helper);
134
if (code < 0 && errno == ENOENT)
135
die("Unable to find remote helper for '%s'", data->name);
@@ -174,11 +184,6 @@ static struct child_process *get_helper(struct transport *transport)
184
refspecs[refspec_nr++] = strdup(buf.buf + strlen("refspec "));
185
} else if (!strcmp(capname, "connect")) {
186
data->connect = 1;
177
- } else if (!strcmp(buf.buf, "gitdir")) {
178
- struct strbuf gitdir = STRBUF_INIT;
179
- strbuf_addf(&gitdir, "gitdir %s\n", get_git_dir());
180
- sendline(data, &gitdir);
181
- strbuf_release(&gitdir);
187
} else if (mandatory) {
188
die("Unknown mandatory capability %s. This remote "
189
"helper probably needs newer version of Git.\n",