Skip to content

Commit 97b2fa0

Browse files
peffgitster
authored andcommitted
fetch-pack: drop custom loose object cache
Commit 024aa46 (fetch-pack.c: use oidset to check existence of loose object, 2018-03-14) added a cache to avoid calling stat() for a bunch of loose objects we don't have. Now that OBJECT_INFO_QUICK handles this caching itself, we can drop the custom solution. Note that this might perform slightly differently, as the original code stopped calling readdir() when we saw more loose objects than there were refs. So: 1. The old code might have spent work on readdir() to fill the cache, but then decided there were too many loose objects, wasting that effort. 2. The new code might spend a lot of time on readdir() if you have a lot of loose objects, even though there are very few objects to ask about. In practice it probably won't matter either way; see the previous commit for some discussion of the tradeoff. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 61c7711 commit 97b2fa0

File tree

1 file changed

+2
-37
lines changed

1 file changed

+2
-37
lines changed

fetch-pack.c

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -636,23 +636,6 @@ struct loose_object_iter {
636636
struct ref *refs;
637637
};
638638

639-
/*
640-
* If the number of refs is not larger than the number of loose objects,
641-
* this function stops inserting.
642-
*/
643-
static int add_loose_objects_to_set(const struct object_id *oid,
644-
const char *path,
645-
void *data)
646-
{
647-
struct loose_object_iter *iter = data;
648-
oidset_insert(iter->loose_object_set, oid);
649-
if (iter->refs == NULL)
650-
return 1;
651-
652-
iter->refs = iter->refs->next;
653-
return 0;
654-
}
655-
656639
/*
657640
* Mark recent commits available locally and reachable from a local ref as
658641
* COMPLETE. If args->no_dependents is false, also mark COMPLETE remote refs as
@@ -670,30 +653,14 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
670653
struct ref *ref;
671654
int old_save_commit_buffer = save_commit_buffer;
672655
timestamp_t cutoff = 0;
673-
struct oidset loose_oid_set = OIDSET_INIT;
674-
int use_oidset = 0;
675-
struct loose_object_iter iter = {&loose_oid_set, *refs};
676-
677-
/* Enumerate all loose objects or know refs are not so many. */
678-
use_oidset = !for_each_loose_object(add_loose_objects_to_set,
679-
&iter, 0);
680656

681657
save_commit_buffer = 0;
682658

683659
for (ref = *refs; ref; ref = ref->next) {
684660
struct object *o;
685-
unsigned int flags = OBJECT_INFO_QUICK;
686661

687-
if (use_oidset &&
688-
!oidset_contains(&loose_oid_set, &ref->old_oid)) {
689-
/*
690-
* I know this does not exist in the loose form,
691-
* so check if it exists in a non-loose form.
692-
*/
693-
flags |= OBJECT_INFO_IGNORE_LOOSE;
694-
}
695-
696-
if (!has_object_file_with_flags(&ref->old_oid, flags))
662+
if (!has_object_file_with_flags(&ref->old_oid,
663+
OBJECT_INFO_QUICK))
697664
continue;
698665
o = parse_object(the_repository, &ref->old_oid);
699666
if (!o)
@@ -710,8 +677,6 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
710677
}
711678
}
712679

713-
oidset_clear(&loose_oid_set);
714-
715680
if (!args->deepen) {
716681
for_each_ref(mark_complete_oid, NULL);
717682
for_each_cached_alternate(NULL, mark_alternate_complete);

0 commit comments

Comments
 (0)