merge: Make '--log' an integer option for number of shortlog entries
Change the command-line '--log' option from a boolean option to an integer option, and parse the optional integer provided on the command-line into the 'shortlog_len' variable. Also update the documentation accordingly. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Reported-by: Yaroslav Halchenko <debian@onerussian.com> Thanks-to: Jonathan Nieder <jrnieder@gmail.com> Thanks-to: Johannes Sixt <j.sixt@viscovery.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ramkumar Ramachandra committed
Sep 8, 2010 at 23:29 UTC
96e9420cd357728949571b42eb0249881ae3a78e
4 files changed
+37
-24
Documentation/git-fmt-merge-msg.txt
+6
-4
@@ -9,8 +9,8 @@ git-fmt-merge-msg - Produce a merge commit message
9
SYNOPSIS
10
--------
11
[verse]
12
-'git fmt-merge-msg' [-m <message>] [--log | --no-log] <$GIT_DIR/FETCH_HEAD
13
-'git fmt-merge-msg' [-m <message>] [--log | --no-log] -F <file>
12
+'git fmt-merge-msg' [-m <message>] [--log[=<n>] | --no-log] <$GIT_DIR/FETCH_HEAD
13
+'git fmt-merge-msg' [-m <message>] [--log[=<n>] | --no-log] -F <file>
14
15
DESCRIPTION
16
-----------
@@ -24,10 +24,12 @@ automatically invoking 'git merge'.
24
OPTIONS
25
-------
26
27
---log::
27
+--log[=<n>]::
28
In addition to branch names, populate the log message with
29
one-line descriptions from the actual commits that are being
30
- merged.
30
+ merged. At most <n> commits from each merge parent will be
31
+ used (20 if <n> is omitted). This overrides the `merge.log`
32
+ configuration variable.
33
34
--no-log::
35
Do not list one-line descriptions from the actual commits being
Documentation/merge-options.txt
+3
-3
@@ -16,11 +16,11 @@ inspect and further tweak the merge result before committing.
16
With --no-ff Generate a merge commit even if the merge
17
resolved as a fast-forward.
18
19
---log::
19
+--log[=<n>]::
20
--no-log::
21
In addition to branch names, populate the log message with
22
- one-line descriptions from the actual commits that are being
23
- merged.
22
+ one-line descriptions from at most <n> actual commits that are being
23
+ merged. See also linkgit:git-fmt-merge-msg[1].
24
+
25
With --no-log do not list one-line descriptions from the
26
actual commits being merged.
builtin/fmt-merge-msg.c
+18
-10
@@ -7,21 +7,24 @@
7
#include "string-list.h"
8
9
static const char * const fmt_merge_msg_usage[] = {
10
- "git fmt-merge-msg [-m <message>] [--log|--no-log] [--file <file>]",
10
+ "git fmt-merge-msg [-m <message>] [--log[=<n>]|--no-log] [--file <file>]",
11
NULL
12
};
13
14
-static int merge_summary;
14
+static int shortlog_len;
15
16
static int fmt_merge_msg_config(const char *key, const char *value, void *cb)
17
{
18
static int found_merge_log = 0;
19
if (!strcmp("merge.log", key)) {
20
found_merge_log = 1;
21
- merge_summary = git_config_bool(key, value);
21
+ shortlog_len = git_config_bool(key, value) ? DEFAULT_MERGE_LOG_LEN : 0;
22
+ return 0;
23
+ }
24
+ if (!found_merge_log && !strcmp("merge.summary", key)) {
25
+ shortlog_len = git_config_bool(key, value) ? DEFAULT_MERGE_LOG_LEN : 0;
26
+ return 0;
27
}
23
- if (!found_merge_log && !strcmp("merge.summary", key))
24
- merge_summary = git_config_bool(key, value);
28
return 0;
29
}
30
@@ -318,10 +321,13 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
321
const char *inpath = NULL;
322
const char *message = NULL;
323
struct option options[] = {
321
- OPT_BOOLEAN(0, "log", &merge_summary, "populate log with the shortlog"),
322
- { OPTION_BOOLEAN, 0, "summary", &merge_summary, NULL,
324
+ { OPTION_INTEGER, 0, "log", &shortlog_len, "n",
325
+ "populate log with at most <n> entries from shortlog",
326
+ PARSE_OPT_OPTARG, NULL, DEFAULT_MERGE_LOG_LEN },
327
+ { OPTION_INTEGER, 0, "summary", &shortlog_len, "n",
328
"alias for --log (deprecated)",
324
- PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
329
+ PARSE_OPT_OPTARG | PARSE_OPT_HIDDEN, NULL,
330
+ DEFAULT_MERGE_LOG_LEN },
331
OPT_STRING('m', "message", &message, "text",
332
"use <text> as start of message"),
333
OPT_FILENAME('F', "file", &inpath, "file to read from"),
@@ -337,12 +343,14 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
343
0);
344
if (argc > 0)
345
usage_with_options(fmt_merge_msg_usage, options);
340
- if (message && !merge_summary) {
346
+ if (message && !shortlog_len) {
347
char nl = '\n';
348
write_in_full(STDOUT_FILENO, message, strlen(message));
349
write_in_full(STDOUT_FILENO, &nl, 1);
350
return 0;
351
}
352
+ if (shortlog_len < 0)
353
+ die("Negative --log=%d", shortlog_len);
354
355
if (inpath && strcmp(inpath, "-")) {
356
in = fopen(inpath, "r");
@@ -357,7 +365,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
365
strbuf_addstr(&output, message);
366
ret = fmt_merge_msg(&input, &output,
367
message ? 0 : 1,
360
- merge_summary ? DEFAULT_MERGE_LOG_LEN : 0);
368
+ shortlog_len);
369
370
if (ret)
371
return ret;
builtin/merge.c
+10
-7
@@ -42,7 +42,7 @@ static const char * const builtin_merge_usage[] = {
42
NULL
43
};
44
45
-static int show_diffstat = 1, option_log, squash;
45
+static int show_diffstat = 1, shortlog_len, squash;
46
static int option_commit = 1, allow_fast_forward = 1;
47
static int fast_forward_only;
48
static int allow_trivial = 1, have_message;
@@ -175,8 +175,9 @@ static struct option builtin_merge_options[] = {
175
OPT_BOOLEAN(0, "stat", &show_diffstat,
176
"show a diffstat at the end of the merge"),
177
OPT_BOOLEAN(0, "summary", &show_diffstat, "(synonym to --stat)"),
178
- OPT_BOOLEAN(0, "log", &option_log,
179
- "add list of one-line log to merge commit message"),
178
+ { OPTION_INTEGER, 0, "log", &shortlog_len, "n",
179
+ "add (at most <n>) entries from shortlog to merge commit message",
180
+ PARSE_OPT_OPTARG, NULL, DEFAULT_MERGE_LOG_LEN },
181
OPT_BOOLEAN(0, "squash", &squash,
182
"create a single commit instead of doing a merge"),
183
OPT_BOOLEAN(0, "commit", &option_commit,
@@ -501,8 +502,10 @@ static int git_merge_config(const char *k, const char *v, void *cb)
502
return git_config_string(&pull_twohead, k, v);
503
else if (!strcmp(k, "pull.octopus"))
504
return git_config_string(&pull_octopus, k, v);
504
- else if (!strcmp(k, "merge.log") || !strcmp(k, "merge.summary"))
505
- option_log = git_config_bool(k, v);
505
+ else if (!strcmp(k, "merge.log") || !strcmp(k, "merge.summary")) {
506
+ shortlog_len = git_config_bool(k, v) ? DEFAULT_MERGE_LOG_LEN : 0;
507
+ return 0;
508
+ }
509
return git_diff_ui_config(k, v, cb);
510
}
511
@@ -998,9 +1001,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1001
for (i = 0; i < argc; i++)
1002
merge_name(argv[i], &merge_names);
1003
1001
- if (!have_message || option_log) {
1004
+ if (!have_message || shortlog_len) {
1005
fmt_merge_msg(&merge_names, &merge_msg, !have_message,
1003
- option_log ? DEFAULT_MERGE_LOG_LEN : 0);
1006
+ shortlog_len);
1007
if (merge_msg.len)
1008
strbuf_setlen(&merge_msg, merge_msg.len - 1);
1009
}