obsolete: extract obsolescence marker pulling into a dedicated function
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Wed, 17 Apr 2013 11:47:49 +0200
changeset 19054 d5f968f7716f
parent 19053 f74f2a4e3327
child 19055 0fc41f88f148
obsolete: extract obsolescence marker pulling into a dedicated function Having a dedicated function will allow us to experiment with other exchange strategies in an extension. As we have no solid clues about how to do it right, being able to experiment is vital. Some transaction tricks are necessary for pull. But nothing too scary.
mercurial/localrepo.py
mercurial/obsolete.py
--- a/mercurial/localrepo.py	Wed Apr 17 11:18:36 2013 +0200
+++ b/mercurial/localrepo.py	Wed Apr 17 11:47:49 2013 +0200
@@ -8,7 +8,7 @@
 from i18n import _
 import peer, changegroup, subrepo, discovery, pushkey, obsolete, repoview
 import changelog, dirstate, filelog, manifest, context, bookmarks, phases
-import lock, transaction, store, encoding, base85
+import lock, transaction, store, encoding
 import scmutil, util, extensions, hook, error, revset
 import match as matchmod
 import merge as mergemod
@@ -1717,17 +1717,15 @@
                 # should be seen as public
                 phases.advanceboundary(self, phases.public, subset)
 
-            if obsolete._enabled:
-                self.ui.debug('fetching remote obsolete markers\n')
-                remoteobs = remote.listkeys('obsolete')
-                if 'dump0' in remoteobs:
-                    if tr is None:
-                        tr = self.transaction(trname)
-                    for key in sorted(remoteobs, reverse=True):
-                        if key.startswith('dump'):
-                            data = base85.b85decode(remoteobs[key])
-                            self.obsstore.mergemarkers(tr, data)
-                    self.invalidatevolatilesets()
+            def gettransaction():
+                if tr is None:
+                    return self.transaction(trname)
+                return tr
+
+            obstr = obsolete.syncpull(self, remote, gettransaction)
+            if obstr is not None:
+                tr = obstr
+
             if tr is not None:
                 tr.close()
         finally:
--- a/mercurial/obsolete.py	Wed Apr 17 11:18:36 2013 +0200
+++ b/mercurial/obsolete.py	Wed Apr 17 11:47:49 2013 +0200
@@ -386,6 +386,27 @@
             msg = _('failed to push some obsolete markers!\n')
             repo.ui.warn(msg)
 
+def syncpull(repo, remote, gettransaction):
+    """utility function to pull bookmark to a remote
+
+    The `gettransaction` is function that return the pull transaction, creating
+    one if necessary. We return the transaction to inform the calling code that
+    a new transaction have been created (when applicable).
+
+    Exists mostly to allow overridding for experimentation purpose"""
+    tr = None
+    if _enabled:
+        repo.ui.debug('fetching remote obsolete markers\n')
+        remoteobs = remote.listkeys('obsolete')
+        if 'dump0' in remoteobs:
+            tr = gettransaction()
+            for key in sorted(remoteobs, reverse=True):
+                if key.startswith('dump'):
+                    data = base85.b85decode(remoteobs[key])
+                    repo.obsstore.mergemarkers(tr, data)
+            repo.invalidatevolatilesets()
+    return tr
+
 def allmarkers(repo):
     """all obsolete markers known in a repository"""
     for markerdata in repo.obsstore: