[PATCH 32/38] pack v4: parse delta base reference
- From
Nicolas Pitre <nico@fluxnic.net>
- Date
- Sep 5, 2013, 06:19 UTC
- Message-ID
- <1378362001-1738-33-git-send-email-nico@fluxnic.net>
- In-Reply-To
- <1378362001-1738-1-git-send-email-nico@fluxnic.net>
There is only one type of delta with pack v4. The base reference encoding already handles either an offset (via the pack index) or a literal SHA1.
We assume in the literal SHA1 case that the object lives in the same pack, just like with previous pack versions.
Signed-off-by: Nicolas Pitre <nico@fluxnic.net> --- sha1_file.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/sha1_file.c b/sha1_file.c index 67eb903..f3bfa28 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1686,7 +1686,19 @@ static off_t get_delta_base(struct packed_git *p, * that is assured. An OFS_DELTA longer than the hash size * is stupid, as then a REF_DELTA would be smaller to store. */ - if (type == OBJ_OFS_DELTA) { + if (p->version >= 4) { + if (base_info[0] != 0) { + const unsigned char *cp = base_info; + unsigned int base_index = decode_varint(&cp); + if (!base_index || base_index - 1 >= p->num_objects) + return 0; /* out of bounds */ + *curpos += cp - base_info; + base_offset = nth_packed_object_offset(p, base_index - 1); + } else { + base_offset = find_pack_entry_one(base_info+1, p); + *curpos += 21; + } + } else if (type == OBJ_OFS_DELTA) { const unsigned char *cp = base_info; base_offset = decode_varint(&cp); base_offset = delta_obj_offset - base_offset;
-- 1.8.4.38.g317e65b