grim/hgwebplus

make everything work with python3

2020-04-07, Gary Kramlich
55245dd39901
Parents ae8e40ca6b8f
Children 51796d95ff7e
make everything work with python3
  • +28 -25
    hgkeeper.py
  • --- a/hgkeeper.py Tue Apr 07 21:04:37 2020 -0500
    +++ b/hgkeeper.py Tue Apr 07 23:38:27 2020 -0500
    @@ -21,7 +21,7 @@
    @templatefilter(b'md5', intype=bytes)
    def md5(text):
    - return hashlib_md5(text).hexdigest()
    + return hashlib_md5(text).hexdigest().encode('ascii')
    def _diffstattmplgen(orig, context, ctx, statgen, parity):
    @@ -38,21 +38,22 @@
    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,
    - },
    - )
    +
    + data = {
    + 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,
    + }
    +
    + yield context.process(template, data)
    +
    # right now we just capture the starting line numbers as that's all we need
    RE_DIFF = re.compile(r'^@@ -(\d+),\d+ \+(\d+),\d+ @@')
    @@ -153,8 +154,8 @@
    diffhunks = patch.diffhunks(repo, basectx, ctx, m, opts=diffopts)
    for blockno, (fctx1, fctx2, header, hunks) in enumerate(diffhunks, 1):
    - filea, fileb = "/dev/null", "/dev/null"
    - reva, revb = "", ""
    + filea, fileb = b'/dev/null', b'/dev/null'
    + reva, revb = b'', b''
    if fctx1 is not None:
    filea = fctx1.path()
    @@ -177,15 +178,15 @@
    args = (lines, blockno, lineidprefix, filea, reva, fileb, revb)
    l = templateutil.mappedgenerator(_prettyprintdifflines, args)
    - changetype = 'modified'
    - if filea == '/dev/null':
    - changetype = 'added'
    - elif fileb == '/dev/null':
    - changetype = 'removed'
    + changetype = b'modified'
    + if filea == b'/dev/null':
    + changetype = b'added'
    + elif fileb == b'/dev/null':
    + changetype = b'removed'
    elif filea != fileb:
    - changetype = 'renamed'
    + changetype = b'renamed'
    - yield {
    + data = {
    b'blockno': blockno,
    b'changetype': changetype,
    b'filea': filea,
    @@ -196,6 +197,8 @@
    b'revb': revb,
    }
    + yield data
    +
    def extsetup(ui):
    extensions.wrapfunction(webutil, "_diffstattmplgen", _diffstattmplgen)