changeset 2658:2be3001847cb 0.9.1

Merge with crew
author Matt Mackall <mpm@selenic.com>
date Mon, 24 Jul 2006 17:06:39 -0500
parents 6024216754f4 (diff) e6a7a6a33a62 (current diff)
children 93b765f30c07 489c3bacce96
files
diffstat 3 files changed, 44 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Mon Jul 24 13:47:29 2006 -0700
+++ b/mercurial/commands.py	Mon Jul 24 17:06:39 2006 -0500
@@ -943,7 +943,7 @@
     %d   dirname of file being printed, or '.' if in repo root
     %p   root-relative path name of file being printed
     """
-    ctx = repo.changectx(opts['rev'] or -1)
+    ctx = repo.changectx(opts['rev'] or "-1")
     for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, ctx.node()):
         fp = make_file(repo, opts['output'], ctx.node(), pathname=abs)
         fp.write(ctx.filectx(abs).data())
@@ -2088,13 +2088,28 @@
             dodiff(ui, ui, repo, prev, n)
             ui.write("\n")
 
-def parents(ui, repo, rev=None, branches=None, **opts):
+def parents(ui, repo, file_=None, rev=None, branches=None, **opts):
     """show the parents of the working dir or revision
 
     Print the working directory's parent revisions.
     """
+    # legacy
+    if file_ and not rev:
+        try:
+            rev = repo.lookup(file_)
+            file_ = None
+        except hg.RepoError:
+            pass
+        else:
+            ui.warn(_("'hg parent REV' is deprecated, "
+                      "please use 'hg parents -r REV instead\n"))
+
     if rev:
-        p = repo.changelog.parents(repo.lookup(rev))
+        if file_:
+            ctx = repo.filectx(file_, changeid=rev)
+        else:
+            ctx = repo.changectx(rev)
+        p = [cp.node() for cp in ctx.parents()]
     else:
         p = repo.dirstate.parents()
 
@@ -3049,9 +3064,10 @@
     "^parents":
         (parents,
          [('b', 'branches', None, _('show branches')),
+          ('r', 'rev', '', _('show parents from the specified rev')),
           ('', 'style', '', _('display using template map file')),
           ('', 'template', '', _('display with template'))],
-         _('hg parents [-b] [REV]')),
+         _('hg parents [-b] [-r REV] [FILE]')),
     "paths": (paths, [], _('hg paths [NAME]')),
     "^pull":
         (pull,
--- a/mercurial/context.py	Mon Jul 24 13:47:29 2006 -0700
+++ b/mercurial/context.py	Mon Jul 24 17:06:39 2006 -0500
@@ -11,9 +11,8 @@
     def __init__(self, repo, changeid):
         """changeid is a revision number, node, or tag"""
         self._repo = repo
-        self._id = changeid
 
-        self._node = self._repo.lookup(self._id)
+        self._node = self._repo.lookup(changeid)
         self._rev = self._repo.changelog.rev(self._node)
 
     def changeset(self):
@@ -74,39 +73,40 @@
            fileid can be a file revision or node."""
         self._repo = repo
         self._path = path
-        self._id = changeid
-        self._fileid = fileid
 
-        if self._id:
+        assert changeid or fileid
+
+        if not fileid:
             # if given a changeset id, go ahead and look up the file
-            self._changeset = self._repo.changelog.read(self._id)
-            node, flag = self._repo.manifest.find(self._changeset[0], path)
+            self._changeid = changeid
+            self._changectx = self.changectx()
             self._filelog = self._repo.file(self._path)
-            self._filenode = node
-        elif self._fileid:
+            self._filenode = self._changectx.filenode(self._path)
+        else:
             # else be lazy
             self._filelog = self._repo.file(self._path)
-            self._filenode = self._filelog.lookup(self._fileid)
+            self._filenode = self._filelog.lookup(fileid)
+            self._changeid = self._filelog.linkrev(self._filenode)
         self._filerev = self._filelog.rev(self._filenode)
 
-    def changeset(self):
+    def changectx(self):
         try:
-            return self._changeset
+            return self._changectx
         except AttributeError:
-            self._changeset = self._repo.changelog.read(self.node())
-            return self._changeset
+            self._changectx = changectx(self._repo, self._changeid)
+            return self._changectx
 
     def filerev(self): return self._filerev
     def filenode(self): return self._filenode
     def filelog(self): return self._filelog
 
-    def rev(self): return self.changeset().rev()
-    def node(self): return self.changeset().node()
-    def user(self): return self.changeset().user()
-    def date(self): return self.changeset().date()
-    def files(self): return self.changeset().files()
-    def description(self): return self.changeset().description()
-    def manifest(self): return self.changeset().manifest()
+    def rev(self): return self.changectx().rev()
+    def node(self): return self.changectx().node()
+    def user(self): return self.changectx().user()
+    def date(self): return self.changectx().date()
+    def files(self): return self.changectx().files()
+    def description(self): return self.changectx().description()
+    def manifest(self): return self.changectx().manifest()
 
     def data(self): return self._filelog.read(self._filenode)
     def metadata(self): return self._filelog.readmeta(self._filenode)
--- a/mercurial/revlog.py	Mon Jul 24 13:47:29 2006 -0700
+++ b/mercurial/revlog.py	Mon Jul 24 17:06:39 2006 -0500
@@ -469,7 +469,8 @@
             return self.nodemap[node]
         except KeyError:
             raise RevlogError(_('%s: no node %s') % (self.indexfile, hex(node)))
-    def linkrev(self, node): return self.index[self.rev(node)][-4]
+    def linkrev(self, node):
+        return (node == nullid) and -1 or self.index[self.rev(node)][-4]
     def parents(self, node):
         if node == nullid: return (nullid, nullid)
         r = self.rev(node)
@@ -746,10 +747,7 @@
         if id in self.nodemap:
             return id
         if type(id) == type(0):
-            rev = id
-            if rev < 0: rev = self.count() + rev
-            if rev < 0 or rev >= self.count(): return None
-            return self.node(rev)
+            return self.node(id)
         try:
             rev = int(id)
             if str(rev) != id: raise ValueError