issue1420: hg diff -c <rev>

Stepan Koltsov yozh at mx1.ru
Mon Jan 12 15:38:44 CST 2009


Hi, guys,

Please, apply a patch for issue 1420: hg diff "--change <rev>" flag,
like SVN (repeating a message I've sent a month ago).

http://www.selenic.com/mercurial/bts/issue1420
http://www.selenic.com/mercurial/bts/file786/change.diff -- patch

===
diff -r 6aafd75fb924 mercurial/commands.py
--- a/mercurial/commands.py	Tue Dec 02 13:06:18 2008 -0600
+++ b/mercurial/commands.py	Wed Dec 17 14:42:52 2008 +0000
@@ -1007,7 +1007,15 @@ def diff(ui, repo, *pats, **opts):
     Use the --git option to generate diffs in the git extended diff
     format. Read the diffs help topic for more information.
     """
-    node1, node2 = cmdutil.revpair(repo, opts.get('rev'))
+    revopts = opts.get('rev')
+    changeopt = opts.get('change')
+    if revopts and changeopt:
+        raise util.Abort(_('cannot specify --rev and --change at the
same time'))
+    elif changeopt:
+        node2 = repo.lookup(changeopt)
+        node1 = repo[node2].parents()[0].node()
+    else:
+        node1, node2 = cmdutil.revpair(repo, revopts)

     m = cmdutil.match(repo, pats, opts)
     it = patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, opts))
@@ -3158,7 +3166,8 @@ table = {
     "debugwalk": (debugwalk, walkopts, _('[OPTION]... [FILE]...')),
     "^diff":
         (diff,
-         [('r', 'rev', [], _('revision'))
+         [('r', 'rev', [], _('revision')),
+          ('c', 'change', '', _('change made by revision'))
          ] + diffopts + diffopts2 + walkopts,
          _('[OPTION]... [-r REV1 [-r REV2]] [FILE]...')),
     "^export":
diff -r 6aafd75fb924 tests/test-diff-change
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-diff-change	Wed Dec 17 14:42:52 2008 +0000
@@ -0,0 +1,61 @@
+#!/bin/sh -e
+
+# test of hg diff --change
+
+set -e
+
+ec() {
+	echo "invoking $@:"
+	"$@"
+}
+
+hg init a
+cd a
+
+echo "first" > file.txt
+hg add file.txt
+hg commit -m 'first commit' # 0
+
+echo "second" > file.txt
+hg commit -m 'second commit' # 1
+
+echo "third" > file.txt
+hg commit -m 'third commit' # 2
+
+ec hg diff --nodates --change 1
+
+echo
+
+#rev=$(hg log -r 1 --template '{node|short}')
+rev=e9b286083166
+ec hg diff --nodates --change "$rev"
+
+##
+# Testing diff -c when merge
+
+for i in 1 2 3 4 5 6 7 8 9 10; do
+    echo $i >> file.txt
+done
+hg commit -m "lots of text" # 3
+
+sed -i -e 's,^2$,x,' file.txt
+hg commit -m "changed 2 to x" # 4
+
+hg up -r 3 > /dev/null 2>&1 # updated, merged, removed, unresolved
+sed -i -e 's,^8$,y,' file.txt
+hg commit -m "change 8 to y" > /dev/null 2>&1 # 5 # created new head
+
+hg up -C -r 4 > /dev/null 2>&1 # updated, merged, removed, unresolved
+hg merge -r 5 > /dev/null 2>&1 # updated, merged, removed, unresolved
+hg commit -m "merging 8 to y" # 6
+
+echo
+ec hg diff --nodates --change 6 # must be similar to hg diff
--nodates --change 5
+
+#echo
+#hg log
+
+echo
+echo "EOF"
+
+# vim: set ts=4 sw=4 et:
diff -r 6aafd75fb924 tests/test-diff-change.out
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-diff-change.out	Wed Dec 17 14:42:52 2008 +0000
@@ -0,0 +1,30 @@
+invoking hg diff --nodates --change 1:
+diff -r 4bb65dda5db4 -r e9b286083166 file.txt
+--- a/file.txt
++++ b/file.txt
+@@ -1,1 +1,1 @@
+-first
++second
+
+invoking hg diff --nodates --change e9b286083166:
+diff -r 4bb65dda5db4 -r e9b286083166 file.txt
+--- a/file.txt
++++ b/file.txt
+@@ -1,1 +1,1 @@
+-first
++second
+
+invoking hg diff --nodates --change 6:
+diff -r e8a0797e73a6 -r aa9873050139 file.txt
+--- a/file.txt
++++ b/file.txt
+@@ -6,6 +6,6 @@
+ 5
+ 6
+ 7
+-8
++y
+ 9
+ 10
+
+EOF
diff -r 6aafd75fb924 tests/test-help.out
--- a/tests/test-help.out	Tue Dec 02 13:06:18 2008 -0600
+++ b/tests/test-help.out	Wed Dec 17 14:42:52 2008 +0000
@@ -221,6 +221,7 @@ options:
 options:

  -r --rev                  revision
+ -c --change               change made by revision
  -a --text                 treat all files as text
  -g --git                  use git extended diff format
     --nodates              don't include dates in diff headers

===

s.


More information about the Mercurial-devel mailing list