@matheusbsbs / matheus-bagliano / commits / 6fae74b418
Fork 0

revision: add "--no-diff-merges" option to counteract "-m"

The "-m" option sets revs->ignore_merges to "0", but there's no way to undo it. This probably isn't something anybody overly cares about, since "1" is already the default, but it will serve as an escape hatch when we flip the default for ignore_merges to "0" in more situations. We'll also add a few extra niceties: - initialize the value to "-1" to indicate "not set", and then resolve it to the normal 0/1 bool in setup_revisions(). This lets any tweak functions, as well as setup_revisions() itself, avoid clobbering the user's preference (which until now they couldn't actually express). - since we now have --no-diff-merges, let's add the matching --diff-merges, which is just a synonym for "-m". Then we don't even need to document --no-diff-merges separately; it countermands the long form of "-m" in the usual way. The new test shows that this behaves just the same as the current behavior without "-m". Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 29, 2020 at 16:10 UTC 6fae74b418da05a80897487805c833fd0b253df3
6 files changed +90 -6
Documentation/rev-list-options.txt
+1
@@ -1148,6 +1148,7 @@ options may be given. See linkgit:git-diff-files[1] for more options.
1148 rename or copy detection have been requested).
1149
1150 -m::
1151 +--diff-merges::
1152 This flag makes the merge commits show the full diff like
1153 regular commits; for each merge parent, a separate log entry
1154 and diff is generated. An exception is that only diff against
builtin/log.c
+2 -2
@@ -599,8 +599,8 @@ static int show_tree_object(const struct object_id *oid,
599 static void show_setup_revisions_tweak(struct rev_info *rev,
600 struct setup_revision_opt *opt)
601 {
602 - if (rev->ignore_merges) {
603 - /* There was no "-m" on the command line */
602 + if (rev->ignore_merges < 0) {
603 + /* There was no "-m" variant on the command line */
604 rev->ignore_merges = 0;
605 if (!rev->first_parent_only && !rev->combine_merges) {
606 /* No "--first-parent", "-c", or "--cc" */
revision.c
+7 -3
@@ -1795,7 +1795,7 @@ void repo_init_revisions(struct repository *r,
1795
1796 revs->repo = r;
1797 revs->abbrev = DEFAULT_ABBREV;
1798 - revs->ignore_merges = 1;
1798 + revs->ignore_merges = -1;
1799 revs->simplify_history = 1;
1800 revs->pruning.repo = r;
1801 revs->pruning.flags.recursive = 1;
@@ -2323,8 +2323,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
2323 revs->diff = 1;
2324 revs->diffopt.flags.recursive = 1;
2325 revs->diffopt.flags.tree_in_recursive = 1;
2326 - } else if (!strcmp(arg, "-m")) {
2326 + } else if (!strcmp(arg, "-m") || !strcmp(arg, "--diff-merges")) {
2327 revs->ignore_merges = 0;
2328 + } else if (!strcmp(arg, "--no-diff-merges")) {
2329 + revs->ignore_merges = 1;
2330 } else if (!strcmp(arg, "-c")) {
2331 revs->diff = 1;
2332 revs->dense_combined_merges = 0;
@@ -2834,8 +2836,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
2836 copy_pathspec(&revs->diffopt.pathspec,
2837 &revs->prune_data);
2838 }
2837 - if (revs->combine_merges)
2839 + if (revs->combine_merges && revs->ignore_merges < 0)
2840 revs->ignore_merges = 0;
2841 + if (revs->ignore_merges < 0)
2842 + revs->ignore_merges = 1;
2843 if (revs->combined_all_paths && !revs->combine_merges)
2844 die("--combined-all-paths makes no sense without -c or --cc");
2845
revision.h
+1 -1
@@ -190,11 +190,11 @@ struct rev_info {
190 show_root_diff:1,
191 no_commit_id:1,
192 verbose_header:1,
193 - ignore_merges:1,
193 combine_merges:1,
194 combined_all_paths:1,
195 dense_combined_merges:1,
196 always_show_header:1;
197 + int ignore_merges:2;
198
199 /* Format info */
200 int show_notes;
t/t4013-diff-various.sh
+1
@@ -297,6 +297,7 @@ log --root --patch-with-stat --summary master
297 log --root -c --patch-with-stat --summary master
298 # improved by Timo's patch
299 log --root --cc --patch-with-stat --summary master
300 +log --no-diff-merges -p --first-parent master
301 log -p --first-parent master
302 log -m -p --first-parent master
303 log -m -p master
t/t4013/diff.log_--no-diff-merges_-p_--first-parent_master new
+78
@@ -0,0 +1,78 @@
1 +$ git log --no-diff-merges -p --first-parent master
2 +commit 59d314ad6f356dd08601a4cd5e530381da3e3c64
3 +Merge: 9a6d494 c7a2ab9
4 +Author: A U Thor <author@example.com>
5 +Date: Mon Jun 26 00:04:00 2006 +0000
6 +
7 + Merge branch 'side' into master
8 +
9 +commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
10 +Author: A U Thor <author@example.com>
11 +Date: Mon Jun 26 00:02:00 2006 +0000
12 +
13 + Third
14 +
15 +diff --git a/dir/sub b/dir/sub
16 +index 8422d40..cead32e 100644
17 +--- a/dir/sub
18 ++++ b/dir/sub
19 +@@ -2,3 +2,5 @@ A
20 + B
21 + C
22 + D
23 ++E
24 ++F
25 +diff --git a/file1 b/file1
26 +new file mode 100644
27 +index 0000000..b1e6722
28 +--- /dev/null
29 ++++ b/file1
30 +@@ -0,0 +1,3 @@
31 ++A
32 ++B
33 ++C
34 +
35 +commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44
36 +Author: A U Thor <author@example.com>
37 +Date: Mon Jun 26 00:01:00 2006 +0000
38 +
39 + Second
40 +
41 + This is the second commit.
42 +
43 +diff --git a/dir/sub b/dir/sub
44 +index 35d242b..8422d40 100644
45 +--- a/dir/sub
46 ++++ b/dir/sub
47 +@@ -1,2 +1,4 @@
48 + A
49 + B
50 ++C
51 ++D
52 +diff --git a/file0 b/file0
53 +index 01e79c3..b414108 100644
54 +--- a/file0
55 ++++ b/file0
56 +@@ -1,3 +1,6 @@
57 + 1
58 + 2
59 + 3
60 ++4
61 ++5
62 ++6
63 +diff --git a/file2 b/file2
64 +deleted file mode 100644
65 +index 01e79c3..0000000
66 +--- a/file2
67 ++++ /dev/null
68 +@@ -1,3 +0,0 @@
69 +-1
70 +-2
71 +-3
72 +
73 +commit 444ac553ac7612cc88969031b02b3767fb8a353a
74 +Author: A U Thor <author@example.com>
75 +Date: Mon Jun 26 00:00:00 2006 +0000
76 +
77 + Initial
78 +$