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

[PATCH] git-mailsplit: with maildirs try to process new/ if cur/ is empty

From
Gerrit Pape <pape@smarden.org>
Date
Nov 5, 2007, 12:49 UTC
Message-ID
<20071105124920.17726.qmail@746e9cce42b49f.315fe32.mid.smarden.org>
In-Reply-To
<20071026160118.GA5076@ferdyx.org>

When saving patches to a maildir with e.g. mutt, the files are put into the new/ subdirectory of the maildir, not cur/. This makes git-am state "Nothing to do.". This patch lets git-mailsplit additional check new/ after reading cur/.

This was reported by Joey Hess through
 http://bugs.debian.org/447396
Signed-off-by: Gerrit Pape <pape@smarden.org>
---
On Fri, Oct 26, 2007 at 06:01:18PM +0200, Fernando J. Pereda wrote:
> By that reasoning, you should make it parse both cur/ and new/.
Okay.
 builtin-mailsplit.c |   36 ++++++++++++++++++++----------------
 1 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/builtin-mailsplit.c b/builtin-mailsplit.c
index 74b0470..79e8ee0 100644
--- a/builtin-mailsplit.c
+++ b/builtin-mailsplit.c
@@ -101,19 +101,26 @@ static int populate_maildir_list(struct path_list *list, const char *path)
 {
 	DIR *dir;
 	struct dirent *dent;
+	char name[PATH_MAX];
+	char *sub[] = { "cur", "new" };
+	int i;
 
-	if ((dir = opendir(path)) == NULL) {
-		error("cannot opendir %s (%s)", path, strerror(errno));
-		return -1;
-	}
+	for (i = 0; i < 2; ++i) {
+		snprintf(name, sizeof(name), "%s/%s", path, sub[i]);
+		if ((dir = opendir(name)) == NULL) {
+			error("cannot opendir %s (%s)", name, strerror(errno));
+			return -1;
+		}
 
-	while ((dent = readdir(dir)) != NULL) {
-		if (dent->d_name[0] == '.')
-			continue;
-		path_list_insert(dent->d_name, list);
-	}
+		while ((dent = readdir(dir)) != NULL) {
+			if (dent->d_name[0] == '.')
+				continue;
+			snprintf(name, sizeof(name), "%s/%s", sub[i], dent->d_name);
+			path_list_insert(name, list);
+		}
 
-	closedir(dir);
+		closedir(dir);
+	}
 
 	return 0;
 }
@@ -122,19 +129,17 @@ static int split_maildir(const char *maildir, const char *dir,
 	int nr_prec, int skip)
 {
 	char file[PATH_MAX];
-	char curdir[PATH_MAX];
 	char name[PATH_MAX];
 	int ret = -1;
 	int i;
 	struct path_list list = {NULL, 0, 0, 1};
 
-	snprintf(curdir, sizeof(curdir), "%s/cur", maildir);
-	if (populate_maildir_list(&list, curdir) < 0)
+	if (populate_maildir_list(&list, maildir) < 0)
 		goto out;
 
 	for (i = 0; i < list.nr; i++) {
 		FILE *f;
-		snprintf(file, sizeof(file), "%s/%s", curdir, list.items[i].path);
+		snprintf(file, sizeof(file), "%s/%s", maildir, list.items[i].path);
 		f = fopen(file, "r");
 		if (!f) {
 			error("cannot open mail %s (%s)", file, strerror(errno));
@@ -152,10 +157,9 @@ static int split_maildir(const char *maildir, const char *dir,
 		fclose(f);
 	}
 
-	path_list_clear(&list, 1);
-
 	ret = skip;
 out:
+	path_list_clear(&list, 1);
 	return ret;
 }
 
-- 
1.5.3.5
Previous: Fernando J. PeredaNext: Jakub Narebski
Message 3 of 20 in “git-mailsplit: with maildirs try to process new/ if cur/ is empty”
  1. git-mailsplit: with maildirs try to process new/ if cur/ is emptyGerrit Pape, Oct 26, 2007
  2. Fernando J. PeredaOct 26, 2007
  3. git-mailsplit: with maildirs try to process new/ if cur/ is emptyGerrit Pape, Nov 5, 2007
  4. Jakub NarebskiNov 5, 2007
  5. Jeff KingNov 5, 2007
  6. Alex RiesenNov 5, 2007
  7. Michael CohenNov 6, 2007
  8. Alex RiesenNov 6, 2007
  9. Jeff KingNov 6, 2007
  10. Johannes SchindelinNov 6, 2007
  11. Jeff KingNov 6, 2007
  12. Johannes SchindelinNov 6, 2007
  13. Karl HasselströmNov 6, 2007
  14. Johannes SchindelinNov 6, 2007
  15. Alex RiesenNov 6, 2007
  16. git-mailsplit: with maildirs not only process cur/, but also new/Gerrit Pape, Nov 6, 2007
  17. Junio C HamanoNov 8, 2007
  18. Jeff KingNov 8, 2007
  19. Alex RiesenNov 8, 2007
  20. Fernando J. PeredaNov 8, 2007

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.