comparison mercurial/hgweb/webutil.py @ 29216:ead25aa27a43

py3: convert to next() function next(..) was introduced in py2.6 and .next() is not available in py3 https://docs.python.org/2/library/functions.html#next
author timeless <timeless@mozdev.org>
date Mon, 16 May 2016 21:30:53 +0000
parents 94494031f659
children dd0ff715a82c
comparison
equal deleted inserted replaced
29215:f5983805574e 29216:ead25aa27a43
73 return self._first() is not None 73 return self._first() is not None
74 74
75 def _first(self): 75 def _first(self):
76 """return the minimum non-filtered changeset or None""" 76 """return the minimum non-filtered changeset or None"""
77 try: 77 try:
78 return iter(self._revlog).next() 78 return next(iter(self._revlog))
79 except StopIteration: 79 except StopIteration:
80 return None 80 return None
81 81
82 def hex(self, rev): 82 def hex(self, rev):
83 return hex(self._revlog.node(rev)) 83 return hex(self._revlog.node(rev))
245 elif ctx.node() not in heads: 245 elif ctx.node() not in heads:
246 status = 'inactive' 246 status = 'inactive'
247 else: 247 else:
248 status = 'open' 248 status = 'open'
249 yield { 249 yield {
250 'parity': parity.next(), 250 'parity': next(parity),
251 'branch': ctx.branch(), 251 'branch': ctx.branch(),
252 'status': status, 252 'status': status,
253 'node': ctx.hex(), 253 'node': ctx.hex(),
254 'date': ctx.date() 254 'date': ctx.date()
255 } 255 }
367 parity = paritygen(web.stripecount) 367 parity = paritygen(web.stripecount)
368 for blockno, f in enumerate(ctx.files()): 368 for blockno, f in enumerate(ctx.files()):
369 template = f in ctx and 'filenodelink' or 'filenolink' 369 template = f in ctx and 'filenodelink' or 'filenolink'
370 files.append(tmpl(template, 370 files.append(tmpl(template,
371 node=ctx.hex(), file=f, blockno=blockno + 1, 371 node=ctx.hex(), file=f, blockno=blockno + 1,
372 parity=parity.next())) 372 parity=next(parity)))
373 373
374 basectx = basechangectx(web.repo, req) 374 basectx = basechangectx(web.repo, req)
375 if basectx is None: 375 if basectx is None:
376 basectx = ctx.p1() 376 basectx = ctx.p1()
377 377
448 node2 = ctx.node() 448 node2 = ctx.node()
449 449
450 block = [] 450 block = []
451 for chunk in patch.diff(repo, node1, node2, m, opts=diffopts): 451 for chunk in patch.diff(repo, node1, node2, m, opts=diffopts):
452 if chunk.startswith('diff') and block: 452 if chunk.startswith('diff') and block:
453 blockno = blockcount.next() 453 blockno = next(blockcount)
454 yield tmpl('diffblock', parity=parity.next(), blockno=blockno, 454 yield tmpl('diffblock', parity=next(parity), blockno=blockno,
455 lines=prettyprintlines(''.join(block), blockno)) 455 lines=prettyprintlines(''.join(block), blockno))
456 block = [] 456 block = []
457 if chunk.startswith('diff') and style != 'raw': 457 if chunk.startswith('diff') and style != 'raw':
458 chunk = ''.join(chunk.splitlines(True)[1:]) 458 chunk = ''.join(chunk.splitlines(True)[1:])
459 block.append(chunk) 459 block.append(chunk)
460 blockno = blockcount.next() 460 blockno = next(blockcount)
461 yield tmpl('diffblock', parity=parity.next(), blockno=blockno, 461 yield tmpl('diffblock', parity=next(parity), blockno=blockno,
462 lines=prettyprintlines(''.join(block), blockno)) 462 lines=prettyprintlines(''.join(block), blockno))
463 463
464 def compare(tmpl, context, leftlines, rightlines): 464 def compare(tmpl, context, leftlines, rightlines):
465 '''Generator function that provides side-by-side comparison data.''' 465 '''Generator function that provides side-by-side comparison data.'''
466 466
519 yield stats, maxname, maxtotal, addtotal, removetotal, binary 519 yield stats, maxname, maxtotal, addtotal, removetotal, binary
520 520
521 def diffsummary(statgen): 521 def diffsummary(statgen):
522 '''Return a short summary of the diff.''' 522 '''Return a short summary of the diff.'''
523 523
524 stats, maxname, maxtotal, addtotal, removetotal, binary = statgen.next() 524 stats, maxname, maxtotal, addtotal, removetotal, binary = next(statgen)
525 return _(' %d files changed, %d insertions(+), %d deletions(-)\n') % ( 525 return _(' %d files changed, %d insertions(+), %d deletions(-)\n') % (
526 len(stats), addtotal, removetotal) 526 len(stats), addtotal, removetotal)
527 527
528 def diffstat(tmpl, ctx, statgen, parity): 528 def diffstat(tmpl, ctx, statgen, parity):
529 '''Return a diffstat template for each file in the diff.''' 529 '''Return a diffstat template for each file in the diff.'''
530 530
531 stats, maxname, maxtotal, addtotal, removetotal, binary = statgen.next() 531 stats, maxname, maxtotal, addtotal, removetotal, binary = next(statgen)
532 files = ctx.files() 532 files = ctx.files()
533 533
534 def pct(i): 534 def pct(i):
535 if maxtotal == 0: 535 if maxtotal == 0:
536 return 0 536 return 0
541 template = filename in files and 'diffstatlink' or 'diffstatnolink' 541 template = filename in files and 'diffstatlink' or 'diffstatnolink'
542 total = adds + removes 542 total = adds + removes
543 fileno += 1 543 fileno += 1
544 yield tmpl(template, node=ctx.hex(), file=filename, fileno=fileno, 544 yield tmpl(template, node=ctx.hex(), file=filename, fileno=fileno,
545 total=total, addpct=pct(adds), removepct=pct(removes), 545 total=total, addpct=pct(adds), removepct=pct(removes),
546 parity=parity.next()) 546 parity=next(parity))
547 547
548 class sessionvars(object): 548 class sessionvars(object):
549 def __init__(self, vars, start='?'): 549 def __init__(self, vars, start='?'):
550 self.start = start 550 self.start = start
551 self.vars = vars 551 self.vars = vars