X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=commit.c;h=8f403180e5903bfa3da9df76b2cda213135c58d3;hb=1f5881bb5f4da97d0bb23024ae91079137326c7e;hp=3ac421ac349e64f89cdd2f319b732cbb6d10cc44;hpb=6b7242aa1acc3c7835f80522914ffc4b2e789a29;p=git.git diff --git a/commit.c b/commit.c index 3ac421ac..8f403180 100644 --- a/commit.c +++ b/commit.c @@ -1,8 +1,9 @@ -#include #include "tag.h" #include "commit.h" #include "cache.h" +int save_commit_buffer = 1; + struct sort_node { /* @@ -33,26 +34,37 @@ enum cmit_fmt get_commit_format(const char *arg) return CMIT_FMT_SHORT; if (!strcmp(arg, "=full")) return CMIT_FMT_FULL; + if (!strcmp(arg, "=oneline")) + return CMIT_FMT_ONELINE; die("invalid --pretty format"); } -static struct commit *check_commit(struct object *obj, const unsigned char *sha1) +static struct commit *check_commit(struct object *obj, + const unsigned char *sha1, + int quiet) { if (obj->type != commit_type) { - error("Object %s is a %s, not a commit", - sha1_to_hex(sha1), obj->type); + if (!quiet) + error("Object %s is a %s, not a commit", + sha1_to_hex(sha1), obj->type); return NULL; } return (struct commit *) obj; } -struct commit *lookup_commit_reference(const unsigned char *sha1) +struct commit *lookup_commit_reference_gently(const unsigned char *sha1, + int quiet) { struct object *obj = deref_tag(parse_object(sha1)); if (!obj) return NULL; - return check_commit(obj, sha1); + return check_commit(obj, sha1, quiet); +} + +struct commit *lookup_commit_reference(const unsigned char *sha1) +{ + return lookup_commit_reference_gently(sha1, 0); } struct commit *lookup_commit(const unsigned char *sha1) @@ -67,7 +79,7 @@ struct commit *lookup_commit(const unsigned char *sha1) } if (!obj->type) obj->type = commit_type; - return check_commit(obj, sha1); + return check_commit(obj, sha1, 0); } static unsigned long parse_commit_date(const char *buf) @@ -253,7 +265,7 @@ int parse_commit(struct commit *item) sha1_to_hex(item->object.sha1)); } ret = parse_commit_buffer(item, buffer, size); - if (!ret) { + if (save_commit_buffer && !ret) { item->buffer = buffer; return 0; } @@ -346,10 +358,12 @@ static int get_one_line(const char *msg, unsigned long len) static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf, const char *line) { char *date; - unsigned int namelen; + int namelen; unsigned long time; int tz, ret; + if (fmt == CMIT_FMT_ONELINE) + return 0; date = strchr(line, '>'); if (!date) return 0; @@ -373,6 +387,9 @@ static int is_empty_line(const char *line, int len) static int add_parent_info(enum cmit_fmt fmt, char *buf, const char *line, int parents) { int offset = 0; + + if (fmt == CMIT_FMT_ONELINE) + return offset; switch (parents) { case 1: break; @@ -393,6 +410,7 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const char *msg, unsigned l int hdr = 1, body = 0; unsigned long offset = 0; int parents = 0; + int indent = (fmt == CMIT_FMT_ONELINE) ? 0 : 4; for (;;) { const char *line = msg; @@ -416,7 +434,8 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const char *msg, unsigned l if (hdr) { if (linelen == 1) { hdr = 0; - buf[offset++] = '\n'; + if (fmt != CMIT_FMT_ONELINE) + buf[offset++] = '\n'; continue; } if (fmt == CMIT_FMT_RAW) { @@ -446,13 +465,23 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const char *msg, unsigned l } else { body = 1; } - memset(buf + offset, ' ', 4); - memcpy(buf + offset + 4, line, linelen); - offset += linelen + 4; + + memset(buf + offset, ' ', indent); + memcpy(buf + offset + indent, line, linelen); + offset += linelen + indent; + 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'; } - /* Make sure there is an EOLN */ - if (buf[offset - 1] != '\n') - buf[offset++] = '\n'; buf[offset] = '\0'; return offset; }