changeset 4673:d8442fc0da8d

Merge with crew
author Patrick Mezard <pmezard@gmail.com>
date Thu, 21 Jun 2007 22:19:41 +0200
parents 150afe6becf6 (diff) 272c0a09b203 (current diff)
children 723e0ddb6ada
files mercurial/commands.py mercurial/util.py
diffstat 8 files changed, 89 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -262,11 +262,9 @@ def dispatch(ui, args):
         os.chdir(cwd)
 
     # read the local repository .hgrc into a local ui object
-    # this will trigger its extensions to load
-    path = earlygetopt(["-R", "--repository", "--repo"], args)
+    path = findrepo() or ""
     if not path:
-        path = findrepo() or ""
-    lui = ui
+        lui = ui
     if path:
         try:
             lui = commands.ui.ui(parentui=ui)
@@ -274,6 +272,13 @@ def dispatch(ui, args):
         except IOError:
             pass
 
+    # now we can expand paths, even ones in .hg/hgrc
+    rpath = earlygetopt(["-R", "--repository", "--repo"], args)
+    if rpath:
+        path = lui.expandpath(rpath)
+        lui = commands.ui.ui(parentui=ui)
+        lui.readconfig(os.path.join(path, ".hg", "hgrc"))
+
     extensions.loadall(lui)
     # check for fallback encoding
     fallback = lui.config('ui', 'fallbackencoding')
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1432,38 +1432,69 @@ 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, source=None,
+             rev=None, num=None, id=None, branch=None, tags=None):
+    """identify the working copy or specified revision
+
+    With no revision, print a summary of the current state of the repo.
+
+    With a path, do a lookup in another repository.
 
     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.
     """
-    parents = [p for p in repo.dirstate.parents() if p != nullid]
-    if not parents:
-        ui.write(_("unknown\n"))
-        return
 
     hexfunc = ui.debugflag and hex or short
-    modified, added, removed, deleted = repo.status()[:4]
-    output = ["%s%s" %
-              ('+'.join([hexfunc(parent) for parent in parents]),
-              (modified or added or removed or deleted) and "+" or "")]
-
-    if not ui.quiet:
-
-        branch = util.tolocal(repo.workingctx().branch())
-        if branch != 'default':
-            output.append("(%s)" % branch)
+    default = not (num or id or branch or tags)
+    output = []
+
+    if source:
+        source, revs = cmdutil.parseurl(ui.expandpath(source), [])
+        srepo = hg.repository(ui, source)
+        if not rev and revs:
+            rev = revs[0]
+        if not rev:
+            rev = "tip"
+        if num or branch or tags:
+            raise util.Abort(
+                "can't query remote revision number, branch, or tags")
+        output = [hexfunc(srepo.lookup(rev))]
+    elif not rev:
+        ctx = repo.workingctx()
+        parents = ctx.parents()
+        changed = False
+        if default or id or num:
+            changed = ctx.files() + ctx.deleted()
+        if default or id:
+            output = ["%s%s" % ('+'.join([hexfunc(p.node()) for p in parents]),
+                                (changed) and "+" or "")]
+        if num:
+            output.append("%s%s" % ('+'.join([str(p.rev()) for p in parents]),
+                                    (changed) and "+" or ""))
+    else:
+        ctx = repo.changectx(rev)
+        if default or id:
+            output = [hexfunc(ctx.node())]
+        if num:
+            output.append(str(ctx.rev()))
+
+    if not source and default and not ui.quiet:
+        b = util.tolocal(ctx.branch())
+        if b != 'default':
+            output.append("(%s)" % b)
 
         # multiple tags for a single parent separated by '/'
-        parenttags = ['/'.join(tags)
-                      for tags in map(repo.nodetags, parents) if tags]
-        # tags for multiple parents separated by ' + '
-        if parenttags:
-            output.append(' + '.join(parenttags))
+        t = "/".join(ctx.tags())
+        if t:
+            output.append(t)
+
+    if branch:
+        output.append(util.tolocal(ctx.branch()))
+
+    if tags:
+        output.extend(ctx.tags())
 
     ui.write("%s\n" % ' '.join(output))
 
@@ -2826,7 +2857,14 @@ 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')),
+          ('n', 'num', None, _('show local revision number')),
+          ('i', 'id', None, _('show global revision id')),
+          ('b', 'branch', None, _('show branch')),
+          ('t', 'tags', None, _('show tags'))],
+         _('hg identify [-nibt] [-r REV] [SOURCE]')),
     "import|patch":
         (import_,
          [('p', 'strip', 1,
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -67,6 +67,7 @@ class changectx(object):
     def files(self): return self._changeset[3]
     def description(self): return self._changeset[4]
     def branch(self): return self._changeset[5].get("branch")
+    def tags(self): return self._repo.nodetags(self._node)
 
     def parents(self):
         """return contexts for each parent changeset"""
@@ -413,6 +414,11 @@ class workingctx(changectx):
     def clean(self): return self._status[5]
     def branch(self): return self._repo.dirstate.branch()
 
+    def tags(self):
+        t = []
+        [t.extend(p.tags()) for p in self.parents()]
+        return t
+
     def parents(self):
         """return contexts for each parent changeset"""
         return self._parents
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -619,11 +619,11 @@ class hgweb(object):
         'zip': ('application/zip', 'zip', '.zip', None),
         }
 
-    def archive(self, req, id, type_):
+    def archive(self, req, key, type_):
         reponame = re.sub(r"\W+", "-", os.path.basename(self.reponame))
-        cnode = self.repo.lookup(id)
-        arch_version = id
-        if cnode == id or id == 'tip':
+        cnode = self.repo.lookup(key)
+        arch_version = key
+        if cnode == key or key == 'tip':
             arch_version = short(cnode)
         name = "%s-%s" % (reponame, arch_version)
         mimetype, artype, extension, encoding = self.archive_specs[type_]
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1155,9 +1155,6 @@ def opener(base, audit=True):
     this function is used to hide the details of COW semantics and
     remote file access from higher level code.
     """
-    p = base
-    audit_p = audit
-
     def mktempcopy(name, emptyok=False):
         d, fn = os.path.split(name)
         fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, dir=d)
@@ -1212,9 +1209,9 @@ def opener(base, audit=True):
                 posixfile.close(self)
 
     def o(path, mode="r", text=False, atomictemp=False):
-        if audit_p:
+        if audit:
             audit_path(path)
-        f = os.path.join(p, path)
+        f = os.path.join(base, path)
 
         if not text:
             mode += "b" # for that other OS
--- 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
--- a/tests/test-tags.out
+++ b/tests/test-tags.out
@@ -1,4 +1,4 @@
-unknown
+000000000000 tip
 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 0acdaf898367 tip
 tip                                0:0acdaf898367