issue1420: hg diff -c <rev>

Stepan Koltsov yozh at mx1.ru
Thu Dec 11 18:42:30 CST 2008


Hi, all.

some time ago I've created second version of patch for --change flag
for diff subcommand ( http://www.selenic.com/mercurial/bts/issue1420
).

Could someone, please, either apply patch, close issue as "won't fix",
or tell me what's wrong with current patch?

===
diff -r 6aafd75fb924 mercurial/commands.py
--- a/mercurial/commands.py	Tue Dec 02 13:06:18 2008 -0600
+++ b/mercurial/commands.py	Tue Dec 09 14:53:05 2008 +0000
@@ -1007,7 +1007,17 @@
     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')
+    changeopts = opts.get('change')
+    if revopts and changeopts:
+        raise util.Abort(_('cannot specify --rev and --change at the
same time'))
+    elif len(changeopts) > 1:
+        raise util.Abort(_('change can be specified no more then once'))
+    elif changeopts:
+        node2 = repo.lookup(changeopts[0])
+        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 +3168,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":
diff -r 6aafd75fb924 tests/test-diff-change
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-diff-change	Tue Dec 09 14:53:05 2008 +0000
@@ -0,0 +1,25 @@
+#!/bin/sh -e
+
+# test of hg diff --change
+
+hg init a
+cd a
+
+echo hello > file.txt
+hg add file.txt
+hg commit -m 'first commit'
+
+echo "hello world" > file.txt
+hg commit -m 'second commit'
+
+echo "hello again" > file.txt
+hg commit -m 'second commit'
+
+hg diff --nodates --change 1
+
+echo "1234567890"
+
+#rev=$(hg log -r 1 --template '{node|short}')
+rev=24232fce71e3
+hg diff --nodates --change "$rev"
+
diff -r 6aafd75fb924 tests/test-diff-change.out
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-diff-change.out	Tue Dec 09 14:53:05 2008 +0000
@@ -0,0 +1,13 @@
+diff -r d96daf400f63 -r 24232fce71e3 file.txt
+--- a/file.txt
++++ b/file.txt
+@@ -1,1 +1,1 @@
+-hello
++hello world
+1234567890
+diff -r d96daf400f63 -r 24232fce71e3 file.txt
+--- a/file.txt
++++ b/file.txt
+@@ -1,1 +1,1 @@
+-hello
++hello world
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	Tue Dec 09 14:53:05 2008 +0000
@@ -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
===

S.


More information about the Mercurial-devel mailing list