Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial diff not working after move/rename

After moving a file into another directory I cannot display the differences between two revisions any more. E.g.:

hg init

touch a
hg add a
hg ci -m "Added a"

echo "Bli" >> a
hg ci -m "Bli"
echo "Bla" >> a
hg ci -m "Bla"
echo "Blub" >> a
hg ci -m "Blub"

hg diff -r 0 -r 1 a

Results in:

diff -r 8603b08f5a64 -r 16675581549e a
--- a/a Mon Apr 23 09:03:25 2012 +0000
+++ b/a Mon Apr 23 09:03:25 2012 +0000
@@ -0,0 +1,1 @@
+Bli

which is what I expected. However when I now move the file "a" into a directory "b":

mkdir b
hg mv a b/a
hg ci -m "Moved a into b"
cd b
hg diff -r 0 -r 1 a

this results into nothing (no output at all). I also tried to use the git Giff algo:

hg diff --git -r 0 -r 1 a

Again, there is no output at all. The log is seems to be OK:

hg log --follow a

Results in:

changeset:   4:cb8185829bfd
tag:         tip
user:        XXXXXXXXXXXXXXXXXXXXXXXXXXXX
date:        Mon Apr 23 09:08:12 2012 +0000
summary:     Moved a into b

changeset:   3:4d1ba89885c3
user:        XXXXXXXXXXXXXXXXXXXXXXXXXXXX
date:        Mon Apr 23 09:03:26 2012 +0000
summary:     Blub

changeset:   2:e9126dbb50b2
user:        XXXXXXXXXXXXXXXXXXXXXXXXXXXX
date:        Mon Apr 23 09:03:26 2012 +0000
summary:     Bla

changeset:   1:16675581549e
user:        XXXXXXXXXXXXXXXXXXXXXXXXXXXX
date:        Mon Apr 23 09:03:25 2012 +0000
summary:     Bli

changeset:   0:8603b08f5a64
user:        XXXXXXXXXXXXXXXXXXXXXXXXXXXX
date:        Mon Apr 23 09:03:25 2012 +0000
summary:     Added a

Has someone any idea why the diff is not working after moving a file? Your help is greatly appreciated.

like image 776
meisterplanlos Avatar asked Apr 23 '12 09:04

meisterplanlos


1 Answers

This is difficult or impossible with today's Mercurial. I think the closest you can get is

hg log --follow --patch -r 1 a

where Mercurial will track the copies backwards (--follow) before showing the diff (--patch).

In general, Mercurial does not track file identities, it only tracks file names. When you lookup information by revision number, Mercurial will first lookup the revision, and then lookup any filenames in that revision. So hg cat -r 0 a will give you the same result as

hg update -r 0
cat a

i.e., the result is independent of the current working directory parent.

like image 166
Martin Geisler Avatar answered Nov 14 '22 02:11

Martin Geisler