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 <gitster@pobox.com>
Junio C Hamano committed
May 13, 2011 at 13:20 UTC
5266d369b21f8c260fa60d94fb29c3998c521e4a
2 files changed
+11
-1
cache.h
+2
-1
@@ -1030,7 +1030,8 @@ struct object_info {
1030
enum {
1031
OI_CACHED,
1032
OI_LOOSE,
1033
- OI_PACKED
1033
+ OI_PACKED,
1034
+ OI_DBCACHED
1035
} whence;
1036
union {
1037
/*
sha1_file.c
+9
@@ -1697,6 +1697,13 @@ static unsigned long pack_entry_hash(struct packed_git *p, off_t base_offset)
1697
return hash % MAX_DELTA_CACHE;
1698
}
1699
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
+
1707
static void *cache_or_unpack_entry(struct packed_git *p, off_t base_offset,
1708
unsigned long *base_size, enum object_type *type, int keep_cache)
1709
{
@@ -2128,6 +2135,8 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi)
2135
if (status < 0) {
2136
mark_bad_packed_object(e.p, sha1);
2137
status = sha1_object_info_extended(sha1, oi);
2138
+ } else if (in_delta_base_cache(e.p, e.offset)) {
2139
+ oi->whence = OI_DBCACHED;
2140
} else {
2141
oi->whence = OI_PACKED;
2142
oi->u.packed.offset = e.offset;