Skip to content

Commit ba1c052

Browse files
mhaggergitster
authored andcommitted
ref_store: implement refs_peel_ref() generically
We're about to stop storing packed refs in a `ref_cache`. That means that the only way we have left to optimize `peel_ref()` is by checking whether the reference being peeled is the one currently being iterated over (in `current_ref_iter`), and if so, using `ref_iterator_peel()`. But this can be done generically; it doesn't have to be implemented per-backend. So implement `refs_peel_ref()` in `refs.c` and remove the `peel_ref()` method from the refs API. This removes the last callers of a couple of functions, so delete them. More cleanup to come... Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3987ab commit ba1c052

File tree

4 files changed

+17
-78
lines changed

4 files changed

+17
-78
lines changed

refs.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,23 @@ int refs_pack_refs(struct ref_store *refs, unsigned int flags)
17351735
int refs_peel_ref(struct ref_store *refs, const char *refname,
17361736
unsigned char *sha1)
17371737
{
1738-
return refs->be->peel_ref(refs, refname, sha1);
1738+
int flag;
1739+
unsigned char base[20];
1740+
1741+
if (current_ref_iter && current_ref_iter->refname == refname) {
1742+
struct object_id peeled;
1743+
1744+
if (ref_iterator_peel(current_ref_iter, &peeled))
1745+
return -1;
1746+
hashcpy(sha1, peeled.hash);
1747+
return 0;
1748+
}
1749+
1750+
if (refs_read_ref_full(refs, refname,
1751+
RESOLVE_REF_READING, base, &flag))
1752+
return -1;
1753+
1754+
return peel_object(base, sha1);
17391755
}
17401756

17411757
int peel_ref(const char *refname, unsigned char *sha1)

refs/files-backend.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -655,43 +655,6 @@ static int lock_raw_ref(struct files_ref_store *refs,
655655
return ret;
656656
}
657657

658-
static int files_peel_ref(struct ref_store *ref_store,
659-
const char *refname, unsigned char *sha1)
660-
{
661-
struct files_ref_store *refs =
662-
files_downcast(ref_store, REF_STORE_READ | REF_STORE_ODB,
663-
"peel_ref");
664-
int flag;
665-
unsigned char base[20];
666-
667-
if (current_ref_iter && current_ref_iter->refname == refname) {
668-
struct object_id peeled;
669-
670-
if (ref_iterator_peel(current_ref_iter, &peeled))
671-
return -1;
672-
hashcpy(sha1, peeled.hash);
673-
return 0;
674-
}
675-
676-
if (refs_read_ref_full(ref_store, refname,
677-
RESOLVE_REF_READING, base, &flag))
678-
return -1;
679-
680-
/*
681-
* If the reference is packed, read its ref_entry from the
682-
* cache in the hope that we already know its peeled value.
683-
* We only try this optimization on packed references because
684-
* (a) forcing the filling of the loose reference cache could
685-
* be expensive and (b) loose references anyway usually do not
686-
* have REF_KNOWS_PEELED.
687-
*/
688-
if (flag & REF_ISPACKED &&
689-
!refs_peel_ref(refs->packed_ref_store, refname, sha1))
690-
return 0;
691-
692-
return peel_object(base, sha1);
693-
}
694-
695658
struct files_ref_iterator {
696659
struct ref_iterator base;
697660

@@ -3012,7 +2975,6 @@ struct ref_storage_be refs_be_files = {
30122975
files_initial_transaction_commit,
30132976

30142977
files_pack_refs,
3015-
files_peel_ref,
30162978
files_create_symref,
30172979
files_delete_refs,
30182980
files_rename_ref,

refs/packed-backend.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -850,26 +850,6 @@ static struct packed_ref_cache *get_packed_ref_cache(struct packed_ref_store *re
850850
return refs->cache;
851851
}
852852

853-
static struct ref_dir *get_packed_ref_dir(struct packed_ref_cache *packed_ref_cache)
854-
{
855-
return get_ref_dir(packed_ref_cache->cache->root);
856-
}
857-
858-
static struct ref_dir *get_packed_refs(struct packed_ref_store *refs)
859-
{
860-
return get_packed_ref_dir(get_packed_ref_cache(refs));
861-
}
862-
863-
/*
864-
* Return the ref_entry for the given refname from the packed
865-
* references. If it does not exist, return NULL.
866-
*/
867-
static struct ref_entry *get_packed_ref(struct packed_ref_store *refs,
868-
const char *refname)
869-
{
870-
return find_ref_entry(get_packed_refs(refs), refname);
871-
}
872-
873853
static int packed_read_raw_ref(struct ref_store *ref_store,
874854
const char *refname, unsigned char *sha1,
875855
struct strbuf *referent, unsigned int *type)
@@ -896,21 +876,6 @@ static int packed_read_raw_ref(struct ref_store *ref_store,
896876
return 0;
897877
}
898878

899-
static int packed_peel_ref(struct ref_store *ref_store,
900-
const char *refname, unsigned char *sha1)
901-
{
902-
struct packed_ref_store *refs =
903-
packed_downcast(ref_store, REF_STORE_READ | REF_STORE_ODB,
904-
"peel_ref");
905-
struct ref_entry *r = get_packed_ref(refs, refname);
906-
907-
if (!r || peel_entry(r, 0))
908-
return -1;
909-
910-
hashcpy(sha1, r->u.value.peeled.hash);
911-
return 0;
912-
}
913-
914879
struct packed_ref_iterator {
915880
struct ref_iterator base;
916881

@@ -1597,7 +1562,6 @@ struct ref_storage_be refs_be_packed = {
15971562
packed_initial_transaction_commit,
15981563

15991564
packed_pack_refs,
1600-
packed_peel_ref,
16011565
packed_create_symref,
16021566
packed_delete_refs,
16031567
packed_rename_ref,

refs/refs-internal.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,6 @@ typedef int ref_transaction_commit_fn(struct ref_store *refs,
562562
struct strbuf *err);
563563

564564
typedef int pack_refs_fn(struct ref_store *ref_store, unsigned int flags);
565-
typedef int peel_ref_fn(struct ref_store *ref_store,
566-
const char *refname, unsigned char *sha1);
567565
typedef int create_symref_fn(struct ref_store *ref_store,
568566
const char *ref_target,
569567
const char *refs_heads_master,
@@ -668,7 +666,6 @@ struct ref_storage_be {
668666
ref_transaction_commit_fn *initial_transaction_commit;
669667

670668
pack_refs_fn *pack_refs;
671-
peel_ref_fn *peel_ref;
672669
create_symref_fn *create_symref;
673670
delete_refs_fn *delete_refs;
674671
rename_ref_fn *rename_ref;

0 commit comments

Comments
 (0)