Skip to content

Commit

Permalink
merge --no-edit: do not credit people involved in the side branch
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
gitster committed Dec 28, 2012
1 parent bafc478 commit 9bcbb1c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ extern const char git_more_info_string[];
extern void prune_packed_objects(int);

struct fmt_merge_msg_opts {
unsigned add_title:1;
unsigned add_title:1,
credit_people:1;
int shortlog_len;
};

Expand Down
21 changes: 14 additions & 7 deletions builtin/fmt-merge-msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ static void record_person(int which, struct string_list *people,
{
char *name_buf, *name, *name_end;
struct string_list_item *elem;
const char *field = (which == 'a') ? "\nauthor " : "\ncommitter ";
const char *field;

field = (which == 'a') ? "\nauthor " : "\ncommitter ";
name = strstr(commit->buffer, field);
if (!name)
return;
Expand Down Expand Up @@ -323,7 +324,8 @@ static void add_people_info(struct strbuf *out,
static void shortlog(const char *name,
struct origin_data *origin_data,
struct commit *head,
struct rev_info *rev, int limit,
struct rev_info *rev,
struct fmt_merge_msg_opts *opts,
struct strbuf *out)
{
int i, count = 0;
Expand All @@ -335,6 +337,7 @@ static void shortlog(const char *name,
int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
struct strbuf sb = STRBUF_INIT;
const unsigned char *sha1 = origin_data->sha1;
int limit = opts->shortlog_len;

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

if (commit->parents && commit->parents->next) {
/* do not list a merge but count committer */
record_person('c', &committers, commit);
if (opts->credit_people)
record_person('c', &committers, commit);
continue;
}
if (!count)
if (!count && opts->credit_people)
/* the 'tip' committer */
record_person('c', &committers, commit);
record_person('a', &authors, commit);
if (opts->credit_people)
record_person('a', &authors, commit);
count++;
if (subjects.nr > limit)
continue;
Expand All @@ -372,7 +377,8 @@ static void shortlog(const char *name,
string_list_append(&subjects, strbuf_detach(&sb, NULL));
}

add_people_info(out, &authors, &committers);
if (opts->credit_people)
add_people_info(out, &authors, &committers);
if (count > limit)
strbuf_addf(out, "\n* %s: (%d commits)\n", name, count);
else
Expand Down Expand Up @@ -635,7 +641,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
for (i = 0; i < origins.nr; i++)
shortlog(origins.items[i].string,
origins.items[i].util,
head, &rev, opts->shortlog_len, out);
head, &rev, opts, out);
}

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

memset(&opts, 0, sizeof(opts));
opts.add_title = !message;
opts.credit_people = 1;
opts.shortlog_len = shortlog_len;

ret = fmt_merge_msg(&input, &output, &opts);
Expand Down
1 change: 1 addition & 0 deletions builtin/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
memset(&opts, 0, sizeof(opts));
opts.add_title = !have_message;
opts.shortlog_len = shortlog_len;
opts.credit_people = (0 < option_edit);

fmt_merge_msg(&merge_names, &merge_msg, &opts);
if (merge_msg.len)
Expand Down

0 comments on commit 9bcbb1c

Please sign in to comment.