]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/checkout: simplify metadata initialization
authorbrian m. carlson <sandals@crustytoothpaste.net>
Thu, 21 May 2020 02:07:11 +0000 (02:07 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 May 2020 16:55:21 +0000 (09:55 -0700)
When we call init_checkout_metadata in reset_tree, we want to pass the
object ID of the commit in question so that it can be passed to filters,
or if there is no commit, the tree.  We anticipated this latter case,
which can occur elsewhere in the checkout code, but it cannot occur
here.  The only case in which we do not have a commit object is when
invoking git switch with --orphan.  Moreover, we can only hit this code
path without a commit object additionally with either --force or
--discard-changes.

In such a case, there is no point initializing the checkout metadata
with a commit or tree because (a) there is no commit, only the empty
tree, and (b) we will never use the data, since no files will be smudged
when checking out a branch with no files.  Pass the all-zeros object ID
in this case, since we just need some value which is a valid pointer.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Reviewed-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/checkout.c

index 8bc94d392b83624d0cd538fbbd702dc4ad824f7c..c88e651a6d170f4c93c6d81ca5dd38548cdef8a1 100644 (file)
@@ -621,9 +621,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
        opts.src_index = &the_index;
        opts.dst_index = &the_index;
        init_checkout_metadata(&opts.meta, info->refname,
-                              info->commit ? &info->commit->object.oid :
-                              is_null_oid(&info->oid) ? &tree->object.oid :
-                              &info->oid,
+                              info->commit ? &info->commit->object.oid : &null_oid,
                               NULL);
        parse_tree(tree);
        init_tree_desc(&tree_desc, tree->buffer, tree->size);