localrepo: add unbundle support
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 04 Apr 2014 17:50:44 -0700
changeset 20969 7a679918ee2b
parent 20968 33d5fdd9bd99
child 20970 70312c95f2f7
localrepo: add unbundle support Localrepo now supports the unbundle method of pushing changegroups. We plan to use the unbundle call for bundle2 so it is important that all peers supports it. The `peer.unbundle` and `peer.addchangegroup` code path have small difference so cause some test output changes. None of those changes seems problematic.
mercurial/exchange.py
mercurial/localrepo.py
mercurial/wireproto.py
tests/test-acl.t
tests/test-lock-badness.t
--- a/mercurial/exchange.py	Fri Apr 04 17:28:59 2014 -0700
+++ b/mercurial/exchange.py	Fri Apr 04 17:50:44 2014 -0700
@@ -643,14 +643,7 @@
     try:
         check_heads(repo, heads, 'uploading changes')
         # push can proceed
-        try:
-            r = changegroup.addchangegroup(repo, cg, source, url)
-        except util.Abort, inst:
-            # The old code we moved used sys.stderr directly.
-            # We did not changed it to minise code change.
-            # This need to be moved to something proper.
-            # Feel free to do it.
-            sys.stderr.write("abort: %s\n" % inst)
+        r = changegroup.addchangegroup(repo, cg, source, url)
     finally:
         lock.release()
     return r
--- a/mercurial/localrepo.py	Fri Apr 04 17:28:59 2014 -0700
+++ b/mercurial/localrepo.py	Fri Apr 04 17:50:44 2014 -0700
@@ -63,7 +63,7 @@
     return wrapper
 
 moderncaps = set(('lookup', 'branchmap', 'pushkey', 'known', 'getbundle',
-                  'bundle2'))
+                  'bundle2', 'unbundle'))
 legacycaps = moderncaps.union(set(['changegroupsubset']))
 
 class localpeer(peer.peerrepository):
@@ -112,6 +112,15 @@
     # TODO We might want to move the next two calls into legacypeer and add
     # unbundle instead.
 
+    def unbundle(self, cg, heads, url):
+        """apply a bundle on a repo
+
+        This function handles the repo locking itself."""
+        try:
+            return exchange.unbundle(self._repo, cg, heads, 'push', url)
+        except exchange.PushRaced, exc:
+            raise error.ResponseError(_('push failed:'), exc.message)
+
     def lock(self):
         return self._repo.lock()
 
--- a/mercurial/wireproto.py	Fri Apr 04 17:28:59 2014 -0700
+++ b/mercurial/wireproto.py	Fri Apr 04 17:50:44 2014 -0700
@@ -774,5 +774,12 @@
         finally:
             fp.close()
             os.unlink(tempname)
+    except util.Abort, inst:
+        # The old code we moved used sys.stderr directly.
+        # We did not changed it to minise code change.
+        # This need to be moved to something proper.
+        # Feel free to do it.
+        sys.stderr.write("abort: %s\n" % inst)
+        return pushres(0)
     except exchange.PushRaced, exc:
         return pusherr(str(exc))
--- a/tests/test-acl.t	Fri Apr 04 17:28:59 2014 -0700
+++ b/tests/test-acl.t	Fri Apr 04 17:50:44 2014 -0700
@@ -116,9 +116,9 @@
   adding quux/file.py revisions
   files: 3/3 chunks (100.00%)
   added 3 changesets with 3 changes to 3 files
+  updating the branch cache
   listing keys for "phases"
   try to push obsolete markers to remote
-  updating the branch cache
   checking for updated bookmarks
   listing keys for "bookmarks"
   repository tip rolled back to revision 0 (undo push)
@@ -177,9 +177,9 @@
   added 3 changesets with 3 changes to 3 files
   calling hook pretxnchangegroup.acl: hgext.acl.hook
   acl: changes have source "push" - skipping
+  updating the branch cache
   listing keys for "phases"
   try to push obsolete markers to remote
-  updating the branch cache
   checking for updated bookmarks
   listing keys for "bookmarks"
   repository tip rolled back to revision 0 (undo push)
@@ -249,9 +249,9 @@
   acl: path access granted: "f9cafe1212c8"
   acl: branch access granted: "911600dab2ae" on branch "default"
   acl: path access granted: "911600dab2ae"
+  updating the branch cache
   listing keys for "phases"
   try to push obsolete markers to remote
-  updating the branch cache
   checking for updated bookmarks
   listing keys for "bookmarks"
   repository tip rolled back to revision 0 (undo push)
@@ -747,9 +747,9 @@
   acl: path access granted: "f9cafe1212c8"
   acl: branch access granted: "911600dab2ae" on branch "default"
   acl: path access granted: "911600dab2ae"
+  updating the branch cache
   listing keys for "phases"
   try to push obsolete markers to remote
-  updating the branch cache
   checking for updated bookmarks
   listing keys for "bookmarks"
   repository tip rolled back to revision 0 (undo push)
@@ -1067,9 +1067,9 @@
   acl: path access granted: "f9cafe1212c8"
   acl: branch access granted: "911600dab2ae" on branch "default"
   acl: path access granted: "911600dab2ae"
+  updating the branch cache
   listing keys for "phases"
   try to push obsolete markers to remote
-  updating the branch cache
   checking for updated bookmarks
   listing keys for "bookmarks"
   repository tip rolled back to revision 0 (undo push)
@@ -1147,9 +1147,9 @@
   acl: path access granted: "f9cafe1212c8"
   acl: branch access granted: "911600dab2ae" on branch "default"
   acl: path access granted: "911600dab2ae"
+  updating the branch cache
   listing keys for "phases"
   try to push obsolete markers to remote
-  updating the branch cache
   checking for updated bookmarks
   listing keys for "bookmarks"
   repository tip rolled back to revision 0 (undo push)
@@ -1300,9 +1300,9 @@
   acl: path access granted: "f9cafe1212c8"
   acl: branch access granted: "911600dab2ae" on branch "default"
   acl: path access granted: "911600dab2ae"
+  updating the branch cache
   listing keys for "phases"
   try to push obsolete markers to remote
-  updating the branch cache
   checking for updated bookmarks
   listing keys for "bookmarks"
   repository tip rolled back to revision 0 (undo push)
@@ -1501,9 +1501,9 @@
   acl: path access granted: "911600dab2ae"
   acl: branch access granted: "e8fc755d4d82" on branch "foobar"
   acl: path access granted: "e8fc755d4d82"
+  updating the branch cache
   listing keys for "phases"
   try to push obsolete markers to remote
-  updating the branch cache
   checking for updated bookmarks
   listing keys for "bookmarks"
   repository tip rolled back to revision 2 (undo push)
@@ -1807,9 +1807,9 @@
   acl: path access granted: "911600dab2ae"
   acl: branch access granted: "e8fc755d4d82" on branch "foobar"
   acl: path access granted: "e8fc755d4d82"
+  updating the branch cache
   listing keys for "phases"
   try to push obsolete markers to remote
-  updating the branch cache
   checking for updated bookmarks
   listing keys for "bookmarks"
   repository tip rolled back to revision 2 (undo push)
@@ -1895,9 +1895,9 @@
   acl: path access granted: "911600dab2ae"
   acl: branch access granted: "e8fc755d4d82" on branch "foobar"
   acl: path access granted: "e8fc755d4d82"
+  updating the branch cache
   listing keys for "phases"
   try to push obsolete markers to remote
-  updating the branch cache
   checking for updated bookmarks
   listing keys for "bookmarks"
   repository tip rolled back to revision 2 (undo push)
@@ -2056,9 +2056,9 @@
   acl: path access granted: "911600dab2ae"
   acl: branch access granted: "e8fc755d4d82" on branch "foobar"
   acl: path access granted: "e8fc755d4d82"
+  updating the branch cache
   listing keys for "phases"
   try to push obsolete markers to remote
-  updating the branch cache
   checking for updated bookmarks
   listing keys for "bookmarks"
   repository tip rolled back to revision 2 (undo push)
--- a/tests/test-lock-badness.t	Fri Apr 04 17:28:59 2014 -0700
+++ b/tests/test-lock-badness.t	Fri Apr 04 17:50:44 2014 -0700
@@ -34,6 +34,7 @@
 
   $ hg -R b push a
   pushing to a
+  searching for changes
   abort: could not lock repository a: Permission denied
   [255]