Clean up trailing whitespace when pretty-printing commits
Partly because we've messed up and now have some commits with trailing whitespace, but partly because this also just simplifies the code, let's remove trailing whitespace from the end when pretty-printing commits. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Linus Torvalds committed
Apr 14, 2006 at 21:20 UTC
40c2fe003ce2af3ec522f239be274fd1a27422f6
1 file changed
+5
-10
commit.c
+5
-10
@@ -557,16 +557,11 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
557
if (fmt == CMIT_FMT_ONELINE)
558
break;
559
}
560
- if (fmt == CMIT_FMT_ONELINE) {
561
- /* We do not want the terminating newline */
562
- if (buf[offset - 1] == '\n')
563
- offset--;
564
- }
565
- else {
566
- /* Make sure there is an EOLN */
567
- if (buf[offset - 1] != '\n')
568
- buf[offset++] = '\n';
569
- }
560
+ while (offset && isspace(buf[offset-1]))
561
+ offset--;
562
+ /* Make sure there is an EOLN for the non-oneline case */
563
+ if (fmt != CMIT_FMT_ONELINE)
564
+ buf[offset++] = '\n';
565
buf[offset] = '\0';
566
return offset;
567
}