@matheusbsbs / matheus-bagliano / commits / d50a4bc4e9
Fork 0

git-mailsplit: with maildirs not only process cur/, but also new/

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> Acked-by: Jeff King <peff@peff.net> Acked-by: Alex Riesen <raa.lkml@gmail.com> Acked-by: Fernando J. Pereda <ferdy@gentoo.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Gerrit Pape committed Nov 6, 2007 at 08:54 UTC d50a4bc4e91f03cecc337e5e95dc4c0e0a4054f0
1 file changed +22 -16
builtin-mailsplit.c
+22 -16
@@ -101,20 +101,29 @@ static int populate_maildir_list(struct path_list *list, const char *path)
101 {
102 DIR *dir;
103 struct dirent *dent;
104 + char name[PATH_MAX];
105 + char *subs[] = { "cur", "new", NULL };
106 + char **sub;
107 +
108 + for (sub = subs; *sub; ++sub) {
109 + snprintf(name, sizeof(name), "%s/%s", path, *sub);
110 + if ((dir = opendir(name)) == NULL) {
111 + if (errno == ENOENT)
112 + continue;
113 + error("cannot opendir %s (%s)", name, strerror(errno));
114 + return -1;
115 + }
116
105 - if ((dir = opendir(path)) == NULL) {
106 - error("cannot opendir %s (%s)", path, strerror(errno));
107 - return -1;
108 - }
117 + while ((dent = readdir(dir)) != NULL) {
118 + if (dent->d_name[0] == '.')
119 + continue;
120 + snprintf(name, sizeof(name), "%s/%s", *sub, dent->d_name);
121 + path_list_insert(name, list);
122 + }
123
110 - while ((dent = readdir(dir)) != NULL) {
111 - if (dent->d_name[0] == '.')
112 - continue;
113 - path_list_insert(dent->d_name, list);
124 + closedir(dir);
125 }
126
116 - closedir(dir);
117 -
127 return 0;
128 }
129
@@ -122,19 +131,17 @@ static int split_maildir(const char *maildir, const char *dir,
131 int nr_prec, int skip)
132 {
133 char file[PATH_MAX];
125 - char curdir[PATH_MAX];
134 char name[PATH_MAX];
135 int ret = -1;
136 int i;
137 struct path_list list = {NULL, 0, 0, 1};
138
131 - snprintf(curdir, sizeof(curdir), "%s/cur", maildir);
132 - if (populate_maildir_list(&list, curdir) < 0)
139 + if (populate_maildir_list(&list, maildir) < 0)
140 goto out;
141
142 for (i = 0; i < list.nr; i++) {
143 FILE *f;
137 - snprintf(file, sizeof(file), "%s/%s", curdir, list.items[i].path);
144 + snprintf(file, sizeof(file), "%s/%s", maildir, list.items[i].path);
145 f = fopen(file, "r");
146 if (!f) {
147 error("cannot open mail %s (%s)", file, strerror(errno));
@@ -152,10 +159,9 @@ static int split_maildir(const char *maildir, const char *dir,
159 fclose(f);
160 }
161
155 - path_list_clear(&list, 1);
156 -
162 ret = skip;
163 out:
164 + path_list_clear(&list, 1);
165 return ret;
166 }
167