Skip to content

Commit 9dd389f

Browse files
mhaggergitster
authored andcommitted
packed_ref_store: get rid of the ref_cache entirely
Now that everything has been changed to read what it needs directly out of the `packed-refs` file, `packed_ref_store` doesn't need to maintain a `ref_cache` at all. So get rid of it. First of all, this will save a lot of memory and lots of little allocations. Instead of needing to store complicated parsed data structures in memory, we just mmap the file (potentially sharing memory with other processes) and parse only what we need. Moreover, since the mmapped access to the file reads only the parts of the file that it needs, this might save reading all of the data from disk at all (at least if the file starts out sorted). Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ba1c052 commit 9dd389f

File tree

1 file changed

+2
-27
lines changed

1 file changed

+2
-27
lines changed

refs/packed-backend.c

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ struct packed_ref_cache {
4545
*/
4646
struct packed_ref_store *refs;
4747

48-
struct ref_cache *cache;
49-
5048
/* Is the `packed-refs` file currently mmapped? */
5149
int mmapped;
5250

@@ -148,7 +146,6 @@ static void release_packed_ref_buffer(struct packed_ref_cache *packed_refs)
148146
static int release_packed_ref_cache(struct packed_ref_cache *packed_refs)
149147
{
150148
if (!--packed_refs->referrers) {
151-
free_ref_cache(packed_refs->cache);
152149
stat_validity_clear(&packed_refs->validity);
153150
release_packed_ref_buffer(packed_refs);
154151
free(packed_refs);
@@ -719,15 +716,10 @@ static const char *find_reference_location(struct packed_ref_cache *cache,
719716
static struct packed_ref_cache *read_packed_refs(struct packed_ref_store *refs)
720717
{
721718
struct packed_ref_cache *packed_refs = xcalloc(1, sizeof(*packed_refs));
722-
struct ref_dir *dir;
723-
struct ref_iterator *iter;
724719
int sorted = 0;
725-
int ok;
726720

727721
packed_refs->refs = refs;
728722
acquire_packed_ref_cache(packed_refs);
729-
packed_refs->cache = create_ref_cache(NULL, NULL);
730-
packed_refs->cache->root->flag &= ~REF_INCOMPLETE;
731723
packed_refs->peeled = PEELED_NONE;
732724

733725
if (!load_contents(packed_refs))
@@ -800,23 +792,6 @@ static struct packed_ref_cache *read_packed_refs(struct packed_ref_store *refs)
800792
packed_refs->eof = buf_copy + size;
801793
}
802794

803-
dir = get_ref_dir(packed_refs->cache->root);
804-
iter = mmapped_ref_iterator_begin(
805-
packed_refs,
806-
packed_refs->buf + packed_refs->header_len,
807-
packed_refs->eof);
808-
while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
809-
struct ref_entry *entry =
810-
create_ref_entry(iter->refname, iter->oid, iter->flags);
811-
812-
if ((iter->flags & REF_KNOWS_PEELED))
813-
ref_iterator_peel(iter, &entry->u.value.peeled);
814-
add_ref_entry(dir, entry);
815-
}
816-
817-
if (ok != ITER_DONE)
818-
die("error reading packed-refs file %s", refs->path);
819-
820795
return packed_refs;
821796
}
822797

@@ -975,8 +950,8 @@ static struct ref_iterator *packed_ref_iterator_begin(
975950
else
976951
start = packed_refs->buf + packed_refs->header_len;
977952

978-
iter->iter0 = mmapped_ref_iterator_begin(
979-
packed_refs, start, packed_refs->eof);
953+
iter->iter0 = mmapped_ref_iterator_begin(packed_refs,
954+
start, packed_refs->eof);
980955

981956
iter->flags = flags;
982957

0 commit comments

Comments
 (0)