summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-09-05 13:04:28 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-09-06 09:06:26 (GMT)
commite9ce897b9fe5a92719eb991ecc0291dd72aab868 (patch)
treedacbec3e7aa4a08afc0563c524d1820c31a1bfea
parent6c6b08d26999405a5c67dbabe6f9f232d658fd26 (diff)
downloadgit-e9ce897b9fe5a92719eb991ecc0291dd72aab868.zip
git-e9ce897b9fe5a92719eb991ecc0291dd72aab868.tar.gz
git-e9ce897b9fe5a92719eb991ecc0291dd72aab868.tar.bz2
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>
-rw-r--r--builtin/reset.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/builtin/reset.c b/builtin/reset.c
index d72c7d1..7023005 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -44,7 +44,7 @@ static inline int is_merge(void)
static int reset_index(const struct object_id *oid, int reset_type, int quiet)
{
- int nr = 1;
+ int nr = 0;
struct tree_desc desc[2];
struct tree *tree;
struct unpack_trees_options opts;
@@ -75,14 +75,16 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
struct object_id head_oid;
if (get_oid("HEAD", &head_oid))
return error(_("You do not have a valid HEAD."));
- if (!fill_tree_descriptor(desc, &head_oid))
+ if (!fill_tree_descriptor(desc + nr, &head_oid))
return error(_("Failed to find tree of HEAD."));
nr++;
opts.fn = twoway_merge;
}
- if (!fill_tree_descriptor(desc + nr - 1, oid))
+ if (!fill_tree_descriptor(desc + nr, oid))
return error(_("Failed to find tree of %s."), oid_to_hex(oid));
+ nr++;
+
if (unpack_trees(nr, desc, &opts))
return -1;