X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=commit.c;h=2717dd81c346d89bf5d6727e3aa1f5b65ff39aca;hb=refs%2Fheads%2Fmaint;hp=d534c9ba586ddf75be9104aa3d4a3845a54d39f2;hpb=9f2700cacd8b8e472eddd0442857e85da23834f2;p=git.git diff --git a/commit.c b/commit.c index d534c9ba..2717dd81 100644 --- a/commit.c +++ b/commit.c @@ -160,8 +160,8 @@ struct commit_graft *read_graft_line(char *buf, int len) if (buf[len-1] == '\n') buf[--len] = 0; - if (buf[0] == '#') - return 0; + if (buf[0] == '#' || buf[0] == '\0') + return NULL; if ((len + 1) % 41) { bad_graft_data: error("bad graft data: %s", buf); @@ -192,6 +192,8 @@ int read_graft_file(const char *graft_file) /* The format is just "Commit Parent1 Parent2 ...\n" */ int len = strlen(buf); struct commit_graft *graft = read_graft_line(buf, len); + if (!graft) + continue; if (register_commit_graft(graft, 1)) error("duplicate graft data: %s", buf); } @@ -400,11 +402,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 +559,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; }