示例#1
0
def filerevision(web, tmpl, fctx):
    f = fctx.path()
    text = fctx.data()
    parity = paritygen(web.stripecount)

    if binary(text):
        mt = mimetypes.guess_type(f)[0] or 'application/octet-stream'
        text = '(binary:%s)' % mt

    def lines():
        for lineno, t in enumerate(text.splitlines(1)):
            yield {"line": t,
                   "lineid": "l%d" % (lineno + 1),
                   "linenumber": "% 6d" % (lineno + 1),
                   "parity": parity.next()}

    return tmpl("filerevision",
                file=f,
                path=webutil.up(f),
                text=lines(),
                rev=fctx.rev(),
                node=hex_(fctx.node()),
                author=fctx.user(),
                date=fctx.date(),
                desc=fctx.description(),
                branch=webutil.nodebranchnodefault(fctx),
                parent=webutil.parents(fctx),
                child=webutil.children(fctx),
                rename=webutil.renamelink(fctx),
                permissions=fctx.manifest().flags(f))
示例#2
0
def status(web, tmpl, ctx, path, st, datefmt='isodate'):
    """\
    Based on hgweb.manifest, adapted to included features found in
    hg status.

    Initial parameters are the same as manifest.  New parameters:

    ctx
        - should be the workingctx
    st 
        - the tuple returned from repo.status
    datefmt
        - the date format of the full filelist.
    """

    changetypes = (
        'modified', 'added', 'removed', 'deleted', 'unknown', 'ignored',
        'clean',
    )
    # status listing
    statlist = dict(zip(changetypes, st))
    filestatlist = {}
    for k, v in statlist.iteritems():
        for f in v:
            filestatlist[f] = k
    mf = ctx.manifest()
    node = ctx.node()

    files = {}
    parity = paritygen(web.stripecount)

    if path and path[-1] != "/":
        path += "/"
    l = len(path)
    abspath = "/" + path

    for f, n in mf.items():
        if f[:l] != path:
            continue
        remain = f[l:]
        if "/" in remain:
            short = remain[:remain.index("/") + 1] # bleah
            files[short] = (f, None)
        else:
            short = os.path.basename(remain)
            files[short] = (f, n)

    def filelist(**map):
        fl = files.keys()
        fl.sort()
        for f in fl:
            full, fnode = files[f]
            if not fnode:
                continue
            fctx = ctx.filectx(full)
            yield {"file": full,
                   "status": filestatlist[full],
                   "parity": parity.next(),
                   "basename": f,
                   "date": fctx.changectx().date(),
                   "size": fctx.size(),
                   "permissions": mf.flags(full),
                   }

    def dirlist(**map):
        fl = files.keys()
        fl.sort()
        for f in fl:
            full, fnode = files[f]
            if fnode:
                continue

            yield {"parity": parity.next(),
                   "path": "%s%s" % (abspath, f),
                   "basename": f[:-1]}

    def fulllist(**map):
        for i in dirlist():
            # remove first slash
            i['file'] = i['path'][1:]
            i['permissions'] = 'drwxr-xr-x'
            yield i
        for i in filelist():
            i['date'] = utils.filter(i['date'], datefmt)
            i['permissions'] = utils.filter(i['permissions'], 'permissions')
            yield i

    return tmpl("status",
                 rev=ctx.rev(),
                 node=hex_(node),
                 path=abspath,
                 up=webutil.up(abspath),
                 upparity=parity.next(),
                 fentries=filelist,
                 dentries=dirlist,
                 aentries=fulllist,
                 archives=[], # web.archivelist(hex_(node)),
                 tags=webutil.nodetagsdict(web.repo, ctx),
                 branches=webutil.nodebranchdict(web.repo, ctx))