[PATCH 5 of 6] localrepo: add repo.peer() and switch from repo to peer as appropriate

Peter Arrenbrecht peter.arrenbrecht at gmail.com
Wed Jun 8 16:45:32 UTC 2011


# HG changeset patch
# User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
# Date 1307550649 -7200
localrepo: add repo.peer() and switch from repo to peer as appropriate

diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -128,7 +128,7 @@
                         continue
                     if pulls:
                         if source != repo:
-                            repo.pull(source, heads=pulls)
+                            repo.pull(source.peer(), heads=pulls)
                         merge.update(repo, pulls[-1], False, False, None)
                         p1, p2 = repo.dirstate.parents()
                         pulls = []
@@ -173,7 +173,7 @@
                         if patchfile:
                             os.unlink(patchfile)
             if pulls:
-                repo.pull(source, heads=pulls)
+                repo.pull(source.peer(), heads=pulls)
                 merge.update(repo, pulls[-1], False, False, None)
         finally:
             self.saveseries(revmap, merges)
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -20,17 +20,18 @@
     path = util.expandpath(util.localpath(path))
     return (os.path.isfile(path) and bundlerepo or localrepo)
 
-def addbranchrevs(lrepo, repo, branches, revs):
+def addbranchrevs(lrepo, other, branches, revs):
+    peer = other.peer() # a courtesy to callers using a localrepo for other
     hashbranch, branches = branches
     if not hashbranch and not branches:
         return revs or None, revs and revs[0] or None
     revs = revs and list(revs) or []
-    if not repo.capable('branchmap'):
+    if not peer.capable('branchmap'):
         if branches:
             raise util.Abort(_("remote branch lookup not supported"))
         revs.append(hashbranch)
         return revs, revs[0]
-    branchmap = repo.branchmap()
+    branchmap = peer.branchmap()
 
     def primary(branch):
         if branch == '.':
@@ -251,7 +252,7 @@
         source, branch = parseurl(origsource, branch)
         srcpeer = peer(ui, opts, source)
     else:
-        srcpeer = source
+        srcpeer = source.peer() # in case we were called with a localrepo
         branch = (None, branch or [])
         origsource = source = srcpeer.url()
     rev, checkout = addbranchrevs(srcpeer, srcpeer, branch, rev)
diff --git a/mercurial/repo.py b/mercurial/repo.py
--- a/mercurial/repo.py
+++ b/mercurial/repo.py
@@ -15,6 +15,10 @@
         '''return peer as a repository - currently a no-op'''
         return self
 
+    def peer(self):
+        '''return the peer view of this repo - currently a no-op'''
+        return self
+
     def capable(self, name):
         '''tell whether repo supports named capability.
         return False if not supported.



More information about the Mercurial-devel mailing list