Subject: Re: wishlist bugreport: make limit configurable for do_fmt_merge_msg (merge.log)

From: Jonathan Nieder <[email-masked]>
Date: Fri, 20 Aug 2010 03:16:41 -0500

Ramkumar Ramachandra wrote:

>     fmt-merge-msg: Make the number of log entries in shortlog configurable
>     
>     Introduce a new configuration option called merge.logLimit to limit
>     the number of log entries displayed in the shortlog of a merge commit
>     configurable. Set the default value to 20.

Neat.  Sign-off?

> +++ b/builtin/fmt-merge-msg.c
> @@ -22,6 +23,8 @@ static int fmt_merge_msg_config(const char *key, const char *value, void *cb)
>  	}
>  	if (!found_merge_log && !strcmp("merge.summary", key))
>  		merge_summary = git_config_bool(key, value);
> +	if (!strcmp("merge.logLimit", key))
> +		log_limit = git_config_int(key, value);

Maybe something like the following would be good on top (or maybe not;
you decide).

-- 8< --
Subject: fmt-merge-msg --log-limit to override merge.loglimit configuration

Yes, one can already use "git -c merge.loglimit=n fmt-merge-msg", but
maybe providing an option name makes it more obvious that this can
be overridden on the command-line.

This also provides --log-limit=0 / "[merge] loglimit = 0" to not limit
the number of commits summarized at all, which I would expect to
be the most interesting case.  So you can use
"git fmt-merge-msg --log-limit=0" in your scripts to get a message
like

	Merge branch 'long-topic'

	 * log-topic:
	   commit 1
	   commit 2
[...]
	   commit 1001
	   commit 1002

and not to limit the number of commits summarized at all.

This patch does not propagate the option from "git merge" yet.

Signed-off-by: Jonathan Nieder <[email-masked]>
---
Also untested.  I still haven't figured out the context where this
would be most useful, just thought it sounded like a fun idea.

diff --git a/Documentation/git-fmt-merge-msg.txt b/Documentation/git-fmt-merge-msg.txt
index a585dbe..3066392 100644
--- a/Documentation/git-fmt-merge-msg.txt
+++ b/Documentation/git-fmt-merge-msg.txt
@@ -9,8 +9,8 @@ git-fmt-merge-msg - Produce a merge commit message
 SYNOPSIS
 --------
 [verse]
-'git fmt-merge-msg' [--log | --no-log] <$GIT_DIR/FETCH_HEAD
-'git fmt-merge-msg' [--log | --no-log] -F <file>
+'git fmt-merge-msg' [--log | --no-log] [--log-limit=<n>] <$GIT_DIR/FETCH_HEAD
+'git fmt-merge-msg' [--log | --no-log] [--log-limit=<n>] -F <file>
 
 DESCRIPTION
 -----------
@@ -38,6 +38,11 @@ OPTIONS
 	Synonyms to --log and --no-log; these are deprecated and will be
 	removed in the future.
 
+--log-limit <n>::
+	Truncate --log output after <n> lines, instead of 20.  This
+	overrides the merge.loglimit configuration.  If <n> is 0,
+	do not truncate --log output at all.
+
 -F <file>::
 --file <file>::
 	Take the list of merged objects from <file> instead of
@@ -54,6 +59,11 @@ merge.summary::
 	Synonym to `merge.log`; this is deprecated and will be removed in
 	the future.
 
+merge.loglimit::
+	How many commits (at maximum) to print from each merge
+	parent when the `--log` option is used.  The default is 20.
+	Can be overridden by the `--log-limit` option.
+
 SEE ALSO
 --------
 linkgit:git-merge[1]
diff --git a/Documentation/merge-config.txt b/Documentation/merge-config.txt
index a403155..fd861b8 100644
--- a/Documentation/merge-config.txt
+++ b/Documentation/merge-config.txt
@@ -10,6 +10,11 @@ merge.log::
 	Whether to include summaries of merged commits in newly created
 	merge commit messages. False by default.
 
+merge.loglimit::
+	How many merged commits to summarize in the merge message if
+	`--log` is used.  The default is 20.  See also
+	linkgit:git-fmt-merge-msg[1].
+
 merge.renameLimit::
 	The number of files to consider when performing rename detection
 	during a merge; if not specified, defaults to the value of
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 2c1d15b..e1aefa7 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -7,7 +7,7 @@
 #include "string-list.h"
 
 static const char * const fmt_merge_msg_usage[] = {
-	"git fmt-merge-msg [--log|--no-log] [--file <file>]",
+	"git fmt-merge-msg [--log|--no-log] [--log-limit=<num>] [--file <file>]",
 	NULL
 };
 
@@ -172,7 +172,7 @@ static void shortlog(const char *name, unsigned char *sha1,
 			continue;
 
 		count++;
-		if (subjects.nr > log_limit)
+		if (log_limit && subjects.nr > log_limit)
 			continue;
 
 		format_commit_message(commit, "%s", &sb, &ctx);
@@ -185,13 +185,13 @@ static void shortlog(const char *name, unsigned char *sha1,
 			string_list_append(&subjects, strbuf_detach(&sb, NULL));
 	}
 
-	if (count > log_limit)
+	if (log_limit && count > log_limit)
 		strbuf_addf(out, "\n* %s: (%d commits)\n", name, count);
 	else
 		strbuf_addf(out, "\n* %s:\n", name);
 
 	for (i = 0; i < subjects.nr; i++)
-		if (i >= log_limit)
+		if (log_limit && i >= log_limit)
 			strbuf_addf(out, "  ...\n");
 		else
 			strbuf_addf(out, "  %s\n", subjects.items[i].string);
@@ -327,6 +327,8 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
 		{ OPTION_BOOLEAN, 0, "summary", &merge_summary, NULL,
 		  "alias for --log (deprecated)",
 		  PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
+		OPT_INTEGER(0, "log-limit", &log_limit,
+			"truncate shortlog after <n> lines (0 for no limit)"),
 		OPT_FILENAME('F', "file", &inpath, "file to read from"),
 		OPT_END()
 	};
--