@matheusbsbs / matheus-bagliano / commits / f4ee3eb689
Fork 0

stripspace: make sure not to leave an incomplete line.

When dealing with a commit log message for human consumption, it never makes sense to keep a log that ends with an incomplete line, so make it a part of the clean-up process done by git-stripspace. Acked-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Apr 12, 2006 at 13:10 UTC f4ee3eb68906f079dea45de4f1bbb03d68189eb3
1 file changed +8 -3
stripspace.c
+8 -3
@@ -6,9 +6,9 @@
6 * Remove empty lines from the beginning and end.
7 *
8 * Turn multiple consecutive empty lines into just one
9 - * empty line.
9 + * empty line. Return true if it is an incomplete line.
10 */
11 -static void cleanup(char *line)
11 +static int cleanup(char *line)
12 {
13 int len = strlen(line);
14
@@ -21,16 +21,19 @@ static void cleanup(char *line)
21 len--;
22 line[len] = 0;
23 } while (len > 1);
24 + return 0;
25 }
26 + return 1;
27 }
28
29 int main(int argc, char **argv)
30 {
31 int empties = -1;
32 + int incomplete = 0;
33 char line[1024];
34
35 while (fgets(line, sizeof(line), stdin)) {
33 - cleanup(line);
36 + incomplete = cleanup(line);
37
38 /* Not just an empty line? */
39 if (line[0] != '\n') {
@@ -44,5 +47,7 @@ int main(int argc, char **argv)
47 continue;
48 empties++;
49 }
50 + if (incomplete)
51 + putchar('\n');
52 return 0;
53 }