[PATCH 3 of 6 V2] peer: introduce canpush and improve error message

Sune Foldager cryo at cyanite.org
Fri Jul 13 15:12:45 CDT 2012


# HG changeset patch
# User Sune Foldager <cryo at cyanite.org>
# Date 1342209148 -7200
# Node ID 7a27d84d6ede52603e7a3bd73bbd1a1253882a56
# Parent  90653c34a9c26b7c3896e91e6f3ddf965e9b99d2
peer: introduce canpush and improve error message

diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -167,6 +167,10 @@
     def _file(self, f):
         self._repo.file(f)
 
+class bundlepeer(localrepo.localpeer):
+    def canpush(self):
+        return False
+
 class bundlerepository(localrepo.localrepository):
     def __init__(self, ui, path, bundlename):
         self._tempparent = None
@@ -272,6 +276,9 @@
     def cancopy(self):
         return False
 
+    def peer(self):
+        return bundlepeer(self)
+
     def getcwd(self):
         return os.getcwd() # always outside the repo
 
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -49,6 +49,9 @@
     def cancopy(self):
         return self._repo.cancopy() # so bundlerepo can override
 
+    def canpush(self):
+        return True
+
     def url(self):
         return self._repo.url()
 
@@ -1801,6 +1804,8 @@
         # unbundle assumes local user cannot lock remote repo (new ssh
         # servers, http servers).
 
+        if not remote.canpush():
+            raise util.Abort(_("destination does not support push"))
         # get local lock as we might write phase data
         locallock = self.lock()
         try:
diff --git a/mercurial/peer.py b/mercurial/peer.py
--- a/mercurial/peer.py
+++ b/mercurial/peer.py
@@ -45,5 +45,8 @@
     def cancopy(self):
         return False
 
+    def canpush(self):
+        return True
+
     def close(self):
         pass
diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py
+++ b/mercurial/statichttprepo.py
@@ -79,6 +79,8 @@
 class statichttppeer(localrepo.localpeer):
     def local(self):
         return None
+    def canpush(self):
+        return False
 
 class statichttprepository(localrepo.localrepository):
     def __init__(self, ui, path):
diff --git a/tests/test-static-http.t b/tests/test-static-http.t
--- a/tests/test-static-http.t
+++ b/tests/test-static-http.t
@@ -91,7 +91,7 @@
   $ hg commit -m"test"
   $ hg push
   pushing to static-http://localhost:$HGPORT/remote
-  abort: cannot lock static-http repository
+  abort: destination does not support push
   [255]
 
 trying clone -r


More information about the Mercurial-devel mailing list