sapling/fastannotate/hgwebsupport.py
Jun Wu fc1e2d9c80 fastannotate: add hgweb support
Summary:
This adds fastannotate support for hgweb. There are some issues with "path"
handling, which will be addressed in follow up patches.

A minor change has been made in this patch to support revision numbers
(previously only global changeset hashes are supported).

Test Plan:
Run `hg serve --config fastannotate.hgweb=1` on the `hg-committed` repo, open
the following URL and confirm it's using fastannotate:
http://localhost:8000/annotate/9af6f8434430/mercurial/commands.py

Reviewers: #sourcecontrol, simonfar

Reviewed By: simonfar

Subscribers: simonfar, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3993636

Signature: t1:3993636:1476026586:cb0628aa7107bdbfde852a6a1471f70dcb21a5ef
2016-10-09 15:19:18 +01:00

41 lines
1.4 KiB
Python

# Copyright 2016-present Facebook. All Rights Reserved.
#
# hgwebsupport: fastannotate support for hgweb
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
from mercurial import (
extensions,
patch,
)
from mercurial.hgweb import webutil
from fastannotate import context
def _annotate(orig, fctx, ui):
diffopts = patch.difffeatureopts(ui, untrusted=True,
section='annotate', whitespace=True)
aopts = context.annotateopts(diffopts=diffopts)
master = ui.config('fastannotate', 'mainbranch', 'default')
with context.annotatecontext(fctx.repo(), fctx.path(), aopts) as ac:
# fastannotate returns: [(nodeid, linenum, path)], [linecontent]
annotated, contents = ac.annotate(fctx.rev(), master=master,
showpath=True, showlines=True)
# convert to what fctx.annotate returns: [((fctx, number), linecontent)]
fctxmap = {} # {(nodeid, path): fctx}
repo = fctx.repo()
results = []
for i, (hsh, linenum, path) in enumerate(annotated):
if (hsh, path) not in fctxmap:
fctxmap[(hsh, path)] = context.resolvefctx(repo, hsh, path)
results.append(((fctxmap[(hsh, path)], linenum), contents[i]))
return results
def replacehgwebannotate():
extensions.wrapfunction(webutil, 'annotate', _annotate)