Skip to content

Commit 4285a98

Browse files
committed
Merge branch 'jk/log-fp-implies-m' into next
"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 bd87775 + 5fbb4bc commit 4285a98

9 files changed

+158
-55
lines changed

Documentation/diff-options.txt

Lines changed: 5 additions & 0 deletions
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

Lines changed: 41 additions & 2 deletions
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

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

builtin/log.c

Lines changed: 3 additions & 4 deletions
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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,7 @@ void repo_init_revisions(struct repository *r,
18171817

18181818
revs->repo = r;
18191819
revs->abbrev = DEFAULT_ABBREV;
1820-
revs->ignore_merges = 1;
1820+
revs->ignore_merges = -1;
18211821
revs->simplify_history = 1;
18221822
revs->pruning.repo = r;
18231823
revs->pruning.flags.recursive = 1;
@@ -2345,8 +2345,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
23452345
revs->diff = 1;
23462346
revs->diffopt.flags.recursive = 1;
23472347
revs->diffopt.flags.tree_in_recursive = 1;
2348-
} else if (!strcmp(arg, "-m")) {
2348+
} else if (!strcmp(arg, "-m") || !strcmp(arg, "--diff-merges")) {
23492349
revs->ignore_merges = 0;
2350+
} else if (!strcmp(arg, "--no-diff-merges")) {
2351+
revs->ignore_merges = 1;
23502352
} else if (!strcmp(arg, "-c")) {
23512353
revs->diff = 1;
23522354
revs->dense_combined_merges = 0;
@@ -2856,8 +2858,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
28562858
copy_pathspec(&revs->diffopt.pathspec,
28572859
&revs->prune_data);
28582860
}
2859-
if (revs->combine_merges)
2861+
if (revs->combine_merges && revs->ignore_merges < 0)
28602862
revs->ignore_merges = 0;
2863+
if (revs->ignore_merges < 0)
2864+
revs->ignore_merges = 1;
28612865
if (revs->combined_all_paths && !revs->combine_merges)
28622866
die("--combined-all-paths makes no sense without -c or --cc");
28632867

revision.h

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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
Lines changed: 78 additions & 0 deletions
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 <[email protected]>
5+
Date: Mon Jun 26 00:04:00 2006 +0000
6+
7+
Merge branch 'side'
8+
9+
commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
10+
Author: A U Thor <[email protected]>
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 <[email protected]>
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 <[email protected]>
75+
Date: Mon Jun 26 00:00:00 2006 +0000
76+
77+
Initial
78+
$

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

Lines changed: 22 additions & 0 deletions
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 <[email protected]>
1133
Date: Mon Jun 26 00:02:00 2006 +0000

0 commit comments

Comments
 (0)