133
break;
134
case SHORTLOG_GROUP_TRAILER:
135
die(_("using %s with stdin is not supported"), "--group=trailer");
136
+ case SHORTLOG_GROUP_FORMAT:
137
+ die(_("using %s with stdin is not supported"), "--group=format");
138
default:
139
BUG("unhandled shortlog group");
140
}
205
unuse_commit_buffer(commit, commit_buffer);
206
}
207
208
+static int shortlog_needs_dedup(const struct shortlog *log)
209
+{
210
+ return HAS_MULTI_BITS(log->groups) || log->format.nr > 1 || log->trailers.nr;
211
+}
212
+
213
+static void insert_records_from_format(struct shortlog *log,
214
+ struct strset *dups,
215
+ struct commit *commit,
216
+ struct pretty_print_context *ctx,
217
+ const char *oneline)
218
+{
219
+ struct strbuf buf = STRBUF_INIT;
220
+ struct string_list_item *item;
221
+
222
+ for_each_string_list_item(item, &log->format) {
223
+ strbuf_reset(&buf);
224
+
225
+ format_commit_message(commit, item->string, &buf, ctx);
226
+
227
+ if (!shortlog_needs_dedup(log) || strset_add(dups, buf.buf))
228
+ insert_one_record(log, buf.buf, oneline);
229
+ }
230
+
231
+ strbuf_release(&buf);
232
+}
233
+
234
void shortlog_add_commit(struct shortlog *log, struct commit *commit)
235
{
236
struct strbuf ident = STRBUF_INIT;
272
insert_one_record(log, ident.buf, oneline_str);
273
}
274
insert_records_from_trailers(log, &dups, commit, &ctx, oneline_str);
275
+ insert_records_from_format(log, &dups, commit, &ctx, oneline_str);
276
277
strset_clear(&dups);
278
strbuf_release(&ident);
344
if (unset) {
345
log->groups = 0;
346
string_list_clear(&log->trailers, 0);
347
+ string_list_clear(&log->format, 0);
348
} else if (!strcasecmp(arg, "author"))
349
log->groups |= SHORTLOG_GROUP_AUTHOR;
350
else if (!strcasecmp(arg, "committer"))
352
else if (skip_prefix(arg, "trailer:", &field)) {
353
log->groups |= SHORTLOG_GROUP_TRAILER;
354
string_list_append(&log->trailers, field);
325
- } else
355
+ } else if (skip_prefix(arg, "format:", &field)) {
356
+ log->groups |= SHORTLOG_GROUP_FORMAT;
357
+ string_list_append(&log->format, field);
358
+ } else if (strchr(arg, '%')) {
359
+ log->groups |= SHORTLOG_GROUP_FORMAT;
360
+ string_list_append(&log->format, arg);
361
+ } else {
362
return error(_("unknown group type: %s"), arg);
363
+ }
364
365
return 0;
366
}
378
log->in2 = DEFAULT_INDENT2;
379
log->trailers.strdup_strings = 1;
380
log->trailers.cmp = strcasecmp;
381
+ log->format.strdup_strings = 1;
382
}
383
384
int cmd_shortlog(int argc, const char **argv, const char *prefix)
519
log->list.strdup_strings = 1;
520
string_list_clear(&log->list, 1);
521
clear_mailmap(&log->mailmap);
522
+ string_list_clear(&log->format, 0);
523
}