From: Robert Stanca <robert.stanca7@gmail.com>
To: git@vger.kernel.org
Cc: Robert Stanca <robert.stanca7@gmail.com>
Subject: [PATCH] [GSOC] remove_temporary_files(): reimplement using iterators
Date: Sat, 1 Apr 2017 03:24:58 +0300 [thread overview]
Message-ID: <20170401002458.3494-1-robert.stanca7@gmail.com> (raw)
Replaces recursive traversing of opendir with dir_iterator
Signed-off-by: Robert Stanca <robert.stanca7@gmail.com>
---
builtin/repack.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/builtin/repack.c b/builtin/repack.c
index 677bc7c81..dba465814 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -7,6 +7,8 @@
#include "strbuf.h"
#include "string-list.h"
#include "argv-array.h"
+#include "iterator.h"
+#include "dir-iterator.h"
static int delta_base_offset = 1;
static int pack_kept_objects = -1;
@@ -49,12 +51,7 @@ static void remove_temporary_files(void)
{
struct strbuf buf = STRBUF_INIT;
size_t dirlen, prefixlen;
- DIR *dir;
- struct dirent *e;
-
- dir = opendir(packdir);
- if (!dir)
- return;
+ struct dir_iterator *diter = dir_iterator_begin(packdir);
/* Point at the slash at the end of ".../objects/pack/" */
dirlen = strlen(packdir) + 1;
@@ -62,14 +59,13 @@ static void remove_temporary_files(void)
/* Hold the length of ".tmp-%d-pack-" */
prefixlen = buf.len - dirlen;
- while ((e = readdir(dir))) {
- if (strncmp(e->d_name, buf.buf + dirlen, prefixlen))
+ while (dir_iterator_advance(diter) == ITER_OK) {
+ if (strncmp(diter->relative_path, buf.buf + dirlen, prefixlen))
continue;
strbuf_setlen(&buf, dirlen);
- strbuf_addstr(&buf, e->d_name);
+ strbuf_addstr(&buf, diter->relative_path);
unlink(buf.buf);
}
- closedir(dir);
strbuf_release(&buf);
}
--
2.12.2.575.gb14f27f91.dirty
next reply other threads:[~2017-04-01 0:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-01 0:24 Robert Stanca [this message]
2017-04-01 5:37 ` [PATCH] [GSOC] remove_temporary_files(): reimplement using iterators Jeff King
2017-04-01 5:41 ` Jeff King
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170401002458.3494-1-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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).