]> git.ipfire.org Git - thirdparty/git.git/commit - builtin/index-pack.c
index-pack: fix allocation of sorted_by_pos array
authorJunio C Hamano <gitster@pobox.com>
Fri, 3 Jul 2015 16:51:57 +0000 (09:51 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 4 Jul 2015 22:26:03 +0000 (15:26 -0700)
commit781d93067d3ab8b448a4c8989a6e3cac17009061
tree9c6761d76dcfb971581ffcf2f8790a0246b66f79
parentc6458e60ed0f3e26a1df88bf5a3da8b091b0ce15
index-pack: fix allocation of sorted_by_pos array

When c6458e60 (index-pack: kill union delta_base to save memory,
2015-04-18) attempted to reduce the memory footprint of index-pack,
one of the key thing it did was to keep track of ref-deltas and
ofs-deltas separately.

In fix_unresolved_deltas(), however it forgot that it now wants to
look only at ref deltas in one place.  The code allocated an array
for nr_unresolved, which is sum of number of ref- and ofs-deltas
minus nr_resolved, which may be larger or smaller than the number
ref-deltas.  Depending on nr_resolved, this was either under or over
allocating.

Also, the old code before this change had to use 'i' and 'n' because
some of the things we see in the (old) deltas[] array we scanned
with 'i' would not make it into the sorted_by_pos[] array in the old
world order, but now because you have only ref delta in a separate
ref_deltas[] array, they increment lock&step.  We no longer need
separate variables.  And most importantly, we shouldn't pass the
nr_unresolved parameter, as this number does not play a role in the
working of this helper function.

Helped-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/index-pack.c