Add support for taking over transports that turn out to be smart.
Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Ilari Liusvaara15 years agocommitted byJunio C Hamano
@ -81,6 +85,7 @@ static struct child_process *get_helper(struct transport *transport)
@@ -81,6 +85,7 @@ static struct child_process *get_helper(struct transport *transport)
const char **refspecs = NULL;
int refspec_nr = 0;
int refspec_alloc = 0;
int duped;
if (data->helper)
return data->helper;
@ -99,9 +104,19 @@ static struct child_process *get_helper(struct transport *transport)
@@ -99,9 +104,19 @@ static struct child_process *get_helper(struct transport *transport)
die("Unable to run helper: git %s", helper->argv[0]);
data->helper = helper;
/*
* Open the output as FILE* so strbuf_getline() can be used.
* Do this with duped fd because fclose() will close the fd,
* and stuff like taking over will require the fd to remain.
*
*/
duped = dup(helper->out);
if (duped < 0)
die_errno("Can't dup helper output fd");
data->out = xfdopen(duped, "r");
write_constant(helper->in, "capabilities\n");
data->out = xfdopen(helper->out, "r");
while (1) {
const char *capname;
int mandatory = 0;
@ -163,6 +178,7 @@ static int disconnect_helper(struct transport *transport)
@@ -163,6 +178,7 @@ static int disconnect_helper(struct transport *transport)
strbuf_addf(&buf, "\n");
sendline(data, &buf);
close(data->helper->in);
close(data->helper->out);
fclose(data->out);
finish_command(data->helper);
free((char *)data->helper->argv[0]);
@ -583,5 +599,6 @@ int transport_helper_init(struct transport *transport, const char *name)
@@ -583,5 +599,6 @@ int transport_helper_init(struct transport *transport, const char *name)
@ -447,6 +453,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
@@ -447,6 +453,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
connect_setup(transport, for_push, 0);
get_remote_heads(data->fd[0], &refs, 0, NULL,
for_push ? REF_NORMAL : 0, &data->extra_have);
data->got_remote_heads = 1;
return refs;
}
@ -477,9 +484,10 @@ static int fetch_refs_via_pack(struct transport *transport,
@@ -477,9 +484,10 @@ static int fetch_refs_via_pack(struct transport *transport,
@ -490,6 +498,7 @@ static int fetch_refs_via_pack(struct transport *transport,
@@ -490,6 +498,7 @@ static int fetch_refs_via_pack(struct transport *transport,
if (finish_connect(data->conn))
refs = NULL;
data->conn = NULL;
data->got_remote_heads = 0;
free_refs(refs_tmp);
@ -718,12 +727,13 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
@@ -718,12 +727,13 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re