Skip to content

Commit

Permalink
pack-objects: Prefer shallower deltas if the size is equal
Browse files Browse the repository at this point in the history
Change "try_delta" so that if it finds a delta that has the same size
but shallower depth than the existing delta, it will prefer the
shallower one.  This makes certain delta trees vastly less deep.

Signed-off-by: Brian Downing <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
bdowning authored and gitster committed Jul 9, 2007
1 parent 1ed8415 commit 848d732
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion builtin-pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
if (max_size == 0)
return 0;
if (trg_entry->delta && trg_entry->delta_size <= max_size)
max_size = trg_entry->delta_size-1;
max_size = trg_entry->delta_size;
src_size = src_entry->size;
sizediff = src_size < trg_size ? trg_size - src_size : 0;
if (sizediff >= max_size)
Expand Down Expand Up @@ -1371,6 +1371,12 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
return 0;

if (trg_entry->delta_data) {
/* Prefer only shallower same-sized deltas. */
if (delta_size == trg_entry->delta_size &&
src_entry->depth + 1 >= trg_entry->depth) {
free(delta_buf);
return 0;
}
delta_cache_size -= trg_entry->delta_size;
free(trg_entry->delta_data);
}
Expand Down

0 comments on commit 848d732

Please sign in to comment.