clean: only lstat files in pathspec

Even though "git clean" takes pathspec to limit the part of the working tree to be cleaned, it checked the paths it encounters during its directory traversal with lstat(2), before checking if the path is within the pathspec. Ignore paths outside pathspec and proceed without checking with lstat(2). Even if such a path is unreadable due to e.g. EPERM, "git clean" should not care. Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Turner committed May 18, 2015 at 14:08 UTC 838d6a928fc3aef3827d9a45e6aac044fea7451e
1 file changed +3 -3
builtin/clean.c
+3 -3
@@ -940,15 +940,15 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
940 if (!cache_name_is_other(ent->name, ent->len))
941 continue;
942
943 - if (lstat(ent->name, &st))
944 - die_errno("Cannot lstat '%s'", ent->name);
945 -
943 if (pathspec.nr)
944 matches = dir_path_match(ent, &pathspec, 0, NULL);
945
946 if (pathspec.nr && !matches)
947 continue;
948
949 + if (lstat(ent->name, &st))
950 + die_errno("Cannot lstat '%s'", ent->name);
951 +
952 if (S_ISDIR(st.st_mode) && !remove_directories &&
953 matches != MATCHED_EXACTLY)
954 continue;