teach get_remote_heads to read from a memory buffer
authorJeff King <peff@peff.net>
Wed, 20 Feb 2013 20:06:45 +0000 (15:06 -0500)
committerJunio C Hamano <gitster@pobox.com>
Sun, 24 Feb 2013 08:17:38 +0000 (00:17 -0800)
Now that we can read packet data from memory as easily as a
descriptor, get_remote_heads can take either one as a
source. This will allow further refactoring in remote-curl.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch-pack.c
builtin/send-pack.c
cache.h
connect.c
remote-curl.c
transport.c
index c21cc2c778ae35229f49cddfc55921c0ff7fb8b4..03ed2caae33886078b8182ef46c33f07cf3d56a0 100644 (file)
@@ -125,7 +125,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
                                   args.verbose ? CONNECT_VERBOSE : 0);
        }
 
-       get_remote_heads(fd[0], &ref, 0, NULL);
+       get_remote_heads(fd[0], NULL, 0, &ref, 0, NULL);
 
        ref = fetch_pack(&args, fd, conn, ref, dest,
                         &sought, pack_lockfile_ptr);
index 87785197cd2e801f8cf5bf06b97ef030be2f7fba..152c4ea092a44ff9e70e293ddeecb4ad7105e25d 100644 (file)
@@ -207,7 +207,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
 
        memset(&extra_have, 0, sizeof(extra_have));
 
-       get_remote_heads(fd[0], &remote_refs, REF_NORMAL, &extra_have);
+       get_remote_heads(fd[0], NULL, 0, &remote_refs, REF_NORMAL, &extra_have);
 
        transport_verify_remote_names(nr_refspecs, refspecs);
 
diff --git a/cache.h b/cache.h
index e493563f4c07e6adcd00a1b2476926d69a4a67f8..db646a2ff87ee64d42bccd506456f983ac31062f 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1049,7 +1049,9 @@ struct extra_have_objects {
        int nr, alloc;
        unsigned char (*array)[20];
 };
-extern struct ref **get_remote_heads(int in, struct ref **list, unsigned int flags, struct extra_have_objects *);
+extern struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
+                                    struct ref **list, unsigned int flags,
+                                    struct extra_have_objects *);
 extern int server_supports(const char *feature);
 extern int parse_feature_request(const char *features, const char *feature);
 extern const char *server_feature_value(const char *feature, int *len_ret);
index 3d999999e5130e08cfc2c2195436ab6d082e041a..f57efd06c1d7ab01076b67d37ed24e34e17c4ebb 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -62,8 +62,8 @@ static void die_initial_contact(int got_at_least_one_head)
 /*
  * Read all the refs from the other end
  */
-struct ref **get_remote_heads(int in, struct ref **list,
-                             unsigned int flags,
+struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
+                             struct ref **list, unsigned int flags,
                              struct extra_have_objects *extra_have)
 {
        int got_at_least_one_head = 0;
@@ -76,7 +76,7 @@ struct ref **get_remote_heads(int in, struct ref **list,
                int len, name_len;
                char *buffer = packet_buffer;
 
-               len = packet_read(in, NULL, NULL,
+               len = packet_read(in, &src_buf, &src_len,
                                  packet_buffer, sizeof(packet_buffer),
                                  PACKET_READ_GENTLE_ON_EOF |
                                  PACKET_READ_CHOMP_NEWLINE);
index c8379a53f0e7ea53ee126d0260717020c5fc5ab4..24c86264d279f58c6207c0c46eb9a18d0035d43b 100644 (file)
@@ -192,7 +192,7 @@ static struct ref *parse_git_refs(struct discovery *heads, int for_push)
 
        if (start_async(&async))
                die("cannot start thread to parse advertised refs");
-       get_remote_heads(async.out, &list,
+       get_remote_heads(async.out, NULL, 0, &list,
                        for_push ? REF_NORMAL : 0, NULL);
        close(async.out);
        if (finish_async(&async))
index 886ffd8b1e1c9dbb31f3156844790ff98d5ecde3..62df466c1a82705c3e1d0cb21aa6f316710f0cfe 100644 (file)
@@ -507,7 +507,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
        struct ref *refs;
 
        connect_setup(transport, for_push, 0);
-       get_remote_heads(data->fd[0], &refs,
+       get_remote_heads(data->fd[0], NULL, 0, &refs,
                         for_push ? REF_NORMAL : 0, &data->extra_have);
        data->got_remote_heads = 1;
 
@@ -541,7 +541,7 @@ static int fetch_refs_via_pack(struct transport *transport,
 
        if (!data->got_remote_heads) {
                connect_setup(transport, 0, 0);
-               get_remote_heads(data->fd[0], &refs_tmp, 0, NULL);
+               get_remote_heads(data->fd[0], NULL, 0, &refs_tmp, 0, NULL);
                data->got_remote_heads = 1;
        }
 
@@ -799,7 +799,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
                struct ref *tmp_refs;
                connect_setup(transport, 1, 0);
 
-               get_remote_heads(data->fd[0], &tmp_refs, REF_NORMAL, NULL);
+               get_remote_heads(data->fd[0], NULL, 0, &tmp_refs, REF_NORMAL, NULL);
                data->got_remote_heads = 1;
        }