git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] [GSOC] remove_temporary_files(): reimplement using iterators

From
RSRobert Stanca <robert.stanca7@gmail.com>
Date
Apr 1, 2017, 00:24 UTC
Message-ID
<20170401002458.3494-1-robert.stanca7@gmail.com>
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: Jeff King
Message 1 of 3 in “[GSOC] remove_temporary_files(): reimplement using iterators”
  1. [GSOC] remove_temporary_files(): reimplement using iteratorsRobert Stanca, Apr 1, 2017
  2. Jeff KingApr 1, 2017
  3. Jeff KingApr 1, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.