Bug 2816 - diff --stat marks empty files binary
Summary: diff --stat marks empty files binary
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: All All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-19 05:24 UTC by Antoine Pitrou
Modified: 2012-05-13 04:55 UTC (History)
6 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Antoine Pitrou 2011-05-19 05:24 UTC
$ touch a
$ hg ci -A -m "add a"
ajout de a
$ hg di -c tip 
diff --git a/a b/a
new file mode 100644
$ hg di -c tip --stat
 a |  Bin 
 1 files changed, 0 insertions(+), 0 deletions(-)
Comment 1 Idan Kamara 2011-05-20 05:58 UTC
What do we want the output here to be? Changing it to:

 a |  0
 0 files changed, 0 insertions(+), 0 deletions(-)

Doesn't seem right.

There was a similar thread on the git mailing list a while back: 
http://git.661346.n2.nabble.com/quot-git-diff-stat-quot-doesn-t-show-added-
empty-file-td2143867.html

Also I played with --stat some more and it seems it doesn't play nice with 
other "non-content file changes" such as renames and mode changes.

Continuing on your example:

$ hg mv a b
$ hg ci -m "rename"
$ hg di -g -c tip --stat
 a |  Bin 
 1 files changed, 0 insertions(+), 0 deletions(-)

And there seems to be another minor issue here and that's the files changed 
count. I'm not sure file creations count as file changes (diffstat(1) agrees 
on this).

I'll open new issues for these.
Comment 2 Antoine Pitrou 2011-05-20 08:03 UTC
> What do we want the output here to be? Changing it to:
> 
>  a |  0
>  0 files changed, 0 insertions(+), 0 deletions(-)
> 
> Doesn't seem right.

It would be fine with me. After all the file *is* empty.

The issue I have with the "Bin" marking is that it gives a piece of
false information: these files are not binary and are not handled as
such by hg.
Comment 3 Éric Araujo 2011-10-22 19:51 UTC
> It would be fine with me. After all the file *is* empty.
With me too, as long as we could get “1 file changed” instead of 0.

> Also I played with --stat some more and it seems it doesn't play nice with
> other "non-content file changes" such as renames and mode changes.
Maybe the command could say “n other changes” or something similar.  Is this
important enough than I should open a bug?
Comment 4 Patrick Mézard 2011-10-24 05:52 UTC
I have sent a patch about this:

  http://www.selenic.com/pipermail/mercurial-devel/2011-October/035197.html

It does not really address empty files but instead mark as binary only files
touched by binary hunks (from git or regular diffs). It means the stat
reported will still be weird for renames/copies/mode changes but these
require a format extension I guess and should be addressed in another issue.
Comment 5 HG Bot 2011-10-26 13:00 UTC
Fixed by http://selenic.com/repo/hg/rev/628a4a9e411d
Patrick Mezard <pmezard@gmail.com>
diffstat: be more picky when marking file as 'binary' (issue2816)

(please test the fix)
Comment 6 Bugzilla 2012-05-12 09:20 UTC

--- Bug imported by bugzilla@serpentine.com 2012-05-12 09:20 EDT  ---

This bug was previously known as _bug_ 2816 at http://mercurial.selenic.com/bts/issue2816