Skip to content

Commit 40c2fe0

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cad1ed9 commit 40c2fe0

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

commit.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -557,16 +557,11 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
557557
if (fmt == CMIT_FMT_ONELINE)
558558
break;
559559
}
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';
570565
buf[offset] = '\0';
571566
return offset;
572567
}

0 commit comments

Comments
 (0)