[PATCH 2 of 4] push: elevate phase transaction to cover entire operation

Eric Sumner ericsumner at fb.com
Tue Nov 25 12:26:27 CST 2014


# HG changeset patch
# User Eric Sumner <ericsumner at fb.com>
# Date 1416611198 28800
#      Fri Nov 21 15:06:38 2014 -0800
# Node ID ed01cf6d09c8682dfd8292f1333bce11be02bc1f
# Parent  0b5ec0d98ac188df2afa03457e3f551e28e1eb28
push: elevate phase transaction to cover entire operation

This patch series is intended to allow bundle2 push reply part handlers to
make changes to the local repository; it has been developed in parallel with
an extension that allows the server to rebase incoming changesets while applying
them.

Most pushes already open a transaction in order to sync phase information.
This diff replaces that transaction with one that spans the entire push
operation.

This transaction will be used in a later patch to guard repository changes
made during the reply handler.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -104,6 +104,8 @@
         self.outobsmarkers = set()
         # outgoing bookmarks
         self.outbookmarks = []
+        # transaction manager
+        self.trmanager = None
 
     @util.propertycache
     def futureheads(self):
@@ -204,6 +206,10 @@
         msg = 'cannot lock source repository: %s\n' % err
         pushop.ui.debug(msg)
     try:
+        if pushop.locallocked:
+            pushop.trmanager = transactionmanager(repo,
+                                                  'push-response',
+                                                  pushop.remote.url())
         pushop.repo.checkpush(pushop)
         lock = None
         unbundle = pushop.remote.capable('unbundle')
@@ -222,7 +228,11 @@
         finally:
             if lock is not None:
                 lock.release()
+        if pushop.trmanager:
+            pushop.trmanager.close()
     finally:
+        if pushop.trmanager:
+            pushop.trmanager.release()
         if locallock is not None:
             locallock.release()
 
@@ -693,13 +703,11 @@
 
 def _localphasemove(pushop, nodes, phase=phases.public):
     """move <nodes> to <phase> in the local source repo"""
-    if pushop.locallocked:
-        tr = pushop.repo.transaction('push-phase-sync')
-        try:
-            phases.advanceboundary(pushop.repo, tr, phase, nodes)
-            tr.close()
-        finally:
-            tr.release()
+    if pushop.trmanager:
+        phases.advanceboundary(pushop.repo,
+                               pushop.trmanager.transaction(),
+                               phase,
+                               nodes)
     else:
         # repo is not locked, do not change any phases!
         # Informs the user that phases should have been moved when
diff --git a/tests/test-bundle2-exchange.t b/tests/test-bundle2-exchange.t
--- a/tests/test-bundle2-exchange.t
+++ b/tests/test-bundle2-exchange.t
@@ -176,6 +176,9 @@
   remote: added 1 changesets with 0 changes to 0 files (-1 heads)
   remote: 1 new obsolescence markers
   updating bookmark book_eea1
+  pre-close-tip:02de42196ebe draft book_02de
+  postclose-tip:02de42196ebe draft book_02de
+  b2x-transactionclose hook: HG_SOURCE=push-response HG_URL=file:$TESTTMP/other
   $ hg -R other log -G
   o    3:eea13746799a public Nicolas Dumazet <nicdumz.commits at gmail.com> book_eea1 G
   |\
@@ -254,6 +257,9 @@
   remote: postclose-tip:5fddd98957c8 draft book_5fdd
   remote: b2x-transactionclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2-EXP=1 HG_NEW_OBSMARKERS=1 HG_NODE=5fddd98957c8a54a4d436dfe1da9d87f21a1b97b HG_SOURCE=serve HG_URL=remote:ssh:127.0.0.1
   remote: changegroup hook: HG_BUNDLE2-EXP=1 HG_NODE=5fddd98957c8a54a4d436dfe1da9d87f21a1b97b HG_SOURCE=serve HG_URL=remote:ssh:127.0.0.1
+  pre-close-tip:02de42196ebe draft book_02de
+  postclose-tip:02de42196ebe draft book_02de
+  b2x-transactionclose hook: HG_SOURCE=push-response HG_URL=ssh://user@dummy/other
   $ hg -R other log -G
   o  6:5fddd98957c8 draft Nicolas Dumazet <nicdumz.commits at gmail.com> book_5fdd C
   |
@@ -292,6 +298,9 @@
   remote: added 1 changesets with 1 changes to 1 files
   remote: 1 new obsolescence markers
   updating bookmark book_32af
+  pre-close-tip:02de42196ebe draft book_02de
+  postclose-tip:02de42196ebe draft book_02de
+  b2x-transactionclose hook: HG_SOURCE=push-response HG_URL=http://localhost:$HGPORT2/
   $ cat other-error.log
 
 Check final content.


More information about the Mercurial-devel mailing list