Skip to contentSkip to conversation

combined diff, but not condensed, howto?

PATCH In review Johannes Sixt 2 participants 9 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

After a merge conflict, 'git diff' shows a combined diff, which presents only the parts that conflicted or where there are near-by changes from different parents (potential conflicts). Is there a command line switch so that *all* changes are shown, even non-conflicting ones?

'git diff', 'git diff --cc', and 'git diff -c' all show the same output.

-- Hannes

#1 lore raw
Quoted 4 lines · Johannes Sixt

After a merge conflict, 'git diff' shows a combined diff, which presents only the parts that conflicted or where there are near-by changes from different parents (potential conflicts). Is there a command line switch so that *all* changes are shown, even non-conflicting ones?

Like "git diff HEAD"?

#2 lore raw
Quoted 8 lines · Junio C Hamano
Quoted 4 lines · Johannes Sixt

After a merge conflict, 'git diff' shows a combined diff, which presents only the parts that conflicted or where there are near-by changes from different parents (potential conflicts). Is there a command line switch so that *all* changes are shown, even non-conflicting ones?

Like "git diff HEAD"?

No. Something that produces

@@@ -23,5 -23,5 +23,7 @@@
A
B
++<<<<<<< HEAD:foo
+C
++=======
+ D
++>>>>>>> 97d7fee2cb068f215a593c6e5623b265db45d3bc:foo
E
F
@@@ -50,4 -50,5 +53,5 @@@
G
H
+I
J
K
@@@ -60,5 -61,4 +63,4 @@@
L
M
- N
O
P

#3 lore raw
Quoted 11 lines · Johannes Sixt
Quoted 8 lines · Junio C Hamano
Quoted 4 lines · Johannes Sixt

After a merge conflict, 'git diff' shows a combined diff, which presents only the parts that conflicted or where there are near-by changes from different parents (potential conflicts). Is there a command line switch so that *all* changes are shown, even non-conflicting ones?

Like "git diff HEAD"?

No. Something that produces

...

Ah, I see what you mean.

It all happens inside combine-diff.c::make_hunks(). If you pass dense==0, you should be able to get all the uninteresting hunks, I think.

Perhaps

	$ git diff --base -c

???

#4 lore raw
Quoted 13 lines · Junio C Hamano
Quoted 9 lines · Johannes Sixt
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · Johannes Sixt

After a merge conflict, 'git diff' shows a combined diff, which presents only the parts that conflicted or where there are near-by changes from different parents (potential conflicts). Is there a command line switch so that *all* changes are shown, even non-conflicting ones?

Like "git diff HEAD"?

No. Something that produces

...

Quoted 8 lines

Ah, I see what you mean.

It all happens inside combine-diff.c::make_hunks(). If you pass dense==0, you should be able to get all the uninteresting hunks, I think.

Perhaps

	$ git diff --base -c

Yes, that does it!

Thanks,
-- Hannes

#5 lore raw
Quoted 10 lines · Johannes Sixt

Junio C Hamano schrieb:
...

Quoted 6 lines

It all happens inside combine-diff.c::make_hunks(). If you pass dense==0, you should be able to get all the uninteresting hunks, I think.

Perhaps

	$ git diff --base -c

Yes, that does it!

It may do so, but I do not necessarily agree with the logic.

It is very much Ok and useful for "git diff" to default to "--cc -p", and it may be fine for "git diff-files -p" to default to "--cc".

But I think ideally an explicit "git diff -c" and "git diff-files -c -p" should not turn the "dense combined" mode on.

The commonality of these two functions is striking and calls for proper refactoring, but aside from that, I think a patch like this should be applied. What do you think?

---

 builtin-diff-files.c |    7 ++++++-
 builtin-diff.c       |    7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
builtin-diff-files.c +6 -1
index 9bf10bb..2b578c7 100644
@@ -50,7 +50,12 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
 	    3 < rev.max_count)
 		usage(diff_files_usage);
 
-	if (rev.max_count == -1 &&
+	/*
+	 * "diff-files --base -p" should not combine merges because it
+	 * was not asked to.  "diff-files -c -p" should not densify
+	 * (the user should ask with "diff-files --cc" explicitly).
+	 */
+	if (rev.max_count == -1 && !rev.combine_merges &&
 	    (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
 		rev.combine_merges = rev.dense_combined_merges = 1;
 
builtin-diff.c +6 -1
index 037c303..9fb30c6 100644
@@ -223,7 +223,12 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
 		argv++; argc--;
 	}
 
-	if (revs->max_count == -1 &&
+	/*
+	 * "diff --base" should not combine merges because it was not
+	 * asked to.  "diff -c" should not densify (the user should ask
+	 * with "diff --cc" explicitly.
+	 */
+	if (revs->max_count == -1 && !revs->combine_merges &&
 	    (revs->diffopt.output_format & DIFF_FORMAT_PATCH))
 		revs->combine_merges = revs->dense_combined_merges = 1;
 
#6 lore raw
Quoted 9 lines · Junio C Hamano

It is very much Ok and useful for "git diff" to default to "--cc -p", and it may be fine for "git diff-files -p" to default to "--cc".

But I think ideally an explicit "git diff -c" and "git diff-files -c -p" should not turn the "dense combined" mode on.

The commonality of these two functions is striking and calls for proper refactoring, but aside from that, I think a patch like this should be applied. What do you think?

This makes a lot of sense. As I mention in my initial post, I was wondering why 'diff -c' was the same as 'diff --cc'.

Quoted 7 lines
builtin-diff-files.c +0 -0
index 9bf10bb..2b578c7 100644
@@ -50,7 +50,12 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
 	    3 < rev.max_count)
 		usage(diff_files_usage);

builtin-diff-files.c int cmd_diff_files(int argc, const char **argv, const char *prefix) · line 60

Quoted 10 lines
builtin-diff-files.c +6 -1
 
-	if (rev.max_count == -1 &&
+	/*
+	 * "diff-files --base -p" should not combine merges because it
+	 * was not asked to.  "diff-files -c -p" should not densify
+	 * (the user should ask with "diff-files --cc" explicitly).
+	 */
+	if (rev.max_count == -1 && !rev.combine_merges &&
 	    (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
 		rev.combine_merges = rev.dense_combined_merges = 1;

Hm... In my tests, a bare 'git diff-files --cc' produces a combined diff, but 'git diff-files -c' does not.

builtin-diff.c static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv · line 229

Quoted 13 lines
builtin-diff.c +4 -1
index 037c303..9fb30c6 100644
@@ -223,7 +223,12 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
 		argv++; argc--;
 	}
 
-	if (revs->max_count == -1 &&
+	/*
+	 * "diff --base" should not combine merges because it was not
+	 * asked to.  "diff -c" should not densify (the user should ask
+	 * with "diff --cc" explicitly.

I don't see why you add "the user should ask with 'diff --cc'" when this becomes the default anyway.

builtin-diff.c static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv · line 233

Quoted 4 lines
builtin-diff.c +2 -0
+	 */
+	if (revs->max_count == -1 && !revs->combine_merges &&
 	    (revs->diffopt.output_format & DIFF_FORMAT_PATCH))
 		revs->combine_merges = revs->dense_combined_merges = 1;

-- Hannes

#7 lore raw

PATCH 1/1 diff/diff-files: do not use --cc too aggressively

Textual diff output for unmerged paths was too eager to give condensed combined diff. This has two problems:

(1) "diff --base/--ours/--theirs" (and "diff-files -p" with the same) is a request to compare with the named stage. We showed "-c -p" output instead;

(2) "diff -c" (and "diff-files -c -p") is a request to view combined diff without condensing (otherwise the user would have explicitly asked for --cc, not -c). We showed "--cc" output anyway.

0fe7c1d (built-in diff: assorted updates, 2006-04-29) claimed to be careful about doing this, but its breakage was hidden because back then "git diff" was still a shell script that did not use the codepath it introduced fully.

---
 builtin-diff-files.c |    7 ++++++-
 builtin-diff.c       |    8 +++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)
builtin-diff-files.c +6 -1
index 9bf10bb..2b578c7 100644
@@ -50,7 +50,12 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
 	    3 < rev.max_count)
 		usage(diff_files_usage);
 
-	if (rev.max_count == -1 &&
+	/*
+	 * "diff-files --base -p" should not combine merges because it
+	 * was not asked to.  "diff-files -c -p" should not densify
+	 * (the user should ask with "diff-files --cc" explicitly).
+	 */
+	if (rev.max_count == -1 && !rev.combine_merges &&
 	    (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
 		rev.combine_merges = rev.dense_combined_merges = 1;
 
builtin-diff.c +7 -1
index 037c303..d5fe775 100644
@@ -223,7 +223,13 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
 		argv++; argc--;
 	}
 
-	if (revs->max_count == -1 &&
+	/*
+	 * "diff --base" should not combine merges because it was not
+	 * asked to.  "diff -c" should not densify (if the user wants
+	 * dense one, --cc can be explicitly asked for, or just rely
+	 * on the default).
+	 */
+	if (revs->max_count == -1 && !revs->combine_merges &&
 	    (revs->diffopt.output_format & DIFF_FORMAT_PATCH))
 		revs->combine_merges = revs->dense_combined_merges = 1;
 
Signature · 1 line
1.6.0.2.412.g0bc80
author Tested-by on v1 1/1
#8 lore raw

Re: [PATCH] diff/diff-files: do not use --cc too aggressively

Quoted 6 lines · Junio C Hamano

Textual diff output for unmerged paths was too eager to give condensed combined diff. This has two problems:

(1) "diff --base/--ours/--theirs" (and "diff-files -p" with the same) is a request to compare with the named stage. We showed "-c -p" output instead;

I cannot reproduce what you describe here. "diff --base/--ours/--theirs" works as expected with and without this patch.

Quoted 3 lines

(2) "diff -c" (and "diff-files -c -p") is a request to view combined diff without condensing (otherwise the user would have explicitly asked for --cc, not -c). We showed "--cc" output anyway.

The patch fixes this:

-- Hannes