changeset 7628:9c6ae2e09e11

diff: add --change option to display single changeset diff (issue1420)
author Stepan Koltsov <yozh@mx1.ru>
date Tue, 13 Jan 2009 10:44:16 +0100
parents fb32ae9c76e7
children 97253bcb44a8
files mercurial/commands.py tests/test-diff-change tests/test-diff-change.out tests/test-help.out
diffstat 4 files changed, 106 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Sat Jan 03 17:15:21 2009 +0100
+++ b/mercurial/commands.py	Tue Jan 13 10:44:16 2009 +0100
@@ -1015,7 +1015,18 @@
     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'))
+
+    revs = opts.get('rev')
+    change = opts.get('change')
+
+    if revs and change:
+        msg = _('cannot specify --rev and --change at the same time')
+        raise util.Abort(msg)
+    elif change:
+        node2 = repo.lookup(change)
+        node1 = repo[node2].parents()[0].node()
+    else:
+        node1, node2 = cmdutil.revpair(repo, revs)
 
     m = cmdutil.match(repo, pats, opts)
     it = patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, opts))
@@ -3172,7 +3183,8 @@
     "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":
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-diff-change	Tue Jan 13 10:44:16 2009 +0100
@@ -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:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-diff-change.out	Tue Jan 13 10:44:16 2009 +0100
@@ -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
--- a/tests/test-help.out	Sat Jan 03 17:15:21 2009 +0100
+++ b/tests/test-help.out	Tue Jan 13 10:44:16 2009 +0100
@@ -221,6 +221,7 @@
 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