summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6203331)
raw | patch | inline | side by side (parent: 6203331)
author | Junio C Hamano <junkio@cox.net> | |
Tue, 9 Aug 2005 05:15:40 +0000 (22:15 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 10 Aug 2005 05:28:23 +0000 (22:28 -0700) |
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>
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>
commit.c | patch | blob | history | |
commit.h | patch | blob | history | |
rev-list.c | patch | blob | history |
diff --git a/commit.c b/commit.c
index 3ac421ac349e64f89cdd2f319b732cbb6d10cc44..59e93d4590da927cc956f043407eaff79cc308aa 100644 (file)
--- a/commit.c
+++ b/commit.c
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;
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;
}
diff --git a/commit.h b/commit.h
index c24ab210611815938f4d61f662f1c82e4959e61f..5d179d4dc891947e1f8421184f1030bfda245cf7 100644 (file)
--- a/commit.h
+++ b/commit.h
CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
CMIT_FMT_SHORT,
CMIT_FMT_FULL,
+ CMIT_FMT_ONELINE,
};
extern enum cmit_fmt get_commit_format(const char *arg);
diff --git a/rev-list.c b/rev-list.c
index 1a03bf7b3754e1644f9a2cee80d9d09b563ee1ec..ce5b8b2ad528830eb0c6572edcdc55d97422952c 100644 (file)
--- a/rev-list.c
+++ b/rev-list.c
parents = parents->next;
}
}
- putchar('\n');
+ if (commit_format == CMIT_FMT_ONELINE)
+ putchar(' ');
+ else
+ putchar('\n');
+
if (verbose_header) {
static char pretty_header[16384];
pretty_print_commit(commit_format, commit->buffer, ~0, pretty_header, sizeof(pretty_header));
commit_format = get_commit_format(arg+8);
verbose_header = 1;
hdr_termination = '\n';
- prefix = "commit ";
+ if (commit_format == CMIT_FMT_ONELINE)
+ prefix = "";
+ else
+ prefix = "commit ";
continue;
}
if (!strncmp(arg, "--no-merges", 11)) {