Skip to content

Commit eca8c62

Browse files
committedAug 18, 2020
Merge branch 'jk/log-fp-implies-m'
"git log --first-parent -p" showed patches only for single-parent commits on the first-parent chain; the "--first-parent" option has been made to imply "-m". Use "--no-diff-merges" to restore the previous behaviour to omit patches for merge commits. * jk/log-fp-implies-m: doc/git-log: clarify handling of merge commit diffs doc/git-log: move "-t" into diff-options list doc/git-log: drop "-r" diff option doc/git-log: move "Diff Formatting" from rev-list-options log: enable "-m" automatically with "--first-parent" revision: add "--no-diff-merges" option to counteract "-m" log: drop "--cc implies -m" logic
2 parents e6ec620 + 5fbb4bc commit eca8c62

9 files changed

+158
-55
lines changed
 

‎Documentation/diff-options.txt

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ ifndef::git-format-patch[]
7373
Synonym for `-p --raw`.
7474
endif::git-format-patch[]
7575

76+
ifdef::git-log[]
77+
-t::
78+
Show the tree objects in the diff output.
79+
endif::git-log[]
80+
7681
--indent-heuristic::
7782
Enable the heuristic that shifts diff hunk boundaries to make patches
7883
easier to read. This is the default.

‎Documentation/git-log.txt

+41-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,47 @@ include::rev-list-options.txt[]
114114

115115
include::pretty-formats.txt[]
116116

117-
COMMON DIFF OPTIONS
118-
-------------------
117+
DIFF FORMATTING
118+
---------------
119+
120+
By default, `git log` does not generate any diff output. The options
121+
below can be used to show the changes made by each commit.
122+
123+
Note that unless one of `-c`, `--cc`, or `-m` is given, merge commits
124+
will never show a diff, even if a diff format like `--patch` is
125+
selected, nor will they match search options like `-S`. The exception is
126+
when `--first-parent` is in use, in which merges are treated like normal
127+
single-parent commits (this can be overridden by providing a
128+
combined-diff option or with `--no-diff-merges`).
129+
130+
-c::
131+
With this option, diff output for a merge commit
132+
shows the differences from each of the parents to the merge result
133+
simultaneously instead of showing pairwise diff between a parent
134+
and the result one at a time. Furthermore, it lists only files
135+
which were modified from all parents.
136+
137+
--cc::
138+
This flag implies the `-c` option and further compresses the
139+
patch output by omitting uninteresting hunks whose contents in
140+
the parents have only two variants and the merge result picks
141+
one of them without modification.
142+
143+
--combined-all-paths::
144+
This flag causes combined diffs (used for merge commits) to
145+
list the name of the file from all parents. It thus only has
146+
effect when -c or --cc are specified, and is likely only
147+
useful if filename changes are detected (i.e. when either
148+
rename or copy detection have been requested).
149+
150+
-m::
151+
--diff-merges::
152+
This flag makes the merge commits show the full diff like
153+
regular commits; for each merge parent, a separate log entry
154+
and diff is generated. An exception is that only diff against
155+
the first parent is shown when `--first-parent` option is given;
156+
in that case, the output represents the changes the merge
157+
brought _into_ the then-current branch.
119158

120159
:git-log: 1
121160
include::diff-options.txt[]

‎Documentation/rev-list-options.txt

-45
Original file line numberDiff line numberDiff line change
@@ -1116,48 +1116,3 @@ ifdef::git-rev-list[]
11161116
by a tab.
11171117
endif::git-rev-list[]
11181118
endif::git-shortlog[]
1119-
1120-
ifndef::git-shortlog[]
1121-
ifndef::git-rev-list[]
1122-
Diff Formatting
1123-
~~~~~~~~~~~~~~~
1124-
1125-
Listed below are options that control the formatting of diff output.
1126-
Some of them are specific to linkgit:git-rev-list[1], however other diff
1127-
options may be given. See linkgit:git-diff-files[1] for more options.
1128-
1129-
-c::
1130-
With this option, diff output for a merge commit
1131-
shows the differences from each of the parents to the merge result
1132-
simultaneously instead of showing pairwise diff between a parent
1133-
and the result one at a time. Furthermore, it lists only files
1134-
which were modified from all parents.
1135-
1136-
--cc::
1137-
This flag implies the `-c` option and further compresses the
1138-
patch output by omitting uninteresting hunks whose contents in
1139-
the parents have only two variants and the merge result picks
1140-
one of them without modification.
1141-
1142-
--combined-all-paths::
1143-
This flag causes combined diffs (used for merge commits) to
1144-
list the name of the file from all parents. It thus only has
1145-
effect when -c or --cc are specified, and is likely only
1146-
useful if filename changes are detected (i.e. when either
1147-
rename or copy detection have been requested).
1148-
1149-
-m::
1150-
This flag makes the merge commits show the full diff like
1151-
regular commits; for each merge parent, a separate log entry
1152-
and diff is generated. An exception is that only diff against
1153-
the first parent is shown when `--first-parent` option is given;
1154-
in that case, the output represents the changes the merge
1155-
brought _into_ the then-current branch.
1156-
1157-
-r::
1158-
Show recursive diffs.
1159-
1160-
-t::
1161-
Show the tree objects in the diff output. This implies `-r`.
1162-
endif::git-rev-list[]
1163-
endif::git-shortlog[]

‎builtin/log.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,8 @@ static int show_tree_object(const struct object_id *oid,
599599
static void show_setup_revisions_tweak(struct rev_info *rev,
600600
struct setup_revision_opt *opt)
601601
{
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 */
604604
rev->ignore_merges = 0;
605605
if (!rev->first_parent_only && !rev->combine_merges) {
606606
/* No "--first-parent", "-c", or "--cc" */
@@ -732,8 +732,7 @@ static void log_setup_revisions_tweak(struct rev_info *rev,
732732
if (!rev->diffopt.output_format && rev->combine_merges)
733733
rev->diffopt.output_format = DIFF_FORMAT_PATCH;
734734

735-
/* Turn -m on when --cc/-c was given */
736-
if (rev->combine_merges)
735+
if (rev->first_parent_only && rev->ignore_merges < 0)
737736
rev->ignore_merges = 0;
738737
}
739738

‎revision.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ void repo_init_revisions(struct repository *r,
18151815

18161816
revs->repo = r;
18171817
revs->abbrev = DEFAULT_ABBREV;
1818-
revs->ignore_merges = 1;
1818+
revs->ignore_merges = -1;
18191819
revs->simplify_history = 1;
18201820
revs->pruning.repo = r;
18211821
revs->pruning.flags.recursive = 1;
@@ -2343,8 +2343,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
23432343
revs->diff = 1;
23442344
revs->diffopt.flags.recursive = 1;
23452345
revs->diffopt.flags.tree_in_recursive = 1;
2346-
} else if (!strcmp(arg, "-m")) {
2346+
} else if (!strcmp(arg, "-m") || !strcmp(arg, "--diff-merges")) {
23472347
revs->ignore_merges = 0;
2348+
} else if (!strcmp(arg, "--no-diff-merges")) {
2349+
revs->ignore_merges = 1;
23482350
} else if (!strcmp(arg, "-c")) {
23492351
revs->diff = 1;
23502352
revs->dense_combined_merges = 0;
@@ -2854,8 +2856,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
28542856
copy_pathspec(&revs->diffopt.pathspec,
28552857
&revs->prune_data);
28562858
}
2857-
if (revs->combine_merges)
2859+
if (revs->combine_merges && revs->ignore_merges < 0)
28582860
revs->ignore_merges = 0;
2861+
if (revs->ignore_merges < 0)
2862+
revs->ignore_merges = 1;
28592863
if (revs->combined_all_paths && !revs->combine_merges)
28602864
die("--combined-all-paths makes no sense without -c or --cc");
28612865

‎revision.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ struct rev_info {
190190
show_root_diff:1,
191191
no_commit_id:1,
192192
verbose_header:1,
193-
ignore_merges:1,
194193
combine_merges:1,
195194
combined_all_paths:1,
196195
dense_combined_merges:1,
197196
always_show_header:1;
197+
int ignore_merges:2;
198198

199199
/* Format info */
200200
int show_notes;

‎t/t4013-diff-various.sh

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ log --root --patch-with-stat --summary master
297297
log --root -c --patch-with-stat --summary master
298298
# improved by Timo's patch
299299
log --root --cc --patch-with-stat --summary master
300+
log --no-diff-merges -p --first-parent master
300301
log -p --first-parent master
301302
log -m -p --first-parent master
302303
log -m -p master
Original file line numberDiff line numberDiff line change
@@ -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'
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+
$

‎t/t4013/diff.log_-p_--first-parent_master

+22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@ Date: Mon Jun 26 00:04:00 2006 +0000
66

77
Merge branch 'side'
88

9+
diff --git a/dir/sub b/dir/sub
10+
index cead32e..992913c 100644
11+
--- a/dir/sub
12+
+++ b/dir/sub
13+
@@ -4,3 +4,5 @@ C
14+
D
15+
E
16+
F
17+
+1
18+
+2
19+
diff --git a/file0 b/file0
20+
index b414108..10a8a9f 100644
21+
--- a/file0
22+
+++ b/file0
23+
@@ -4,3 +4,6 @@
24+
4
25+
5
26+
6
27+
+A
28+
+B
29+
+C
30+
931
commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
1032
Author: A U Thor <author@example.com>
1133
Date: Mon Jun 26 00:02:00 2006 +0000

0 commit comments

Comments
 (0)
Please sign in to comment.