Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In mercurial, how to see diff between in a merge changeset and one parent without changes from the other parent?

Tags:

mercurial

Consider this trivial repo:

mkdir temp
cd temp
hg init
echo abc > file1
hg ci -A -m init
echo def >> file1
echo hey > file2
hg ci -A -m A
hg up -r0
echo ghi >> file1
echo hey > file3
hg ci -A -m B
hg merge
hg ci -m merge

During merge, take "ghi" (doesn't really matter which side).

The DAG is:

0 - 2 - 3
 \- 1 -/

hg diff -r1:3 shows file1 change and new file3.

hg diff -r2:3 shows new file2. Same for hg log -p -r3 and hg st --change 3, because 2 is the first parent.

My question is: how can I see the changes between 1 and 3 minus the changes in 2, which is conceptually d(1:3) - d(0:2)?

I expect to see only file1 change. hg log -r3 -v only shows "files: file1" (I guess because it's the only file in the change ctx), but curiously, hg log -r3 --debug also shows "files+: file2".

If I run hg view (provided by the bundled hgk extension) and click on r3, it shows only file1. I can't read tcl/tk code, but it seems like the trick is in a contmergediff function where it gets the list of files in a merge, in which it somehow omits file2.

FWIW, TortoiseHg is different from all of the above: clicking on r3 shows "M file1" and "A file2" in the file list, but shows no actual change in file1. Click "Other Parent" shows "M file1" and "A file3", which is the same as "diff -r1:3".

A real world use case is this: r1 is mine, and r2 is a colleague's. Earlier, the colleague reviewed r1 (diff 0:1), but he didn't merge it before asking for review of r2. So I reviewed r2 (diff 0:2), and later he did the merge. Then when I see diff 1:3, I have to forget about that I've ever reviewed r2. If the merge diff is small, I can just use hgk. But if it's big, I really need to see it in vdiff.


(UPDATE) Now there's a mergediff extension. If someone tries and finds it work, please add an answer.

like image 879
Geoffrey Zheng Avatar asked Dec 01 '10 21:12

Geoffrey Zheng


1 Answers

Here's a guess (though I'm not sure if it really does what you want). The command

$ hg log --template {files} -r <merge-revision>

lists the files, which have been changed by a merge. This output could be used as a list of files for the diff command, to show only the changes you're interested in.

Applied to your example, the following should show what the merge did with your contributions in revision 1:

$ hg diff -r 1:3 $(hg log --template '{files}' -r 3)
diff --git a/file1 b/file1
--- a/file1
+++ b/file1
@@ -1,2 +1,2 @@
 abc
-def
+ghi

Similarly, the command below should show you how the merge affected your colleague's changes in revision 2:

$ hg diff -r 2:3 $(hg log --template '{files}' -r 3)
# no output, since your colleague decided to keep her *ghi*
like image 164
Oben Sonne Avatar answered Oct 05 '22 06:10

Oben Sonne