git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/5] diff-merges: implement log.diffMerges-m-imply-p config

From
Sergey Organov <sorganov@gmail.com>
Date
Nov 27, 2022, 09:37 UTC
Message-ID
<20221127093721.31012-3-sorganov@gmail.com>
In-Reply-To
<20221127093721.31012-1-sorganov@gmail.com>

Historically, `-m` doesn't imply `-p` whereas similar `-c` and `--cc` options do. Simply fixing this inconsistency by unconditional modification of `-m` semantics appeared to be a bad idea, as it broke some legacy scripts.

Implement "log.diffMerges-m-imply-p" boolean configuration variable that allows user to enable implication of `-p` by `-m`.

Signed-off-by: Sergey Organov <sorganov@gmail.com>
---
 Documentation/config/log.txt   | 3 +++
 Documentation/diff-options.txt | 6 ++++--
 builtin/log.c                  | 2 ++
 diff-merges.c                  | 8 ++++++++
 diff-merges.h                  | 2 ++
 t/t4013-diff-various.sh        | 9 +++++++++
 t/t9902-completion.sh          | 3 +++
 7 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/Documentation/config/log.txt b/Documentation/config/log.txt
index 9c6be643bcf6..265a57312e58 100644
--- a/Documentation/config/log.txt
+++ b/Documentation/config/log.txt
@@ -40,6 +40,9 @@ diffs for merge commits when `-p` option is not used.
 log.diffMergesHide::
 	`true` implies `--diff-merges=hide` option.
 
+log.diffMerges-m-imply-p::
+	`true` enables implication of `-p` by `-m`.
+
 log.follow::
 	If `true`, `git log` will act as if the `--follow` option was used when
 	a single <path> is given.  This has the same limitations as `--follow`,
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 351d51215717..e64066af8d96 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -48,12 +48,14 @@ ifdef::git-log[]
 --diff-merges=on:::
 --diff-merges=m:::
 -m:::
-	This option makes diff output for merge commits to be shown in
+	These options make diff output for merge commits to be shown in
 	the default format. The default format could be changed using
 	`log.diffMerges` configuration parameter, which default value
 	is `separate`.
 +
-	`-m` is a shortcut for '--diff-merges=on --diff-merges=hide'
+	`-m` is a shortcut for '--diff-merges=on --diff-merges=hide'.
+	In addition it implies `-p` when `log.diffMerges-m-imply-p` is
+	active.
 +
 --diff-merges=first-parent:::
 --diff-merges=1:::
diff --git a/builtin/log.c b/builtin/log.c
index e031021e53b2..332b5e478cc5 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -583,6 +583,8 @@ static int git_log_config(const char *var, const char *value, void *cb)
 		return diff_merges_config(value);
 	if (!strcmp(var, "log.diffmergeshide"))
 		return diff_merges_hide_config(git_config_bool(var, value));
+	if (!strcmp(var, "log.diffmerges-m-imply-p"))
+		return diff_merges_m_imply_p_config(git_config_bool(var, value));
 	if (!strcmp(var, "log.showroot")) {
 		default_show_root = git_config_bool(var, value);
 		return 0;
diff --git a/diff-merges.c b/diff-merges.c
index 55fe5b70c102..1fbf476d378e 100644
--- a/diff-merges.c
+++ b/diff-merges.c
@@ -8,6 +8,7 @@ static void set_separate(struct rev_info *revs);
 static diff_merges_setup_func_t set_to_default = set_separate;
 static int suppress_m_parsing;
 static int hide = 0;
+static int m_imply_p = 0;
 
 static void suppress(struct rev_info *revs)
 {
@@ -143,6 +144,12 @@ int diff_merges_hide_config(int on)
 	return 0;
 }
 
+int diff_merges_m_imply_p_config(int on)
+{
+	m_imply_p = on;
+	return 0;
+}
+
 void diff_merges_suppress_m_parsing(void)
 {
 	suppress_m_parsing = 1;
@@ -157,6 +164,7 @@ int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
 	if (!suppress_m_parsing && !strcmp(arg, "-m")) {
 		set_to_default(revs);
 		set_hide(revs);
+		revs->merges_imply_patch = m_imply_p;
 	} else if (!strcmp(arg, "-c")) {
 		set_combined(revs);
 		revs->merges_imply_patch = 1;
diff --git a/diff-merges.h b/diff-merges.h
index e86e5381693b..9f0b3901fe82 100644
--- a/diff-merges.h
+++ b/diff-merges.h
@@ -13,6 +13,8 @@ int diff_merges_config(const char *value);
 
 int diff_merges_hide_config(int hide);
 
+int diff_merges_m_imply_p_config(int on);
+
 void diff_merges_suppress_m_parsing(void);
 
 int diff_merges_parse_opts(struct rev_info *revs, const char **argv);
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index 4fc8ba2fc59c..1789dd6063c5 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -548,6 +548,15 @@ test_expect_success 'git config log.diffMerges hide: has no effect on --cc' '
 	test_cmp expected actual
 '
 
+test_expect_success 'git config log.diffMerges-m-imply-p has proper effect' '
+	git log -m -p master >result &&
+	process_diffs result >expected &&
+	test_config log.diffMerges-m-imply-p true &&
+	git log -m master >result &&
+	process_diffs result >actual &&
+	test_cmp expected actual
+'
+
 # -m in "git diff-index" means "match missing", that differs
 # from its meaning in "git diff". Let's check it in diff-index.
 # The line in the output for removed file should disappear when
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index fc6b0722216a..26a7e4ff877c 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -2498,6 +2498,7 @@ test_expect_success 'git config - variable name' '
 	log.decorate Z
 	log.diffMerges Z
 	log.diffMergesHide Z
+	log.diffMerges-m-imply-p Z
 	EOF
 '
 
@@ -2527,6 +2528,7 @@ test_expect_success 'git -c - variable name' '
 	log.decorate=Z
 	log.diffMerges=Z
 	log.diffMergesHide=Z
+	log.diffMerges-m-imply-p=Z
 	EOF
 '
 
@@ -2550,6 +2552,7 @@ test_expect_success 'git clone --config= - variable name' '
 	log.decorate=Z
 	log.diffMerges=Z
 	log.diffMergesHide=Z
+	log.diffMerges-m-imply-p=Z
 	EOF
 '
 
-- 
2.37.3.526.g5f84746cb16b
Previous: Sergey OrganovNext: Sergey Organov
Message 5 of 39 in “diff-merges: more features”
  1. 0/5 diff-merges: more featuresSergey Organov, Nov 27, 2022
  2. 1/5 diff-merges: implement [no-]hide option and log.diffMergesHide configSergey Organov, Nov 27, 2022
  3. Glen ChooDec 8, 2022
  4. Sergey OrganovDec 8, 2022
  5. 2/5 diff-merges: implement log.diffMerges-m-imply-p configSergey Organov, Nov 27, 2022
  6. 3/5 diff-merges: implement log.diffMergesForce configSergey Organov, Nov 27, 2022
  7. Junio C HamanoNov 28, 2022
  8. Sergey OrganovNov 28, 2022
  9. Junio C HamanoNov 29, 2022
  10. Ævar Arnfjörð BjarmasonNov 29, 2022
  11. Sergey OrganovNov 30, 2022
  12. Junio C HamanoNov 30, 2022
  13. Jeff KingNov 29, 2022
  14. Sergey OrganovNov 30, 2022
  15. Elijah NewrenNov 29, 2022
  16. Sergey OrganovNov 30, 2022
  17. 4/5 diff-merges: support list of values for --diff-mergesSergey Organov, Nov 27, 2022
  18. 5/5 diff-merges: issue warning on lone '-m' optionSergey Organov, Nov 27, 2022
  19. Junio C HamanoNov 28, 2022
  20. Sergey OrganovNov 28, 2022
  21. Elijah NewrenNov 29, 2022
  22. Sergey OrganovNov 30, 2022
  23. Elijah NewrenDec 1, 2022
  24. Sergey OrganovDec 1, 2022
  25. Glen ChooDec 7, 2022
  26. Sergey OrganovDec 8, 2022
  27. Glen ChooDec 8, 2022
  28. Sergey OrganovDec 10, 2022
  29. Glen ChooDec 8, 2022
  30. Sergey OrganovDec 8, 2022
  31. 0/5 diff-merges: more features to fix '-m'Sergey Organov, Dec 17, 2022
  32. 1/5 diff-merges: implement [no-]hide option and log.diffMergesHide configSergey Organov, Dec 17, 2022
  33. 2/5 diff-merges: implement log.diffMerges-m-imply-p configSergey Organov, Dec 17, 2022
  34. 3/5 diff-merges: support list of values for --diff-mergesSergey Organov, Dec 17, 2022
  35. 4/5 diff-merges: issue warning on lone '-m' optionSergey Organov, Dec 17, 2022
  36. 5/5 diff-merges: improve --diff-merges documentationSergey Organov, Dec 17, 2022
  37. Junio C HamanoDec 18, 2022
  38. Sergey OrganovDec 19, 2022
  39. Sergey OrganovDec 19, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.