Skip to content

Commit 1624333

Browse files
vdyegitster
authored andcommitted
reset: reorder wildcard pathspec conditions
Rearrange conditions in method determining whether index expansion is necessary when a pathspec is specified for `git reset`, placing less expensive condition first. Additionally, add details & examples to related code comments to help with readability. Helped-by: Elijah Newren <[email protected]> Signed-off-by: Victoria Dye <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb01b26 commit 1624333

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

builtin/reset.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,16 @@ static int pathspec_needs_expanded_index(const struct pathspec *pathspec)
204204
/*
205205
* Special case: if the pattern is a path inside the cone
206206
* followed by only wildcards, the pattern cannot match
207-
* partial sparse directories, so we don't expand the index.
207+
* partial sparse directories, so we know we don't need to
208+
* expand the index.
209+
*
210+
* Examples:
211+
* - in-cone/foo***: doesn't need expanded index
212+
* - not-in-cone/bar*: may need expanded index
213+
* - **.c: may need expanded index
208214
*/
209-
if (path_in_cone_mode_sparse_checkout(item.original, &the_index) &&
210-
strspn(item.original + item.nowildcard_len, "*") == item.len - item.nowildcard_len)
215+
if (strspn(item.original + item.nowildcard_len, "*") == item.len - item.nowildcard_len &&
216+
path_in_cone_mode_sparse_checkout(item.original, &the_index))
211217
continue;
212218

213219
for (pos = 0; pos < active_nr; pos++) {

0 commit comments

Comments
 (0)