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

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

From
RSRobert Stanca <robert.stanca7@gmail.com>
Date
Mar 28, 2017, 01:39 UTC
Message-ID
<1490665185-11809-1-git-send-email-robert.stanca7@gmail.com>
Replaces recursive traversing of opendir with dir_iterator.
Signed-off-by: Robert Stanca <robert.stanca7@gmail.com>
---
 builtin/repack.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/builtin/repack.c b/builtin/repack.c
index 677bc7c..27a5597 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;
@@ -86,26 +88,21 @@ static void remove_pack_on_signal(int signo)
  */
 static void get_non_kept_pack_filenames(struct string_list *fname_list)
 {
-	DIR *dir;
-	struct dirent *e;
+	struct dir_iterator *diter = dir_iterator_begin(packdir);
 	char *fname;
 
-	if (!(dir = opendir(packdir)))
-		return;
-
-	while ((e = readdir(dir)) != NULL) {
+	while (dir_iterator_advance(diter) == ITER_OK) {
 		size_t len;
-		if (!strip_suffix(e->d_name, ".pack", &len))
+		if (!strip_suffix(diter->relative_path, ".pack", &len))
 			continue;
 
-		fname = xmemdupz(e->d_name, len);
+		fname = xmemdupz(diter->relative_path, len);
 
 		if (!file_exists(mkpath("%s/%s.keep", packdir, fname)))
 			string_list_append_nodup(fname_list, fname);
 		else
 			free(fname);
 	}
-	closedir(dir);
 }
 
 static void remove_redundant_pack(const char *dir_name, const char *base_name)
-- 
2.7.4




Hi , this is my first patch submission for Git Gsoc. I ran full tests and local tests with
prove --timer --jobs 15 ./t*pack*.sh .

Have a great day,
             Robert.
Next: Stefan Beller
Message 1 of 2 in “[GSOC] get_non_kept_pack_filenames(): reimplement using iterators”
  1. [GSOC] get_non_kept_pack_filenames(): reimplement using iteratorsRobert Stanca, Mar 28, 2017
  2. Stefan BellerMar 28, 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.