exchange: only push the set of marker relevant to want we push
authorPierre-Yves David <pierre-yves.david@fb.com>
Thu, 27 Feb 2014 19:58:08 -0800
changeset 817 c2bf0eb727f1
parent 816 03587920dfd9
child 819 0b6af104fd78
exchange: only push the set of marker relevant to want we push We now compute all markers relevant to pushed set. And just send just those one. So you are no longer pushing markers that point to changeset your are not pushing. See the in line comment for details about what "relevant" is. Multiple nice output have been added in the process.
hgext/evolve.py
tests/test-corrupt.t
tests/test-obsolete.t
tests/test-tutorial.t
--- a/hgext/evolve.py	Thu Feb 27 18:30:55 2014 -0800
+++ b/hgext/evolve.py	Thu Feb 27 19:58:08 2014 -0800
@@ -46,6 +46,7 @@
 from mercurial import context
 from mercurial import copies
 from mercurial import error
+from mercurial import exchange
 from mercurial import extensions
 from mercurial import hg
 from mercurial import lock as lockmod
@@ -2074,3 +2075,61 @@
     return seenmarkers
 
 
+_pushkeyescape = getattr(obsolete, '_pushkeyescape', None)
+if _pushkeyescape is None:
+    def _pushkeyescape(markers):
+        """encode markers into a dict suitable for pushkey exchange
+
+        - binary data are base86 encoded
+        - splited in chunk less than 5300 bytes"""
+        parts = []
+        currentlen = _maxpayload * 2  # ensure we create a new part
+        for marker in markers:
+            nextdata = _encodeonemarker(marker)
+            if (len(nextdata) + currentlen > _maxpayload):
+                currentpart = []
+                currentlen = 0
+                parts.append(currentpart)
+            currentpart.append(nextdata)
+            currentlen += len(nextdata)
+        keys = {}
+        for idx, part in enumerate(reversed(parts)):
+            data = ''.join([_pack('>B', _fmversion)] + part)
+            keys['dump%i' % idx] = base85.b85encode(data)
+        return keys
+
+
+
+@eh.wrapfunction(exchange, '_pushobsolete')
+def _pushobsolete(orig, pushop):
+    """utility function to push obsolete markers to a remote"""
+    pushop.ui.debug('try to push obsolete markers to remote\n')
+    repo = pushop.repo
+    remote = pushop.remote
+    unfi = repo.unfiltered()
+    if (obsolete._enabled and repo.obsstore and
+        'obsolete' in remote.listkeys('namespaces')):
+        repo.ui.status("OBSEXC: computing relevant nodes\n")
+        nodes = [ctx.node() for ctx in unfi.set('::%ln', pushop.commonheads)]
+        repo.ui.status("OBSEXC: computing markers relevant to %i nodes\n"
+                       % len(nodes))
+        markers = repo.obsstore.relevantmarkers(nodes)
+        rslts = []
+        repo.ui.status("OBSEXC: encoding %i markers\n" % len(markers))
+        remotedata = obsolete._pushkeyescape(markers).items()
+        totalbytes = sum(len(d) for k,d in remotedata)
+        sentbytes = 0
+        repo.ui.status("OBSEXC: sending %i pushkey payload (%i bytes)\n"
+                        % (len(remotedata), totalbytes))
+        for key, data in remotedata:
+            repo.ui.progress('OBSEXC', sentbytes, item=key, unit="bytes",
+                             total=totalbytes)
+            rslts.append(remote.pushkey('obsolete', key, '', data))
+            sentbytes += len(data)
+            repo.ui.progress('OBSEXC', sentbytes, item=key, unit="bytes",
+                             total=totalbytes)
+        repo.ui.progress('OBSEXC', None)
+        if [r for r in rslts if not r]:
+            msg = _('failed to push some obsolete markers!\n')
+            repo.ui.warn(msg)
+        repo.ui.status("OBSEXC: DONE\n")
--- a/tests/test-corrupt.t	Thu Feb 27 18:30:55 2014 -0800
+++ b/tests/test-corrupt.t	Thu Feb 27 19:58:08 2014 -0800
@@ -111,6 +111,11 @@
   adding manifests
   adding file changes
   added 1 changesets with 2 changes to 2 files
+  OBSEXC: computing relevant nodes
+  OBSEXC: computing markers relevant to 4 nodes
+  OBSEXC: encoding 2 markers
+  OBSEXC: sending 1 pushkey payload (184 bytes)
+  OBSEXC: DONE
   $ hg -R ../other verify
   checking changesets
   checking manifests
--- a/tests/test-obsolete.t	Thu Feb 27 18:30:55 2014 -0800
+++ b/tests/test-obsolete.t	Thu Feb 27 19:58:08 2014 -0800
@@ -181,6 +181,11 @@
   adding manifests
   adding file changes
   added 5 changesets with 5 changes to 5 files (+1 heads)
+  OBSEXC: computing relevant nodes
+  OBSEXC: computing markers relevant to 5 nodes
+  OBSEXC: encoding 2 markers
+  OBSEXC: sending 1 pushkey payload (154 bytes)
+  OBSEXC: DONE
   $ hg -R ../other-new verify
   checking changesets
   checking manifests
@@ -234,6 +239,11 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files (+1 heads)
+  OBSEXC: computing relevant nodes
+  OBSEXC: computing markers relevant to 5 nodes
+  OBSEXC: encoding 3 markers
+  OBSEXC: sending 1 pushkey payload (230 bytes)
+  OBSEXC: DONE
   $ qlog -R ../other-new
   5
   - 95de7fc6918d
@@ -255,6 +265,11 @@
   pushing to ../other-new
   searching for changes
   no changes found
+  OBSEXC: computing relevant nodes
+  OBSEXC: computing markers relevant to 5 nodes
+  OBSEXC: encoding 3 markers
+  OBSEXC: sending 1 pushkey payload (230 bytes)
+  OBSEXC: DONE
   [1]
 
   $ hg up --hidden -q .^ # 3
@@ -526,6 +541,11 @@
   adding manifests
   adding file changes
   added 2 changesets with 1 changes to [12] files (re)
+  OBSEXC: computing relevant nodes
+  OBSEXC: computing markers relevant to 5 nodes
+  OBSEXC: encoding 7 markers
+  OBSEXC: sending 1 pushkey payload (565 bytes)
+  OBSEXC: DONE
   $ hg up -q 10
   $ mkcommit "obsol_d'''"
   created new head
@@ -537,6 +557,11 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files (+1 heads)
+  OBSEXC: computing relevant nodes
+  OBSEXC: computing markers relevant to 5 nodes
+  OBSEXC: encoding 8 markers
+  OBSEXC: sending 1 pushkey payload (642 bytes)
+  OBSEXC: DONE
   $ cd ..
 
 check bumped detection
--- a/tests/test-tutorial.t	Thu Feb 27 18:30:55 2014 -0800
+++ b/tests/test-tutorial.t	Thu Feb 27 19:58:08 2014 -0800
@@ -402,6 +402,11 @@
   adding manifests
   adding file changes
   added 3 changesets with 3 changes to 1 files
+  OBSEXC: computing relevant nodes
+  OBSEXC: computing markers relevant to 5 nodes
+  OBSEXC: encoding 6 markers
+  OBSEXC: sending 1 pushkey payload (609 bytes)
+  OBSEXC: DONE
 
 for simplicity sake we get the bathroom change in line again
 
@@ -712,6 +717,11 @@
   adding manifests
   adding file changes
   added 2 changesets with 2 changes to 1 files (+1 heads)
+  OBSEXC: computing relevant nodes
+  OBSEXC: computing markers relevant to 7 nodes
+  OBSEXC: encoding 10 markers
+  OBSEXC: sending 1 pushkey payload (1004 bytes)
+  OBSEXC: DONE
 
 remote get a warning that current working directory is based on an obsolete changeset