summaryrefslogtreecommitdiff
path: root/mercurial/hgweb/webcommands.py
diff options
context:
space:
mode:
Diffstat (limited to 'mercurial/hgweb/webcommands.py')
-rw-r--r--mercurial/hgweb/webcommands.py232
1 files changed, 52 insertions, 180 deletions
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
index 9cd5c0a..fc43ca3 100644
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -8,11 +8,11 @@
import os, mimetypes, re, cgi, copy
import webutil
from mercurial import error, encoding, archival, templater, templatefilters
-from mercurial.node import short, hex, nullid
+from mercurial.node import short, hex
from mercurial.util import binary
from common import paritygen, staticfile, get_contact, ErrorResponse
from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND
-from mercurial import graphmod, patch
+from mercurial import graphmod
from mercurial import help as helpmod
from mercurial.i18n import _
@@ -22,7 +22,7 @@ from mercurial.i18n import _
__all__ = [
'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev',
'manifest', 'tags', 'bookmarks', 'branches', 'summary', 'filediff', 'diff',
- 'comparison', 'annotate', 'filelog', 'archive', 'static', 'graph', 'help',
+ 'annotate', 'filelog', 'archive', 'static', 'graph', 'help',
]
def log(web, req, tmpl):
@@ -124,8 +124,7 @@ def _search(web, req, tmpl):
def changelist(**map):
count = 0
- lower = encoding.lower
- qw = lower(query).split()
+ qw = query.lower().split()
def revgen():
for i in xrange(len(web.repo) - 1, 0, -100):
@@ -140,9 +139,9 @@ def _search(web, req, tmpl):
for ctx in revgen():
miss = 0
for q in qw:
- if not (q in lower(ctx.user()) or
- q in lower(ctx.description()) or
- q in lower(" ".join(ctx.files()))):
+ if not (q in ctx.user().lower() or
+ q in ctx.description().lower() or
+ q in " ".join(ctx.files()).lower()):
miss = 1
break
if miss:
@@ -262,10 +261,10 @@ def changeset(web, req, tmpl):
files = []
parity = paritygen(web.stripecount)
- for blockno, f in enumerate(ctx.files()):
+ for f in ctx.files():
template = f in ctx and 'filenodelink' or 'filenolink'
files.append(tmpl(template,
- node=ctx.hex(), file=f, blockno=blockno + 1,
+ node=ctx.hex(), file=f,
parity=parity.next()))
style = web.config('web', 'style', 'paper')
@@ -303,14 +302,6 @@ def changeset(web, req, tmpl):
rev = changeset
-def decodepath(path):
- """Hook for mapping a path in the repository to a path in the
- working copy.
-
- Extensions (e.g., largefiles) can override this to remap files in
- the virtual file system presented by the manifest command below."""
- return path
-
def manifest(web, req, tmpl):
ctx = webutil.changectx(web.repo, req)
path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0])
@@ -326,17 +317,13 @@ def manifest(web, req, tmpl):
l = len(path)
abspath = "/" + path
- for full, n in mf.iteritems():
- # the virtual path (working copy path) used for the full
- # (repository) path
- f = decodepath(full)
-
+ for f, n in mf.iteritems():
if f[:l] != path:
continue
remain = f[l:]
elements = remain.split('/')
if len(elements) == 1:
- files[remain] = full
+ files[remain] = f
else:
h = dirs # need to retain ref to dirs (root)
for elem in elements[0:-1]:
@@ -394,7 +381,8 @@ def manifest(web, req, tmpl):
branches=webutil.nodebranchdict(web.repo, ctx))
def tags(web, req, tmpl):
- i = reversed(web.repo.tagslist())
+ i = web.repo.tagslist()
+ i.reverse()
parity = paritygen(web.stripecount)
def entries(notip=False, limit=0, **map):
@@ -440,7 +428,7 @@ def branches(web, req, tmpl):
tips = (web.repo[n] for t, n in web.repo.branchtags().iteritems())
heads = web.repo.heads()
parity = paritygen(web.stripecount)
- sortkey = lambda ctx: (not ctx.closesbranch(), ctx.rev())
+ sortkey = lambda ctx: ('close' not in ctx.extra(), ctx.rev())
def entries(limit, **map):
count = 0
@@ -465,7 +453,8 @@ def branches(web, req, tmpl):
latestentry=lambda **x: entries(1, **x))
def summary(web, req, tmpl):
- i = reversed(web.repo.tagslist())
+ i = web.repo.tagslist()
+ i.reverse()
def tagentries(**map):
parity = paritygen(web.stripecount)
@@ -556,7 +545,6 @@ def filediff(web, req, tmpl):
if fctx is not None:
n = fctx.node()
path = fctx.path()
- ctx = fctx.changectx()
else:
n = ctx.node()
# path already defined in except clause
@@ -566,7 +554,7 @@ def filediff(web, req, tmpl):
if 'style' in req.form:
style = req.form['style'][0]
- diffs = webutil.diffs(web.repo, tmpl, ctx, [path], parity, style)
+ diffs = webutil.diffs(web.repo, tmpl, fctx or ctx, [path], parity, style)
rename = fctx and webutil.renamelink(fctx) or []
ctx = fctx and fctx or ctx
return tmpl("filediff",
@@ -584,74 +572,10 @@ def filediff(web, req, tmpl):
diff = filediff
-def comparison(web, req, tmpl):
- ctx = webutil.changectx(web.repo, req)
- if 'file' not in req.form:
- raise ErrorResponse(HTTP_NOT_FOUND, 'file not given')
- path = webutil.cleanpath(web.repo, req.form['file'][0])
- rename = path in ctx and webutil.renamelink(ctx[path]) or []
-
- parsecontext = lambda v: v == 'full' and -1 or int(v)
- if 'context' in req.form:
- context = parsecontext(req.form['context'][0])
- else:
- context = parsecontext(web.config('web', 'comparisoncontext', '5'))
-
- def filelines(f):
- if binary(f.data()):
- mt = mimetypes.guess_type(f.path())[0]
- if not mt:
- mt = 'application/octet-stream'
- return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))]
- return f.data().splitlines()
-
- if path in ctx:
- fctx = ctx[path]
- rightrev = fctx.filerev()
- rightnode = fctx.filenode()
- rightlines = filelines(fctx)
- parents = fctx.parents()
- if not parents:
- leftrev = -1
- leftnode = nullid
- leftlines = ()
- else:
- pfctx = parents[0]
- leftrev = pfctx.filerev()
- leftnode = pfctx.filenode()
- leftlines = filelines(pfctx)
- else:
- rightrev = -1
- rightnode = nullid
- rightlines = ()
- fctx = ctx.parents()[0][path]
- leftrev = fctx.filerev()
- leftnode = fctx.filenode()
- leftlines = filelines(fctx)
-
- comparison = webutil.compare(tmpl, context, leftlines, rightlines)
- return tmpl('filecomparison',
- file=path,
- node=hex(ctx.node()),
- rev=ctx.rev(),
- date=ctx.date(),
- desc=ctx.description(),
- author=ctx.user(),
- rename=rename,
- branch=webutil.nodebranchnodefault(ctx),
- parent=webutil.parents(fctx),
- child=webutil.children(fctx),
- leftrev=leftrev,
- leftnode=hex(leftnode),
- rightrev=rightrev,
- rightnode=hex(rightnode),
- comparison=comparison)
-
def annotate(web, req, tmpl):
fctx = webutil.filectx(web.repo, req)
f = fctx.path()
parity = paritygen(web.stripecount)
- diffopts = patch.diffopts(web.repo.ui, untrusted=True, section='annotate')
def annotate(**map):
last = None
@@ -661,8 +585,7 @@ def annotate(web, req, tmpl):
lines = enumerate([((fctx.filectx(fctx.filerev()), 1),
'(binary:%s)' % mt)])
else:
- lines = enumerate(fctx.annotate(follow=True, linenumber=True,
- diffopts=diffopts))
+ lines = enumerate(fctx.annotate(follow=True, linenumber=True))
for lineno, ((f, targetline), l) in lines:
fnode = f.filenode()
@@ -817,9 +740,7 @@ def static(web, req, tmpl):
def graph(web, req, tmpl):
- ctx = webutil.changectx(web.repo, req)
- rev = ctx.rev()
-
+ rev = webutil.changectx(web.repo, req).rev()
bg_height = 39
revcount = web.maxshortchanges
if 'revcount' in req.form:
@@ -832,94 +753,45 @@ def graph(web, req, tmpl):
morevars = copy.copy(tmpl.defaults['sessionvars'])
morevars['revcount'] = revcount * 2
- count = len(web.repo)
- pos = rev
- start = max(0, pos - revcount + 1)
- end = min(count, start + revcount)
- pos = end - 1
-
- uprev = min(max(0, count - 1), rev + revcount)
+ max_rev = len(web.repo) - 1
+ revcount = min(max_rev, revcount)
+ revnode = web.repo.changelog.node(rev)
+ revnode_hex = hex(revnode)
+ uprev = min(max_rev, rev + revcount)
downrev = max(0, rev - revcount)
- changenav = webutil.revnavgen(pos, revcount, count, web.repo.changectx)
-
- dag = graphmod.dagwalker(web.repo, range(start, end)[::-1])
- tree = list(graphmod.colored(dag, web.repo))
-
- def getcolumns(tree):
- cols = 0
- for (id, type, ctx, vtx, edges) in tree:
- if type != graphmod.CHANGESET:
- continue
- cols = max(cols, max([edge[0] for edge in edges] or [0]),
- max([edge[1] for edge in edges] or [0]))
- return cols
-
- def graphdata(usetuples, **map):
- data = []
-
- row = 0
- for (id, type, ctx, vtx, edges) in tree:
- if type != graphmod.CHANGESET:
- continue
- node = str(ctx)
- age = templatefilters.age(ctx.date())
- desc = templatefilters.firstline(ctx.description())
- desc = cgi.escape(templatefilters.nonempty(desc))
- user = cgi.escape(templatefilters.person(ctx.user()))
- branch = ctx.branch()
- try:
- branchnode = web.repo.branchtip(branch)
- except error.RepoLookupError:
- branchnode = None
- branch = branch, branchnode == ctx.node()
-
- if usetuples:
- data.append((node, vtx, edges, desc, user, age, branch,
- ctx.tags(), ctx.bookmarks()))
- else:
- edgedata = [dict(col=edge[0], nextcol=edge[1],
- color=(edge[2] - 1) % 6 + 1,
- width=edge[3], bcolor=edge[4])
- for edge in edges]
-
- data.append(
- dict(node=node,
- col=vtx[0],
- color=(vtx[1] - 1) % 6 + 1,
- edges=edgedata,
- row=row,
- nextrow=row + 1,
- desc=desc,
- user=user,
- age=age,
- bookmarks=webutil.nodebookmarksdict(
- web.repo, ctx.node()),
- branches=webutil.nodebranchdict(web.repo, ctx),
- inbranch=webutil.nodeinbranch(web.repo, ctx),
- tags=webutil.nodetagsdict(web.repo, ctx.node())))
-
- row += 1
-
- return data
-
- cols = getcolumns(tree)
- rows = len(tree)
- canvasheight = (rows + 1) * bg_height - 27
+ count = len(web.repo)
+ changenav = webutil.revnavgen(rev, revcount, count, web.repo.changectx)
+ startrev = rev
+ # if starting revision is less than 60 set it to uprev
+ if rev < web.maxshortchanges:
+ startrev = uprev
+
+ dag = graphmod.dagwalker(web.repo, range(startrev, downrev - 1, -1))
+ tree = list(graphmod.colored(dag))
+ canvasheight = (len(tree) + 1) * bg_height - 27
+ data = []
+ for (id, type, ctx, vtx, edges) in tree:
+ if type != graphmod.CHANGESET:
+ continue
+ node = str(ctx)
+ age = templatefilters.age(ctx.date())
+ desc = templatefilters.firstline(ctx.description())
+ desc = cgi.escape(templatefilters.nonempty(desc))
+ user = cgi.escape(templatefilters.person(ctx.user()))
+ branch = ctx.branch()
+ branch = branch, web.repo.branchtags().get(branch) == ctx.node()
+ data.append((node, vtx, edges, desc, user, age, branch, ctx.tags(),
+ ctx.bookmarks()))
return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev,
lessvars=lessvars, morevars=morevars, downrev=downrev,
- cols=cols, rows=rows,
- canvaswidth=(cols + 1) * bg_height,
- truecanvasheight=rows * bg_height,
- canvasheight=canvasheight, bg_height=bg_height,
- jsdata=lambda **x: graphdata(True, **x),
- nodes=lambda **x: graphdata(False, **x),
- node=ctx.hex(), changenav=changenav)
+ canvasheight=canvasheight, jsdata=data, bg_height=bg_height,
+ node=revnode_hex, changenav=changenav)
def _getdoc(e):
doc = e[0].__doc__
if doc:
- doc = _(doc).split('\n')[0]
+ doc = doc.split('\n')[0]
else:
doc = _('(no help text available)')
return doc
@@ -931,7 +803,8 @@ def help(web, req, tmpl):
if not topicname:
def topics(**map):
for entries, summary, _ in helpmod.helptable:
- yield {'topic': entries[0], 'summary': summary}
+ entries = sorted(entries, key=len)
+ yield {'topic': entries[-1], 'summary': summary}
early, other = [], []
primary = lambda s: s.split('|')[0]
@@ -961,7 +834,6 @@ def help(web, req, tmpl):
u = webutil.wsgiui()
u.pushbuffer()
- u.verbose = True
try:
commands.help_(u, topicname)
except error.UnknownCommand: