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>
Nguyễn Thái Ngọc Duy committed
Dec 5, 2013 at 20:02 UTC
13eb4626c43b3116bb431671d593565eadc36852
6 files changed
+14
-22
builtin/send-pack.c
+2
-3
@@ -10,6 +10,7 @@
10
#include "quote.h"
11
#include "transport.h"
12
#include "version.h"
13
+#include "sha1-array.h"
14
15
static const char send_pack_usage[] =
16
"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)
100
const char *dest = NULL;
101
int fd[2];
102
struct child_process *conn;
102
- struct extra_have_objects extra_have;
103
+ struct sha1_array extra_have = SHA1_ARRAY_INIT;
104
struct ref *remote_refs, *local_refs;
105
int ret;
106
int helper_status = 0;
@@ -228,8 +229,6 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
229
args.verbose ? CONNECT_VERBOSE : 0);
230
}
231
231
- memset(&extra_have, 0, sizeof(extra_have));
232
-
232
get_remote_heads(fd[0], NULL, 0, &remote_refs, REF_NORMAL, &extra_have);
233
234
transport_verify_remote_names(nr_refspecs, refspecs);
connect.c
+3
-9
@@ -8,6 +8,7 @@
8
#include "connect.h"
9
#include "url.h"
10
#include "string-list.h"
11
+#include "sha1-array.h"
12
13
static char *server_capabilities;
14
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)
46
return check_ref(ref->name, strlen(ref->name), flags);
47
}
48
48
-static void add_extra_have(struct extra_have_objects *extra, unsigned char *sha1)
49
-{
50
- ALLOC_GROW(extra->array, extra->nr + 1, extra->alloc);
51
- hashcpy(&(extra->array[extra->nr][0]), sha1);
52
- extra->nr++;
53
-}
54
-
49
static void die_initial_contact(int got_at_least_one_head)
50
{
51
if (got_at_least_one_head)
@@ -122,7 +116,7 @@ static void annotate_refs_with_symref_info(struct ref *ref)
116
*/
117
struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
118
struct ref **list, unsigned int flags,
125
- struct extra_have_objects *extra_have)
119
+ struct sha1_array *extra_have)
120
{
121
struct ref **orig_list = list;
122
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,
154
155
if (extra_have &&
156
name_len == 5 && !memcmp(".have", name, 5)) {
163
- add_extra_have(extra_have, old_sha1);
157
+ sha1_array_append(extra_have, old_sha1);
158
continue;
159
}
160
remote.h
+2
-5
@@ -137,13 +137,10 @@ int check_ref_type(const struct ref *ref, int flags);
137
*/
138
void free_refs(struct ref *ref);
139
140
-struct extra_have_objects {
141
- int nr, alloc;
142
- unsigned char (*array)[20];
143
-};
140
+struct sha1_array;
141
extern struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
142
struct ref **list, unsigned int flags,
146
- struct extra_have_objects *);
143
+ struct sha1_array *extra_have);
144
145
int resolve_remote_symref(struct ref *ref, struct ref *list);
146
int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1);
send-pack.c
+4
-3
@@ -10,6 +10,7 @@
10
#include "quote.h"
11
#include "transport.h"
12
#include "version.h"
13
+#include "sha1-array.h"
14
15
static int feed_object(const unsigned char *sha1, int fd, int negative)
16
{
@@ -28,7 +29,7 @@ static int feed_object(const unsigned char *sha1, int fd, int negative)
29
/*
30
* Make a pack stream and spit it out into file descriptor fd
31
*/
31
-static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *extra, struct send_pack_args *args)
32
+static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, struct send_pack_args *args)
33
{
34
/*
35
* 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
72
* parameters by writing to the pipe.
73
*/
74
for (i = 0; i < extra->nr; i++)
74
- if (!feed_object(extra->array[i], po.in, 1))
75
+ if (!feed_object(extra->sha1[i], po.in, 1))
76
break;
77
78
while (refs) {
@@ -177,7 +178,7 @@ static int sideband_demux(int in, int out, void *data)
178
int send_pack(struct send_pack_args *args,
179
int fd[], struct child_process *conn,
180
struct ref *remote_refs,
180
- struct extra_have_objects *extra_have)
181
+ struct sha1_array *extra_have)
182
{
183
int in = fd[0];
184
int out = fd[1];
send-pack.h
+1
-1
@@ -16,6 +16,6 @@ struct send_pack_args {
16
17
int send_pack(struct send_pack_args *args,
18
int fd[], struct child_process *conn,
19
- struct ref *remote_refs, struct extra_have_objects *extra_have);
19
+ struct ref *remote_refs, struct sha1_array *extra_have);
20
21
#endif
transport.c
+2
-1
@@ -14,6 +14,7 @@
14
#include "url.h"
15
#include "submodule.h"
16
#include "string-list.h"
17
+#include "sha1-array.h"
18
19
/* rsync support */
20
@@ -454,7 +455,7 @@ struct git_transport_data {
455
struct child_process *conn;
456
int fd[2];
457
unsigned got_remote_heads : 1;
457
- struct extra_have_objects extra_have;
458
+ struct sha1_array extra_have;
459
};
460
461
static int set_git_option(struct git_transport_options *opts,