git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Counter-intuitive result from diff -C --stat
@ 2016-12-28  8:09 Mike Hommey
  2017-01-01  1:15 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Hommey @ 2016-12-28  8:09 UTC (permalink / raw
  To: git

Hi,

So I was checking out differences between two branches, accounting for
file moves with -C, and was surprised by the number of insertions and
deletions that it indicated, because it was telling me I had removed
more than I added, which I really don't think is true.

I took a closer look, and what happens is that I had a lot of stuff in
a __init__.py file that I moved to another file, while keeping a now
new, empty, __init__.py file.

Which means while diff counts the deletions from __init__.py, it doesn't
count the additions from the move because it is a move, leading to a
counter-intuitive result.

Here's how to reproduce in case code makes more sense than prose:

/tmp$ git init g
Initialized empty Git repository in /tmp/g/.git/
/tmp$ cd g
/tmp/g$ echo foo > foo
/tmp/g$ git add foo
/tmp/g$ git commit -m foo
[master (root-commit) 14749a7] foo
 1 file changed, 1 insertion(+)
 create mode 100644 foo
/tmp/g$ git mv foo bar
/tmp/g$ touch foo
/tmp/g$ git add foo
/tmp/g$ git commit -m bar
[master 9fbf50e] bar
 2 files changed, 1 insertion(+), 1 deletion(-)
 create mode 100644 bar
/tmp/g$ git diff HEAD~ -C --stat
 foo => bar | 0
 foo        | 1 -
 2 files changed, 1 deletion(-)

I'm actually not sure what the right thing would be. I guess this is a
case where -B should help, but it doesn't.

Any thoughts?

Mike

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Counter-intuitive result from diff -C --stat
  2016-12-28  8:09 Counter-intuitive result from diff -C --stat Mike Hommey
@ 2017-01-01  1:15 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2017-01-01  1:15 UTC (permalink / raw
  To: Mike Hommey; +Cc: git

Mike Hommey <mh@glandium.org> writes:

> Hi,
>
> So I was checking out differences between two branches, accounting for
> file moves with -C, and was surprised by the number of insertions and
> deletions that it indicated, because it was telling me I had removed
> more than I added, which I really don't think is true.
>
> I took a closer look, and what happens is that I had a lot of stuff in
> a __init__.py file that I moved to another file, while keeping a now
> new, empty, __init__.py file.
>
> Which means while diff counts the deletions from __init__.py, it doesn't
> count the additions from the move because it is a move, leading to a
> counter-intuitive result.

Intuition is in the eyes of observer.  

A pairing of the original and the result you saw might be not very
useful (which I have no opinion on), but in the context of the
chosen pairing of the original and the result, in order to produce
the final result, you started from a copy of the original and
removed quite a lot while adding just a bit, so what you saw was an
outcome that was deliberately designed.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-01-01  1:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-28  8:09 Counter-intuitive result from diff -C --stat Mike Hommey
2017-01-01  1:15 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).