##// END OF EJS Templates
bundle: extend the format of --type to support version and compression...
Pierre-Yves David -
r26531:15ce7851 default
parent child Browse files
Show More
@@ -10,7 +10,7 b' from i18n import _'
10 10 import os, sys, errno, re, tempfile, cStringIO, shutil
11 11 import util, scmutil, templater, patch, error, templatekw, revlog, copies
12 12 import match as matchmod
13 import repair, graphmod, revset, phases, obsolete, pathutil, changegroup
13 import repair, graphmod, revset, phases, obsolete, pathutil
14 14 import changelog
15 15 import bookmarks
16 16 import encoding
@@ -3331,19 +3331,50 b' class dirstateguard(object):'
3331 3331 raise util.Abort(msg)
3332 3332 self._abort()
3333 3333
3334 def parsebundletype(bundletype):
3334 _bundlecompspecs = {'none': None,
3335 'bzip2': 'BZ',
3336 'gzip': 'GZ',
3337 }
3338
3339 _bundleversionspecs = {'v1': '01',
3340 'v2': '02',
3341 'bundle2': '02', #legacy
3342 }
3343
3344 def parsebundletype(repo, spec):
3335 3345 """return the internal bundle type to use from a user input
3336 3346
3337 3347 This is parsing user specified bundle type as accepted in:
3338 3348
3339 3349 'hg bundle --type TYPE'.
3350
3351 It accept format in the form [compression][-version]|[version]
3340 3352 """
3341 btypes = {'none': 'HG10UN',
3342 'bzip2': 'HG10BZ',
3343 'gzip': 'HG10GZ',
3344 'bundle2': 'HG20'}
3345 bundletype = btypes.get(bundletype)
3346 if bundletype not in changegroup.bundletypes:
3353 comp, version = None, None
3354
3355 if '-' in spec:
3356 comp, version = spec.split('-', 1)
3357 elif spec in _bundlecompspecs:
3358 comp = spec
3359 elif spec in _bundleversionspecs:
3360 version = spec
3361 else:
3347 3362 raise util.Abort(_('unknown bundle type specified with --type'))
3348 return bundletype
3349
3363
3364 if comp is None:
3365 comp = 'BZ'
3366 else:
3367 try:
3368 comp = _bundlecompspecs[comp]
3369 except KeyError:
3370 raise util.Abort(_('unknown bundle type specified with --type'))
3371
3372 if version is None:
3373 version = '01'
3374 else:
3375 try:
3376 version = _bundleversionspecs[version]
3377 except KeyError:
3378 raise util.Abort(_('unknown bundle type specified with --type'))
3379
3380 return version, comp
@@ -1219,9 +1219,11 b' def bundle(ui, repo, fname, dest=None, *'
1219 1219 parameters. To create a bundle containing all changesets, use
1220 1220 -a/--all (or --base null).
1221 1221
1222 You can change compression method with the -t/--type option.
1223 The available compression methods are: none, bzip2, and
1224 gzip (by default, bundles are compressed using bzip2).
1222 You can change bundle format with the -t/--type option. You can
1223 specify a compression, a bundle version or both using a dash
1224 (comp-version). The available compression methods are: none, bzip2,
1225 and gzip (by default, bundles are compressed using bzip2). The
1226 available format are: v1, v2 (default to v1).
1225 1227
1226 1228 The bundle file can then be transferred using conventional means
1227 1229 and applied to another repository with the unbundle or pull
@@ -1238,7 +1240,7 b' def bundle(ui, repo, fname, dest=None, *'
1238 1240 revs = scmutil.revrange(repo, opts['rev'])
1239 1241
1240 1242 bundletype = opts.get('type', 'bzip2').lower()
1241 bundletype = cmdutil.parsebundletype(bundletype)
1243 cgversion, bcompression = cmdutil.parsebundletype(repo, bundletype)
1242 1244
1243 1245 if opts.get('all'):
1244 1246 base = ['null']
@@ -1253,7 +1255,8 b' def bundle(ui, repo, fname, dest=None, *'
1253 1255 common = [repo.lookup(rev) for rev in base]
1254 1256 heads = revs and map(repo.lookup, revs) or revs
1255 1257 cg = changegroup.getchangegroup(repo, 'bundle', heads=heads,
1256 common=common, bundlecaps=bundlecaps)
1258 common=common, bundlecaps=bundlecaps,
1259 version=cgversion)
1257 1260 outgoing = None
1258 1261 else:
1259 1262 dest = ui.expandpath(dest or 'default-push', dest or 'default')
@@ -1266,12 +1269,22 b' def bundle(ui, repo, fname, dest=None, *'
1266 1269 force=opts.get('force'),
1267 1270 portable=True)
1268 1271 cg = changegroup.getlocalchangegroup(repo, 'bundle', outgoing,
1269 bundlecaps)
1272 bundlecaps, version=cgversion)
1270 1273 if not cg:
1271 1274 scmutil.nochangesfound(ui, repo, outgoing and outgoing.excluded)
1272 1275 return 1
1273 1276
1274 changegroup.writebundle(ui, cg, fname, bundletype)
1277 if cgversion == '01': #bundle1
1278 if bcompression is None:
1279 bcompression = 'UN'
1280 bversion = 'HG10' + bcompression
1281 bcompression = None
1282 else:
1283 assert cgversion == '02'
1284 bversion = 'HG20'
1285
1286
1287 changegroup.writebundle(ui, cg, fname, bversion, compression=bcompression)
1275 1288
1276 1289 @command('cat',
1277 1290 [('o', 'output', '',
@@ -29,7 +29,7 b' bundle w/o type option'
29 29
30 30 test bundle types
31 31
32 $ for t in "None" "bzip2" "gzip"; do
32 $ for t in "None" "bzip2" "gzip" "none-v2" "v2" "v1" "gzip-v1"; do
33 33 > echo % test bundle type $t
34 34 > hg init t$t
35 35 > cd t1
@@ -58,6 +58,34 b' test bundle types'
58 58 HG10GZ
59 59 c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
60 60
61 % test bundle type none-v2
62 searching for changes
63 1 changesets found
64 HG20\x00\x00 (esc)
65 Stream params: {}
66 changegroup -- "{'version': '01'}"
67 c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
68
69 % test bundle type v2
70 searching for changes
71 1 changesets found
72 HG20\x00\x00 (esc)
73 Stream params: {'Compression': 'BZ'}
74 changegroup -- "{'version': '01'}"
75 c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
76
77 % test bundle type v1
78 searching for changes
79 1 changesets found
80 HG10BZ
81 c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
82
83 % test bundle type gzip-v1
84 searching for changes
85 1 changesets found
86 HG10GZ
87 c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
88
61 89
62 90 test garbage file
63 91
General Comments 0
You need to be logged in to leave comments. Login now