aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2013-12-05 20:02:29 +0700
committerJunio C Hamano <gitster@pobox.com>2013-12-10 16:14:15 -0800
commit13eb4626c43b3116bb431671d593565eadc36852 (patch)
tree01f7f161d5eedaaf3498eef791cbefbcf6234f68
parent75f8cbab2a2ddc50728ade82baad223ed54bb040 (diff)
downloadgit-13eb4626c43b3116bb431671d593565eadc36852.tar.gz
git-13eb4626c43b3116bb431671d593565eadc36852.tar.xz
remote.h: replace struct extra_have_objects with struct sha1_array
The latter can do everything the former can and is used in many more places. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/send-pack.c5
-rw-r--r--connect.c12
-rw-r--r--remote.h7
-rw-r--r--send-pack.c7
-rw-r--r--send-pack.h2
-rw-r--r--transport.c3
6 files changed, 14 insertions, 22 deletions
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index 4482f16ef..faaa60384 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -10,6 +10,7 @@
#include "quote.h"
#include "transport.h"
#include "version.h"
+#include "sha1-array.h"
static const char send_pack_usage[] =
"git send-pack [--all | --mirror] [--dry-run] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n"
@@ -99,7 +100,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
const char *dest = NULL;
int fd[2];
struct child_process *conn;
- struct extra_have_objects extra_have;
+ struct sha1_array extra_have = SHA1_ARRAY_INIT;
struct ref *remote_refs, *local_refs;
int ret;
int helper_status = 0;
@@ -228,8 +229,6 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
args.verbose ? CONNECT_VERBOSE : 0);
}
- memset(&extra_have, 0, sizeof(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/connect.c b/connect.c
index 06e88b070..48eec414f 100644
--- a/connect.c
+++ b/connect.c
@@ -8,6 +8,7 @@
#include "connect.h"
#include "url.h"
#include "string-list.h"
+#include "sha1-array.h"
static char *server_capabilities;
static const char *parse_feature_value(const char *, const char *, int *);
@@ -45,13 +46,6 @@ int check_ref_type(const struct ref *ref, int flags)
return check_ref(ref->name, strlen(ref->name), flags);
}
-static void add_extra_have(struct extra_have_objects *extra, unsigned char *sha1)
-{
- ALLOC_GROW(extra->array, extra->nr + 1, extra->alloc);
- hashcpy(&(extra->array[extra->nr][0]), sha1);
- extra->nr++;
-}
-
static void die_initial_contact(int got_at_least_one_head)
{
if (got_at_least_one_head)
@@ -122,7 +116,7 @@ static void annotate_refs_with_symref_info(struct ref *ref)
*/
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)
+ struct sha1_array *extra_have)
{
struct ref **orig_list = list;
int got_at_least_one_head = 0;
@@ -160,7 +154,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
if (extra_have &&
name_len == 5 && !memcmp(".have", name, 5)) {
- add_extra_have(extra_have, old_sha1);
+ sha1_array_append(extra_have, old_sha1);
continue;
}
diff --git a/remote.h b/remote.h
index 131130a61..984519bc6 100644
--- a/remote.h
+++ b/remote.h
@@ -137,13 +137,10 @@ int check_ref_type(const struct ref *ref, int flags);
*/
void free_refs(struct ref *ref);
-struct extra_have_objects {
- int nr, alloc;
- unsigned char (*array)[20];
-};
+struct sha1_array;
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 *);
+ struct sha1_array *extra_have);
int resolve_remote_symref(struct ref *ref, struct ref *list);
int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1);
diff --git a/send-pack.c b/send-pack.c
index fab62e3da..14005faef 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -10,6 +10,7 @@
#include "quote.h"
#include "transport.h"
#include "version.h"
+#include "sha1-array.h"
static int feed_object(const unsigned char *sha1, int fd, int negative)
{
@@ -28,7 +29,7 @@ static int feed_object(const unsigned char *sha1, int fd, int negative)
/*
* Make a pack stream and spit it out into file descriptor fd
*/
-static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *extra, struct send_pack_args *args)
+static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, struct send_pack_args *args)
{
/*
* The child becomes pack-objects --revs; we feed
@@ -71,7 +72,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
* parameters by writing to the pipe.
*/
for (i = 0; i < extra->nr; i++)
- if (!feed_object(extra->array[i], po.in, 1))
+ if (!feed_object(extra->sha1[i], po.in, 1))
break;
while (refs) {
@@ -177,7 +178,7 @@ static int sideband_demux(int in, int out, void *data)
int send_pack(struct send_pack_args *args,
int fd[], struct child_process *conn,
struct ref *remote_refs,
- struct extra_have_objects *extra_have)
+ struct sha1_array *extra_have)
{
int in = fd[0];
int out = fd[1];
diff --git a/send-pack.h b/send-pack.h
index 05d7ab118..8e843924c 100644
--- a/send-pack.h
+++ b/send-pack.h
@@ -16,6 +16,6 @@ struct send_pack_args {
int send_pack(struct send_pack_args *args,
int fd[], struct child_process *conn,
- struct ref *remote_refs, struct extra_have_objects *extra_have);
+ struct ref *remote_refs, struct sha1_array *extra_have);
#endif
diff --git a/transport.c b/transport.c
index 7202b7777..12e46ad66 100644
--- a/transport.c
+++ b/transport.c
@@ -14,6 +14,7 @@
#include "url.h"
#include "submodule.h"
#include "string-list.h"
+#include "sha1-array.h"
/* rsync support */
@@ -454,7 +455,7 @@ struct git_transport_data {
struct child_process *conn;
int fd[2];
unsigned got_remote_heads : 1;
- struct extra_have_objects extra_have;
+ struct sha1_array extra_have;
};
static int set_git_option(struct git_transport_options *opts,