Skip to content

Commit cf6c52f

Browse files
committed
Merge branch 'jc/maint-fmt-merge-msg-no-edit-lose-credit'
Stop spending cycles to compute information to be placed on commented lines in "merge --no-edit", which will be discarded anyway. * jc/maint-fmt-merge-msg-no-edit-lose-credit: merge --no-edit: do not credit people involved in the side branch
2 parents 44fe835 + 9bcbb1c commit cf6c52f

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

builtin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ extern const char git_more_info_string[];
1515
extern void prune_packed_objects(int);
1616

1717
struct fmt_merge_msg_opts {
18-
unsigned add_title:1;
18+
unsigned add_title:1,
19+
credit_people:1;
1920
int shortlog_len;
2021
};
2122

builtin/fmt-merge-msg.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ static void record_person(int which, struct string_list *people,
232232
{
233233
char *name_buf, *name, *name_end;
234234
struct string_list_item *elem;
235-
const char *field = (which == 'a') ? "\nauthor " : "\ncommitter ";
235+
const char *field;
236236

237+
field = (which == 'a') ? "\nauthor " : "\ncommitter ";
237238
name = strstr(commit->buffer, field);
238239
if (!name)
239240
return;
@@ -323,7 +324,8 @@ static void add_people_info(struct strbuf *out,
323324
static void shortlog(const char *name,
324325
struct origin_data *origin_data,
325326
struct commit *head,
326-
struct rev_info *rev, int limit,
327+
struct rev_info *rev,
328+
struct fmt_merge_msg_opts *opts,
327329
struct strbuf *out)
328330
{
329331
int i, count = 0;
@@ -335,6 +337,7 @@ static void shortlog(const char *name,
335337
int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
336338
struct strbuf sb = STRBUF_INIT;
337339
const unsigned char *sha1 = origin_data->sha1;
340+
int limit = opts->shortlog_len;
338341

339342
branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);
340343
if (!branch || branch->type != OBJ_COMMIT)
@@ -351,13 +354,15 @@ static void shortlog(const char *name,
351354

352355
if (commit->parents && commit->parents->next) {
353356
/* do not list a merge but count committer */
354-
record_person('c', &committers, commit);
357+
if (opts->credit_people)
358+
record_person('c', &committers, commit);
355359
continue;
356360
}
357-
if (!count)
361+
if (!count && opts->credit_people)
358362
/* the 'tip' committer */
359363
record_person('c', &committers, commit);
360-
record_person('a', &authors, commit);
364+
if (opts->credit_people)
365+
record_person('a', &authors, commit);
361366
count++;
362367
if (subjects.nr > limit)
363368
continue;
@@ -372,7 +377,8 @@ static void shortlog(const char *name,
372377
string_list_append(&subjects, strbuf_detach(&sb, NULL));
373378
}
374379

375-
add_people_info(out, &authors, &committers);
380+
if (opts->credit_people)
381+
add_people_info(out, &authors, &committers);
376382
if (count > limit)
377383
strbuf_addf(out, "\n* %s: (%d commits)\n", name, count);
378384
else
@@ -635,7 +641,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
635641
for (i = 0; i < origins.nr; i++)
636642
shortlog(origins.items[i].string,
637643
origins.items[i].util,
638-
head, &rev, opts->shortlog_len, out);
644+
head, &rev, opts, out);
639645
}
640646

641647
strbuf_complete_line(out);
@@ -690,6 +696,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
690696

691697
memset(&opts, 0, sizeof(opts));
692698
opts.add_title = !message;
699+
opts.credit_people = 1;
693700
opts.shortlog_len = shortlog_len;
694701

695702
ret = fmt_merge_msg(&input, &output, &opts);

builtin/merge.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12221222
memset(&opts, 0, sizeof(opts));
12231223
opts.add_title = !have_message;
12241224
opts.shortlog_len = shortlog_len;
1225+
opts.credit_people = (0 < option_edit);
12251226

12261227
fmt_merge_msg(&merge_names, &merge_msg, &opts);
12271228
if (merge_msg.len)

0 commit comments

Comments
 (0)