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().
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
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);