infinitepush: drop the scratchbookmarksparttype bundle2 part
authorPulkit Goyal <7895pulkit@gmail.com>
Thu, 08 Feb 2018 17:27:47 +0530
changeset 37195 5a9692d0d6fc
parent 37194 e702ca152b33
child 37196 320b1f95f676
infinitepush: drop the scratchbookmarksparttype bundle2 part The scratchbookmarksparttype bundle2 part was used in backupcommands.py which we deleted in an earlier changeset. We don't need this part anymore. Moreover we now have bookmarks bundle2 part in core which we can use. This patch also drops the related encoding and decoding functions. Differential Revision: https://phab.mercurial-scm.org/D2102
hgext/infinitepush/__init__.py
hgext/infinitepush/bundleparts.py
hgext/infinitepush/common.py
--- a/hgext/infinitepush/__init__.py	Thu Feb 08 17:18:28 2018 +0530
+++ b/hgext/infinitepush/__init__.py	Thu Feb 08 17:27:47 2018 +0530
@@ -91,13 +91,11 @@
 import contextlib
 import errno
 import functools
-import json
 import logging
 import os
 import random
 import re
 import socket
-import struct
 import subprocess
 import sys
 import tempfile
@@ -682,19 +680,6 @@
                     return "%s %s\n" % (0, r)
     return _lookup
 
-def _decodebookmarks(stream):
-    sizeofjsonsize = struct.calcsize('>i')
-    size = struct.unpack('>i', stream.read(sizeofjsonsize))[0]
-    unicodedict = json.loads(stream.read(size))
-    # python json module always returns unicode strings. We need to convert
-    # it back to bytes string
-    result = {}
-    for bookmark, node in unicodedict.iteritems():
-        bookmark = bookmark.encode('ascii')
-        node = node.encode('ascii')
-        result[bookmark] = node
-    return result
-
 def _update(orig, ui, repo, node=None, rev=None, **opts):
     if rev and node:
         raise error.Abort(_("please specify just one revision"))
@@ -985,7 +970,6 @@
     return handlereply
 
 bundle2.capabilities[bundleparts.scratchbranchparttype] = ()
-bundle2.capabilities[bundleparts.scratchbookmarksparttype] = ()
 
 def _getrevs(bundle, oldnode, force, bookmark):
     'extracts and validates the revs to be imported'
@@ -1059,7 +1043,6 @@
 
     bundler = bundle2.bundle20(repo.ui)
     cgparams = None
-    scratchbookpart = None
     with bundle2.partiterator(repo, op, unbundler) as parts:
         for part in parts:
             bundlepart = None
@@ -1084,14 +1067,6 @@
                     op.records.add(scratchbranchparttype + '_skippushkey', True)
                     op.records.add(scratchbranchparttype + '_skipphaseheads',
                                    True)
-            elif part.type == bundleparts.scratchbookmarksparttype:
-                # Save this for later processing. Details below.
-                #
-                # Upstream https://phab.mercurial-scm.org/D1389 and its
-                # follow-ups stop part.seek support to reduce memory usage
-                # (https://bz.mercurial-scm.org/5691). So we need to copy
-                # the part so it can be consumed later.
-                scratchbookpart = bundleparts.copiedpart(part)
             else:
                 if handleallparts or part.type in partforwardingwhitelist:
                     # Ideally we would not process any parts, and instead just
@@ -1137,12 +1112,6 @@
                 # we would rather see the original exception
                 pass
 
-    # The scratch bookmark part is sent as part of a push backup. It needs to be
-    # processed after the main bundle has been stored, so that any commits it
-    # references are available in the store.
-    if scratchbookpart:
-        bundle2._processpart(op, scratchbookpart)
-
 def storebundle(op, params, bundlefile):
     log = _getorcreateinfinitepushlogger(op)
     parthandlerstart = time.time()
@@ -1269,26 +1238,6 @@
 
     return 1
 
-@bundle2.parthandler(bundleparts.scratchbookmarksparttype)
-def bundle2scratchbookmarks(op, part):
-    '''Handler deletes bookmarks first then adds new bookmarks.
-    '''
-    index = op.repo.bundlestore.index
-    decodedbookmarks = _decodebookmarks(part)
-    toinsert = {}
-    todelete = []
-    for bookmark, node in decodedbookmarks.iteritems():
-        if node:
-            toinsert[bookmark] = node
-        else:
-            todelete.append(bookmark)
-    log = _getorcreateinfinitepushlogger(op)
-    with logservicecall(log, bundleparts.scratchbookmarksparttype), index:
-        if todelete:
-            index.deletebookmarks(todelete)
-        if toinsert:
-            index.addmanybookmarks(toinsert)
-
 def _maybeaddpushbackpart(op, bookmark, newnode, oldnode, params):
     if params.get('pushbackbookmarks'):
         if op.reply and 'pushback' in op.reply.capabilities:
--- a/hgext/infinitepush/bundleparts.py	Thu Feb 08 17:18:28 2018 +0530
+++ b/hgext/infinitepush/bundleparts.py	Thu Feb 08 17:27:47 2018 +0530
@@ -18,11 +18,9 @@
 
 from . import common
 
-encodebookmarks = common.encodebookmarks
 isremotebooksenabled = common.isremotebooksenabled
 
 scratchbranchparttype = 'b2x:infinitepush'
-scratchbookmarksparttype = 'b2x:infinitepushscratchbookmarks'
 
 def getscratchbranchparts(repo, peer, outgoing, confignonforwardmove,
                          ui, bookmark, create):
@@ -85,15 +83,6 @@
 
     return parts
 
-def getscratchbookmarkspart(peer, bookmarks):
-    if scratchbookmarksparttype not in bundle2.bundle2caps(peer):
-        raise error.Abort(
-            _('no server support for %r') % scratchbookmarksparttype)
-
-    return bundle2.bundlepart(
-        scratchbookmarksparttype.upper(),
-        data=encodebookmarks(bookmarks))
-
 def _validaterevset(repo, revset, bookmark):
     """Abort if the revs to be pushed aren't valid for a scratch branch."""
     if not repo.revs(revset):
--- a/hgext/infinitepush/common.py	Thu Feb 08 17:18:28 2018 +0530
+++ b/hgext/infinitepush/common.py	Thu Feb 08 17:27:47 2018 +0530
@@ -5,9 +5,7 @@
 
 from __future__ import absolute_import
 
-import json
 import os
-import struct
 import tempfile
 
 from mercurial.node import hex
@@ -21,14 +19,6 @@
     return ('remotenames' in extensions._extensions and
             ui.configbool('remotenames', 'bookmarks'))
 
-def encodebookmarks(bookmarks):
-    encoded = {}
-    for bookmark, node in bookmarks.iteritems():
-        encoded[bookmark] = node
-    dumped = json.dumps(encoded)
-    result = struct.pack('>i', len(dumped)) + dumped
-    return result
-
 def downloadbundle(repo, unknownbinhead):
     index = repo.bundlestore.index
     store = repo.bundlestore.store