mercurial/hgweb/webutil.py
changeset 36885 c68e79dcf21c
parent 36865 3d60a22e27f5
child 36886 563fd95a6efb
equal deleted inserted replaced
36884:ece242db5000 36885:c68e79dcf21c
   387         'bookmarks': nodebookmarksdict(repo, node),
   387         'bookmarks': nodebookmarksdict(repo, node),
   388         'parent': lambda **x: parents(ctx),
   388         'parent': lambda **x: parents(ctx),
   389         'child': lambda **x: children(ctx),
   389         'child': lambda **x: children(ctx),
   390     }
   390     }
   391 
   391 
   392 def changelistentry(web, ctx, tmpl):
   392 def changelistentry(web, ctx):
   393     '''Obtain a dictionary to be used for entries in a changelist.
   393     '''Obtain a dictionary to be used for entries in a changelist.
   394 
   394 
   395     This function is called when producing items for the "entries" list passed
   395     This function is called when producing items for the "entries" list passed
   396     to the "shortlog" and "changelog" templates.
   396     to the "shortlog" and "changelog" templates.
   397     '''
   397     '''
   398     repo = web.repo
   398     repo = web.repo
   399     rev = ctx.rev()
   399     rev = ctx.rev()
   400     n = ctx.node()
   400     n = ctx.node()
   401     showtags = showtag(repo, tmpl, 'changelogtag', n)
   401     showtags = showtag(repo, web.tmpl, 'changelogtag', n)
   402     files = listfilediffs(tmpl, ctx.files(), n, web.maxfiles)
   402     files = listfilediffs(web.tmpl, ctx.files(), n, web.maxfiles)
   403 
   403 
   404     entry = commonentry(repo, ctx)
   404     entry = commonentry(repo, ctx)
   405     entry.update(
   405     entry.update(
   406         allparents=lambda **x: parents(ctx),
   406         allparents=lambda **x: parents(ctx),
   407         parent=lambda **x: parents(ctx, rev - 1),
   407         parent=lambda **x: parents(ctx, rev - 1),
   415     if 'node' in req.req.qsparams:
   415     if 'node' in req.req.qsparams:
   416         return templatefilters.revescape(req.req.qsparams['node'])
   416         return templatefilters.revescape(req.req.qsparams['node'])
   417     else:
   417     else:
   418         return short(ctx.node())
   418         return short(ctx.node())
   419 
   419 
   420 def changesetentry(web, req, tmpl, ctx):
   420 def changesetentry(web, req, ctx):
   421     '''Obtain a dictionary to be used to render the "changeset" template.'''
   421     '''Obtain a dictionary to be used to render the "changeset" template.'''
   422 
   422 
   423     showtags = showtag(web.repo, tmpl, 'changesettag', ctx.node())
   423     showtags = showtag(web.repo, web.tmpl, 'changesettag', ctx.node())
   424     showbookmarks = showbookmark(web.repo, tmpl, 'changesetbookmark',
   424     showbookmarks = showbookmark(web.repo, web.tmpl, 'changesetbookmark',
   425                                  ctx.node())
   425                                  ctx.node())
   426     showbranch = nodebranchnodefault(ctx)
   426     showbranch = nodebranchnodefault(ctx)
   427 
   427 
   428     files = []
   428     files = []
   429     parity = paritygen(web.stripecount)
   429     parity = paritygen(web.stripecount)
   430     for blockno, f in enumerate(ctx.files()):
   430     for blockno, f in enumerate(ctx.files()):
   431         template = 'filenodelink' if f in ctx else 'filenolink'
   431         template = 'filenodelink' if f in ctx else 'filenolink'
   432         files.append(tmpl(template,
   432         files.append(web.tmpl(template,
   433                           node=ctx.hex(), file=f, blockno=blockno + 1,
   433                               node=ctx.hex(), file=f, blockno=blockno + 1,
   434                           parity=next(parity)))
   434                               parity=next(parity)))
   435 
   435 
   436     basectx = basechangectx(web.repo, req)
   436     basectx = basechangectx(web.repo, req)
   437     if basectx is None:
   437     if basectx is None:
   438         basectx = ctx.p1()
   438         basectx = ctx.p1()
   439 
   439 
   440     style = web.config('web', 'style')
   440     style = web.config('web', 'style')
   441     if 'style' in req.req.qsparams:
   441     if 'style' in req.req.qsparams:
   442         style = req.req.qsparams['style']
   442         style = req.req.qsparams['style']
   443 
   443 
   444     diff = diffs(web, tmpl, ctx, basectx, None, style)
   444     diff = diffs(web, ctx, basectx, None, style)
   445 
   445 
   446     parity = paritygen(web.stripecount)
   446     parity = paritygen(web.stripecount)
   447     diffstatsgen = diffstatgen(ctx, basectx)
   447     diffstatsgen = diffstatgen(ctx, basectx)
   448     diffstats = diffstat(tmpl, ctx, diffstatsgen, parity)
   448     diffstats = diffstat(web.tmpl, ctx, diffstatsgen, parity)
   449 
   449 
   450     return dict(
   450     return dict(
   451         diff=diff,
   451         diff=diff,
   452         symrev=symrevorshortnode(req, ctx),
   452         symrev=symrevorshortnode(req, ctx),
   453         basenode=basectx.hex(),
   453         basenode=basectx.hex(),
   464     for f in files[:max]:
   464     for f in files[:max]:
   465         yield tmpl('filedifflink', node=hex(node), file=f)
   465         yield tmpl('filedifflink', node=hex(node), file=f)
   466     if len(files) > max:
   466     if len(files) > max:
   467         yield tmpl('fileellipses')
   467         yield tmpl('fileellipses')
   468 
   468 
   469 def diffs(web, tmpl, ctx, basectx, files, style, linerange=None,
   469 def diffs(web, ctx, basectx, files, style, linerange=None,
   470           lineidprefix=''):
   470           lineidprefix=''):
   471 
   471 
   472     def prettyprintlines(lines, blockno):
   472     def prettyprintlines(lines, blockno):
   473         for lineno, l in enumerate(lines, 1):
   473         for lineno, l in enumerate(lines, 1):
   474             difflineno = "%d.%d" % (blockno, lineno)
   474             difflineno = "%d.%d" % (blockno, lineno)
   478                 ltype = "difflineminus"
   478                 ltype = "difflineminus"
   479             elif l.startswith('@'):
   479             elif l.startswith('@'):
   480                 ltype = "difflineat"
   480                 ltype = "difflineat"
   481             else:
   481             else:
   482                 ltype = "diffline"
   482                 ltype = "diffline"
   483             yield tmpl(ltype,
   483             yield web.tmpl(
   484                        line=l,
   484                 ltype,
   485                        lineno=lineno,
   485                 line=l,
   486                        lineid=lineidprefix + "l%s" % difflineno,
   486                 lineno=lineno,
   487                        linenumber="% 8s" % difflineno)
   487                 lineid=lineidprefix + "l%s" % difflineno,
       
   488                 linenumber="% 8s" % difflineno)
   488 
   489 
   489     repo = web.repo
   490     repo = web.repo
   490     if files:
   491     if files:
   491         m = match.exact(repo.root, repo.getcwd(), files)
   492         m = match.exact(repo.root, repo.getcwd(), files)
   492     else:
   493     else:
   507                 s1, l1, s2, l2 = hunkrange
   508                 s1, l1, s2, l2 = hunkrange
   508                 if not mdiff.hunkinrange((s2, l2), linerange):
   509                 if not mdiff.hunkinrange((s2, l2), linerange):
   509                     continue
   510                     continue
   510             lines.extend(hunklines)
   511             lines.extend(hunklines)
   511         if lines:
   512         if lines:
   512             yield tmpl('diffblock', parity=next(parity), blockno=blockno,
   513             yield web.tmpl('diffblock', parity=next(parity), blockno=blockno,
   513                        lines=prettyprintlines(lines, blockno))
   514                            lines=prettyprintlines(lines, blockno))
   514 
   515 
   515 def compare(tmpl, context, leftlines, rightlines):
   516 def compare(tmpl, context, leftlines, rightlines):
   516     '''Generator function that provides side-by-side comparison data.'''
   517     '''Generator function that provides side-by-side comparison data.'''
   517 
   518 
   518     def compline(type, leftlineno, leftline, rightlineno, rightline):
   519     def compline(type, leftlineno, leftline, rightlineno, rightline):