grim/hgwebplus

Parents 894b0edb6871
Children af1578cd9cdd
A few tweaks, wrap the diffstat template generator to add the lines added/removed per file as well as if it's binary or not
  • +47 -3
    hgkeeper.py
  • --- a/hgkeeper.py Sat Mar 21 17:36:51 2020 -0500
    +++ b/hgkeeper.py Sat Mar 21 23:56:43 2020 -0500
    @@ -2,7 +2,8 @@
    import hashlib
    -from mercurial import registrar
    +from mercurial import extensions, patch, registrar
    +from mercurial.hgweb import webutil
    filters = {}
    templatefilter = registrar.templatefilter(filters)
    @@ -16,11 +17,54 @@
    @templatefilter(b'md5', intype=bytes)
    def md5(text):
    - return hexdigest('md5', text)
    + return hexdigest(b'md5', text)
    @templatefilter(b'sha256', intype=bytes)
    def sha256(text):
    - return hexdigest('sha256', text)
    + return hexdigest(b'sha256', text)
    +
    +
    +def diffstats(web):
    + ctx = webutil.changectx(web.repo, web.req)
    + basectx = ctx.p1()
    +
    + diffopts = patch.diffopts(ui, {b'noprefix', False})
    + return patch.diffstatdata(util.iterlines(ctx.diff(basectx, opts=diffopts)))
    +
    +def _diffstattmplgen(orig, context, ctx, statgen, parity):
    + stats, maxname, maxtotal, addtotal, removetotal, binary = next(statgen)
    + files = ctx.files()
    +
    + def pct(i):
    + if maxtotal == 0:
    + return 0
    + return (float(i) / maxtotal) * 100
    +
    + fileno = 0
    + for filename, adds, removes, isbinary in stats:
    + template = b'diffstatlink' if filename in files else b'diffstatnolink'
    + total = adds + removes
    + fileno += 1
    + yield context.process(
    + template,
    + {
    + b'node': ctx.hex(),
    + b'file': filename,
    + b'fileno': fileno,
    + b'total': total,
    + b'added': adds,
    + b'addpct': pct(adds),
    + b'removed': removes,
    + b'removepct': pct(removes),
    + b'parity': next(parity),
    + b'binary': isbinary,
    + },
    + )
    +
    +
    +def extsetup(ui):
    + extensions.wrapfunction(webutil, "_diffstattmplgen", _diffstattmplgen)
    +