241 if branch != 'default': |
241 if branch != 'default': |
242 branches.append({"name": branch}) |
242 branches.append({"name": branch}) |
243 return branches |
243 return branches |
244 |
244 |
245 def showtag(repo, tmpl, t1, node=nullid, **args): |
245 def showtag(repo, tmpl, t1, node=nullid, **args): |
|
246 args = pycompat.byteskwargs(args) |
246 for t in repo.nodetags(node): |
247 for t in repo.nodetags(node): |
247 yield tmpl(t1, tag=t, **args) |
248 lm = args.copy() |
|
249 lm['tag'] = t |
|
250 yield tmpl.generate(t1, lm) |
248 |
251 |
249 def showbookmark(repo, tmpl, t1, node=nullid, **args): |
252 def showbookmark(repo, tmpl, t1, node=nullid, **args): |
|
253 args = pycompat.byteskwargs(args) |
250 for t in repo.nodebookmarks(node): |
254 for t in repo.nodebookmarks(node): |
251 yield tmpl(t1, bookmark=t, **args) |
255 lm = args.copy() |
|
256 lm['bookmark'] = t |
|
257 yield tmpl.generate(t1, lm) |
252 |
258 |
253 def branchentries(repo, stripecount, limit=0): |
259 def branchentries(repo, stripecount, limit=0): |
254 tips = [] |
260 tips = [] |
255 heads = repo.heads() |
261 heads = repo.heads() |
256 parity = paritygen(stripecount) |
262 parity = paritygen(stripecount) |
441 |
447 |
442 files = [] |
448 files = [] |
443 parity = paritygen(web.stripecount) |
449 parity = paritygen(web.stripecount) |
444 for blockno, f in enumerate(ctx.files()): |
450 for blockno, f in enumerate(ctx.files()): |
445 template = 'filenodelink' if f in ctx else 'filenolink' |
451 template = 'filenodelink' if f in ctx else 'filenolink' |
446 files.append(web.tmpl(template, |
452 files.append(web.tmpl.generate(template, { |
447 node=ctx.hex(), file=f, blockno=blockno + 1, |
453 'node': ctx.hex(), |
448 parity=next(parity))) |
454 'file': f, |
|
455 'blockno': blockno + 1, |
|
456 'parity': next(parity), |
|
457 })) |
449 |
458 |
450 basectx = basechangectx(web.repo, web.req) |
459 basectx = basechangectx(web.repo, web.req) |
451 if basectx is None: |
460 if basectx is None: |
452 basectx = ctx.p1() |
461 basectx = ctx.p1() |
453 |
462 |
474 archives=web.archivelist(ctx.hex()), |
483 archives=web.archivelist(ctx.hex()), |
475 **pycompat.strkwargs(commonentry(web.repo, ctx))) |
484 **pycompat.strkwargs(commonentry(web.repo, ctx))) |
476 |
485 |
477 def listfilediffs(tmpl, files, node, max): |
486 def listfilediffs(tmpl, files, node, max): |
478 for f in files[:max]: |
487 for f in files[:max]: |
479 yield tmpl('filedifflink', node=hex(node), file=f) |
488 yield tmpl.generate('filedifflink', {'node': hex(node), 'file': f}) |
480 if len(files) > max: |
489 if len(files) > max: |
481 yield tmpl('fileellipses') |
490 yield tmpl.generate('fileellipses', {}) |
482 |
491 |
483 def diffs(web, ctx, basectx, files, style, linerange=None, |
492 def diffs(web, ctx, basectx, files, style, linerange=None, |
484 lineidprefix=''): |
493 lineidprefix=''): |
485 |
494 |
486 def prettyprintlines(lines, blockno): |
495 def prettyprintlines(lines, blockno): |
492 ltype = "difflineminus" |
501 ltype = "difflineminus" |
493 elif l.startswith('@'): |
502 elif l.startswith('@'): |
494 ltype = "difflineat" |
503 ltype = "difflineat" |
495 else: |
504 else: |
496 ltype = "diffline" |
505 ltype = "diffline" |
497 yield web.tmpl( |
506 yield web.tmpl.generate(ltype, { |
498 ltype, |
507 'line': l, |
499 line=l, |
508 'lineno': lineno, |
500 lineno=lineno, |
509 'lineid': lineidprefix + "l%s" % difflineno, |
501 lineid=lineidprefix + "l%s" % difflineno, |
510 'linenumber': "% 8s" % difflineno, |
502 linenumber="% 8s" % difflineno) |
511 }) |
503 |
512 |
504 repo = web.repo |
513 repo = web.repo |
505 if files: |
514 if files: |
506 m = match.exact(repo.root, repo.getcwd(), files) |
515 m = match.exact(repo.root, repo.getcwd(), files) |
507 else: |
516 else: |
522 s1, l1, s2, l2 = hunkrange |
531 s1, l1, s2, l2 = hunkrange |
523 if not mdiff.hunkinrange((s2, l2), linerange): |
532 if not mdiff.hunkinrange((s2, l2), linerange): |
524 continue |
533 continue |
525 lines.extend(hunklines) |
534 lines.extend(hunklines) |
526 if lines: |
535 if lines: |
527 yield web.tmpl('diffblock', parity=next(parity), blockno=blockno, |
536 yield web.tmpl.generate('diffblock', { |
528 lines=prettyprintlines(lines, blockno)) |
537 'parity': next(parity), |
|
538 'blockno': blockno, |
|
539 'lines': prettyprintlines(lines, blockno), |
|
540 }) |
529 |
541 |
530 def compare(tmpl, context, leftlines, rightlines): |
542 def compare(tmpl, context, leftlines, rightlines): |
531 '''Generator function that provides side-by-side comparison data.''' |
543 '''Generator function that provides side-by-side comparison data.''' |
532 |
544 |
533 def compline(type, leftlineno, leftline, rightlineno, rightline): |
545 def compline(type, leftlineno, leftline, rightlineno, rightline): |
534 lineid = leftlineno and ("l%d" % leftlineno) or '' |
546 lineid = leftlineno and ("l%d" % leftlineno) or '' |
535 lineid += rightlineno and ("r%d" % rightlineno) or '' |
547 lineid += rightlineno and ("r%d" % rightlineno) or '' |
536 llno = '%d' % leftlineno if leftlineno else '' |
548 llno = '%d' % leftlineno if leftlineno else '' |
537 rlno = '%d' % rightlineno if rightlineno else '' |
549 rlno = '%d' % rightlineno if rightlineno else '' |
538 return tmpl('comparisonline', |
550 return tmpl.generate('comparisonline', { |
539 type=type, |
551 'type': type, |
540 lineid=lineid, |
552 'lineid': lineid, |
541 leftlineno=leftlineno, |
553 'leftlineno': leftlineno, |
542 leftlinenumber="% 6s" % llno, |
554 'leftlinenumber': "% 6s" % llno, |
543 leftline=leftline or '', |
555 'leftline': leftline or '', |
544 rightlineno=rightlineno, |
556 'rightlineno': rightlineno, |
545 rightlinenumber="% 6s" % rlno, |
557 'rightlinenumber': "% 6s" % rlno, |
546 rightline=rightline or '') |
558 'rightline': rightline or '', |
|
559 }) |
547 |
560 |
548 def getblock(opcodes): |
561 def getblock(opcodes): |
549 for type, llo, lhi, rlo, rhi in opcodes: |
562 for type, llo, lhi, rlo, rhi in opcodes: |
550 len1 = lhi - llo |
563 len1 = lhi - llo |
551 len2 = rhi - rlo |
564 len2 = rhi - rlo |
571 rightlineno=i + 1, |
584 rightlineno=i + 1, |
572 rightline=rightlines[i]) |
585 rightline=rightlines[i]) |
573 |
586 |
574 s = difflib.SequenceMatcher(None, leftlines, rightlines) |
587 s = difflib.SequenceMatcher(None, leftlines, rightlines) |
575 if context < 0: |
588 if context < 0: |
576 yield tmpl('comparisonblock', lines=getblock(s.get_opcodes())) |
589 yield tmpl.generate('comparisonblock', |
|
590 {'lines': getblock(s.get_opcodes())}) |
577 else: |
591 else: |
578 for oc in s.get_grouped_opcodes(n=context): |
592 for oc in s.get_grouped_opcodes(n=context): |
579 yield tmpl('comparisonblock', lines=getblock(oc)) |
593 yield tmpl.generate('comparisonblock', {'lines': getblock(oc)}) |
580 |
594 |
581 def diffstatgen(ctx, basectx): |
595 def diffstatgen(ctx, basectx): |
582 '''Generator function that provides the diffstat data.''' |
596 '''Generator function that provides the diffstat data.''' |
583 |
597 |
584 stats = patch.diffstatdata( |
598 stats = patch.diffstatdata( |
608 fileno = 0 |
622 fileno = 0 |
609 for filename, adds, removes, isbinary in stats: |
623 for filename, adds, removes, isbinary in stats: |
610 template = 'diffstatlink' if filename in files else 'diffstatnolink' |
624 template = 'diffstatlink' if filename in files else 'diffstatnolink' |
611 total = adds + removes |
625 total = adds + removes |
612 fileno += 1 |
626 fileno += 1 |
613 yield tmpl(template, node=ctx.hex(), file=filename, fileno=fileno, |
627 yield tmpl.generate(template, { |
614 total=total, addpct=pct(adds), removepct=pct(removes), |
628 'node': ctx.hex(), |
615 parity=next(parity)) |
629 'file': filename, |
|
630 'fileno': fileno, |
|
631 'total': total, |
|
632 'addpct': pct(adds), |
|
633 'removepct': pct(removes), |
|
634 'parity': next(parity), |
|
635 }) |
616 |
636 |
617 class sessionvars(object): |
637 class sessionvars(object): |
618 def __init__(self, vars, start='?'): |
638 def __init__(self, vars, start='?'): |
619 self.start = start |
639 self.start = start |
620 self.vars = vars |
640 self.vars = vars |