Re: [PATCH] Make git-mailinfo strip whitespace from the start of the mail file.

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] Make git-mailinfo strip whitespace from the start of the mail file.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:43:46

"Simon Sasburg" [off-list ref] writes:
quoted
Just to help me understand why this change is needed...

Are you using mailinfo directly without splitting with mailsplit
first?
Well, when using gmail's web interface, when reading a mail, there is
this option to show the raw mail text (headers+body) with the 'show
original' option.

If you do 'save as..' in your browser to save what you get with that,
and try to do git-am on that file, it fails because it starts with
some whitespace.

With this patch git-am works on these files.

So, i'm not using mailsplit or any other mail tools at all, just my
browser and git.
Ah, I meant "git-mailsplit", which is the command internally run
by "git-am" to preprocess the file and to split it into
individual mail pieces to be fed to "git-mailinfo".

That may suggest the change is better done in git-mailsplit not
git-mailinfo.

Or perhaps both.

[PATCH] Make git-mailsplit strip whitespace from the start of the mailbox file.

From: Simon Sasburg <hidden>
Date: 2016-06-15 22:43:46

Signed-off-by: Simon Sasburg <redacted>
---

Ah, i see.

Well, this patch also fixes the problem in my case.

 builtin-mailsplit.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/builtin-mailsplit.c b/builtin-mailsplit.c
index 43fc373..3fdeb23 100644
--- a/builtin-mailsplit.c
+++ b/builtin-mailsplit.c
@@ -164,6 +164,7 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,
 {
 	char name[PATH_MAX];
 	int ret = -1;
+	int peek;
 
 	FILE *f = !strcmp(file, "-") ? stdin : fopen(file, "r");
 	int file_done = 0;
@@ -173,6 +174,11 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,
 		goto out;
 	}
 
+	do {
+		peek = fgetc(f);
+	} while (peek == ' ' || peek == '\r' || peek == '\n');
+	ungetc(peek, f);
+
 	if (fgets(buf, sizeof(buf), f) == NULL) {
 		/* empty stdin is OK */
 		if (f != stdin) {
-- 
1.5.3.4.504.gdf75-dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help