After this commit, all @webcommand function no longer use their
"tmpl" argument. Instead, they use the templater attached to the
requestcontext.
This is the same exact object. So there should be no difference in
behavior.
durin42 |
hg-reviewers |
After this commit, all @webcommand function no longer use their
"tmpl" argument. Instead, they use the templater attached to the
requestcontext.
This is the same exact object. So there should be no difference in
behavior.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
Path | Packages | |||
---|---|---|---|---|
M | hgext/highlight/__init__.py (14 lines) | |||
M | mercurial/hgweb/webcommands.py (89 lines) |
ctx = fctx.changectx() | ctx = fctx.changectx() | ||||
tree = fileset.parse(expr) | tree = fileset.parse(expr) | ||||
mctx = fileset.matchctx(ctx, subset=[fctx.path()], status=None) | mctx = fileset.matchctx(ctx, subset=[fctx.path()], status=None) | ||||
if fctx.path() in fileset.getset(mctx, tree): | if fctx.path() in fileset.getset(mctx, tree): | ||||
highlight.pygmentize(field, fctx, style, tmpl, | highlight.pygmentize(field, fctx, style, tmpl, | ||||
guessfilenameonly=filenameonly) | guessfilenameonly=filenameonly) | ||||
def filerevision_highlight(orig, web, req, tmpl, fctx): | def filerevision_highlight(orig, web, req, fctx): | ||||
mt = ''.join(tmpl('mimetype', encoding=encoding.encoding)) | mt = ''.join(web.tmpl('mimetype', encoding=encoding.encoding)) | ||||
# only pygmentize for mimetype containing 'html' so we both match | # only pygmentize for mimetype containing 'html' so we both match | ||||
# 'text/html' and possibly 'application/xhtml+xml' in the future | # 'text/html' and possibly 'application/xhtml+xml' in the future | ||||
# so that we don't have to touch the extension when the mimetype | # so that we don't have to touch the extension when the mimetype | ||||
# for a template changes; also hgweb optimizes the case that a | # for a template changes; also hgweb optimizes the case that a | ||||
# raw file is sent using rawfile() and doesn't call us, so we | # raw file is sent using rawfile() and doesn't call us, so we | ||||
# can't clash with the file's content-type here in case we | # can't clash with the file's content-type here in case we | ||||
# pygmentize a html file | # pygmentize a html file | ||||
if 'html' in mt: | if 'html' in mt: | ||||
pygmentize(web, 'fileline', fctx, tmpl) | pygmentize(web, 'fileline', fctx, web.tmpl) | ||||
return orig(web, req, tmpl, fctx) | return orig(web, req, fctx) | ||||
def annotate_highlight(orig, web, req, tmpl): | def annotate_highlight(orig, web, req, tmpl): | ||||
mt = ''.join(tmpl('mimetype', encoding=encoding.encoding)) | mt = ''.join(web.tmpl('mimetype', encoding=encoding.encoding)) | ||||
if 'html' in mt: | if 'html' in mt: | ||||
fctx = webutil.filectx(web.repo, req) | fctx = webutil.filectx(web.repo, req) | ||||
pygmentize(web, 'annotateline', fctx, tmpl) | pygmentize(web, 'annotateline', fctx, web.tmpl) | ||||
return orig(web, req, tmpl) | return orig(web, req, web.tmpl) | ||||
def generate_css(web, req, tmpl): | def generate_css(web, req, tmpl): | ||||
pg_style = web.config('web', 'pygments_style', 'colorful') | pg_style = web.config('web', 'pygments_style', 'colorful') | ||||
fmter = highlight.HtmlFormatter(style=pg_style) | fmter = highlight.HtmlFormatter(style=pg_style) | ||||
web.res.headers['Content-Type'] = 'text/css' | web.res.headers['Content-Type'] = 'text/css' | ||||
web.res.setbodybytes(''.join([ | web.res.setbodybytes(''.join([ | ||||
'/* pygments_style = %s */\n\n' % pg_style, | '/* pygments_style = %s */\n\n' % pg_style, | ||||
fmter.get_style_defs(''), | fmter.get_style_defs(''), |
defined, the default is ``tip``. This form is equivalent to the | defined, the default is ``tip``. This form is equivalent to the | ||||
``changelog`` handler. | ``changelog`` handler. | ||||
For URLs of the form ``/log/{revision}/{file}``, the history for a specific | For URLs of the form ``/log/{revision}/{file}``, the history for a specific | ||||
file will be shown. This form is equivalent to the ``filelog`` handler. | file will be shown. This form is equivalent to the ``filelog`` handler. | ||||
""" | """ | ||||
if web.req.qsparams.get('file'): | if web.req.qsparams.get('file'): | ||||
return filelog(web, req, tmpl) | return filelog(web, req, None) | ||||
else: | else: | ||||
return changelog(web, req, tmpl) | return changelog(web, req, None) | ||||
@webcommand('rawfile') | @webcommand('rawfile') | ||||
def rawfile(web, req, tmpl): | def rawfile(web, req, tmpl): | ||||
guessmime = web.configbool('web', 'guessmime') | guessmime = web.configbool('web', 'guessmime') | ||||
path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', '')) | path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', '')) | ||||
if not path: | if not path: | ||||
return manifest(web, req, tmpl) | return manifest(web, req, None) | ||||
try: | try: | ||||
fctx = webutil.filectx(web.repo, req) | fctx = webutil.filectx(web.repo, req) | ||||
except error.LookupError as inst: | except error.LookupError as inst: | ||||
try: | try: | ||||
return manifest(web, req, tmpl) | return manifest(web, req, None) | ||||
except ErrorResponse: | except ErrorResponse: | ||||
raise inst | raise inst | ||||
path = fctx.path() | path = fctx.path() | ||||
text = fctx.data() | text = fctx.data() | ||||
mt = 'application/binary' | mt = 'application/binary' | ||||
if guessmime: | if guessmime: | ||||
mt = mimetypes.guess_type(path)[0] | mt = mimetypes.guess_type(path)[0] | ||||
if mt is None: | if mt is None: | ||||
if util.binary(text): | if util.binary(text): | ||||
mt = 'application/binary' | mt = 'application/binary' | ||||
else: | else: | ||||
mt = 'text/plain' | mt = 'text/plain' | ||||
if mt.startswith('text/'): | if mt.startswith('text/'): | ||||
mt += '; charset="%s"' % encoding.encoding | mt += '; charset="%s"' % encoding.encoding | ||||
web.res.headers['Content-Type'] = mt | web.res.headers['Content-Type'] = mt | ||||
filename = (path.rpartition('/')[-1] | filename = (path.rpartition('/')[-1] | ||||
.replace('\\', '\\\\').replace('"', '\\"')) | .replace('\\', '\\\\').replace('"', '\\"')) | ||||
web.res.headers['Content-Disposition'] = 'inline; filename="%s"' % filename | web.res.headers['Content-Disposition'] = 'inline; filename="%s"' % filename | ||||
web.res.setbodybytes(text) | web.res.setbodybytes(text) | ||||
return web.res.sendresponse() | return web.res.sendresponse() | ||||
def _filerevision(web, req, tmpl, fctx): | def _filerevision(web, req, fctx): | ||||
f = fctx.path() | f = fctx.path() | ||||
text = fctx.data() | text = fctx.data() | ||||
parity = paritygen(web.stripecount) | parity = paritygen(web.stripecount) | ||||
ishead = fctx.filerev() in fctx.filelog().headrevs() | ishead = fctx.filerev() in fctx.filelog().headrevs() | ||||
if util.binary(text): | if util.binary(text): | ||||
mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' | mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' | ||||
text = '(binary:%s)' % mt | text = '(binary:%s)' % mt | ||||
If ``path`` is a file, information about that file will be shown via | If ``path`` is a file, information about that file will be shown via | ||||
the ``filerevision`` template. | the ``filerevision`` template. | ||||
If ``path`` is not defined, information about the root directory will | If ``path`` is not defined, information about the root directory will | ||||
be rendered. | be rendered. | ||||
""" | """ | ||||
if web.req.qsparams.get('style') == 'raw': | if web.req.qsparams.get('style') == 'raw': | ||||
return rawfile(web, req, tmpl) | return rawfile(web, req, None) | ||||
path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', '')) | path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', '')) | ||||
if not path: | if not path: | ||||
return manifest(web, req, tmpl) | return manifest(web, req, None) | ||||
try: | try: | ||||
return _filerevision(web, req, tmpl, webutil.filectx(web.repo, req)) | return _filerevision(web, req, webutil.filectx(web.repo, req)) | ||||
except error.LookupError as inst: | except error.LookupError as inst: | ||||
try: | try: | ||||
return manifest(web, req, tmpl) | return manifest(web, req, None) | ||||
except ErrorResponse: | except ErrorResponse: | ||||
raise inst | raise inst | ||||
def _search(web, tmpl): | def _search(web): | ||||
MODE_REVISION = 'rev' | MODE_REVISION = 'rev' | ||||
MODE_KEYWORD = 'keyword' | MODE_KEYWORD = 'keyword' | ||||
MODE_REVSET = 'revset' | MODE_REVSET = 'revset' | ||||
def revsearch(ctx): | def revsearch(ctx): | ||||
yield ctx | yield ctx | ||||
def keywordsearch(query): | def keywordsearch(query): | ||||
return MODE_KEYWORD, query | return MODE_KEYWORD, query | ||||
def changelist(**map): | def changelist(**map): | ||||
count = 0 | count = 0 | ||||
for ctx in searchfunc[0](funcarg): | for ctx in searchfunc[0](funcarg): | ||||
count += 1 | count += 1 | ||||
n = ctx.node() | n = ctx.node() | ||||
showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n) | showtags = webutil.showtag(web.repo, web.tmpl, 'changelogtag', n) | ||||
files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles) | files = webutil.listfilediffs(web.tmpl, ctx.files(), n, | ||||
web.maxfiles) | |||||
yield tmpl('searchentry', | yield web.tmpl( | ||||
'searchentry', | |||||
parity=next(parity), | parity=next(parity), | ||||
changelogtag=showtags, | changelogtag=showtags, | ||||
files=files, | files=files, | ||||
**pycompat.strkwargs(webutil.commonentry(web.repo, ctx))) | **pycompat.strkwargs(webutil.commonentry(web.repo, ctx))) | ||||
if count >= revcount: | if count >= revcount: | ||||
break | break | ||||
query = web.req.qsparams['rev'] | query = web.req.qsparams['rev'] | ||||
revcount = web.maxchanges | revcount = web.maxchanges | ||||
if 'revcount' in web.req.qsparams: | if 'revcount' in web.req.qsparams: | ||||
try: | try: | ||||
revcount = int(web.req.qsparams.get('revcount', revcount)) | revcount = int(web.req.qsparams.get('revcount', revcount)) | ||||
revcount = max(revcount, 1) | revcount = max(revcount, 1) | ||||
tmpl.defaults['sessionvars']['revcount'] = revcount | web.tmpl.defaults['sessionvars']['revcount'] = revcount | ||||
except ValueError: | except ValueError: | ||||
pass | pass | ||||
lessvars = copy.copy(tmpl.defaults['sessionvars']) | lessvars = copy.copy(web.tmpl.defaults['sessionvars']) | ||||
lessvars['revcount'] = max(revcount // 2, 1) | lessvars['revcount'] = max(revcount // 2, 1) | ||||
lessvars['rev'] = query | lessvars['rev'] = query | ||||
morevars = copy.copy(tmpl.defaults['sessionvars']) | morevars = copy.copy(web.tmpl.defaults['sessionvars']) | ||||
morevars['revcount'] = revcount * 2 | morevars['revcount'] = revcount * 2 | ||||
morevars['rev'] = query | morevars['rev'] = query | ||||
mode, funcarg = getsearchmode(query) | mode, funcarg = getsearchmode(query) | ||||
if 'forcekw' in web.req.qsparams: | if 'forcekw' in web.req.qsparams: | ||||
showforcekw = '' | showforcekw = '' | ||||
showunforcekw = searchfuncs[mode][1] | showunforcekw = searchfuncs[mode][1] | ||||
For non-searches, the ``changelog`` template will be rendered. | For non-searches, the ``changelog`` template will be rendered. | ||||
""" | """ | ||||
query = '' | query = '' | ||||
if 'node' in web.req.qsparams: | if 'node' in web.req.qsparams: | ||||
ctx = webutil.changectx(web.repo, req) | ctx = webutil.changectx(web.repo, req) | ||||
symrev = webutil.symrevorshortnode(req, ctx) | symrev = webutil.symrevorshortnode(req, ctx) | ||||
elif 'rev' in web.req.qsparams: | elif 'rev' in web.req.qsparams: | ||||
return _search(web, tmpl) | return _search(web) | ||||
else: | else: | ||||
ctx = web.repo['tip'] | ctx = web.repo['tip'] | ||||
symrev = 'tip' | symrev = 'tip' | ||||
def changelist(): | def changelist(): | ||||
revs = [] | revs = [] | ||||
if pos != -1: | if pos != -1: | ||||
revs = web.repo.changelog.revs(pos, 0) | revs = web.repo.changelog.revs(pos, 0) | ||||
curcount = 0 | curcount = 0 | ||||
for rev in revs: | for rev in revs: | ||||
curcount += 1 | curcount += 1 | ||||
if curcount > revcount + 1: | if curcount > revcount + 1: | ||||
break | break | ||||
entry = webutil.changelistentry(web, web.repo[rev], tmpl) | entry = webutil.changelistentry(web, web.repo[rev], web.tmpl) | ||||
entry['parity'] = next(parity) | entry['parity'] = next(parity) | ||||
yield entry | yield entry | ||||
if shortlog: | if shortlog: | ||||
revcount = web.maxshortchanges | revcount = web.maxshortchanges | ||||
else: | else: | ||||
revcount = web.maxchanges | revcount = web.maxchanges | ||||
if 'revcount' in web.req.qsparams: | if 'revcount' in web.req.qsparams: | ||||
try: | try: | ||||
revcount = int(web.req.qsparams.get('revcount', revcount)) | revcount = int(web.req.qsparams.get('revcount', revcount)) | ||||
revcount = max(revcount, 1) | revcount = max(revcount, 1) | ||||
tmpl.defaults['sessionvars']['revcount'] = revcount | web.tmpl.defaults['sessionvars']['revcount'] = revcount | ||||
except ValueError: | except ValueError: | ||||
pass | pass | ||||
lessvars = copy.copy(tmpl.defaults['sessionvars']) | lessvars = copy.copy(web.tmpl.defaults['sessionvars']) | ||||
lessvars['revcount'] = max(revcount // 2, 1) | lessvars['revcount'] = max(revcount // 2, 1) | ||||
morevars = copy.copy(tmpl.defaults['sessionvars']) | morevars = copy.copy(web.tmpl.defaults['sessionvars']) | ||||
morevars['revcount'] = revcount * 2 | morevars['revcount'] = revcount * 2 | ||||
count = len(web.repo) | count = len(web.repo) | ||||
pos = ctx.rev() | pos = ctx.rev() | ||||
parity = paritygen(web.stripecount) | parity = paritygen(web.stripecount) | ||||
changenav = webutil.revnav(web.repo).gen(pos, revcount, count) | changenav = webutil.revnav(web.repo).gen(pos, revcount, count) | ||||
--------- | --------- | ||||
Show basic information about a set of changesets. | Show basic information about a set of changesets. | ||||
This accepts the same parameters as the ``changelog`` handler. The only | This accepts the same parameters as the ``changelog`` handler. The only | ||||
difference is the ``shortlog`` template will be rendered instead of the | difference is the ``shortlog`` template will be rendered instead of the | ||||
``changelog`` template. | ``changelog`` template. | ||||
""" | """ | ||||
return changelog(web, req, tmpl, shortlog=True) | return changelog(web, req, None, shortlog=True) | ||||
@webcommand('changeset') | @webcommand('changeset') | ||||
def changeset(web, req, tmpl): | def changeset(web, req, tmpl): | ||||
""" | """ | ||||
/changeset[/{revision}] | /changeset[/{revision}] | ||||
----------------------- | ----------------------- | ||||
Show information about a single changeset. | Show information about a single changeset. | ||||
A URL path argument is the changeset identifier to show. See ``hg help | A URL path argument is the changeset identifier to show. See ``hg help | ||||
revisions`` for possible values. If not defined, the ``tip`` changeset | revisions`` for possible values. If not defined, the ``tip`` changeset | ||||
will be shown. | will be shown. | ||||
The ``changeset`` template is rendered. Contents of the ``changesettag``, | The ``changeset`` template is rendered. Contents of the ``changesettag``, | ||||
``changesetbookmark``, ``filenodelink``, ``filenolink``, and the many | ``changesetbookmark``, ``filenodelink``, ``filenolink``, and the many | ||||
templates related to diffs may all be used to produce the output. | templates related to diffs may all be used to produce the output. | ||||
""" | """ | ||||
ctx = webutil.changectx(web.repo, req) | ctx = webutil.changectx(web.repo, req) | ||||
return web.sendtemplate( | return web.sendtemplate( | ||||
'changeset', | 'changeset', | ||||
**webutil.changesetentry(web, req, tmpl, ctx)) | **webutil.changesetentry(web, req, web.tmpl, ctx)) | ||||
rev = webcommand('rev')(changeset) | rev = webcommand('rev')(changeset) | ||||
def decodepath(path): | def decodepath(path): | ||||
"""Hook for mapping a path in the repository to a path in the | """Hook for mapping a path in the repository to a path in the | ||||
working copy. | working copy. | ||||
Extensions (e.g., largefiles) can override this to remap files in | Extensions (e.g., largefiles) can override this to remap files in | ||||
for k, n in i: | for k, n in i: | ||||
if k == "tip": # skip tip | if k == "tip": # skip tip | ||||
continue | continue | ||||
count += 1 | count += 1 | ||||
if count > 10: # limit to 10 tags | if count > 10: # limit to 10 tags | ||||
break | break | ||||
yield tmpl("tagentry", | yield web.tmpl( | ||||
'tagentry', | |||||
parity=next(parity), | parity=next(parity), | ||||
tag=k, | tag=k, | ||||
node=hex(n), | node=hex(n), | ||||
date=web.repo[n].date()) | date=web.repo[n].date()) | ||||
def bookmarks(**map): | def bookmarks(**map): | ||||
parity = paritygen(web.stripecount) | parity = paritygen(web.stripecount) | ||||
marks = [b for b in web.repo._bookmarks.items() if b[1] in web.repo] | marks = [b for b in web.repo._bookmarks.items() if b[1] in web.repo] | ||||
sortkey = lambda b: (web.repo[b[1]].rev(), b[0]) | sortkey = lambda b: (web.repo[b[1]].rev(), b[0]) | ||||
marks = sorted(marks, key=sortkey, reverse=True) | marks = sorted(marks, key=sortkey, reverse=True) | ||||
for k, n in marks[:10]: # limit to 10 bookmarks | for k, n in marks[:10]: # limit to 10 bookmarks | ||||
yield {'parity': next(parity), | yield {'parity': next(parity), | ||||
'bookmark': k, | 'bookmark': k, | ||||
'date': web.repo[n].date(), | 'date': web.repo[n].date(), | ||||
'node': hex(n)} | 'node': hex(n)} | ||||
def changelist(**map): | def changelist(**map): | ||||
parity = paritygen(web.stripecount, offset=start - end) | parity = paritygen(web.stripecount, offset=start - end) | ||||
l = [] # build a list in forward order for efficiency | l = [] # build a list in forward order for efficiency | ||||
revs = [] | revs = [] | ||||
if start < end: | if start < end: | ||||
revs = web.repo.changelog.revs(start, end - 1) | revs = web.repo.changelog.revs(start, end - 1) | ||||
for i in revs: | for i in revs: | ||||
ctx = web.repo[i] | ctx = web.repo[i] | ||||
l.append(tmpl( | l.append(web.tmpl( | ||||
'shortlogentry', | 'shortlogentry', | ||||
parity=next(parity), | parity=next(parity), | ||||
**pycompat.strkwargs(webutil.commonentry(web.repo, ctx)))) | **pycompat.strkwargs(webutil.commonentry(web.repo, ctx)))) | ||||
for entry in reversed(l): | for entry in reversed(l): | ||||
yield entry | yield entry | ||||
tip = web.repo['tip'] | tip = web.repo['tip'] | ||||
path = fctx.path() | path = fctx.path() | ||||
ctx = fctx.changectx() | ctx = fctx.changectx() | ||||
basectx = ctx.p1() | basectx = ctx.p1() | ||||
style = web.config('web', 'style') | style = web.config('web', 'style') | ||||
if 'style' in web.req.qsparams: | if 'style' in web.req.qsparams: | ||||
style = web.req.qsparams['style'] | style = web.req.qsparams['style'] | ||||
diffs = webutil.diffs(web, tmpl, ctx, basectx, [path], style) | diffs = webutil.diffs(web, web.tmpl, ctx, basectx, [path], style) | ||||
if fctx is not None: | if fctx is not None: | ||||
rename = webutil.renamelink(fctx) | rename = webutil.renamelink(fctx) | ||||
ctx = fctx | ctx = fctx | ||||
else: | else: | ||||
rename = [] | rename = [] | ||||
ctx = ctx | ctx = ctx | ||||
return web.sendtemplate( | return web.sendtemplate( | ||||
else: | else: | ||||
pfctx = parent[path] | pfctx = parent[path] | ||||
leftlines = filelines(pfctx) | leftlines = filelines(pfctx) | ||||
else: | else: | ||||
rightlines = () | rightlines = () | ||||
pfctx = ctx.parents()[0][path] | pfctx = ctx.parents()[0][path] | ||||
leftlines = filelines(pfctx) | leftlines = filelines(pfctx) | ||||
comparison = webutil.compare(tmpl, context, leftlines, rightlines) | comparison = webutil.compare(web.tmpl, context, leftlines, rightlines) | ||||
if fctx is not None: | if fctx is not None: | ||||
rename = webutil.renamelink(fctx) | rename = webutil.renamelink(fctx) | ||||
ctx = fctx | ctx = fctx | ||||
else: | else: | ||||
rename = [] | rename = [] | ||||
ctx = ctx | ctx = ctx | ||||
return web.sendtemplate( | return web.sendtemplate( | ||||
frev -= 1 | frev -= 1 | ||||
fctx = web.repo.filectx(f, fl.linkrev(frev)) | fctx = web.repo.filectx(f, fl.linkrev(frev)) | ||||
revcount = web.maxshortchanges | revcount = web.maxshortchanges | ||||
if 'revcount' in web.req.qsparams: | if 'revcount' in web.req.qsparams: | ||||
try: | try: | ||||
revcount = int(web.req.qsparams.get('revcount', revcount)) | revcount = int(web.req.qsparams.get('revcount', revcount)) | ||||
revcount = max(revcount, 1) | revcount = max(revcount, 1) | ||||
tmpl.defaults['sessionvars']['revcount'] = revcount | web.tmpl.defaults['sessionvars']['revcount'] = revcount | ||||
except ValueError: | except ValueError: | ||||
pass | pass | ||||
lrange = webutil.linerange(req) | lrange = webutil.linerange(req) | ||||
lessvars = copy.copy(tmpl.defaults['sessionvars']) | lessvars = copy.copy(web.tmpl.defaults['sessionvars']) | ||||
lessvars['revcount'] = max(revcount // 2, 1) | lessvars['revcount'] = max(revcount // 2, 1) | ||||
morevars = copy.copy(tmpl.defaults['sessionvars']) | morevars = copy.copy(web.tmpl.defaults['sessionvars']) | ||||
morevars['revcount'] = revcount * 2 | morevars['revcount'] = revcount * 2 | ||||
patch = 'patch' in web.req.qsparams | patch = 'patch' in web.req.qsparams | ||||
if patch: | if patch: | ||||
lessvars['patch'] = morevars['patch'] = web.req.qsparams['patch'] | lessvars['patch'] = morevars['patch'] = web.req.qsparams['patch'] | ||||
descend = 'descend' in web.req.qsparams | descend = 'descend' in web.req.qsparams | ||||
if descend: | if descend: | ||||
lessvars['descend'] = morevars['descend'] = web.req.qsparams['descend'] | lessvars['descend'] = morevars['descend'] = web.req.qsparams['descend'] | ||||
diffstyle = web.config('web', 'style') | diffstyle = web.config('web', 'style') | ||||
if 'style' in web.req.qsparams: | if 'style' in web.req.qsparams: | ||||
diffstyle = web.req.qsparams['style'] | diffstyle = web.req.qsparams['style'] | ||||
def diff(fctx, linerange=None): | def diff(fctx, linerange=None): | ||||
ctx = fctx.changectx() | ctx = fctx.changectx() | ||||
basectx = ctx.p1() | basectx = ctx.p1() | ||||
path = fctx.path() | path = fctx.path() | ||||
return webutil.diffs(web, tmpl, ctx, basectx, [path], diffstyle, | return webutil.diffs(web, web.tmpl, ctx, basectx, [path], diffstyle, | ||||
linerange=linerange, | linerange=linerange, | ||||
lineidprefix='%s-' % ctx.hex()[:12]) | lineidprefix='%s-' % ctx.hex()[:12]) | ||||
linerange = None | linerange = None | ||||
if lrange is not None: | if lrange is not None: | ||||
linerange = webutil.formatlinerange(*lrange) | linerange = webutil.formatlinerange(*lrange) | ||||
# deactivate numeric nav links when linerange is specified as this | # deactivate numeric nav links when linerange is specified as this | ||||
# would required a dedicated "revnav" class | # would required a dedicated "revnav" class | ||||
rev = ctx.rev() | rev = ctx.rev() | ||||
bg_height = 39 | bg_height = 39 | ||||
revcount = web.maxshortchanges | revcount = web.maxshortchanges | ||||
if 'revcount' in web.req.qsparams: | if 'revcount' in web.req.qsparams: | ||||
try: | try: | ||||
revcount = int(web.req.qsparams.get('revcount', revcount)) | revcount = int(web.req.qsparams.get('revcount', revcount)) | ||||
revcount = max(revcount, 1) | revcount = max(revcount, 1) | ||||
tmpl.defaults['sessionvars']['revcount'] = revcount | web.tmpl.defaults['sessionvars']['revcount'] = revcount | ||||
except ValueError: | except ValueError: | ||||
pass | pass | ||||
lessvars = copy.copy(tmpl.defaults['sessionvars']) | lessvars = copy.copy(web.tmpl.defaults['sessionvars']) | ||||
lessvars['revcount'] = max(revcount // 2, 1) | lessvars['revcount'] = max(revcount // 2, 1) | ||||
morevars = copy.copy(tmpl.defaults['sessionvars']) | morevars = copy.copy(web.tmpl.defaults['sessionvars']) | ||||
morevars['revcount'] = revcount * 2 | morevars['revcount'] = revcount * 2 | ||||
graphtop = web.req.qsparams.get('graphtop', ctx.hex()) | graphtop = web.req.qsparams.get('graphtop', ctx.hex()) | ||||
graphvars = copy.copy(tmpl.defaults['sessionvars']) | graphvars = copy.copy(web.tmpl.defaults['sessionvars']) | ||||
graphvars['graphtop'] = graphtop | graphvars['graphtop'] = graphtop | ||||
count = len(web.repo) | count = len(web.repo) | ||||
pos = rev | pos = rev | ||||
uprev = min(max(0, count - 1), rev + revcount) | uprev = min(max(0, count - 1), rev + revcount) | ||||
downrev = max(0, rev - revcount) | downrev = max(0, rev - revcount) | ||||
changenav = webutil.revnav(web.repo).gen(pos, revcount, count) | changenav = webutil.revnav(web.repo).gen(pos, revcount, count) |