D2102: infinitepush: drop the scratchbookmarksparttype bundle2 part

2018-03-30 Thread pulkit (Pulkit Goyal)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG5a9692d0d6fc: infinitepush: drop the 
scratchbookmarksparttype bundle2 part (authored by pulkit, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2102?vs=5363=7417

REVISION DETAIL
  https://phab.mercurial-scm.org/D2102

AFFECTED FILES
  hgext/infinitepush/__init__.py
  hgext/infinitepush/bundleparts.py
  hgext/infinitepush/common.py

CHANGE DETAILS

diff --git a/hgext/infinitepush/common.py b/hgext/infinitepush/common.py
--- a/hgext/infinitepush/common.py
+++ b/hgext/infinitepush/common.py
@@ -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
diff --git a/hgext/infinitepush/bundleparts.py 
b/hgext/infinitepush/bundleparts.py
--- a/hgext/infinitepush/bundleparts.py
+++ b/hgext/infinitepush/bundleparts.py
@@ -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):
diff --git a/hgext/infinitepush/__init__.py b/hgext/infinitepush/__init__.py
--- a/hgext/infinitepush/__init__.py
+++ b/hgext/infinitepush/__init__.py
@@ -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 

D2102: infinitepush: drop the scratchbookmarksparttype bundle2 part

2018-02-09 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2102

AFFECTED FILES
  hgext/infinitepush/__init__.py
  hgext/infinitepush/bundleparts.py
  hgext/infinitepush/common.py

CHANGE DETAILS

diff --git a/hgext/infinitepush/common.py b/hgext/infinitepush/common.py
--- a/hgext/infinitepush/common.py
+++ b/hgext/infinitepush/common.py
@@ -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
diff --git a/hgext/infinitepush/bundleparts.py 
b/hgext/infinitepush/bundleparts.py
--- a/hgext/infinitepush/bundleparts.py
+++ b/hgext/infinitepush/bundleparts.py
@@ -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):
diff --git a/hgext/infinitepush/__init__.py b/hgext/infinitepush/__init__.py
--- a/hgext/infinitepush/__init__.py
+++ b/hgext/infinitepush/__init__.py
@@ -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