fmt_merge_msg: Change fmt_merge_msg API to accept shortlog_len
Give "shortlog_len" parameter to the fmt_merge_msg(), remove its "merge_summary" parameter, and remove fmt_merge_msg_shortlog() function. In the updated API, shortlog_len == 0 means no shortlog is given. The parameter "merge_title" controls if the title of the merge commit is autogenerated (it reads something like "Merge branch ..."), and typically it is set to true when the caller does not give its own message. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Mentored-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
fdc4408a89
commit
1876166aaa
@ -7,6 +7,8 @@
|
|||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
#include "notes.h"
|
#include "notes.h"
|
||||||
|
|
||||||
|
#define DEFAULT_MERGE_LOG_LEN 20
|
||||||
|
|
||||||
extern const char git_version_string[];
|
extern const char git_version_string[];
|
||||||
extern const char git_usage_string[];
|
extern const char git_usage_string[];
|
||||||
extern const char git_more_info_string[];
|
extern const char git_more_info_string[];
|
||||||
@ -14,9 +16,8 @@ extern const char git_more_info_string[];
|
|||||||
extern void list_common_cmds_help(void);
|
extern void list_common_cmds_help(void);
|
||||||
extern const char *help_unknown_cmd(const char *cmd);
|
extern const char *help_unknown_cmd(const char *cmd);
|
||||||
extern void prune_packed_objects(int);
|
extern void prune_packed_objects(int);
|
||||||
extern int fmt_merge_msg(int merge_summary, struct strbuf *in,
|
extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
|
||||||
struct strbuf *out);
|
int merge_title, int shortlog_len);
|
||||||
extern int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out);
|
|
||||||
extern int commit_notes(struct notes_tree *t, const char *msg);
|
extern int commit_notes(struct notes_tree *t, const char *msg);
|
||||||
|
|
||||||
struct notes_rewrite_cfg {
|
struct notes_rewrite_cfg {
|
||||||
|
@ -255,9 +255,9 @@ static void do_fmt_merge_msg_title(struct strbuf *out,
|
|||||||
strbuf_addf(out, " into %s\n", current_branch);
|
strbuf_addf(out, " into %s\n", current_branch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_fmt_merge_msg(int merge_title, int merge_summary,
|
static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
|
||||||
struct strbuf *in, struct strbuf *out) {
|
struct strbuf *out, int shortlog_len) {
|
||||||
int limit = 20, i = 0, pos = 0;
|
int i = 0, pos = 0;
|
||||||
unsigned char head_sha1[20];
|
unsigned char head_sha1[20];
|
||||||
const char *current_branch;
|
const char *current_branch;
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ static int do_fmt_merge_msg(int merge_title, int merge_summary,
|
|||||||
if (merge_title)
|
if (merge_title)
|
||||||
do_fmt_merge_msg_title(out, current_branch);
|
do_fmt_merge_msg_title(out, current_branch);
|
||||||
|
|
||||||
if (merge_summary) {
|
if (shortlog_len) {
|
||||||
struct commit *head;
|
struct commit *head;
|
||||||
struct rev_info rev;
|
struct rev_info rev;
|
||||||
|
|
||||||
@ -303,17 +303,14 @@ static int do_fmt_merge_msg(int merge_title, int merge_summary,
|
|||||||
|
|
||||||
for (i = 0; i < origins.nr; i++)
|
for (i = 0; i < origins.nr; i++)
|
||||||
shortlog(origins.items[i].string, origins.items[i].util,
|
shortlog(origins.items[i].string, origins.items[i].util,
|
||||||
head, &rev, limit, out);
|
head, &rev, shortlog_len, out);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) {
|
int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
|
||||||
return do_fmt_merge_msg(1, merge_summary, in, out);
|
int merge_title, int shortlog_len) {
|
||||||
}
|
return do_fmt_merge_msg(merge_title, in, out, shortlog_len);
|
||||||
|
|
||||||
int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out) {
|
|
||||||
return do_fmt_merge_msg(0, 1, in, out);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
|
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
|
||||||
@ -355,12 +352,13 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
if (strbuf_read(&input, fileno(in), 0) < 0)
|
if (strbuf_read(&input, fileno(in), 0) < 0)
|
||||||
die_errno("could not read input file");
|
die_errno("could not read input file");
|
||||||
if (message) {
|
|
||||||
|
if (message)
|
||||||
strbuf_addstr(&output, message);
|
strbuf_addstr(&output, message);
|
||||||
ret = fmt_merge_msg_shortlog(&input, &output);
|
ret = fmt_merge_msg(&input, &output,
|
||||||
} else {
|
message ? 0 : 1,
|
||||||
ret = fmt_merge_msg(merge_summary, &input, &output);
|
merge_summary ? DEFAULT_MERGE_LOG_LEN : 0);
|
||||||
}
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
write_in_full(STDOUT_FILENO, output.buf, output.len);
|
write_in_full(STDOUT_FILENO, output.buf, output.len);
|
||||||
|
@ -998,14 +998,12 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
|
|||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
merge_name(argv[i], &merge_names);
|
merge_name(argv[i], &merge_names);
|
||||||
|
|
||||||
if (have_message && option_log)
|
if (!have_message || option_log) {
|
||||||
fmt_merge_msg_shortlog(&merge_names, &merge_msg);
|
fmt_merge_msg(&merge_names, &merge_msg, !have_message,
|
||||||
else if (!have_message)
|
option_log ? DEFAULT_MERGE_LOG_LEN : 0);
|
||||||
fmt_merge_msg(option_log, &merge_names, &merge_msg);
|
if (merge_msg.len)
|
||||||
|
strbuf_setlen(&merge_msg, merge_msg.len - 1);
|
||||||
|
}
|
||||||
if (!(have_message && !option_log) && merge_msg.len)
|
|
||||||
strbuf_setlen(&merge_msg, merge_msg.len-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (head_invalid || !argc)
|
if (head_invalid || !argc)
|
||||||
|
Loading…
Reference in New Issue
Block a user