]> git.ipfire.org Git - thirdparty/git.git/commit
repack: move `pack_geometry` struct to the stack
authorTaylor Blau <me@ttaylorr.com>
Wed, 9 Aug 2023 20:32:42 +0000 (16:32 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 9 Aug 2023 21:31:01 +0000 (14:31 -0700)
commit99d51978bed53e7453dfd0ec4f9c2edf5efff705
tree132660f0acdcdfd89d8982022b7549e06347a5b3
parentcb888bb6991bb10bddedf9ddc9651ec25da6137d
repack: move `pack_geometry` struct to the stack

The `pack_geometry` struct is used to maintain and partition a list of
packfiles into a "frozen" set (to be left alone), and a non-frozen set
(to be combined into a single new pack). In the previous commit, we
removed a leak caused by neglecting to free() the heap allocated space
used to store the structure itself.

But there is no need for this structure to live on the heap anyway.
Instead, let's move it to be stack allocated, eliminating the
possibility of a direct leak like the one addressed in the previous
patch.

The one minor hitch is that we use the NULL-ness of the pack_geometry's
struct pointer to determine whether or not we are performing a geometric
repack with `--geometric=<d>`. But since we only initialize the
pack_geometry structure when the `geometric_factor` is non-zero, we can
use that variable (based on whether or not it is equal to zero) to
determine whether or not we are performing a geometric repack.

There are a couple of spots that have access to a pointer to the
pack_geometry struct, but not the geometric_factor itself. Instead of
passing in an additional variable, let's make the geometric_factor a
field of the pack_geometry struct.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/repack.c