Commit a6192d7c98976edb0ce4fd10438ac7a19c283598

Carlos Martín Nieto 2013-11-11T15:32:13

remote: update head list on push A previous commit forgot to update the head list after push as well, leading to wrong output of git_remote_ls().

diff --git a/src/transports/smart.c b/src/transports/smart.c
index 53f8805..5242beb 100644
--- a/src/transports/smart.c
+++ b/src/transports/smart.c
@@ -63,6 +63,24 @@ static int git_smart__set_callbacks(
 	return 0;
 }
 
+int git_smart__update_heads(transport_smart *t)
+{
+	size_t i;
+	git_pkt *pkt;
+
+	git_vector_clear(&t->heads);
+	git_vector_foreach(&t->refs, i, pkt) {
+		git_pkt_ref *ref = (git_pkt_ref *) pkt;
+		if (pkt->type != GIT_PKT_REF)
+			continue;
+
+		if (git_vector_insert(&t->heads, &ref->head) < 0)
+			return -1;
+	}
+
+	return 0;
+}
+
 static int git_smart__connect(
 	git_transport *transport,
 	const char *url,
@@ -74,7 +92,6 @@ static int git_smart__connect(
 	transport_smart *t = (transport_smart *)transport;
 	git_smart_subtransport_stream *stream;
 	int error;
-	size_t i;
 	git_pkt *pkt;
 	git_pkt_ref *first;
 	git_smart_service_t service;
@@ -142,14 +159,7 @@ static int git_smart__connect(
 	}
 
 	/* Keep a list of heads for _ls */
-	git_vector_foreach(&t->refs, i, pkt) {
-		git_pkt_ref *ref = (git_pkt_ref *) pkt;
-		if (pkt->type != GIT_PKT_REF)
-			continue;
-
-		if (git_vector_insert(&t->heads, &ref->head) < 0)
-			return -1;
-	}
+	git_smart__update_heads(t);
 
 	if (t->rpc && git_smart__reset_stream(t, false) < 0)
 		return -1;
diff --git a/src/transports/smart.h b/src/transports/smart.h
index b46a798..32f0be7 100644
--- a/src/transports/smart.h
+++ b/src/transports/smart.h
@@ -174,6 +174,8 @@ int git_smart__download_pack(
 int git_smart__negotiation_step(git_transport *transport, void *data, size_t len);
 int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream **out);
 
+int git_smart__update_heads(transport_smart *t);
+
 /* smart_pkt.c */
 int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len);
 int git_pkt_buffer_flush(git_buf *buf);
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index 4fe7c0d..ee1d343 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -32,7 +32,6 @@ int git_smart__store_refs(transport_smart *t, int flushes)
 	/* Clear existing refs in case git_remote_connect() is called again
 	 * after git_remote_disconnect().
 	 */
-	git_vector_clear(&t->heads);
 	git_vector_foreach(refs, i, ref) {
 		git__free(ref->head.name);
 		git__free(ref);
@@ -945,8 +944,13 @@ int git_smart__push(git_transport *transport, git_push *push)
 		push->transfer_progress_cb(push->pb->nr_written, push->pb->nr_objects, packbuilder_payload.last_bytes, push->transfer_progress_cb_payload);
 	}
 
-	if (push->status.length)
+	if (push->status.length) {
 		error = update_refs_from_report(&t->refs, &push->specs, &push->status);
+		if (error < 0)
+			goto done;
+
+		error = git_smart__update_heads(t);
+	}
 
 done:
 	git_buf_free(&pktline);