summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-08-08 22:15:40 -0700
committerJunio C Hamano <junkio@cox.net>2005-08-09 22:28:23 -0700
commitd87449c553262a24df26648633c7c73b2db7dcc6 (patch)
tree8ff9a656ea6b550dd915444fa2f18c86338f63cf /commit.c
parent62033318abbe648e8be49121b0a3570c07d38a9d (diff)
downloadgit-d87449c553262a24df26648633c7c73b2db7dcc6.tar.gz
Introduce --pretty=oneline format.
This introduces --pretty=oneline to git-rev-tree and git-rev-list commands to show only the first line of the commit message, without frills. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/commit.c b/commit.c
index 3ac421ac34..59e93d4590 100644
--- a/commit.c
+++ b/commit.c
@@ -33,6 +33,8 @@ 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");
}
@@ -350,6 +352,8 @@ static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf, const c
unsigned long time;
int tz, ret;
+ if (fmt == CMIT_FMT_ONELINE)
+ return 0;
date = strchr(line, '>');
if (!date)
return 0;
@@ -373,6 +377,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 +400,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 +424,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 +455,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;
}