Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 1f2e108

Browse files
peffgitster
authored andcommitted
clean: simplify dir/not-dir logic
When we get a list of paths from read_directory, we further prune it to create the final list of items to remove. The code paths for directories and non-directories repeat the same "add to list" code. This patch restructures the code so that we don't repeat ourselves. Also, by following a "if (condition) continue" pattern like the pathspec check above, it makes it more obvious that the conditional is about excluding directories under certain circumstances. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cf424f5 commit 1f2e108

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

builtin/clean.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -967,15 +967,12 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
967967
if (pathspec.nr && !matches)
968968
continue;
969969

970-
if (S_ISDIR(st.st_mode)) {
971-
if (remove_directories || (matches == MATCHED_EXACTLY)) {
972-
rel = relative_path(ent->name, prefix, &buf);
973-
string_list_append(&del_list, rel);
974-
}
975-
} else {
976-
rel = relative_path(ent->name, prefix, &buf);
977-
string_list_append(&del_list, rel);
978-
}
970+
if (S_ISDIR(st.st_mode) && !remove_directories &&
971+
matches != MATCHED_EXACTLY)
972+
continue;
973+
974+
rel = relative_path(ent->name, prefix, &buf);
975+
string_list_append(&del_list, rel);
979976
}
980977

981978
if (interactive && del_list.nr > 0)

0 commit comments

Comments
 (0)