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

[[GSoC][PATCH …]] In notes-merge.c updated notes_merge_commit()

From
URUTKARSH RAI <utkarsh.rai60@gmail.com>
Date
Apr 5, 2019, 16:58 UTC
Message-ID
<01020169ee702e51-e9c8d564-10f5-49e9-a411-fd7ceaef7afc-000000@eu-west-1.amazonses.com>
Updated notes_merge_commit() by replacing readdir() ,opendir() apis by replacing them with dir_iterator_advance() and dir_iterator_begin() respectively.
Signed-off-by: ur10 <utkarsh.rai60@gmail.com>
---
 notes-merge.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/notes-merge.c b/notes-merge.c
index 280aa8e6c1b04..dc4e2cce7151a 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -13,6 +13,8 @@
 #include "strbuf.h"
 #include "notes-utils.h"
 #include "commit-reach.h"
+#include "dir-iterator.h"
+#include "iterator.h"
 
 struct notes_merge_pair {
 	struct object_id obj, base, local, remote;
@@ -673,8 +675,8 @@ int notes_merge_commit(struct notes_merge_options *o,
 	 * commit message and parents from 'partial_commit'.
 	 * Finally store the new commit object OID into 'result_oid'.
 	 */
-	DIR *dir;
-	struct dirent *e;
+	struct dir_iterator *iter;
+	int ok;
 	struct strbuf path = STRBUF_INIT;
 	const char *buffer = get_commit_buffer(partial_commit, NULL);
 	const char *msg = strstr(buffer, "\n\n");
@@ -689,27 +691,27 @@ int notes_merge_commit(struct notes_merge_options *o,
 		die("partial notes commit has empty message");
 	msg += 2;
 
-	dir = opendir(path.buf);
-	if (!dir)
+	iter = dir_iterator_begin(path.buf);
+	if (!iter)
 		die_errno("could not open %s", path.buf);
 
 	strbuf_addch(&path, '/');
 	baselen = path.len;
-	while ((e = readdir(dir)) != NULL) {
+	while ((ok = dir_iterator_advance(iter) )== ITER_OK) {
 		struct stat st;
 		struct object_id obj_oid, blob_oid;
 
-		if (is_dot_or_dotdot(e->d_name))
+		if (is_dot_or_dotdot(iter->basename))
 			continue;
 
-		if (get_oid_hex(e->d_name, &obj_oid)) {
+		if (get_oid_hex(iter->basename, &obj_oid)) {
 			if (o->verbosity >= 3)
 				printf("Skipping non-SHA1 entry '%s%s'\n",
-					path.buf, e->d_name);
+					path.buf, iter->basename);
 			continue;
 		}
 
-		strbuf_addstr(&path, e->d_name);
+		strbuf_addstr(&path,iter->basename);
 		/* write file as blob, and add to partial_tree */
 		if (stat(path.buf, &st))
 			die_errno("Failed to stat '%s'", path.buf);
@@ -731,7 +733,7 @@ int notes_merge_commit(struct notes_merge_options *o,
 		printf("Finalized notes merge commit: %s\n",
 			oid_to_hex(result_oid));
 	strbuf_release(&path);
-	closedir(dir);
+	
 	return 0;
 }
 

--
https://github.com/git/git/pull/594
Next: Thomas Gummerer
Message 1 of 3 in “] In notes-merge.c updated notes_merge_commit()”
  1. UTKARSH RAIApr 5, 2019
  2. Thomas GummererApr 6, 2019
  3. Taylor BlauApr 9, 2019

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.