threads / discuss / 15564

combined diff, but not condensed, howto?

Subject: combined diff, but not condensed, howto?

## tl;dr

9 messages between Sep 17, 2008 and Sep 18, 2008.

replies: 8people: 2as markdown or json

Johannes Sixt· Sep 17, 2008, 08:00 UTC · lore

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
Junio C Hamano· Sep 17, 2008, 16:58 UTC · re: Johannes Sixt · lore

Re: combined diff, but not condensed, howto?

Johannes Sixt <j.sixt@viscovery.net> writes:
> 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"?
Johannes Sixt· Sep 18, 2008, 05:57 UTC · re: Junio C Hamano · lore

Re: combined diff, but not condensed, howto?

Junio C Hamano schrieb:
Show 8 quoted lines
> Johannes Sixt <j.sixt@viscovery.net> writes:
> 
>> 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
Junio C Hamano· Sep 18, 2008, 06:14 UTC · re: Johannes Sixt · lore

Re: combined diff, but not condensed, howto?

Johannes Sixt <j.sixt@viscovery.net> writes:
Show 11 quoted lines
> Junio C Hamano schrieb:
>> Johannes Sixt <j.sixt@viscovery.net> writes:
>> 
>>> 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
???
Johannes Sixt· Sep 18, 2008, 06:24 UTC · re: Junio C Hamano · lore

Re: combined diff, but not condensed, howto?

Junio C Hamano schrieb:
Show 21 quoted lines
> Johannes Sixt <j.sixt@viscovery.net> writes:
> 
>> Junio C Hamano schrieb:
>>> Johannes Sixt <j.sixt@viscovery.net> writes:
>>>
>>>> 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
Yes, that does it!

Thanks, -- Hannes

Junio C Hamano· Sep 18, 2008, 07:01 UTC · re: Johannes Sixt · lore

Re: combined diff, but not condensed, howto?

Johannes Sixt <j.sixt@viscovery.net> writes:
Show 10 quoted lines
> Junio C Hamano schrieb:
> ...
>> 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(-)
diff --git i/builtin-diff-files.c w/builtin-diff-files.c
index 9bf10bb..2b578c7 100644
--- i/builtin-diff-files.c
+++ w/builtin-diff-files.c
@@ -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;
 
diff --git i/builtin-diff.c w/builtin-diff.c
index 037c303..9fb30c6 100644
--- i/builtin-diff.c
+++ w/builtin-diff.c
@@ -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;
 
Johannes Sixt· Sep 18, 2008, 07:30 UTC · re: Junio C Hamano · lore

Re: combined diff, but not condensed, howto?

Junio C Hamano schrieb:
Show 9 quoted lines
> 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'.

Show 17 quoted lines
> diff --git i/builtin-diff-files.c w/builtin-diff-files.c
> index 9bf10bb..2b578c7 100644
> --- i/builtin-diff-files.c
> +++ w/builtin-diff-files.c
> @@ -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;

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

Show 13 quoted lines
> diff --git i/builtin-diff.c w/builtin-diff.c
> index 037c303..9fb30c6 100644
> --- i/builtin-diff.c
> +++ w/builtin-diff.c
> @@ -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.

> +	 */
> +	if (revs->max_count == -1 && !revs->combine_merges &&
>  	    (revs->diffopt.output_format & DIFF_FORMAT_PATCH))
>  		revs->combine_merges = revs->dense_combined_merges = 1;
-- Hannes
Junio C Hamano· Sep 18, 2008, 09:08 UTC · re: Johannes Sixt · lore

[PATCH] 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.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-diff-files.c |    7 ++++++-
 builtin-diff.c       |    8 +++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/builtin-diff-files.c b/builtin-diff-files.c
index 9bf10bb..2b578c7 100644
--- a/builtin-diff-files.c
+++ b/builtin-diff-files.c
@@ -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;
 
diff --git a/builtin-diff.c b/builtin-diff.c
index 037c303..d5fe775 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -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;
 
-- 
1.6.0.2.412.g0bc80
Johannes Sixt· Sep 18, 2008, 09:30 UTC · re: Junio C Hamano · lore

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

Junio C Hamano schrieb:
Show 6 quoted lines
> 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.

>  (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:
Tested-by: Johannes Sixt <johannes.sixt@telecom.at>
-- Hannes

← back to recent threads