comparison hgext/evolve.py @ 1034:5fd28e46e8f5

evolve: move OBSEXC progress in a dedicated function This will help use to rework them.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 08 Aug 2014 17:10:31 -0700
parents 908273755215
children 59bc29c84ce0
comparison
equal deleted inserted replaced
1033:908273755215 1034:5fd28e46e8f5
2227 2227
2228 def obsexcmsg(ui, message): 2228 def obsexcmsg(ui, message):
2229 message = 'OBSEXC: ' + message 2229 message = 'OBSEXC: ' + message
2230 ui.status(message) 2230 ui.status(message)
2231 2231
2232 def obsexcprg(ui, *args, **kwargs):
2233 ui.progress('OBSEXC', *args, **kwargs)
2234
2232 2235
2233 @command('debugobsoleterelevant', 2236 @command('debugobsoleterelevant',
2234 [], 2237 [],
2235 'REVSET') 2238 'REVSET')
2236 def debugobsoleterelevant(ui, repo, *revsets): 2239 def debugobsoleterelevant(ui, repo, *revsets):
2305 @util.propertycache 2308 @util.propertycache
2306 def length(self): 2309 def length(self):
2307 return len(self.getvalue()) 2310 return len(self.getvalue())
2308 2311
2309 def read(self, size): 2312 def read(self, size):
2310 self.ui.progress('OBSEXC', self.tell(), unit="bytes", 2313 obsexcprg(self.ui, self.tell(), unit="bytes", total=self.length)
2311 total=self.length)
2312 return StringIO.read(self, size) 2314 return StringIO.read(self, size)
2313 2315
2314 def __iter__(self): 2316 def __iter__(self):
2315 d = self.read(4096) 2317 d = self.read(4096)
2316 while d: 2318 while d:
2398 obsdata.ui = repo.ui 2400 obsdata.ui = repo.ui
2399 obsexcmsg(repo.ui, "pushing %i markers (%i bytes)\n" 2401 obsexcmsg(repo.ui, "pushing %i markers (%i bytes)\n"
2400 % (len(markers), len(obsdata.getvalue()))) 2402 % (len(markers), len(obsdata.getvalue())))
2401 bundler.newpart('EVOLVE:B2X:OBSMARKERV1', data=obsdata) 2403 bundler.newpart('EVOLVE:B2X:OBSMARKERV1', data=obsdata)
2402 def callback(op): 2404 def callback(op):
2403 repo.ui.progress('OBSEXC', None) 2405 obsexcprg(repo.ui, None)
2404 obsexcmsg(repo.ui, "DONE\n") 2406 obsexcmsg(repo.ui, "DONE\n")
2405 return callback 2407 return callback
2406 bundle2partsgenerators.append(_pushb2phases) 2408 bundle2partsgenerators.append(_pushb2phases)
2407 bundle2partsgenerators.append(_pushb2obsmarker) 2409 bundle2partsgenerators.append(_pushb2obsmarker)
2408 2410
2484 raise util.Abort('missing support for %s' % exc) 2486 raise util.Abort('missing support for %s' % exc)
2485 try: 2487 try:
2486 op = bundle2.processbundle(pushop.repo, reply) 2488 op = bundle2.processbundle(pushop.repo, reply)
2487 except bundle2.UnknownPartError, exc: 2489 except bundle2.UnknownPartError, exc:
2488 raise util.Abort('missing support for %s' % exc) 2490 raise util.Abort('missing support for %s' % exc)
2489 repo.ui.progress('OBSEXC', None) 2491 obsexcprg(repo.ui, None)
2490 elif remote.capable('_evoext_pushobsmarkers_0'): 2492 elif remote.capable('_evoext_pushobsmarkers_0'):
2491 obsdata = pushobsmarkerStringIO() 2493 obsdata = pushobsmarkerStringIO()
2492 _encodemarkersstream(obsdata, markers) 2494 _encodemarkersstream(obsdata, markers)
2493 obsdata.seek(0) 2495 obsdata.seek(0)
2494 obsdata.ui = repo.ui 2496 obsdata.ui = repo.ui
2495 obsexcmsg(repo.ui, "pushing %i markers (%i bytes)\n" 2497 obsexcmsg(repo.ui, "pushing %i markers (%i bytes)\n"
2496 % (len(markers), len(obsdata.getvalue()))) 2498 % (len(markers), len(obsdata.getvalue())))
2497 remote.evoext_pushobsmarkers_0(obsdata) 2499 remote.evoext_pushobsmarkers_0(obsdata)
2498 repo.ui.progress('OBSEXC', None) 2500 obsexcprg(repo.ui, None)
2499 else: 2501 else:
2500 rslts = [] 2502 rslts = []
2501 remotedata = _pushkeyescape(markers).items() 2503 remotedata = _pushkeyescape(markers).items()
2502 totalbytes = sum(len(d) for k,d in remotedata) 2504 totalbytes = sum(len(d) for k,d in remotedata)
2503 sentbytes = 0 2505 sentbytes = 0
2504 obsexcmsg(repo.ui, "pushing %i markers in %i pushkey payload (%i bytes)\n" 2506 obsexcmsg(repo.ui, "pushing %i markers in %i pushkey payload (%i bytes)\n"
2505 % (len(markers), len(remotedata), totalbytes)) 2507 % (len(markers), len(remotedata), totalbytes))
2506 for key, data in remotedata: 2508 for key, data in remotedata:
2507 repo.ui.progress('OBSEXC', sentbytes, item=key, unit="bytes", 2509 obsexcprg(repo.ui, sentbytes, item=key, unit="bytes",
2508 total=totalbytes) 2510 total=totalbytes)
2509 rslts.append(remote.pushkey('obsolete', key, '', data)) 2511 rslts.append(remote.pushkey('obsolete', key, '', data))
2510 sentbytes += len(data) 2512 sentbytes += len(data)
2511 repo.ui.progress('OBSEXC', sentbytes, item=key, unit="bytes", 2513 obsexcprg(repo.ui, sentbytes, item=key, unit="bytes",
2512 total=totalbytes) 2514 total=totalbytes)
2513 repo.ui.progress('OBSEXC', None) 2515 obsexcprg(repo.ui, None)
2514 if [r for r in rslts if not r]: 2516 if [r for r in rslts if not r]:
2515 msg = _('failed to push some obsolete markers!\n') 2517 msg = _('failed to push some obsolete markers!\n')
2516 repo.ui.warn(msg) 2518 repo.ui.warn(msg)
2517 obsexcmsg(repo.ui, "DONE\n") 2519 obsexcmsg(repo.ui, "DONE\n")
2518 2520
2570 obsdata = inpart.read() 2572 obsdata = inpart.read()
2571 else: 2573 else:
2572 length = int(length) 2574 length = int(length)
2573 data = StringIO() 2575 data = StringIO()
2574 current = 0 2576 current = 0
2575 op.ui.progress('OBSEXC', current, unit="bytes", total=length) 2577 obsexcprg(op.repo.ui, current, unit="bytes", total=length)
2576 while current < length: 2578 while current < length:
2577 readsize = min(length-current, 4096) 2579 readsize = min(length-current, 4096)
2578 data.write(inpart.read(readsize)) 2580 data.write(inpart.read(readsize))
2579 current += readsize 2581 current += readsize
2580 op.ui.progress('OBSEXC', current, unit="bytes", total=length) 2582 obsexcprg(op.repo.ui, current, unit="bytes", total=length)
2581 op.ui.progress('OBSEXC', None) 2583 obsexcprg(op.repo.ui, None)
2582 obsdata = data.getvalue() 2584 obsdata = data.getvalue()
2583 totalsize = len(obsdata) 2585 totalsize = len(obsdata)
2584 old = len(op.repo.obsstore._all) 2586 old = len(op.repo.obsstore._all)
2585 op.repo.obsstore.mergemarkers(tr, obsdata) 2587 op.repo.obsstore.mergemarkers(tr, obsdata)
2586 new = len(op.repo.obsstore._all) - old 2588 new = len(op.repo.obsstore._all) - old
2730 length = int(f.read(20)) 2732 length = int(f.read(20))
2731 chunk = 4096 2733 chunk = 4096
2732 current = 0 2734 current = 0
2733 data = StringIO() 2735 data = StringIO()
2734 ui = self.ui 2736 ui = self.ui
2735 ui.progress('OBSEXC', current, unit="bytes", total=length) 2737 obsexcprg(ui, current, unit="bytes", total=length)
2736 while current < length: 2738 while current < length:
2737 readsize = min(length-current, chunk) 2739 readsize = min(length-current, chunk)
2738 data.write(f.read(readsize)) 2740 data.write(f.read(readsize))
2739 current += readsize 2741 current += readsize
2740 ui.progress('OBSEXC', current, unit="bytes", total=length) 2742 obsexcprg(ui, current, unit="bytes", total=length)
2741 ui.progress('OBSEXC', None) 2743 obsexcprg(ui, None)
2742 data.seek(0) 2744 data.seek(0)
2743 return data 2745 return data
2744 2746
2745 @eh.addattr(localrepo.localpeer, 'evoext_pullobsmarkers_0') 2747 @eh.addattr(localrepo.localpeer, 'evoext_pullobsmarkers_0')
2746 def local_pullobsmarkers(self, heads=None, common=None): 2748 def local_pullobsmarkers(self, heads=None, common=None):