# Clean up trailing whitespace when pretty-printing commits

1 messages from 2006-04-15 to 2006-04-15. Participants: Linus Torvalds.
Thread: https://gitlist.dev/t/3875

## Linus Torvalds, 2006-04-15 04:20

Subject: Clean up trailing whitespace when pretty-printing commits
Message-ID: <Pine.LNX.4.64.0604142118550.3701@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0604142118550.3701%40g5.osdl.org

```

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>
---
diff --git a/commit.c b/commit.c
index c7bb8db..ca25574 100644
--- a/commit.c
+++ b/commit.c
@@ -557,16 +557,11 @@ unsigned long pretty_print_commit(enum c
 		if (fmt == CMIT_FMT_ONELINE)
 			break;
 	}
-	if (fmt == CMIT_FMT_ONELINE) {
-		/* We do not want the terminating newline */
-		if (buf[offset - 1] == '\n')
-			offset--;
-	}
-	else {
-		/* Make sure there is an EOLN */
-		if (buf[offset - 1] != '\n')
-			buf[offset++] = '\n';
-	}
+	while (offset && isspace(buf[offset-1]))
+		offset--;
+	/* Make sure there is an EOLN for the non-oneline case */
+	if (fmt != CMIT_FMT_ONELINE)
+		buf[offset++] = '\n';
 	buf[offset] = '\0';
 	return offset;
 }

```
