##// END OF EJS Templates
infinitepush: drop the scratchbookmarksparttype bundle2 part...
Pulkit Goyal -
r37210:5a9692d0 default
parent child Browse files
Show More
@@ -91,13 +91,11 b' import collections'
91 import contextlib
91 import contextlib
92 import errno
92 import errno
93 import functools
93 import functools
94 import json
95 import logging
94 import logging
96 import os
95 import os
97 import random
96 import random
98 import re
97 import re
99 import socket
98 import socket
100 import struct
101 import subprocess
99 import subprocess
102 import sys
100 import sys
103 import tempfile
101 import tempfile
@@ -682,19 +680,6 b' def _lookupwrap(orig):'
682 return "%s %s\n" % (0, r)
680 return "%s %s\n" % (0, r)
683 return _lookup
681 return _lookup
684
682
685 def _decodebookmarks(stream):
686 sizeofjsonsize = struct.calcsize('>i')
687 size = struct.unpack('>i', stream.read(sizeofjsonsize))[0]
688 unicodedict = json.loads(stream.read(size))
689 # python json module always returns unicode strings. We need to convert
690 # it back to bytes string
691 result = {}
692 for bookmark, node in unicodedict.iteritems():
693 bookmark = bookmark.encode('ascii')
694 node = node.encode('ascii')
695 result[bookmark] = node
696 return result
697
698 def _update(orig, ui, repo, node=None, rev=None, **opts):
683 def _update(orig, ui, repo, node=None, rev=None, **opts):
699 if rev and node:
684 if rev and node:
700 raise error.Abort(_("please specify just one revision"))
685 raise error.Abort(_("please specify just one revision"))
@@ -985,7 +970,6 b' def partgen(pushop, bundler):'
985 return handlereply
970 return handlereply
986
971
987 bundle2.capabilities[bundleparts.scratchbranchparttype] = ()
972 bundle2.capabilities[bundleparts.scratchbranchparttype] = ()
988 bundle2.capabilities[bundleparts.scratchbookmarksparttype] = ()
989
973
990 def _getrevs(bundle, oldnode, force, bookmark):
974 def _getrevs(bundle, oldnode, force, bookmark):
991 'extracts and validates the revs to be imported'
975 'extracts and validates the revs to be imported'
@@ -1059,7 +1043,6 b' def processparts(orig, repo, op, unbundl'
1059
1043
1060 bundler = bundle2.bundle20(repo.ui)
1044 bundler = bundle2.bundle20(repo.ui)
1061 cgparams = None
1045 cgparams = None
1062 scratchbookpart = None
1063 with bundle2.partiterator(repo, op, unbundler) as parts:
1046 with bundle2.partiterator(repo, op, unbundler) as parts:
1064 for part in parts:
1047 for part in parts:
1065 bundlepart = None
1048 bundlepart = None
@@ -1084,14 +1067,6 b' def processparts(orig, repo, op, unbundl'
1084 op.records.add(scratchbranchparttype + '_skippushkey', True)
1067 op.records.add(scratchbranchparttype + '_skippushkey', True)
1085 op.records.add(scratchbranchparttype + '_skipphaseheads',
1068 op.records.add(scratchbranchparttype + '_skipphaseheads',
1086 True)
1069 True)
1087 elif part.type == bundleparts.scratchbookmarksparttype:
1088 # Save this for later processing. Details below.
1089 #
1090 # Upstream https://phab.mercurial-scm.org/D1389 and its
1091 # follow-ups stop part.seek support to reduce memory usage
1092 # (https://bz.mercurial-scm.org/5691). So we need to copy
1093 # the part so it can be consumed later.
1094 scratchbookpart = bundleparts.copiedpart(part)
1095 else:
1070 else:
1096 if handleallparts or part.type in partforwardingwhitelist:
1071 if handleallparts or part.type in partforwardingwhitelist:
1097 # Ideally we would not process any parts, and instead just
1072 # Ideally we would not process any parts, and instead just
@@ -1137,12 +1112,6 b' def processparts(orig, repo, op, unbundl'
1137 # we would rather see the original exception
1112 # we would rather see the original exception
1138 pass
1113 pass
1139
1114
1140 # The scratch bookmark part is sent as part of a push backup. It needs to be
1141 # processed after the main bundle has been stored, so that any commits it
1142 # references are available in the store.
1143 if scratchbookpart:
1144 bundle2._processpart(op, scratchbookpart)
1145
1146 def storebundle(op, params, bundlefile):
1115 def storebundle(op, params, bundlefile):
1147 log = _getorcreateinfinitepushlogger(op)
1116 log = _getorcreateinfinitepushlogger(op)
1148 parthandlerstart = time.time()
1117 parthandlerstart = time.time()
@@ -1269,26 +1238,6 b' def bundle2scratchbranch(op, part):'
1269
1238
1270 return 1
1239 return 1
1271
1240
1272 @bundle2.parthandler(bundleparts.scratchbookmarksparttype)
1273 def bundle2scratchbookmarks(op, part):
1274 '''Handler deletes bookmarks first then adds new bookmarks.
1275 '''
1276 index = op.repo.bundlestore.index
1277 decodedbookmarks = _decodebookmarks(part)
1278 toinsert = {}
1279 todelete = []
1280 for bookmark, node in decodedbookmarks.iteritems():
1281 if node:
1282 toinsert[bookmark] = node
1283 else:
1284 todelete.append(bookmark)
1285 log = _getorcreateinfinitepushlogger(op)
1286 with logservicecall(log, bundleparts.scratchbookmarksparttype), index:
1287 if todelete:
1288 index.deletebookmarks(todelete)
1289 if toinsert:
1290 index.addmanybookmarks(toinsert)
1291
1292 def _maybeaddpushbackpart(op, bookmark, newnode, oldnode, params):
1241 def _maybeaddpushbackpart(op, bookmark, newnode, oldnode, params):
1293 if params.get('pushbackbookmarks'):
1242 if params.get('pushbackbookmarks'):
1294 if op.reply and 'pushback' in op.reply.capabilities:
1243 if op.reply and 'pushback' in op.reply.capabilities:
@@ -18,11 +18,9 b' from mercurial import ('
18
18
19 from . import common
19 from . import common
20
20
21 encodebookmarks = common.encodebookmarks
22 isremotebooksenabled = common.isremotebooksenabled
21 isremotebooksenabled = common.isremotebooksenabled
23
22
24 scratchbranchparttype = 'b2x:infinitepush'
23 scratchbranchparttype = 'b2x:infinitepush'
25 scratchbookmarksparttype = 'b2x:infinitepushscratchbookmarks'
26
24
27 def getscratchbranchparts(repo, peer, outgoing, confignonforwardmove,
25 def getscratchbranchparts(repo, peer, outgoing, confignonforwardmove,
28 ui, bookmark, create):
26 ui, bookmark, create):
@@ -85,15 +83,6 b' def getscratchbranchparts(repo, peer, ou'
85
83
86 return parts
84 return parts
87
85
88 def getscratchbookmarkspart(peer, bookmarks):
89 if scratchbookmarksparttype not in bundle2.bundle2caps(peer):
90 raise error.Abort(
91 _('no server support for %r') % scratchbookmarksparttype)
92
93 return bundle2.bundlepart(
94 scratchbookmarksparttype.upper(),
95 data=encodebookmarks(bookmarks))
96
97 def _validaterevset(repo, revset, bookmark):
86 def _validaterevset(repo, revset, bookmark):
98 """Abort if the revs to be pushed aren't valid for a scratch branch."""
87 """Abort if the revs to be pushed aren't valid for a scratch branch."""
99 if not repo.revs(revset):
88 if not repo.revs(revset):
@@ -5,9 +5,7 b''
5
5
6 from __future__ import absolute_import
6 from __future__ import absolute_import
7
7
8 import json
9 import os
8 import os
10 import struct
11 import tempfile
9 import tempfile
12
10
13 from mercurial.node import hex
11 from mercurial.node import hex
@@ -21,14 +19,6 b' def isremotebooksenabled(ui):'
21 return ('remotenames' in extensions._extensions and
19 return ('remotenames' in extensions._extensions and
22 ui.configbool('remotenames', 'bookmarks'))
20 ui.configbool('remotenames', 'bookmarks'))
23
21
24 def encodebookmarks(bookmarks):
25 encoded = {}
26 for bookmark, node in bookmarks.iteritems():
27 encoded[bookmark] = node
28 dumped = json.dumps(encoded)
29 result = struct.pack('>i', len(dumped)) + dumped
30 return result
31
32 def downloadbundle(repo, unknownbinhead):
22 def downloadbundle(repo, unknownbinhead):
33 index = repo.bundlestore.index
23 index = repo.bundlestore.index
34 store = repo.bundlestore.store
24 store = repo.bundlestore.store
General Comments 0
You need to be logged in to leave comments. Login now