packed_ref_store: new struct
Start extracting the packed-refs-related data structures into a new class, `packed_ref_store`. It doesn't yet implement `ref_store`, but it will. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
2f10882166
commit
bdf55fa6b2
@ -47,6 +47,28 @@ struct packed_ref_cache {
|
|||||||
struct stat_validity validity;
|
struct stat_validity validity;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A container for `packed-refs`-related data. It is not (yet) a
|
||||||
|
* `ref_store`.
|
||||||
|
*/
|
||||||
|
struct packed_ref_store {
|
||||||
|
unsigned int store_flags;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A cache of the values read from the `packed-refs` file, if
|
||||||
|
* it might still be current; otherwise, NULL.
|
||||||
|
*/
|
||||||
|
struct packed_ref_cache *cache;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct packed_ref_store *packed_ref_store_create(unsigned int store_flags)
|
||||||
|
{
|
||||||
|
struct packed_ref_store *refs = xcalloc(1, sizeof(*refs));
|
||||||
|
|
||||||
|
refs->store_flags = store_flags;
|
||||||
|
return refs;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Future: need to be in "struct repository"
|
* Future: need to be in "struct repository"
|
||||||
* when doing a full libification.
|
* when doing a full libification.
|
||||||
@ -60,13 +82,14 @@ struct files_ref_store {
|
|||||||
char *packed_refs_path;
|
char *packed_refs_path;
|
||||||
|
|
||||||
struct ref_cache *loose;
|
struct ref_cache *loose;
|
||||||
struct packed_ref_cache *packed;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lock used for the "packed-refs" file. Note that this (and
|
* Lock used for the "packed-refs" file. Note that this (and
|
||||||
* thus the enclosing `files_ref_store`) must not be freed.
|
* thus the enclosing `files_ref_store`) must not be freed.
|
||||||
*/
|
*/
|
||||||
struct lock_file packed_refs_lock;
|
struct lock_file packed_refs_lock;
|
||||||
|
|
||||||
|
struct packed_ref_store *packed_ref_store;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -95,12 +118,12 @@ static int release_packed_ref_cache(struct packed_ref_cache *packed_refs)
|
|||||||
|
|
||||||
static void clear_packed_ref_cache(struct files_ref_store *refs)
|
static void clear_packed_ref_cache(struct files_ref_store *refs)
|
||||||
{
|
{
|
||||||
if (refs->packed) {
|
if (refs->packed_ref_store->cache) {
|
||||||
struct packed_ref_cache *packed_refs = refs->packed;
|
struct packed_ref_cache *packed_refs = refs->packed_ref_store->cache;
|
||||||
|
|
||||||
if (is_lock_file_locked(&refs->packed_refs_lock))
|
if (is_lock_file_locked(&refs->packed_refs_lock))
|
||||||
die("BUG: packed-ref cache cleared while locked");
|
die("BUG: packed-ref cache cleared while locked");
|
||||||
refs->packed = NULL;
|
refs->packed_ref_store->cache = NULL;
|
||||||
release_packed_ref_cache(packed_refs);
|
release_packed_ref_cache(packed_refs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,6 +155,7 @@ static struct ref_store *files_ref_store_create(const char *gitdir,
|
|||||||
refs->gitcommondir = strbuf_detach(&sb, NULL);
|
refs->gitcommondir = strbuf_detach(&sb, NULL);
|
||||||
strbuf_addf(&sb, "%s/packed-refs", refs->gitcommondir);
|
strbuf_addf(&sb, "%s/packed-refs", refs->gitcommondir);
|
||||||
refs->packed_refs_path = strbuf_detach(&sb, NULL);
|
refs->packed_refs_path = strbuf_detach(&sb, NULL);
|
||||||
|
refs->packed_ref_store = packed_ref_store_create(flags);
|
||||||
|
|
||||||
return ref_store;
|
return ref_store;
|
||||||
}
|
}
|
||||||
@ -375,8 +399,8 @@ static void files_ref_path(struct files_ref_store *refs,
|
|||||||
*/
|
*/
|
||||||
static void validate_packed_ref_cache(struct files_ref_store *refs)
|
static void validate_packed_ref_cache(struct files_ref_store *refs)
|
||||||
{
|
{
|
||||||
if (refs->packed &&
|
if (refs->packed_ref_store->cache &&
|
||||||
!stat_validity_check(&refs->packed->validity,
|
!stat_validity_check(&refs->packed_ref_store->cache->validity,
|
||||||
files_packed_refs_path(refs)))
|
files_packed_refs_path(refs)))
|
||||||
clear_packed_ref_cache(refs);
|
clear_packed_ref_cache(refs);
|
||||||
}
|
}
|
||||||
@ -396,10 +420,10 @@ static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *ref
|
|||||||
if (!is_lock_file_locked(&refs->packed_refs_lock))
|
if (!is_lock_file_locked(&refs->packed_refs_lock))
|
||||||
validate_packed_ref_cache(refs);
|
validate_packed_ref_cache(refs);
|
||||||
|
|
||||||
if (!refs->packed)
|
if (!refs->packed_ref_store->cache)
|
||||||
refs->packed = read_packed_refs(packed_refs_file);
|
refs->packed_ref_store->cache = read_packed_refs(packed_refs_file);
|
||||||
|
|
||||||
return refs->packed;
|
return refs->packed_ref_store->cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ref_dir *get_packed_ref_dir(struct packed_ref_cache *packed_ref_cache)
|
static struct ref_dir *get_packed_ref_dir(struct packed_ref_cache *packed_ref_cache)
|
||||||
|
Loading…
Reference in New Issue
Block a user