shortlog: support --pretty=format: option
With this patch, the user can override the default setting, to print the commit messages using a user format instead of the onelines of the commits. Example: $ git shortlog --pretty='format:%s (%h)' <commit>.. Note that shortlog will only respect a user format setting, as the other formats do not make much sense. Wished for by Andrew Morton. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jul 14, 2008 at 19:08 UTC
b526f8ed4de646bb914da43b60322852febde758
2 files changed
+12
builtin-shortlog.c
+11
@@ -154,6 +154,15 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
154
if (!author)
155
die("Missing author: %s",
156
sha1_to_hex(commit->object.sha1));
157
+ if (log->user_format) {
158
+ struct strbuf buf = STRBUF_INIT;
159
+
160
+ pretty_print_commit(CMIT_FMT_USERFORMAT, commit, &buf,
161
+ DEFAULT_ABBREV, "", "", DATE_NORMAL, 0);
162
+ insert_one_record(log, author, buf.buf);
163
+ strbuf_release(&buf);
164
+ return;
165
+ }
166
if (*buffer)
167
buffer++;
168
insert_one_record(log, author, !*buffer ? "<none>" : buffer);
@@ -271,6 +280,8 @@ parse_done:
280
usage_with_options(shortlog_usage, options);
281
}
282
283
+ log.user_format = rev.commit_format == CMIT_FMT_USERFORMAT;
284
+
285
/* assume HEAD if from a tty */
286
if (!nongit && !rev.pending.nr && isatty(0))
287
add_head_to_pending(&rev);
shortlog.h
+1
@@ -11,6 +11,7 @@ struct shortlog {
11
int wrap;
12
int in1;
13
int in2;
14
+ int user_format;
15
16
char *common_repo_prefix;
17
int email;