changeset 4665:091c9e54d306

identify: accept a revision argument
author Matt Mackall <mpm@selenic.com>
date Thu, 21 Jun 2007 11:54:11 -0500
parents dedb8abfd0e1
children 48c94bffdb28
files mercurial/commands.py tests/test-globalopts.out tests/test-help.out
diffstat 3 files changed, 25 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1432,32 +1432,36 @@ def help_(ui, name=None, with_version=Fa
             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 @@ table = {
           ('', '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
+++ b/tests/test-globalopts.out
@@ -136,7 +136,7 @@ list of commands:
  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 @@ list of commands:
  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
+++ b/tests/test-help.out
@@ -59,7 +59,7 @@ list of commands:
  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 @@ use "hg -v help" to show aliases and glo
  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