X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=commit.c;h=ca25574500fe3c88d2cc2953b7dd019b3acab9e7;hb=a3cc31fb059410d6b96786045947bafc2f32ce60;hp=d534c9ba586ddf75be9104aa3d4a3845a54d39f2;hpb=90238fbe43e46e9a679560488401e5a9bb2708bf;p=git.git diff --git a/commit.c b/commit.c index d534c9ba..ca255745 100644 --- 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; }