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>
This commit is contained in:

committed by
Junio C Hamano

parent
b4b872994b
commit
e173587252
@ -47,6 +47,9 @@ arguments. The first argument specifies a remote repository as in git;
|
|||||||
it is either the name of a configured remote or a URL. The second
|
it is either the name of a configured remote or a URL. The second
|
||||||
argument specifies a URL; it is usually of the form
|
argument specifies a URL; it is usually of the form
|
||||||
'<transport>://<address>', but any arbitrary string is possible.
|
'<transport>://<address>', but any arbitrary string is possible.
|
||||||
|
The 'GIT_DIR' environment variable is set up for the remote helper
|
||||||
|
and can be used to determine where to store additional data or from
|
||||||
|
which directory to invoke auxiliary git commands.
|
||||||
|
|
||||||
When git encounters a URL of the form '<transport>://<address>', where
|
When git encounters a URL of the form '<transport>://<address>', where
|
||||||
'<transport>' is a protocol that it cannot handle natively, it
|
'<transport>' is a protocol that it cannot handle natively, it
|
||||||
|
@ -35,7 +35,7 @@ def get_repo(alias, url):
|
|||||||
prefix = 'refs/testgit/%s/' % alias
|
prefix = 'refs/testgit/%s/' % alias
|
||||||
debug("prefix: '%s'", prefix)
|
debug("prefix: '%s'", prefix)
|
||||||
|
|
||||||
repo.gitdir = ""
|
repo.gitdir = os.environ["GIT_DIR"]
|
||||||
repo.alias = alias
|
repo.alias = alias
|
||||||
repo.prefix = prefix
|
repo.prefix = prefix
|
||||||
|
|
||||||
@ -70,7 +70,6 @@ def do_capabilities(repo, args):
|
|||||||
|
|
||||||
print "import"
|
print "import"
|
||||||
print "export"
|
print "export"
|
||||||
print "gitdir"
|
|
||||||
print "refspec refs/heads/*:%s*" % repo.prefix
|
print "refspec refs/heads/*:%s*" % repo.prefix
|
||||||
|
|
||||||
print # end capabilities
|
print # end capabilities
|
||||||
@ -150,22 +149,11 @@ def do_export(repo, args):
|
|||||||
repo.non_local.push(repo.gitdir)
|
repo.non_local.push(repo.gitdir)
|
||||||
|
|
||||||
|
|
||||||
def do_gitdir(repo, args):
|
|
||||||
"""Stores the location of the gitdir.
|
|
||||||
"""
|
|
||||||
|
|
||||||
if not args:
|
|
||||||
die("gitdir needs an argument")
|
|
||||||
|
|
||||||
repo.gitdir = ' '.join(args)
|
|
||||||
|
|
||||||
|
|
||||||
COMMANDS = {
|
COMMANDS = {
|
||||||
'capabilities': do_capabilities,
|
'capabilities': do_capabilities,
|
||||||
'list': do_list,
|
'list': do_list,
|
||||||
'import': do_import,
|
'import': do_import,
|
||||||
'export': do_export,
|
'export': do_export,
|
||||||
'gitdir': do_gitdir,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,6 +105,12 @@ static struct child_process *get_helper(struct transport *transport)
|
|||||||
int refspec_alloc = 0;
|
int refspec_alloc = 0;
|
||||||
int duped;
|
int duped;
|
||||||
int code;
|
int code;
|
||||||
|
char git_dir_buf[sizeof(GIT_DIR_ENVIRONMENT) + PATH_MAX + 1];
|
||||||
|
const char *helper_env[] = {
|
||||||
|
git_dir_buf,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
if (data->helper)
|
if (data->helper)
|
||||||
return data->helper;
|
return data->helper;
|
||||||
@ -120,6 +126,10 @@ static struct child_process *get_helper(struct transport *transport)
|
|||||||
helper->argv[2] = remove_ext_force(transport->url);
|
helper->argv[2] = remove_ext_force(transport->url);
|
||||||
helper->git_cmd = 0;
|
helper->git_cmd = 0;
|
||||||
helper->silent_exec_failure = 1;
|
helper->silent_exec_failure = 1;
|
||||||
|
|
||||||
|
snprintf(git_dir_buf, sizeof(git_dir_buf), "%s=%s", GIT_DIR_ENVIRONMENT, get_git_dir());
|
||||||
|
helper->env = helper_env;
|
||||||
|
|
||||||
code = start_command(helper);
|
code = start_command(helper);
|
||||||
if (code < 0 && errno == ENOENT)
|
if (code < 0 && errno == ENOENT)
|
||||||
die("Unable to find remote helper for '%s'", data->name);
|
die("Unable to find remote helper for '%s'", data->name);
|
||||||
@ -174,11 +184,6 @@ static struct child_process *get_helper(struct transport *transport)
|
|||||||
refspecs[refspec_nr++] = strdup(buf.buf + strlen("refspec "));
|
refspecs[refspec_nr++] = strdup(buf.buf + strlen("refspec "));
|
||||||
} else if (!strcmp(capname, "connect")) {
|
} else if (!strcmp(capname, "connect")) {
|
||||||
data->connect = 1;
|
data->connect = 1;
|
||||||
} else if (!strcmp(buf.buf, "gitdir")) {
|
|
||||||
struct strbuf gitdir = STRBUF_INIT;
|
|
||||||
strbuf_addf(&gitdir, "gitdir %s\n", get_git_dir());
|
|
||||||
sendline(data, &gitdir);
|
|
||||||
strbuf_release(&gitdir);
|
|
||||||
} else if (mandatory) {
|
} else if (mandatory) {
|
||||||
die("Unknown mandatory capability %s. This remote "
|
die("Unknown mandatory capability %s. This remote "
|
||||||
"helper probably needs newer version of Git.\n",
|
"helper probably needs newer version of Git.\n",
|
||||||
|
Reference in New Issue
Block a user