[PATCH] status: add the --change option to display files changed in a revision

Gilles Moris gilles.moris at free.fr
Mon Nov 30 16:52:36 CST 2009


 mercurial/commands.py        |  16 ++++++++++++++--
 tests/test-debugcomplete.out |   2 +-
 tests/test-help.out          |   4 +++-
 tests/test-status            |  23 +++++++++++++++++++++++
 tests/test-status.out        |  19 +++++++++++++++++++
 5 files changed, 60 insertions(+), 4 deletions(-)


# HG changeset patch
# User Gilles Moris <gilles.moris at free.fr>
# Date 1259621466 -3600
# Node ID 814b7c14731aef542e3d1e86bb2cc79602f99a2c
# Parent  2059be77d4f8e33c7746f493f3f9edeee37a0d26
status: add the --change option to display files changed in a revision

This option is similar to the one already used for the diff command.
Unfortunately, the c and C short option are already used for status, so there
is no corresponding short option. However, there is no short option for --rev
either, so that's consistent.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2842,7 +2842,7 @@
 
     If one revision is given, it is used as the base revision.
     If two revisions are given, the differences between them are
-    shown.
+    shown. The --change option can also be used as a shortcut.
 
     The codes used to show the status of files are::
 
@@ -2856,7 +2856,18 @@
         = origin of the previous file listed as A (added)
     """
 
-    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)
+
     cwd = (pats and repo.getcwd()) or ''
     end = opts.get('print0') and '\0' or '\n'
     copy = {}
@@ -3660,6 +3671,7 @@
           ('0', 'print0', None,
            _('end filenames with NUL, for use with xargs')),
           ('', 'rev', [], _('show difference from revision')),
+          ('', 'change', '', _('change made by revision')),
          ] + walkopts,
          _('[OPTION]... [FILE]...')),
     "tag":
diff --git a/tests/test-debugcomplete.out b/tests/test-debugcomplete.out
--- a/tests/test-debugcomplete.out
+++ b/tests/test-debugcomplete.out
@@ -177,7 +177,7 @@
 push: force, rev, ssh, remotecmd
 remove: after, force, include, exclude
 serve: accesslog, daemon, daemon-pipefds, errorlog, port, address, prefix, name, webdir-conf, pid-file, stdio, templates, style, ipv6, certificate
-status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, copies, print0, rev, include, exclude
+status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, copies, print0, rev, change, include, exclude
 summary: remote
 update: clean, check, date, rev
 addremove: similarity, include, exclude, dry-run
diff --git a/tests/test-help.out b/tests/test-help.out
--- a/tests/test-help.out
+++ b/tests/test-help.out
@@ -270,7 +270,8 @@
     parent.
 
     If one revision is given, it is used as the base revision. If two
-    revisions are given, the differences between them are shown.
+    revisions are given, the differences between them are shown. The --change
+    option can also be used as a shortcut.
 
     The codes used to show the status of files are:
 
@@ -297,6 +298,7 @@
  -C --copies     show source of copied files
  -0 --print0     end filenames with NUL, for use with xargs
     --rev        show difference from revision
+    --change     change made by revision
  -I --include    include names matching the given patterns
  -X --exclude    exclude names matching the given patterns
 
diff --git a/tests/test-status b/tests/test-status
--- a/tests/test-status
+++ b/tests/test-status
@@ -91,4 +91,27 @@
 assert "-q" "-u"         1
 assert "-m" "-a"         1
 assert "-r" "-d"         1
+cd ..
 
+hg init repo4
+cd repo4
+touch modified removed deleted
+hg ci -q -A -m 'initial checkin' -d "1000000 0"
+touch added unknown
+hg add added
+hg remove removed
+rm deleted
+echo x > modified
+hg copy modified copied
+hg ci -m 'test checkin' -d "1000001 0"
+rm *
+touch unrelated
+hg ci -q -A -m 'unrelated checkin' -d "1000002 0"
+echo "hg status --change 1:"
+hg status --change 1
+echo "hg status --change 1 unrelated:"
+hg status --change 1 unrelated
+echo "hg status -C --change 1 added modified copied removed deleted:"
+hg status -C --change 1 added modified copied removed deleted
+echo "hg status -A --change 1"
+hg status -A --change 1
diff --git a/tests/test-status.out b/tests/test-status.out
--- a/tests/test-status.out
+++ b/tests/test-status.out
@@ -124,3 +124,22 @@
 adding deleted
 adding modified
 adding removed
+hg status --change 1:
+M modified
+A added
+A copied
+R removed
+hg status --change 1 unrelated:
+hg status -C --change 1 added modified copied removed deleted:
+M modified
+A added
+A copied
+  modified
+R removed
+hg status -A --change 1
+M modified
+A added
+A copied
+  modified
+R removed
+C deleted


More information about the Mercurial-devel mailing list