Skip to content

POC: Simplify clean command's approach remove_dirs #1415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions builtin/clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
goto out;
}

/* first try the simple approach, recursion may not be needed if empty dir, symlink, junction, etc. */
res = dry_run ? 0 : unlink(path->buf);
if (res == 0) {
printf(dry_run ? _(msg_would_remove) : _(msg_remove), path->buf);
ret = res;
goto out;

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

}

/* failure of simple approach needs no message, begin the walk through contents of directory */
dir = opendir(path->buf);
if (!dir) {
/* an empty dir could be removed even if it is unreadble */
Expand Down