diff-files --stat: do not dump core with unmerged index.
[git.git] / commit.c
index d534c9b..ca25574 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -400,11 +400,11 @@ static int get_one_line(const char *msg, unsigned long len)
 
        while (len--) {
                char c = *msg++;
+               if (!c)
+                       break;
                ret++;
                if (c == '\n')
                        break;
-               if (!c)
-                       return 0;
        }
        return ret;
 }
@@ -557,16 +557,11 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
                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;
 }