Skip to content

Commit 1d8b0df

Browse files
committed
Merge branch 'ms/fetch-follow-tag-optim'
The code used in following tags in "git fetch" has been optimized. * ms/fetch-follow-tag-optim: fetch: use oidset to keep the want OIDs for faster lookup
2 parents 1398171 + b7e2d8b commit 1d8b0df

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

builtin/fetch.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "refs.h"
88
#include "refspec.h"
99
#include "object-store.h"
10+
#include "oidset.h"
1011
#include "commit.h"
1112
#include "builtin.h"
1213
#include "string-list.h"
@@ -245,15 +246,13 @@ static void add_merge_config(struct ref **head,
245246
}
246247
}
247248

248-
static int will_fetch(struct ref **head, const unsigned char *sha1)
249+
static void create_fetch_oidset(struct ref **head, struct oidset *out)
249250
{
250251
struct ref *rm = *head;
251252
while (rm) {
252-
if (hasheq(rm->old_oid.hash, sha1))
253-
return 1;
253+
oidset_insert(out, &rm->old_oid);
254254
rm = rm->next;
255255
}
256-
return 0;
257256
}
258257

259258
struct refname_hash_entry {
@@ -319,13 +318,15 @@ static void find_non_local_tags(const struct ref *refs,
319318
{
320319
struct hashmap existing_refs;
321320
struct hashmap remote_refs;
321+
struct oidset fetch_oids = OIDSET_INIT;
322322
struct string_list remote_refs_list = STRING_LIST_INIT_NODUP;
323323
struct string_list_item *remote_ref_item;
324324
const struct ref *ref;
325325
struct refname_hash_entry *item = NULL;
326326

327327
refname_hash_init(&existing_refs);
328328
refname_hash_init(&remote_refs);
329+
create_fetch_oidset(head, &fetch_oids);
329330

330331
for_each_ref(add_one_refname, &existing_refs);
331332
for (ref = refs; ref; ref = ref->next) {
@@ -342,9 +343,9 @@ static void find_non_local_tags(const struct ref *refs,
342343
if (item &&
343344
!has_object_file_with_flags(&ref->old_oid,
344345
OBJECT_INFO_QUICK) &&
345-
!will_fetch(head, ref->old_oid.hash) &&
346+
!oidset_contains(&fetch_oids, &ref->old_oid) &&
346347
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
347-
!will_fetch(head, item->oid.hash))
348+
!oidset_contains(&fetch_oids, &item->oid))
348349
clear_item(item);
349350
item = NULL;
350351
continue;
@@ -358,7 +359,7 @@ static void find_non_local_tags(const struct ref *refs,
358359
*/
359360
if (item &&
360361
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
361-
!will_fetch(head, item->oid.hash))
362+
!oidset_contains(&fetch_oids, &item->oid))
362363
clear_item(item);
363364

364365
item = NULL;
@@ -379,7 +380,7 @@ static void find_non_local_tags(const struct ref *refs,
379380
*/
380381
if (item &&
381382
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
382-
!will_fetch(head, item->oid.hash))
383+
!oidset_contains(&fetch_oids, &item->oid))
383384
clear_item(item);
384385

385386
/*
@@ -406,6 +407,7 @@ static void find_non_local_tags(const struct ref *refs,
406407
}
407408
hashmap_free(&remote_refs, 1);
408409
string_list_clear(&remote_refs_list, 0);
410+
oidset_clear(&fetch_oids);
409411
}
410412

411413
static struct ref *get_ref_map(struct remote *remote,

0 commit comments

Comments
 (0)