Skip to content

Commit 27a7d06

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 660b373 commit 27a7d06

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

builtin/pack-objects.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,7 @@ static void check_object(struct object_entry *entry)
14181418
off_t ofs;
14191419
unsigned char *buf, c;
14201420
enum object_type type;
1421+
unsigned long in_pack_size;
14211422

14221423
buf = use_pack(p, &w_curs, entry->in_pack_offset, &avail);
14231424

@@ -1427,7 +1428,7 @@ static void check_object(struct object_entry *entry)
14271428
*/
14281429
used = unpack_object_header_buffer(buf, avail,
14291430
&type,
1430-
&entry->size);
1431+
&in_pack_size);
14311432
if (used == 0)
14321433
goto give_up;
14331434

@@ -1444,6 +1445,7 @@ static void check_object(struct object_entry *entry)
14441445
default:
14451446
/* Not a delta hence we've already got all we need. */
14461447
oe_set_type(entry, entry->in_pack_type);
1448+
entry->size = in_pack_size;
14471449
entry->in_pack_header_size = used;
14481450
if (oe_type(entry) < OBJ_COMMIT || oe_type(entry) > OBJ_BLOB)
14491451
goto give_up;
@@ -1500,6 +1502,7 @@ static void check_object(struct object_entry *entry)
15001502
* circular deltas.
15011503
*/
15021504
oe_set_type(entry, entry->in_pack_type);
1505+
entry->size = in_pack_size; /* delta size */
15031506
SET_DELTA(entry, base_entry);
15041507
entry->delta_size = entry->size;
15051508
entry->delta_sibling_idx = base_entry->delta_child_idx;
@@ -1509,13 +1512,15 @@ static void check_object(struct object_entry *entry)
15091512
}
15101513

15111514
if (oe_type(entry)) {
1515+
off_t delta_pos;
1516+
15121517
/*
15131518
* This must be a delta and we already know what the
15141519
* final object type is. Let's extract the actual
15151520
* object size from the delta header.
15161521
*/
1517-
entry->size = get_size_from_delta(p, &w_curs,
1518-
entry->in_pack_offset + entry->in_pack_header_size);
1522+
delta_pos = entry->in_pack_offset + entry->in_pack_header_size;
1523+
entry->size = get_size_from_delta(p, &w_curs, delta_pos);
15191524
if (entry->size == 0)
15201525
goto give_up;
15211526
unuse_pack(&w_curs);

pack-objects.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ enum dfs_state {
3232
*
3333
* "size" is the uncompressed object size. Compressed size of the raw
3434
* data for an object in a pack is not stored anywhere but is computed
35-
* and made available when reverse .idx is made.
35+
* and made available when reverse .idx is made. Note that when a
36+
* delta is reused, "size" is the uncompressed _delta_ size, not the
37+
* canonical one after the delta has been applied.
3638
*
3739
* "hash" contains a path name hash which is used for sorting the
3840
* delta list and also during delta searching. Once prepare_pack()

0 commit comments

Comments
 (0)