]> git.proxmox.com Git - libgit2.git/commitdiff
remote: update head list on push
authorCarlos Martín Nieto <cmn@dwim.me>
Mon, 11 Nov 2013 14:32:13 +0000 (15:32 +0100)
committerCarlos Martín Nieto <cmn@dwim.me>
Mon, 11 Nov 2013 14:35:52 +0000 (15:35 +0100)
A previous commit forgot to update the head list after push as well,
leading to wrong output of git_remote_ls().

src/transports/smart.c
src/transports/smart.h
src/transports/smart_protocol.c

index 53f880583cca9a701db11889a660ec4f89dc815a..5242beb65d54a5f1f6262d47b4555446fb7f5521 100644 (file)
@@ -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;
index b46a798a4cd06647fb6f09b031cf4757c470a087..32f0be7f26b93facda03f429d11f349be44b3358 100644 (file)
@@ -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);
index 4fe7c0d094ef6081f67e244a05f227105d3b9d63..ee1d343777bc3da344aa3ab740c97e826833272f 100644 (file)
@@ -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);