Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2013-11-02 03:05:32 +0400
committerCarlos Martín Nieto <cmn@dwim.me>2013-11-11 18:35:51 +0400
commit359dce726d215be65aee719c7316b43e3851c031 (patch)
tree7a4a0c0af01d2d02683a3aed27eca8315f1f9ca0 /src/transports
parent266af6d81960144334c16e061f1d30f94f8a1b46 (diff)
remote: make _ls return the list directly
The callback-based method of listing remote references dates back to the beginning of the network code's lifetime, when we didn't know any better. We need to keep the list around for update_tips() after disconnect() so let's make use of this to simply give the user a pointer to the array so they can write straightforward code instead of having to go through a callback.
Diffstat (limited to 'src/transports')
-rw-r--r--src/transports/local.c10
-rw-r--r--src/transports/smart.c34
-rw-r--r--src/transports/smart.h1
-rw-r--r--src/transports/smart_protocol.c1
4 files changed, 25 insertions, 21 deletions
diff --git a/src/transports/local.c b/src/transports/local.c
index 3163d2eac..4502f0202 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -213,21 +213,17 @@ static int local_connect(
return 0;
}
-static int local_ls(git_transport *transport, git_headlist_cb list_cb, void *payload)
+static int local_ls(const git_remote_head ***out, size_t *size, git_transport *transport)
{
transport_local *t = (transport_local *)transport;
- unsigned int i;
- git_remote_head *head = NULL;
if (!t->have_refs) {
giterr_set(GITERR_NET, "The transport has not yet loaded the refs");
return -1;
}
- git_vector_foreach(&t->refs, i, head) {
- if (list_cb(head, payload))
- return GIT_EUSER;
- }
+ *out = (const git_remote_head **) t->refs.contents;
+ *size = t->refs.length;
return 0;
}
diff --git a/src/transports/smart.c b/src/transports/smart.c
index a681d5f40..53f880583 100644
--- a/src/transports/smart.c
+++ b/src/transports/smart.c
@@ -74,6 +74,7 @@ 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;
@@ -140,6 +141,16 @@ static int git_smart__connect(
git_pkt_free((git_pkt *)first);
}
+ /* 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;
+ }
+
if (t->rpc && git_smart__reset_stream(t, false) < 0)
return -1;
@@ -149,28 +160,17 @@ static int git_smart__connect(
return 0;
}
-static int git_smart__ls(git_transport *transport, git_headlist_cb list_cb, void *payload)
+static int git_smart__ls(const git_remote_head ***out, size_t *size, git_transport *transport)
{
transport_smart *t = (transport_smart *)transport;
- unsigned int i;
- git_pkt *p = NULL;
if (!t->have_refs) {
giterr_set(GITERR_NET, "The transport has not yet loaded the refs");
return -1;
}
- git_vector_foreach(&t->refs, i, p) {
- git_pkt_ref *pkt = NULL;
-
- if (p->type != GIT_PKT_REF)
- continue;
-
- pkt = (git_pkt_ref *)p;
-
- if (list_cb(&pkt->head, payload))
- return GIT_EUSER;
- }
+ *out = (const git_remote_head **) t->heads.contents;
+ *size = t->heads.length;
return 0;
}
@@ -293,6 +293,7 @@ static void git_smart__free(git_transport *transport)
/* Free the subtransport */
t->wrapped->free(t->wrapped);
+ git_vector_free(&t->heads);
git_vector_foreach(refs, i, p)
git_pkt_free(p);
@@ -340,6 +341,11 @@ int git_transport_smart(git_transport **out, git_remote *owner, void *param)
return -1;
}
+ if (git_vector_init(&t->heads, 16, ref_name_cmp) < 0) {
+ git__free(t);
+ return -1;
+ }
+
if (definition->callback(&t->wrapped, &t->parent) < 0) {
git__free(t);
return -1;
diff --git a/src/transports/smart.h b/src/transports/smart.h
index 5232e54de..b46a798a4 100644
--- a/src/transports/smart.h
+++ b/src/transports/smart.h
@@ -140,6 +140,7 @@ typedef struct {
git_smart_subtransport_stream *current_stream;
transport_smart_caps caps;
git_vector refs;
+ git_vector heads;
git_vector common;
git_atomic cancelled;
packetsize_cb packetsize_cb;
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index ce3f115ee..4fe7c0d09 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -32,6 +32,7 @@ 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);