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>
Ramkumar Ramachandra committed
Sep 8, 2010 at 23:29 UTC
1876166aaab56056083e6a61de4423d130d4dcc6
3 files changed
+24
-27
builtin.h
+4
-3
@@ -7,6 +7,8 @@
7
#include "commit.h"
8
#include "notes.h"
9
10
+#define DEFAULT_MERGE_LOG_LEN 20
11
+
12
extern const char git_version_string[];
13
extern const char git_usage_string[];
14
extern const char git_more_info_string[];
@@ -14,9 +16,8 @@ extern const char git_more_info_string[];
16
extern void list_common_cmds_help(void);
17
extern const char *help_unknown_cmd(const char *cmd);
18
extern void prune_packed_objects(int);
17
-extern int fmt_merge_msg(int merge_summary, struct strbuf *in,
18
- struct strbuf *out);
19
-extern int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out);
19
+extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
20
+ int merge_title, int shortlog_len);
21
extern int commit_notes(struct notes_tree *t, const char *msg);
22
23
struct notes_rewrite_cfg {
builtin/fmt-merge-msg.c
+14
-16
@@ -255,9 +255,9 @@ static void do_fmt_merge_msg_title(struct strbuf *out,
255
strbuf_addf(out, " into %s\n", current_branch);
256
}
257
258
-static int do_fmt_merge_msg(int merge_title, int merge_summary,
259
- struct strbuf *in, struct strbuf *out) {
260
- int limit = 20, i = 0, pos = 0;
258
+static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
259
+ struct strbuf *out, int shortlog_len) {
260
+ int i = 0, pos = 0;
261
unsigned char head_sha1[20];
262
const char *current_branch;
263
@@ -288,7 +288,7 @@ static int do_fmt_merge_msg(int merge_title, int merge_summary,
288
if (merge_title)
289
do_fmt_merge_msg_title(out, current_branch);
290
291
- if (merge_summary) {
291
+ if (shortlog_len) {
292
struct commit *head;
293
struct rev_info rev;
294
@@ -303,17 +303,14 @@ static int do_fmt_merge_msg(int merge_title, int merge_summary,
303
304
for (i = 0; i < origins.nr; i++)
305
shortlog(origins.items[i].string, origins.items[i].util,
306
- head, &rev, limit, out);
306
+ head, &rev, shortlog_len, out);
307
}
308
return 0;
309
}
310
311
-int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) {
312
- return do_fmt_merge_msg(1, merge_summary, in, out);
313
-}
314
-
315
-int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out) {
316
- return do_fmt_merge_msg(0, 1, in, out);
311
+int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
312
+ int merge_title, int shortlog_len) {
313
+ return do_fmt_merge_msg(merge_title, in, out, shortlog_len);
314
}
315
316
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)
352
353
if (strbuf_read(&input, fileno(in), 0) < 0)
354
die_errno("could not read input file");
358
- if (message) {
355
+
356
+ if (message)
357
strbuf_addstr(&output, message);
360
- ret = fmt_merge_msg_shortlog(&input, &output);
361
- } else {
362
- ret = fmt_merge_msg(merge_summary, &input, &output);
363
- }
358
+ ret = fmt_merge_msg(&input, &output,
359
+ message ? 0 : 1,
360
+ merge_summary ? DEFAULT_MERGE_LOG_LEN : 0);
361
+
362
if (ret)
363
return ret;
364
write_in_full(STDOUT_FILENO, output.buf, output.len);
builtin/merge.c
+6
-8
@@ -998,14 +998,12 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
998
for (i = 0; i < argc; i++)
999
merge_name(argv[i], &merge_names);
1000
1001
- if (have_message && option_log)
1002
- fmt_merge_msg_shortlog(&merge_names, &merge_msg);
1003
- else if (!have_message)
1004
- fmt_merge_msg(option_log, &merge_names, &merge_msg);
1005
-
1006
-
1007
- if (!(have_message && !option_log) && merge_msg.len)
1008
- strbuf_setlen(&merge_msg, merge_msg.len-1);
1001
+ if (!have_message || option_log) {
1002
+ fmt_merge_msg(&merge_names, &merge_msg, !have_message,
1003
+ option_log ? DEFAULT_MERGE_LOG_LEN : 0);
1004
+ if (merge_msg.len)
1005
+ strbuf_setlen(&merge_msg, merge_msg.len - 1);
1006
+ }
1007
}
1008
1009
if (head_invalid || !argc)