]> git.ipfire.org Git - thirdparty/git.git/commitdiff
revision: add "--no-diff-merges" option to counteract "-m"
authorJeff King <peff@peff.net>
Wed, 29 Jul 2020 20:10:20 +0000 (16:10 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 29 Jul 2020 20:43:57 +0000 (13:43 -0700)
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>
Documentation/rev-list-options.txt
builtin/log.c
revision.c
revision.h
t/t4013-diff-various.sh
t/t4013/diff.log_--no-diff-merges_-p_--first-parent_master [new file with mode: 0644]

index b01b2b677303aeb2575a594c5af781e8391fae51..0785a0cfe91042ea63815dafa39f5dca6e25815d 100644 (file)
@@ -1148,6 +1148,7 @@ options may be given. See linkgit:git-diff-files[1] for more options.
        rename or copy detection have been requested).
 
 -m::
+--diff-merges::
        This flag makes the merge commits show the full diff like
        regular commits; for each merge parent, a separate log entry
        and diff is generated. An exception is that only diff against
index 281d2ae8eb176ecb3f5c0ffd7e82746a3895fd77..39b3d773a965574231b5815ca66477872cb3f0d6 100644 (file)
@@ -599,8 +599,8 @@ static int show_tree_object(const struct object_id *oid,
 static void show_setup_revisions_tweak(struct rev_info *rev,
                                       struct setup_revision_opt *opt)
 {
-       if (rev->ignore_merges) {
-               /* There was no "-m" on the command line */
+       if (rev->ignore_merges < 0) {
+               /* There was no "-m" variant on the command line */
                rev->ignore_merges = 0;
                if (!rev->first_parent_only && !rev->combine_merges) {
                        /* No "--first-parent", "-c", or "--cc" */
index 6aa7f4f56755bdc2b79455c61a9882085980f90a..669bc856694f9853b4067eb2027da4522fd6112e 100644 (file)
@@ -1795,7 +1795,7 @@ void repo_init_revisions(struct repository *r,
 
        revs->repo = r;
        revs->abbrev = DEFAULT_ABBREV;
-       revs->ignore_merges = 1;
+       revs->ignore_merges = -1;
        revs->simplify_history = 1;
        revs->pruning.repo = r;
        revs->pruning.flags.recursive = 1;
@@ -2323,8 +2323,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->diff = 1;
                revs->diffopt.flags.recursive = 1;
                revs->diffopt.flags.tree_in_recursive = 1;
-       } else if (!strcmp(arg, "-m")) {
+       } else if (!strcmp(arg, "-m") || !strcmp(arg, "--diff-merges")) {
                revs->ignore_merges = 0;
+       } else if (!strcmp(arg, "--no-diff-merges")) {
+               revs->ignore_merges = 1;
        } else if (!strcmp(arg, "-c")) {
                revs->diff = 1;
                revs->dense_combined_merges = 0;
@@ -2834,8 +2836,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
                        copy_pathspec(&revs->diffopt.pathspec,
                                      &revs->prune_data);
        }
-       if (revs->combine_merges)
+       if (revs->combine_merges && revs->ignore_merges < 0)
                revs->ignore_merges = 0;
+       if (revs->ignore_merges < 0)
+               revs->ignore_merges = 1;
        if (revs->combined_all_paths && !revs->combine_merges)
                die("--combined-all-paths makes no sense without -c or --cc");
 
index f412ae85ebafe0a1ecb8e2d7d2c56470682820ec..5258024743c11b28a6ea958bbca557f4df7dbedc 100644 (file)
@@ -190,11 +190,11 @@ struct rev_info {
                        show_root_diff:1,
                        no_commit_id:1,
                        verbose_header:1,
-                       ignore_merges:1,
                        combine_merges:1,
                        combined_all_paths:1,
                        dense_combined_merges:1,
                        always_show_header:1;
+       int             ignore_merges:2;
 
        /* Format info */
        int             show_notes;
index 43267d6024fb70110634314d664a885ea477053c..40e222c94520fd661cb66a5f8aaa4cf4499ed997 100755 (executable)
@@ -297,6 +297,7 @@ log --root --patch-with-stat --summary master
 log --root -c --patch-with-stat --summary master
 # improved by Timo's patch
 log --root --cc --patch-with-stat --summary master
+log --no-diff-merges -p --first-parent master
 log -p --first-parent master
 log -m -p --first-parent master
 log -m -p master
diff --git a/t/t4013/diff.log_--no-diff-merges_-p_--first-parent_master b/t/t4013/diff.log_--no-diff-merges_-p_--first-parent_master
new file mode 100644 (file)
index 0000000..94bf185
--- /dev/null
@@ -0,0 +1,78 @@
+$ git log --no-diff-merges -p --first-parent master
+commit 59d314ad6f356dd08601a4cd5e530381da3e3c64
+Merge: 9a6d494 c7a2ab9
+Author: A U Thor <author@example.com>
+Date:   Mon Jun 26 00:04:00 2006 +0000
+
+    Merge branch 'side' into master
+
+commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
+Author: A U Thor <author@example.com>
+Date:   Mon Jun 26 00:02:00 2006 +0000
+
+    Third
+
+diff --git a/dir/sub b/dir/sub
+index 8422d40..cead32e 100644
+--- a/dir/sub
++++ b/dir/sub
+@@ -2,3 +2,5 @@ A
+ B
+ C
+ D
++E
++F
+diff --git a/file1 b/file1
+new file mode 100644
+index 0000000..b1e6722
+--- /dev/null
++++ b/file1
+@@ -0,0 +1,3 @@
++A
++B
++C
+
+commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44
+Author: A U Thor <author@example.com>
+Date:   Mon Jun 26 00:01:00 2006 +0000
+
+    Second
+    
+    This is the second commit.
+
+diff --git a/dir/sub b/dir/sub
+index 35d242b..8422d40 100644
+--- a/dir/sub
++++ b/dir/sub
+@@ -1,2 +1,4 @@
+ A
+ B
++C
++D
+diff --git a/file0 b/file0
+index 01e79c3..b414108 100644
+--- a/file0
++++ b/file0
+@@ -1,3 +1,6 @@
+ 1
+ 2
+ 3
++4
++5
++6
+diff --git a/file2 b/file2
+deleted file mode 100644
+index 01e79c3..0000000
+--- a/file2
++++ /dev/null
+@@ -1,3 +0,0 @@
+-1
+-2
+-3
+
+commit 444ac553ac7612cc88969031b02b3767fb8a353a
+Author: A U Thor <author@example.com>
+Date:   Mon Jun 26 00:00:00 2006 +0000
+
+    Initial
+$