summaryrefslogtreecommitdiff
path: root/fetch-pack.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-01-29 14:02:15 -0800
committerJunio C Hamano <gitster@pobox.com>2013-02-07 13:53:59 -0800
commitf2db854d24f32de7b03dde5a7d7134f5e31100b9 (patch)
tree3654e0cb8fcfc1b96fc66f5a1f199cd81a2e867d /fetch-pack.c
parentdef249911ad0e36a40a0603fc42b7e9cf0b21546 (diff)
downloadgit-f2db854d24f32de7b03dde5a7d7134f5e31100b9.tar.gz
fetch: use struct ref to represent refs to be fetched
Even though "git fetch" has full infrastructure to parse refspecs to be fetched and match them against the list of refs to come up with the final list of refs to be fetched, the list of refs that are requested to be fetched were internally converted to a plain list of strings at the transport layer and then passed to the underlying fetch-pack driver. Stop this conversion and instead pass around an array of refs. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'fetch-pack.c')
-rw-r--r--fetch-pack.c79
1 files changed, 48 insertions, 31 deletions
diff --git a/fetch-pack.c b/fetch-pack.c
index f0acdf7331..915c0b7887 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -520,47 +520,37 @@ static void mark_recent_complete_commits(struct fetch_pack_args *args,
}
}
-static int non_matching_ref(struct string_list_item *item, void *unused)
-{
- if (item->util) {
- item->util = NULL;
- return 0;
- }
- else
- return 1;
-}
-
static void filter_refs(struct fetch_pack_args *args,
- struct ref **refs, struct string_list *sought)
+ struct ref **refs,
+ struct ref **sought, int nr_sought)
{
struct ref *newlist = NULL;
struct ref **newtail = &newlist;
struct ref *ref, *next;
- int sought_pos;
+ int i;
- sought_pos = 0;
+ i = 0;
for (ref = *refs; ref; ref = next) {
int keep = 0;
next = ref->next;
+
if (!memcmp(ref->name, "refs/", 5) &&
check_refname_format(ref->name + 5, 0))
; /* trash */
else {
- while (sought_pos < sought->nr) {
- int cmp = strcmp(ref->name, sought->items[sought_pos].string);
+ while (i < nr_sought) {
+ int cmp = strcmp(ref->name, sought[i]->name);
if (cmp < 0)
break; /* definitely do not have it */
else if (cmp == 0) {
keep = 1; /* definitely have it */
- sought->items[sought_pos++].util = "matched";
- break;
+ sought[i]->matched = 1;
}
- else
- sought_pos++; /* might have it; keep looking */
+ i++;
}
}
- if (! keep && args->fetch_all &&
+ if (!keep && args->fetch_all &&
(!args->depth || prefixcmp(ref->name, "refs/tags/")))
keep = 1;
@@ -573,7 +563,6 @@ static void filter_refs(struct fetch_pack_args *args,
}
}
- filter_string_list(sought, 0, non_matching_ref, NULL);
*refs = newlist;
}
@@ -583,7 +572,8 @@ static void mark_alternate_complete(const struct ref *ref, void *unused)
}
static int everything_local(struct fetch_pack_args *args,
- struct ref **refs, struct string_list *sought)
+ struct ref **refs,
+ struct ref **sought, int nr_sought)
{
struct ref *ref;
int retval;
@@ -634,7 +624,7 @@ static int everything_local(struct fetch_pack_args *args,
}
}
- filter_refs(args, refs, sought);
+ filter_refs(args, refs, sought, nr_sought);
for (retval = 1, ref = *refs; ref ; ref = ref->next) {
const unsigned char *remote = ref->old_sha1;
@@ -764,10 +754,17 @@ static int get_pack(struct fetch_pack_args *args,
return 0;
}
+static int cmp_ref_by_name(const void *a_, const void *b_)
+{
+ const struct ref *a = *((const struct ref **)a_);
+ const struct ref *b = *((const struct ref **)b_);
+ return strcmp(a->name, b->name);
+}
+
static struct ref *do_fetch_pack(struct fetch_pack_args *args,
int fd[2],
const struct ref *orig_ref,
- struct string_list *sought,
+ struct ref **sought, int nr_sought,
char **pack_lockfile)
{
struct ref *ref = copy_ref_list(orig_ref);
@@ -776,6 +773,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
int agent_len;
sort_ref_list(&ref, ref_compare_name);
+ qsort(sought, nr_sought, sizeof(*sought), cmp_ref_by_name);
if (is_repository_shallow() && !server_supports("shallow"))
die("Server does not support shallow clients");
@@ -824,7 +822,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
agent_len, agent_feature);
}
- if (everything_local(args, &ref, sought)) {
+ if (everything_local(args, &ref, sought, nr_sought)) {
packet_flush(fd[1]);
goto all_done;
}
@@ -887,11 +885,32 @@ static void fetch_pack_setup(void)
did_setup = 1;
}
+static int remove_duplicates_in_refs(struct ref **ref, int nr)
+{
+ struct string_list names = STRING_LIST_INIT_NODUP;
+ int src, dst;
+
+ for (src = dst = 0; src < nr; src++) {
+ struct string_list_item *item;
+ item = string_list_insert(&names, ref[src]->name);
+ if (item->util)
+ continue; /* already have it */
+ item->util = ref[src];
+ if (src != dst)
+ ref[dst] = ref[src];
+ dst++;
+ }
+ for (src = dst; src < nr; src++)
+ ref[src] = NULL;
+ string_list_clear(&names, 0);
+ return dst;
+}
+
struct ref *fetch_pack(struct fetch_pack_args *args,
int fd[], struct child_process *conn,
const struct ref *ref,
const char *dest,
- struct string_list *sought,
+ struct ref **sought, int nr_sought,
char **pack_lockfile)
{
struct stat st;
@@ -903,16 +922,14 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
st.st_mtime = 0;
}
- if (sought->nr) {
- sort_string_list(sought);
- string_list_remove_duplicates(sought, 0);
- }
+ if (nr_sought)
+ nr_sought = remove_duplicates_in_refs(sought, nr_sought);
if (!ref) {
packet_flush(fd[1]);
die("no matching remote head");
}
- ref_cpy = do_fetch_pack(args, fd, ref, sought, pack_lockfile);
+ ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought, pack_lockfile);
if (args->depth > 0) {
static struct lock_file lock;