From: Robert Stanca <robert.stanca7@gmail.com>
To: git@vger.kernel.org
Cc: Robert Stanca <robert.stanca7@gmail.com>
Subject: [PATCH] [GSOC] prune_worktrees(): reimplement with dir_iterator
Date: Sat, 1 Apr 2017 04:21:27 +0300 [thread overview]
Message-ID: <1491009687-10419-1-git-send-email-robert.stanca7@gmail.com> (raw)
Replaces recursive traversing of opendir with dir_iterator
Signed-off-by: Robert Stanca <robert.stanca7@gmail.com>
---
builtin/worktree.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 9993ded..7cfd78c 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -10,6 +10,8 @@
#include "refs.h"
#include "utf8.h"
#include "worktree.h"
+#include "iterator.h"
+#include "dir-iterator.h"
static const char * const worktree_usage[] = {
N_("git worktree add [<options>] <path> [<branch>]"),
@@ -91,30 +93,25 @@ static void prune_worktrees(void)
{
struct strbuf reason = STRBUF_INIT;
struct strbuf path = STRBUF_INIT;
- DIR *dir = opendir(git_path("worktrees"));
- struct dirent *d;
+ struct dir_iterator *diter = dir_iterator_begin(git_path("worktrees"));
int ret;
- if (!dir)
- return;
- while ((d = readdir(dir)) != NULL) {
- if (is_dot_or_dotdot(d->d_name))
- continue;
+
+ while (dir_iterator_advance(diter) == ITER_OK) {
strbuf_reset(&reason);
- if (!prune_worktree(d->d_name, &reason))
+ if (!prune_worktree(diter->relative_path, &reason))
continue;
if (show_only || verbose)
printf("%s\n", reason.buf);
if (show_only)
continue;
strbuf_reset(&path);
- strbuf_addstr(&path, git_path("worktrees/%s", d->d_name));
+ strbuf_addstr(&path, git_path("worktrees/%s", diter->relative_path));
ret = remove_dir_recursively(&path, 0);
if (ret < 0 && errno == ENOTDIR)
ret = unlink(path.buf);
if (ret)
error_errno(_("failed to remove '%s'"), path.buf);
}
- closedir(dir);
if (!show_only)
rmdir(git_path("worktrees"));
strbuf_release(&reason);
--
2.7.4
next reply other threads:[~2017-04-01 1:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-01 1:21 Robert Stanca [this message]
2017-04-01 2:29 ` [PATCH] [GSOC] prune_worktrees(): reimplement with dir_iterator Junio C Hamano
2017-04-01 13:29 ` Robert Stanca
2017-04-01 18:33 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1491009687-10419-1-git-send-email-robert.stanca7@gmail.com \
--to=robert.stanca7@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).