identify: accept a revision argument
authorMatt Mackall <mpm@selenic.com>
Thu, 21 Jun 2007 11:54:11 -0500
changeset 4665 091c9e54d306
parent 4664 dedb8abfd0e1
child 4666 48c94bffdb28
identify: accept a revision argument
mercurial/commands.py
tests/test-globalopts.out
tests/test-help.out
--- a/mercurial/commands.py	Thu Jun 21 11:42:39 2007 -0500
+++ b/mercurial/commands.py	Thu Jun 21 11:54:11 2007 -0500
@@ -1432,32 +1432,36 @@
             else:
                 ui.write("%s\n" % first)
 
-def identify(ui, repo):
-    """print information about the working copy
-
-    Print a short summary of the current state of the repo.
+def identify(ui, repo, rev=None):
+    """identify the working copy or specified revision
+
+    With no argument, print a summary of the current state of the repo.
 
     This summary identifies the repository state using one or two parent
     hash identifiers, followed by a "+" if there are uncommitted changes
-    in the working directory, followed by a list of tags for this revision.
+    in the working directory, a list of tags for this revision and a branch
+    name for non-default branches.
     """
 
     hexfunc = ui.debugflag and hex or short
 
-    wctx = repo.workingctx()
-    parents = wctx.parents()
-    changed = wctx.files() + wctx.deleted()
-
-    output = ["%s%s" % ('+'.join([hexfunc(p.node()) for p in parents]),
-                        (changed) and "+" or "")]
+    if not rev:
+        ctx = repo.workingctx()
+        parents = ctx.parents()
+        changed = ctx.files() + ctx.deleted()
+        output = ["%s%s" % ('+'.join([hexfunc(p.node()) for p in parents]),
+                            (changed) and "+" or "")]
+    else:
+        ctx = repo.changectx(rev)
+        output = [hexfunc(ctx.node())]
 
     if not ui.quiet:
-        branch = util.tolocal(wctx.branch())
+        branch = util.tolocal(ctx.branch())
         if branch != 'default':
             output.append("(%s)" % branch)
 
         # multiple tags for a single parent separated by '/'
-        tags = "/".join(wctx.tags())
+        tags = "/".join(ctx.tags())
         if tags:
             output.append(tags)
 
@@ -2821,7 +2825,10 @@
           ('', 'template', '', _('display with template'))],
          _('hg heads [-r REV] [REV]...')),
     "help": (help_, [], _('hg help [COMMAND]')),
-    "identify|id": (identify, [], _('hg identify')),
+    "identify|id":
+        (identify,
+         [('r', 'rev', '', _('identify the specified rev'))],
+         _('hg identify [-r REV]')),
     "import|patch":
         (import_,
          [('p', 'strip', 1,
--- a/tests/test-globalopts.out	Thu Jun 21 11:42:39 2007 -0500
+++ b/tests/test-globalopts.out	Thu Jun 21 11:54:11 2007 -0500
@@ -136,7 +136,7 @@
  grep         search for a pattern in specified files and revisions
  heads        show current repository heads or show branch heads
  help         show help for a command, extension, or list of commands
- identify     print information about the working copy
+ identify     identify the working copy or specified revision
  import       import an ordered set of patches
  incoming     show new changesets found in source
  init         create a new repository in the given directory
@@ -188,7 +188,7 @@
  grep         search for a pattern in specified files and revisions
  heads        show current repository heads or show branch heads
  help         show help for a command, extension, or list of commands
- identify     print information about the working copy
+ identify     identify the working copy or specified revision
  import       import an ordered set of patches
  incoming     show new changesets found in source
  init         create a new repository in the given directory
--- a/tests/test-help.out	Thu Jun 21 11:42:39 2007 -0500
+++ b/tests/test-help.out	Thu Jun 21 11:54:11 2007 -0500
@@ -59,7 +59,7 @@
  grep         search for a pattern in specified files and revisions
  heads        show current repository heads or show branch heads
  help         show help for a command, extension, or list of commands
- identify     print information about the working copy
+ identify     identify the working copy or specified revision
  import       import an ordered set of patches
  incoming     show new changesets found in source
  init         create a new repository in the given directory
@@ -107,7 +107,7 @@
  grep         search for a pattern in specified files and revisions
  heads        show current repository heads or show branch heads
  help         show help for a command, extension, or list of commands
- identify     print information about the working copy
+ identify     identify the working copy or specified revision
  import       import an ordered set of patches
  incoming     show new changesets found in source
  init         create a new repository in the given directory