pack-objects: clarify the use of object_entry::size
While this field most of the time contains the canonical object size, there is one case it does not: when we have found that the base object of the delta in question is also to be packed, we will very happily reuse the delta by copying it over instead of regenerating the new delta. "size" in this case will record the delta size, not canonical object size. Later on in write_reuse_object(), we reconstruct the delta header and "size" is used for this purpose. When this happens, the "type" field contains a delta type instead of a canonical type. Highlight this in the code since it could be tricky to see. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
660b373542
commit
27a7d0679f
@ -1418,6 +1418,7 @@ static void check_object(struct object_entry *entry)
|
||||
off_t ofs;
|
||||
unsigned char *buf, c;
|
||||
enum object_type type;
|
||||
unsigned long in_pack_size;
|
||||
|
||||
buf = use_pack(p, &w_curs, entry->in_pack_offset, &avail);
|
||||
|
||||
@ -1427,7 +1428,7 @@ static void check_object(struct object_entry *entry)
|
||||
*/
|
||||
used = unpack_object_header_buffer(buf, avail,
|
||||
&type,
|
||||
&entry->size);
|
||||
&in_pack_size);
|
||||
if (used == 0)
|
||||
goto give_up;
|
||||
|
||||
@ -1444,6 +1445,7 @@ static void check_object(struct object_entry *entry)
|
||||
default:
|
||||
/* Not a delta hence we've already got all we need. */
|
||||
oe_set_type(entry, entry->in_pack_type);
|
||||
entry->size = in_pack_size;
|
||||
entry->in_pack_header_size = used;
|
||||
if (oe_type(entry) < OBJ_COMMIT || oe_type(entry) > OBJ_BLOB)
|
||||
goto give_up;
|
||||
@ -1500,6 +1502,7 @@ static void check_object(struct object_entry *entry)
|
||||
* circular deltas.
|
||||
*/
|
||||
oe_set_type(entry, entry->in_pack_type);
|
||||
entry->size = in_pack_size; /* delta size */
|
||||
SET_DELTA(entry, base_entry);
|
||||
entry->delta_size = entry->size;
|
||||
entry->delta_sibling_idx = base_entry->delta_child_idx;
|
||||
@ -1509,13 +1512,15 @@ static void check_object(struct object_entry *entry)
|
||||
}
|
||||
|
||||
if (oe_type(entry)) {
|
||||
off_t delta_pos;
|
||||
|
||||
/*
|
||||
* This must be a delta and we already know what the
|
||||
* final object type is. Let's extract the actual
|
||||
* object size from the delta header.
|
||||
*/
|
||||
entry->size = get_size_from_delta(p, &w_curs,
|
||||
entry->in_pack_offset + entry->in_pack_header_size);
|
||||
delta_pos = entry->in_pack_offset + entry->in_pack_header_size;
|
||||
entry->size = get_size_from_delta(p, &w_curs, delta_pos);
|
||||
if (entry->size == 0)
|
||||
goto give_up;
|
||||
unuse_pack(&w_curs);
|
||||
|
Reference in New Issue
Block a user