[Bug 4146] New: `hg diff -b` behaves differently than `diff -b`

mercurial-bugs at selenic.com mercurial-bugs at selenic.com
Wed Jan 15 00:44:18 CST 2014


http://bz.selenic.com/show_bug.cgi?id=4146

          Priority: normal
            Bug ID: 4146
                CC: mercurial-devel at selenic.com
          Assignee: bugzilla at selenic.com
           Summary: `hg diff -b` behaves differently than `diff -b`
          Severity: bug
    Classification: Unclassified
                OS: Linux
          Reporter: g.gherdovich at gmail.com
          Hardware: All
            Status: UNCONFIRMED
           Version: 2.7.2
         Component: Mercurial
           Product: Mercurial

When comparing two versions of a file with `hg diff -b`,
and the two versions are identical except for the newline at the end
(missing in one of the two), mercurial still asserts that
the last line is removed [-] and added [+].

GNU diff, instead, will say that the two files are identical
(provided the `-b` flag).

I wander if this is the desired behaviour for `hg diff`
or if it should follow what `diff -u` does.

To be more clear (here I use both "-b" and "-w" flags, just in case):

===================================================
$ python -c "f=open('foo','w'); f.write('foo')"
$ hg init ; hg add foo ; hg commit -m foo
$ python -c "f=open('foo','w'); f.write('foo\n')"

$ hg diff foo
diff -r 9d171fe0bed2 foo
--- a/foo    Wed Jan 15 07:14:45 2014 +0100
+++ b/foo    Wed Jan 15 07:15:13 2014 +0100
@@ -1,1 +1,1 @@
-foo
\ No newline at end of file
+foo

$ hg diff -b foo
diff -r 9d171fe0bed2 foo
--- a/foo    Wed Jan 15 07:14:45 2014 +0100
+++ b/foo    Wed Jan 15 07:15:31 2014 +0100
@@ -1,1 +1,1 @@
-foo
\ No newline at end of file
+foo

$ hg diff -w foo
diff -r 9d171fe0bed2 foo
--- a/foo    Wed Jan 15 07:14:45 2014 +0100
+++ b/foo    Wed Jan 15 07:15:41 2014 +0100
@@ -1,1 +1,1 @@
-foo
\ No newline at end of file
+foo
===================================================

you can see that the line is signaled as removed and added.

GNU diff on the other hand:

===================================================
$ python -c "f=open('foo1','w'); f.write('foo')"
$ python -c "f=open('foo2','w'); f.write('foo\n')"
$ diff -u foo1 foo2
--- foo1    2014-01-15 07:18:48.856967899 +0100
+++ foo2    2014-01-15 07:19:03.328967757 +0100
@@ -1 +1 @@
-foo
\ No newline at end of file
+foo
$ diff -b foo1 foo2
$ diff -w foo1 foo2
$ 
===================================================

Also: if somebody can explain me the differnce between the flags
"-b" (ignore changes in the amount of white space) and
"-w" (ignore white space when comparing lines).
I must be missing something obvious, but I cannot think of an example
which will pass one diff and not the other.

F.A.Q.: "What are you trying to do?"

I am writing a tool that works like `hg annotate` but on
"conflicted files", the ones containing the >>>>> <<<<<< markers
after `hg merge --tool=internal:merge`.
For each line in a conflicted region I want to know what is
the last revision that touched it (so that I know who to call to resolve the
merge).
For that, I run `hg annotate` on both sides of the merge and
then map the annotation on the conflicted file using `hg diff`.
If a line that never moved is marked as added & removed
because of the missing newline (added by the merge tool),
my strategy gets confused. I hoped that `hg diff -b` could fix that but...

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Mercurial-devel mailing list