Skip to content

Commit 5266d36

Browse files
committed
sha1_object_info_extended(): hint about objects in delta-base cache
An object found in the delta-base cache is not guaranteed to stay there, but we know it came from a pack and it is likely to give us a quick access if we read_sha1_file() it right now, which is a piece of useful information. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9a49059 commit 5266d36

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

cache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,8 @@ struct object_info {
10301030
enum {
10311031
OI_CACHED,
10321032
OI_LOOSE,
1033-
OI_PACKED
1033+
OI_PACKED,
1034+
OI_DBCACHED
10341035
} whence;
10351036
union {
10361037
/*

sha1_file.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,13 @@ static unsigned long pack_entry_hash(struct packed_git *p, off_t base_offset)
16971697
return hash % MAX_DELTA_CACHE;
16981698
}
16991699

1700+
static int in_delta_base_cache(struct packed_git *p, off_t base_offset)
1701+
{
1702+
unsigned long hash = pack_entry_hash(p, base_offset);
1703+
struct delta_base_cache_entry *ent = delta_base_cache + hash;
1704+
return (ent->data && ent->p == p && ent->base_offset == base_offset);
1705+
}
1706+
17001707
static void *cache_or_unpack_entry(struct packed_git *p, off_t base_offset,
17011708
unsigned long *base_size, enum object_type *type, int keep_cache)
17021709
{
@@ -2128,6 +2135,8 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
21282135
if (status < 0) {
21292136
mark_bad_packed_object(e.p, sha1);
21302137
status = sha1_object_info_extended(sha1, oi);
2138+
} else if (in_delta_base_cache(e.p, e.offset)) {
2139+
oi->whence = OI_DBCACHED;
21312140
} else {
21322141
oi->whence = OI_PACKED;
21332142
oi->u.packed.offset = e.offset;

0 commit comments

Comments
 (0)