X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-clean.c;h=05c763cbec61cd41bde3b424c22563c155105fd0;hb=a0f4afb;hp=1c1b6d26e9987800d2a414e49e4f371a4277b96e;hpb=974e6e42f7a66b69bd684af4f637ab064acfdf92;p=git.git diff --git a/builtin-clean.c b/builtin-clean.c index 1c1b6d26e..05c763cbe 100644 --- a/builtin-clean.c +++ b/builtin-clean.c @@ -31,9 +31,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix) int i; int show_only = 0, remove_directories = 0, quiet = 0, ignored = 0; int ignored_only = 0, baselen = 0, config_set = 0, errors = 0; + int rm_flags = REMOVE_DIR_KEEP_NESTED_GIT; struct strbuf directory = STRBUF_INIT; struct dir_struct dir; - const char *path, *base; static const char **pathspec; struct strbuf buf = STRBUF_INIT; const char *qname; @@ -70,6 +70,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix) die("clean.requireForce%s set and -n or -f not given; " "refusing to clean", config_set ? "" : " not"); + if (force > 1) + rm_flags = 0; + dir.flags |= DIR_SHOW_OTHER_DIRECTORIES; if (!ignored) @@ -78,16 +81,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) pathspec = get_pathspec(prefix, argv); read_cache(); - /* - * Calculate common prefix for the pathspec, and - * use that to optimize the directory walk - */ - baselen = common_prefix(pathspec); - path = "."; - base = ""; - if (baselen) - path = base = xmemdupz(*pathspec, baselen); - read_directory(&dir, path, base, baselen, pathspec); + fill_directory(&dir, pathspec); if (pathspec) seen = xmalloc(argc > 0 ? argc : 1); @@ -141,7 +135,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix) (matches == MATCHED_EXACTLY)) { if (!quiet) printf("Removing %s\n", qname); - if (remove_dir_recursively(&directory, 0) != 0) { + if (remove_dir_recursively(&directory, + rm_flags) != 0) { warning("failed to remove '%s'", qname); errors++; }