* git-mailinfo: cut lines at ^M
@ 2006-01-16 19:13 Linus Torvalds
2006-01-16 23:38 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Linus Torvalds @ 2006-01-16 19:13 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List
This changes "eatspace()" to cut lines at the first ^M (\r, CR) character.
Normally it should make no difference at all, since even if you have a
non-UNIX CR/LF end-of-line, it would have removed the ^M at the end of the
line as whitespace.
The main reason for this patch is that I seem to have something buggy in
my mail path (possibly fetchmail) which very occasionally causes the mail
headers to have an appended "^M)" line. This silly thing works around it,
and shouldn't hurt anything else.
The alternative would be to simply disallow control characters in the
commit message (so that I would not commit these things by mistake).
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
Junio, feel free to ignore this. It shouldn't hurt, but admittedly it's a
stupid hack for a problem that has nothing to do with git. The "disallow
control characters" fix is probably better, if you prefer that I can do it
that way instead.
Linus
diff --git a/mailinfo.c b/mailinfo.c
index 0265a29..e1c95a9 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -226,9 +226,19 @@ static int is_multipart_boundary(const c
static int eatspace(char *line)
{
- int len = strlen(line);
- while (len > 0 && isspace(line[len-1]))
- line[--len] = 0;
+ int len, idx;
+
+ len = idx = 0;
+ for (;;) {
+ unsigned char c = line[idx++];
+ if (isspace(c)) {
+ if (c == '\n' || c == '\r')
+ break;
+ continue;
+ }
+ len = idx;
+ }
+ line[len] = 0;
return len;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: git-mailinfo: cut lines at ^M
2006-01-16 19:13 git-mailinfo: cut lines at ^M Linus Torvalds
@ 2006-01-16 23:38 ` Junio C Hamano
2006-01-16 23:49 ` Linus Torvalds
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2006-01-16 23:38 UTC (permalink / raw)
To: Linus Torvalds; +Cc: Git Mailing List
Linus Torvalds <torvalds@osdl.org> writes:
> Junio, feel free to ignore this. It shouldn't hurt, but
> admittedly it's a stupid hack for a problem that has nothing
> to do with git...
This is doing "instead of removing trailing spaces, terminate a
line at the first CR or LF and discard the rest". So your "^M)"
at the end, especially the close paren, is dropped.
I've briefly wondered if a better alternative is to split lines
at "\r\n", "\n", or "\r", which would make the next line begin
with ")" in your example. Normally the first two would have
already been done by fgets(), so the alternative approach would
involve wrapping the use of fgets() with something of our own.
I do not think "keeping the rest of the line after '\r' in the
middle" is worth that trouble, so I am personally fine with your
patch.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-01-16 23:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-16 19:13 git-mailinfo: cut lines at ^M Linus Torvalds
2006-01-16 23:38 ` Junio C Hamano
2006-01-16 23:49 ` Linus Torvalds
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox