All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [GSOC] remove_temporary_files(): reimplement using iterators
@ 2017-04-01  0:24 Robert Stanca
  2017-04-01  5:37 ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: Robert Stanca @ 2017-04-01  0:24 UTC (permalink / raw)
  To: git; +Cc: Robert Stanca

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-01  5:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-01  0:24 [PATCH] [GSOC] remove_temporary_files(): reimplement using iterators Robert Stanca
2017-04-01  5:37 ` Jeff King
2017-04-01  5:41   ` Jeff King

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.