Patchwork [1,of,2] obsolete: extract obsolescence marker pushing in a dedicated function

login
register
mail settings
Submitter Pierre-Yves David
Date April 18, 2013, 5:16 p.m.
Message ID <368a3c420ecf9712b2ef.1366305381@crater2.logilab.fr>
Download mbox | patch
Permalink /patch/1427/
State Accepted, archived
Headers show

Comments

Pierre-Yves David - April 18, 2013, 5:16 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1366190316 -7200
#      Wed Apr 17 11:18:36 2013 +0200
# Node ID 368a3c420ecf9712b2efa3caf894acf447814b3a
# Parent  ab04e87a5f3bcee588b72d615e1aeb42f10d3b99
obsolete: extract obsolescence marker pushing in a dedicated function

Having a dedicated function will allows use to experiment with other exchange
strategy in extension. Has we have not solid clues about how to do it right
being able to experiment is vital.

I intended a more ambitious extraction of push logic, but we are far to advance
in the release cycle for it.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1910,21 +1910,11 @@  class localrepository(object):
                                            str(phases.public))
                         if not r:
                             self.ui.warn(_('updating %s to public failed!\n')
                                             % newremotehead)
                 self.ui.debug('try to push obsolete markers to remote\n')
-                if (obsolete._enabled and self.obsstore and
-                    'obsolete' in remote.listkeys('namespaces')):
-                    rslts = []
-                    remotedata = self.listkeys('obsolete')
-                    for key in sorted(remotedata, reverse=True):
-                        # reverse sort to ensure we end with dump0
-                        data = remotedata[key]
-                        rslts.append(remote.pushkey('obsolete', key, '', data))
-                    if [r for r in rslts if not r]:
-                        msg = _('failed to push some obsolete markers!\n')
-                        self.ui.warn(msg)
+                obsolete.syncpush(self, remote)
             finally:
                 if lock is not None:
                     lock.release()
         finally:
             locallock.release()
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -368,10 +368,28 @@  def pushmarker(repo, key, old, new):
         finally:
             tr.release()
     finally:
         lock.release()
 
+def syncpush(repo, remote):
+    """utility function to push bookmark to a remote
+
+    exist mostly to allow overridding for experimentation purpose"""
+    if (_enabled and repo.obsstore and
+        'obsolete' in remote.listkeys('namespaces')):
+        rslts = []
+        remotedata = repo.listkeys('obsolete')
+        for key in sorted(remotedata, reverse=True):
+            # reverse sort to ensure we end with dump0
+            data = remotedata[key]
+            rslts.append(remote.pushkey('obsolete', key, '', data))
+        if [r for r in rslts if not r]:
+            msg = _('failed to push some obsolete markers!\n')
+            repo.ui.warn(msg)
+
+
+
 def allmarkers(repo):
     """all obsolete markers known in a repository"""
     for markerdata in repo.obsstore:
         yield marker(repo, markerdata)