Skip to content

Commit 8186128

Browse files
bk2204gitster
authored andcommitted
builtin/checkout: simplify metadata initialization
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 <[email protected]> Reviewed-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0c0f8a7 commit 8186128

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

builtin/checkout.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
621621
opts.src_index = &the_index;
622622
opts.dst_index = &the_index;
623623
init_checkout_metadata(&opts.meta, info->refname,
624-
info->commit ? &info->commit->object.oid :
625-
is_null_oid(&info->oid) ? &tree->object.oid :
626-
&info->oid,
624+
info->commit ? &info->commit->object.oid : &null_oid,
627625
NULL);
628626
parse_tree(tree);
629627
init_tree_desc(&tree_desc, tree->buffer, tree->size);

0 commit comments

Comments
 (0)