OSDN Git Service

reset: make tree counting less confusing
authorJeff King <peff@peff.net>
Tue, 5 Sep 2017 13:04:28 +0000 (09:04 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Sep 2017 09:06:26 +0000 (18:06 +0900)
commite9ce897b9fe5a92719eb991ecc0291dd72aab868
treedacbec3e7aa4a08afc0563c524d1820c31a1bfea
parent6c6b08d26999405a5c67dbabe6f9f232d658fd26
reset: make tree counting less confusing

Depending on whether we're in --keep mode, git-reset may
feed one or two trees to unpack_trees(). We start a counter
at "1" and then increment it to "2" only for the two-tree
case. But that means we must always subtract one to find the
correct array slot to fill with each descriptor.

Instead, let's start at "0" and just increment our counter
after adding each tree. This skips the extra subtraction,
and will make things much easier when we start to actually
free our tree buffers.

While we're at it, let's make the first allocation use the
slot at "desc + nr", too, even though we know "nr" is 0 at
that point. It makes the two fill_tree_descriptor() calls
consistent (always "desc + nr", followed by always
incrementing "nr").

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/reset.c