Browse Source

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>
maint
Nguyễn Thái Ngọc Duy 11 years ago committed by Junio C Hamano
parent
commit
13eb4626c4
  1. 5
      builtin/send-pack.c
  2. 12
      connect.c
  3. 7
      remote.h
  4. 7
      send-pack.c
  5. 2
      send-pack.h
  6. 3
      transport.c

5
builtin/send-pack.c

@ -10,6 +10,7 @@ @@ -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) @@ -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) @@ -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);

12
connect.c

@ -8,6 +8,7 @@ @@ -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) @@ -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) @@ -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, @@ -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;
}


7
remote.h

@ -137,13 +137,10 @@ int check_ref_type(const struct ref *ref, int flags); @@ -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);

7
send-pack.c

@ -10,6 +10,7 @@ @@ -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) @@ -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 @@ -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) @@ -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];

2
send-pack.h

@ -16,6 +16,6 @@ struct send_pack_args { @@ -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

3
transport.c

@ -14,6 +14,7 @@ @@ -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 { @@ -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,

Loading…
Cancel
Save