# combined diff, but not condensed, howto?

9 messages from 2008-09-17 to 2008-09-18. Participants: Johannes Sixt, Junio C Hamano.
Thread: https://gitlist.dev/t/15564

## Johannes Sixt, 2008-09-17 08:00

Subject: combined diff, but not condensed, howto?
Message-ID: <48D0B907.7040903@viscovery.net>
URL: https://gitlist.dev/e/48D0B907.7040903%40viscovery.net

```
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, 2008-09-17 16:58

Subject: Re: combined diff, but not condensed, howto?
Message-ID: <7vwsha6761.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vwsha6761.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <48D0B907.7040903@viscovery.net>

```
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, 2008-09-18 05:57

Subject: Re: combined diff, but not condensed, howto?
Message-ID: <48D1EDB7.5070107@viscovery.net>
URL: https://gitlist.dev/e/48D1EDB7.5070107%40viscovery.net
In-Reply-To: <7vwsha6761.fsf@gitster.siamese.dyndns.org>

```
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

@@@ -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, 2008-09-18 06:14

Subject: Re: combined diff, but not condensed, howto?
Message-ID: <7vy71qyo9d.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vy71qyo9d.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <48D1EDB7.5070107@viscovery.net>

```
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

???

```

## Johannes Sixt, 2008-09-18 06:24

Subject: Re: combined diff, but not condensed, howto?
Message-ID: <48D1F426.4040208@viscovery.net>
URL: https://gitlist.dev/e/48D1F426.4040208%40viscovery.net
In-Reply-To: <7vy71qyo9d.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano schrieb:
> 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, 2008-09-18 07:01

Subject: Re: combined diff, but not condensed, howto?
Message-ID: <7vskryym24.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vskryym24.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <48D1F426.4040208@viscovery.net>

```
Johannes Sixt <j.sixt@viscovery.net> writes:

> 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, 2008-09-18 07:30

Subject: Re: combined diff, but not condensed, howto?
Message-ID: <48D203B3.90807@viscovery.net>
URL: https://gitlist.dev/e/48D203B3.90807%40viscovery.net
In-Reply-To: <7vskryym24.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano schrieb:
> 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'.

> 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.

> 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, 2008-09-18 09:08

Subject: [PATCH] diff/diff-files: do not use --cc too aggressively
Message-ID: <7v7i99zuqh.fsf_-_@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v7i99zuqh.fsf_-_%40gitster.siamese.dyndns.org
In-Reply-To: <48D203B3.90807@viscovery.net>

```
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, 2008-09-18 09:30

Subject: Re: [PATCH] diff/diff-files: do not use --cc too aggressively
Message-ID: <48D21FB2.50700@viscovery.net>
URL: https://gitlist.dev/e/48D21FB2.50700%40viscovery.net
In-Reply-To: <7v7i99zuqh.fsf_-_@gitster.siamese.dyndns.org>

```
Junio C Hamano schrieb:
> 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

```
