Skip to content

Commit 9bcbb1c

Browse files
committed
merge --no-edit: do not credit people involved in the side branch
The credit lines "By" and "Via" to credit authors and committers for their contributions on the side branch are meant as a hint to the integrator to decide whom to mention in the log message text. After the integrator saves the message in the editor, they are meant to go away and that is why they are commented out. When a merge is recorded without editing the generated message, however, its contents do not go through the normal stripspace() and these lines are left in the merge. Stop producing them when we know the merge is going to be recorded without editing, i.e. when --no-edit is given. Signed-off-by: Junio C Hamano <[email protected]>
1 parent bafc478 commit 9bcbb1c

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
@@ -16,7 +16,8 @@ extern const char git_more_info_string[];
1616
extern void prune_packed_objects(int);
1717

1818
struct fmt_merge_msg_opts {
19-
unsigned add_title:1;
19+
unsigned add_title:1,
20+
credit_people:1;
2021
int shortlog_len;
2122
};
2223

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
@@ -1324,6 +1324,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13241324
memset(&opts, 0, sizeof(opts));
13251325
opts.add_title = !have_message;
13261326
opts.shortlog_len = shortlog_len;
1327+
opts.credit_people = (0 < option_edit);
13271328

13281329
fmt_merge_msg(&merge_names, &merge_msg, &opts);
13291330
if (merge_msg.len)

0 commit comments

Comments
 (0)