##// END OF EJS Templates
bundlerepo: move temp bundle creation to a separate function...
Durham Goode -
r33888:702a26fe default
parent child Browse files
Show More
@@ -264,24 +264,6 b' def _getfilestarts(bundle):'
264
264
265 class bundlerepository(localrepo.localrepository):
265 class bundlerepository(localrepo.localrepository):
266 def __init__(self, ui, path, bundlename):
266 def __init__(self, ui, path, bundlename):
267 def _writetempbundle(read, suffix, header=''):
268 """Write a temporary file to disk
269
270 This is closure because we need to make sure this tracked by
271 self.tempfile for cleanup purposes."""
272 fdtemp, temp = self.vfs.mkstemp(prefix="hg-bundle-",
273 suffix=".hg10un")
274 self.tempfile = temp
275
276 with os.fdopen(fdtemp, pycompat.sysstr('wb')) as fptemp:
277 fptemp.write(header)
278 while True:
279 chunk = read(2**18)
280 if not chunk:
281 break
282 fptemp.write(chunk)
283
284 return self.vfs.open(self.tempfile, mode="rb")
285 self._tempparent = None
267 self._tempparent = None
286 try:
268 try:
287 localrepo.localrepository.__init__(self, ui, path)
269 localrepo.localrepository.__init__(self, ui, path)
@@ -314,8 +296,8 b' class bundlerepository(localrepo.localre'
314 msg = _('Unsupported changegroup version: %s')
296 msg = _('Unsupported changegroup version: %s')
315 raise error.Abort(msg % version)
297 raise error.Abort(msg % version)
316 if self.bundle.compressed():
298 if self.bundle.compressed():
317 cgstream = _writetempbundle(part.read,
299 cgstream = self._writetempbundle(part.read,
318 ".cg%sun" % version)
300 ".cg%sun" % version)
319
301
320 if cgstream is None:
302 if cgstream is None:
321 raise error.Abort(_('No changegroups found'))
303 raise error.Abort(_('No changegroups found'))
@@ -324,7 +306,8 b' class bundlerepository(localrepo.localre'
324 self.bundle = changegroup.getunbundler(version, cgstream, 'UN')
306 self.bundle = changegroup.getunbundler(version, cgstream, 'UN')
325
307
326 elif self.bundle.compressed():
308 elif self.bundle.compressed():
327 f = _writetempbundle(self.bundle.read, '.hg10un', header='HG10UN')
309 f = self._writetempbundle(self.bundle.read, '.hg10un',
310 header='HG10UN')
328 self.bundlefile = self.bundle = exchange.readbundle(ui, f,
311 self.bundlefile = self.bundle = exchange.readbundle(ui, f,
329 bundlename,
312 bundlename,
330 self.vfs)
313 self.vfs)
@@ -336,6 +319,23 b' class bundlerepository(localrepo.localre'
336 phases.retractboundary(self, None, phases.draft,
319 phases.retractboundary(self, None, phases.draft,
337 [ctx.node() for ctx in self[self.firstnewrev:]])
320 [ctx.node() for ctx in self[self.firstnewrev:]])
338
321
322 def _writetempbundle(self, readfn, suffix, header=''):
323 """Write a temporary file to disk
324 """
325 fdtemp, temp = self.vfs.mkstemp(prefix="hg-bundle-",
326 suffix=".hg10un")
327 self.tempfile = temp
328
329 with os.fdopen(fdtemp, pycompat.sysstr('wb')) as fptemp:
330 fptemp.write(header)
331 while True:
332 chunk = readfn(2**18)
333 if not chunk:
334 break
335 fptemp.write(chunk)
336
337 return self.vfs.open(self.tempfile, mode="rb")
338
339 @localrepo.unfilteredpropertycache
339 @localrepo.unfilteredpropertycache
340 def _phasecache(self):
340 def _phasecache(self):
341 return bundlephasecache(self, self._phasedefaults)
341 return bundlephasecache(self, self._phasedefaults)
General Comments 0
You need to be logged in to leave comments. Login now