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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 10, 2014 at 13:24 UTC 1f2e1088871e777355025a84f80a2d8b5cb04c06
1 file changed +6 -9
builtin/clean.c
+6 -9
@@ -967,15 +967,12 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
967 if (pathspec.nr && !matches)
968 continue;
969
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);
976 }
977
978 if (interactive && del_list.nr > 0)