Пример #1
0
def changelog(web, req, tmpl, shortlog=False):

    query = ''
    if 'node' in req.form:
        ctx = webutil.changectx(web.repo, req)
    elif 'rev' in req.form:
        return _search(web, req, tmpl)
    else:
        ctx = web.repo['tip']

    def changelist():
        revs = []
        if pos != -1:
            revs = web.repo.changelog.revs(pos, 0)
        curcount = 0
        for rev in revs:
            curcount += 1
            if curcount > revcount + 1:
                break

            entry = webutil.changelistentry(web, web.repo[rev], tmpl)
            entry['parity'] = parity.next()
            yield entry

    revcount = shortlog and web.maxshortchanges or web.maxchanges
    if 'revcount' in req.form:
        try:
            revcount = int(req.form.get('revcount', [revcount])[0])
            revcount = max(revcount, 1)
            tmpl.defaults['sessionvars']['revcount'] = revcount
        except ValueError:
            pass

    lessvars = copy.copy(tmpl.defaults['sessionvars'])
    lessvars['revcount'] = max(revcount / 2, 1)
    morevars = copy.copy(tmpl.defaults['sessionvars'])
    morevars['revcount'] = revcount * 2

    count = len(web.repo)
    pos = ctx.rev()
    parity = paritygen(web.stripecount)

    changenav = webutil.revnav(web.repo).gen(pos, revcount, count)

    entries = list(changelist())
    latestentry = entries[:1]
    if len(entries) > revcount:
        nextentry = entries[-1:]
        entries = entries[:-1]
    else:
        nextentry = []

    return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav,
                node=ctx.hex(), rev=pos, changesets=count,
                entries=entries,
                latestentry=latestentry, nextentry=nextentry,
                archives=web.archivelist("tip"), revcount=revcount,
                morevars=morevars, lessvars=lessvars, query=query)
Пример #2
0
def changelog(web, req, tmpl, shortlog=False):
    """
    /changelog[/{revision}]
    -----------------------

    Show information about multiple changesets.

    If the optional ``revision`` URL argument is absent, information about
    all changesets starting at ``tip`` will be rendered. If the ``revision``
    argument is present, changesets will be shown starting from the specified
    revision.

    If ``revision`` is absent, the ``rev`` query string argument may be
    defined. This will perform a search for changesets.

    The argument for ``rev`` can be a single revision, a revision set,
    or a literal keyword to search for in changeset data (equivalent to
    :hg:`log -k`).

    The ``revcount`` query string argument defines the maximum numbers of
    changesets to render.

    For non-searches, the ``changelog`` template will be rendered.
    """

    query = ''
    if 'node' in req.form:
        ctx = webutil.changectx(web.repo, req)
        symrev = webutil.symrevorshortnode(req, ctx)
    elif 'rev' in req.form:
        return _search(web, req, tmpl)
    else:
        ctx = web.repo['tip']
        symrev = 'tip'

    def changelist():
        revs = []
        if pos != -1:
            revs = web.repo.changelog.revs(pos, 0)
        curcount = 0
        for rev in revs:
            curcount += 1
            if curcount > revcount + 1:
                break

            entry = webutil.changelistentry(web, web.repo[rev], tmpl)
            entry['parity'] = parity.next()
            yield entry

    if shortlog:
        revcount = web.maxshortchanges
    else:
        revcount = web.maxchanges

    if 'revcount' in req.form:
        try:
            revcount = int(req.form.get('revcount', [revcount])[0])
            revcount = max(revcount, 1)
            tmpl.defaults['sessionvars']['revcount'] = revcount
        except ValueError:
            pass

    lessvars = copy.copy(tmpl.defaults['sessionvars'])
    lessvars['revcount'] = max(revcount / 2, 1)
    morevars = copy.copy(tmpl.defaults['sessionvars'])
    morevars['revcount'] = revcount * 2

    count = len(web.repo)
    pos = ctx.rev()
    parity = paritygen(web.stripecount)

    changenav = webutil.revnav(web.repo).gen(pos, revcount, count)

    entries = list(changelist())
    latestentry = entries[:1]
    if len(entries) > revcount:
        nextentry = entries[-1:]
        entries = entries[:-1]
    else:
        nextentry = []

    return tmpl(shortlog and 'shortlog' or 'changelog',
                changenav=changenav,
                node=ctx.hex(),
                rev=pos,
                symrev=symrev,
                changesets=count,
                entries=entries,
                latestentry=latestentry,
                nextentry=nextentry,
                archives=web.archivelist("tip"),
                revcount=revcount,
                morevars=morevars,
                lessvars=lessvars,
                query=query)
Пример #3
0
def graph(web, req, tmpl):
    """
    /graph[/{revision}]
    -------------------

    Show information about the graphical topology of the repository.

    Information rendered by this handler can be used to create visual
    representations of repository topology.

    The ``revision`` URL parameter controls the starting changeset.

    The ``revcount`` query string argument can define the number of changesets
    to show information for.

    This handler will render the ``graph`` template.
    """

    if 'node' in req.form:
        ctx = webutil.changectx(web.repo, req)
        symrev = webutil.symrevorshortnode(req, ctx)
    else:
        ctx = web.repo['tip']
        symrev = 'tip'
    rev = ctx.rev()

    bg_height = 39
    revcount = web.maxshortchanges
    if 'revcount' in req.form:
        try:
            revcount = int(req.form.get('revcount', [revcount])[0])
            revcount = max(revcount, 1)
            tmpl.defaults['sessionvars']['revcount'] = revcount
        except ValueError:
            pass

    lessvars = copy.copy(tmpl.defaults['sessionvars'])
    lessvars['revcount'] = max(revcount / 2, 1)
    morevars = copy.copy(tmpl.defaults['sessionvars'])
    morevars['revcount'] = revcount * 2

    count = len(web.repo)
    pos = rev

    uprev = min(max(0, count - 1), rev + revcount)
    downrev = max(0, rev - revcount)
    changenav = webutil.revnav(web.repo).gen(pos, revcount, count)

    tree = []
    if pos != -1:
        allrevs = web.repo.changelog.revs(pos, 0)
        revs = []
        for i in allrevs:
            revs.append(i)
            if len(revs) >= revcount:
                break

        # We have to feed a baseset to dagwalker as it is expecting smartset
        # object. This does not have a big impact on hgweb performance itself
        # since hgweb graphing code is not itself lazy yet.
        dag = graphmod.dagwalker(web.repo, revset.baseset(revs))
        # As we said one line above... not lazy.
        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 = cgi.escape(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,
                             [cgi.escape(x) for x in ctx.tags()
                              ], [cgi.escape(x) for x in ctx.bookmarks()]))
            else:
                edgedata = [{
                    'col': edge[0],
                    'nextcol': edge[1],
                    'color': (edge[2] - 1) % 6 + 1,
                    'width': edge[3],
                    'bcolor': edge[4]
                } for edge in edges]

                data.append({
                    '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

    return tmpl('graph',
                rev=rev,
                symrev=symrev,
                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)
Пример #4
0
def graph(web, req, tmpl):

    ctx = webutil.changectx(web.repo, req)
    rev = ctx.rev()

    bg_height = 39
    revcount = web.maxshortchanges
    if 'revcount' in req.form:
        revcount = int(req.form.get('revcount', [revcount])[0])
        revcount = max(revcount, 1)
        tmpl.defaults['sessionvars']['revcount'] = revcount

    lessvars = copy.copy(tmpl.defaults['sessionvars'])
    lessvars['revcount'] = max(revcount / 2, 1)
    morevars = copy.copy(tmpl.defaults['sessionvars'])
    morevars['revcount'] = revcount * 2

    count = len(web.repo)
    pos = rev

    uprev = min(max(0, count - 1), rev + revcount)
    downrev = max(0, rev - revcount)
    changenav = webutil.revnav(web.repo).gen(pos, revcount, count)

    tree = []
    if pos != -1:
        allrevs = web.repo.changelog.revs(pos, 0)
        revs = []
        for i in allrevs:
            revs.append(i)
            if len(revs) >= revcount:
                break

        dag = graphmod.dagwalker(web.repo, revs)
        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

    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)
Пример #5
0
def changelog(web, req, tmpl, shortlog=False):

    query = ''
    if 'node' in req.form:
        ctx = webutil.changectx(web.repo, req)
    else:
        if 'rev' in req.form:
            query = req.form['rev'][0]
            hi = query
        else:
            hi = 'tip'
        try:
            ctx = web.repo[hi]
        except (error.RepoError, error.LookupError):
            return _search(web, req, tmpl) # XXX redirect to 404 page?

    def changelist(latestonly, **map):
        revs = []
        if pos != -1:
            revs = web.repo.changelog.revs(pos, 0)
        if latestonly:
            revs = (revs.next(),)
        curcount = 0
        for i in revs:
            ctx = web.repo[i]
            n = ctx.node()
            showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n)
            files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles)

            curcount += 1
            if curcount > revcount:
                break
            yield {"parity": parity.next(),
                   "author": ctx.user(),
                   "parent": webutil.parents(ctx, i - 1),
                   "child": webutil.children(ctx, i + 1),
                   "changelogtag": showtags,
                   "desc": ctx.description(),
                   "extra": ctx.extra(),
                   "date": ctx.date(),
                   "files": files,
                   "rev": i,
                   "node": hex(n),
                   "tags": webutil.nodetagsdict(web.repo, n),
                   "bookmarks": webutil.nodebookmarksdict(web.repo, n),
                   "inbranch": webutil.nodeinbranch(web.repo, ctx),
                   "branches": webutil.nodebranchdict(web.repo, ctx)
            }

    revcount = shortlog and web.maxshortchanges or web.maxchanges
    if 'revcount' in req.form:
        revcount = int(req.form.get('revcount', [revcount])[0])
        revcount = max(revcount, 1)
        tmpl.defaults['sessionvars']['revcount'] = revcount

    lessvars = copy.copy(tmpl.defaults['sessionvars'])
    lessvars['revcount'] = max(revcount / 2, 1)
    morevars = copy.copy(tmpl.defaults['sessionvars'])
    morevars['revcount'] = revcount * 2

    count = len(web.repo)
    pos = ctx.rev()
    parity = paritygen(web.stripecount)

    changenav = webutil.revnav(web.repo).gen(pos, revcount, count)

    return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav,
                node=ctx.hex(), rev=pos, changesets=count,
                entries=lambda **x: changelist(latestonly=False, **x),
                latestentry=lambda **x: changelist(latestonly=True, **x),
                archives=web.archivelist("tip"), revcount=revcount,
                morevars=morevars, lessvars=lessvars, query=query)
Пример #6
0
def changelog(web, req, tmpl, shortlog=False):

    query = ''
    if 'node' in req.form:
        ctx = webutil.changectx(web.repo, req)
    elif 'rev' in req.form:
        return _search(web, req, tmpl)
    else:
        ctx = web.repo['tip']

    def changelist():
        revs = []
        if pos != -1:
            revs = web.repo.changelog.revs(pos, 0)
        curcount = 0
        for i in revs:
            ctx = web.repo[i]
            n = ctx.node()
            showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n)
            files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles)

            curcount += 1
            if curcount > revcount + 1:
                break
            yield {"parity": parity.next(),
                   "author": ctx.user(),
                   "parent": webutil.parents(ctx, i - 1),
                   "child": webutil.children(ctx, i + 1),
                   "changelogtag": showtags,
                   "desc": ctx.description(),
                   "extra": ctx.extra(),
                   "date": ctx.date(),
                   "files": files,
                   "rev": i,
                   "node": hex(n),
                   "tags": webutil.nodetagsdict(web.repo, n),
                   "bookmarks": webutil.nodebookmarksdict(web.repo, n),
                   "inbranch": webutil.nodeinbranch(web.repo, ctx),
                   "branches": webutil.nodebranchdict(web.repo, ctx)
            }

    revcount = shortlog and web.maxshortchanges or web.maxchanges
    if 'revcount' in req.form:
        revcount = int(req.form.get('revcount', [revcount])[0])
        revcount = max(revcount, 1)
        tmpl.defaults['sessionvars']['revcount'] = revcount

    lessvars = copy.copy(tmpl.defaults['sessionvars'])
    lessvars['revcount'] = max(revcount / 2, 1)
    morevars = copy.copy(tmpl.defaults['sessionvars'])
    morevars['revcount'] = revcount * 2

    count = len(web.repo)
    pos = ctx.rev()
    parity = paritygen(web.stripecount)

    changenav = webutil.revnav(web.repo).gen(pos, revcount, count)

    entries = list(changelist())
    latestentry = entries[:1]
    if len(entries) > revcount:
        nextentry = entries[-1:]
        entries = entries[:-1]
    else:
        nextentry = []

    return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav,
                node=ctx.hex(), rev=pos, changesets=count,
                entries=entries,
                latestentry=latestentry, nextentry=nextentry,
                archives=web.archivelist("tip"), revcount=revcount,
                morevars=morevars, lessvars=lessvars, query=query)
Пример #7
0
def graph(web, req, tmpl):

    ctx = webutil.changectx(web.repo, req)
    rev = ctx.rev()

    bg_height = 39
    revcount = web.maxshortchanges
    if 'revcount' in req.form:
        revcount = int(req.form.get('revcount', [revcount])[0])
        revcount = max(revcount, 1)
        tmpl.defaults['sessionvars']['revcount'] = revcount

    lessvars = copy.copy(tmpl.defaults['sessionvars'])
    lessvars['revcount'] = max(revcount / 2, 1)
    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)
    downrev = max(0, rev - revcount)
    changenav = webutil.revnav(web.repo).gen(pos, revcount, count)

    tree = []
    if start < end:
        revs = list(web.repo.changelog.revs(end - 1, start))
        dag = graphmod.dagwalker(web.repo, revs)
        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

    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)
Пример #8
0
def changelog(web, req, tmpl, shortlog=False):

    query = ''
    if 'node' in req.form:
        ctx = webutil.changectx(web.repo, req)
    else:
        if 'rev' in req.form:
            query = req.form['rev'][0]
            hi = query
        else:
            hi = 'tip'
        try:
            ctx = web.repo[hi]
        except (error.RepoError, error.LookupError):
            return _search(web, req, tmpl)  # XXX redirect to 404 page?

    def changelist(latestonly, **map):
        l = []  # build a list in forward order for efficiency
        revs = []
        if start < end:
            revs = web.repo.changelog.revs(start, end - 1)
        if latestonly:
            for r in revs:
                pass
            revs = (r, )
        for i in revs:
            ctx = web.repo[i]
            n = ctx.node()
            showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n)
            files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles)

            l.append({
                "parity": parity.next(),
                "author": ctx.user(),
                "parent": webutil.parents(ctx, i - 1),
                "child": webutil.children(ctx, i + 1),
                "changelogtag": showtags,
                "desc": ctx.description(),
                "extra": ctx.extra(),
                "date": ctx.date(),
                "files": files,
                "rev": i,
                "node": hex(n),
                "tags": webutil.nodetagsdict(web.repo, n),
                "bookmarks": webutil.nodebookmarksdict(web.repo, n),
                "inbranch": webutil.nodeinbranch(web.repo, ctx),
                "branches": webutil.nodebranchdict(web.repo, ctx)
            })
        for e in reversed(l):
            yield e

    revcount = shortlog and web.maxshortchanges or web.maxchanges
    if 'revcount' in req.form:
        revcount = int(req.form.get('revcount', [revcount])[0])
        revcount = max(revcount, 1)
        tmpl.defaults['sessionvars']['revcount'] = revcount

    lessvars = copy.copy(tmpl.defaults['sessionvars'])
    lessvars['revcount'] = max(revcount / 2, 1)
    morevars = copy.copy(tmpl.defaults['sessionvars'])
    morevars['revcount'] = revcount * 2

    count = len(web.repo)
    pos = ctx.rev()
    start = max(0, pos - revcount + 1)
    end = pos + 1
    parity = paritygen(web.stripecount, offset=start - end)

    changenav = webutil.revnav(web.repo).gen(pos, revcount, count)

    return tmpl(shortlog and 'shortlog' or 'changelog',
                changenav=changenav,
                node=ctx.hex(),
                rev=pos,
                changesets=count,
                entries=lambda **x: changelist(latestonly=False, **x),
                latestentry=lambda **x: changelist(latestonly=True, **x),
                archives=web.archivelist("tip"),
                revcount=revcount,
                morevars=morevars,
                lessvars=lessvars,
                query=query)
Пример #9
0
def changelog(web, req, tmpl, shortlog=False):

    if 'node' in req.form:
        ctx = webutil.changectx(web.repo, req)
    else:
        if 'rev' in req.form:
            hi = req.form['rev'][0]
        else:
            hi = 'tip'
        try:
            ctx = web.repo[hi]
        except error.RepoError:
            return _search(web, req, tmpl) # XXX redirect to 404 page?

    def changelist(latestonly, **map):
        l = [] # build a list in forward order for efficiency
        revs = []
        if start < end:
            revs = web.repo.changelog.revs(start, end - 1)
        if latestonly:
            for r in revs:
                pass
            revs = (r,)
        for i in revs:
            ctx = web.repo[i]
            n = ctx.node()
            showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n)
            files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles)

            l.append({"parity": parity.next(),
                      "author": ctx.user(),
                      "parent": webutil.parents(ctx, i - 1),
                      "child": webutil.children(ctx, i + 1),
                      "changelogtag": showtags,
                      "desc": ctx.description(),
                      "extra": ctx.extra(),
                      "date": ctx.date(),
                      "files": files,
                      "rev": i,
                      "node": hex(n),
                      "tags": webutil.nodetagsdict(web.repo, n),
                      "bookmarks": webutil.nodebookmarksdict(web.repo, n),
                      "inbranch": webutil.nodeinbranch(web.repo, ctx),
                      "branches": webutil.nodebranchdict(web.repo, ctx)
                     })
        for e in reversed(l):
            yield e

    revcount = shortlog and web.maxshortchanges or web.maxchanges
    if 'revcount' in req.form:
        revcount = int(req.form.get('revcount', [revcount])[0])
        revcount = max(revcount, 1)
        tmpl.defaults['sessionvars']['revcount'] = revcount

    lessvars = copy.copy(tmpl.defaults['sessionvars'])
    lessvars['revcount'] = max(revcount / 2, 1)
    morevars = copy.copy(tmpl.defaults['sessionvars'])
    morevars['revcount'] = revcount * 2

    count = len(web.repo)
    pos = ctx.rev()
    start = max(0, pos - revcount + 1)
    end = min(count, start + revcount)
    pos = end - 1
    parity = paritygen(web.stripecount, offset=start - end)

    changenav = webutil.revnav(web.repo).gen(pos, revcount, count)

    return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav,
                node=ctx.hex(), rev=pos, changesets=count,
                entries=lambda **x: changelist(latestonly=False, **x),
                latestentry=lambda **x: changelist(latestonly=True, **x),
                archives=web.archivelist("tip"), revcount=revcount,
                morevars=morevars, lessvars=lessvars)
Пример #10
0
def graph(web, req, tmpl):

    ctx = webutil.changectx(web.repo, req)
    rev = ctx.rev()

    bg_height = 39
    revcount = web.maxshortchanges
    if 'revcount' in req.form:
        try:
            revcount = int(req.form.get('revcount', [revcount])[0])
            revcount = max(revcount, 1)
            tmpl.defaults['sessionvars']['revcount'] = revcount
        except ValueError:
            pass

    lessvars = copy.copy(tmpl.defaults['sessionvars'])
    lessvars['revcount'] = max(revcount / 2, 1)
    morevars = copy.copy(tmpl.defaults['sessionvars'])
    morevars['revcount'] = revcount * 2

    count = len(web.repo)
    pos = rev

    uprev = min(max(0, count - 1), rev + revcount)
    downrev = max(0, rev - revcount)
    changenav = webutil.revnav(web.repo).gen(pos, revcount, count)

    tree = []
    if pos != -1:
        allrevs = web.repo.changelog.revs(pos, 0)
        revs = []
        for i in allrevs:
            revs.append(i)
            if len(revs) >= revcount:
                break

        # We have to feed a baseset to dagwalker as it is expecting smartset
        # object. This does not have a big impact on hgweb performance itself
        # since hgweb graphing code is not itself lazy yet.
        dag = graphmod.dagwalker(web.repo, revset.baseset(revs))
        # As we said one line above... not lazy.
        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 = cgi.escape(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,
                             [cgi.escape(x) for x in ctx.tags()],
                             [cgi.escape(x) for x in ctx.bookmarks()]))
            else:
                edgedata = [{'col': edge[0], 'nextcol': edge[1],
                             'color': (edge[2] - 1) % 6 + 1,
                             'width': edge[3], 'bcolor': edge[4]}
                            for edge in edges]

                data.append(
                    {'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

    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)
Пример #11
0
def changelog(web, req, tmpl, shortlog=False):

    query = ''
    if 'node' in req.form:
        ctx = webutil.changectx(web.repo, req)
    elif 'rev' in req.form:
        return _search(web, req, tmpl)
    else:
        ctx = web.repo['tip']

    def changelist():
        revs = []
        if pos != -1:
            revs = web.repo.changelog.revs(pos, 0)
        curcount = 0
        for i in revs:
            ctx = web.repo[i]
            n = ctx.node()
            showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n)
            files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles)

            curcount += 1
            if curcount > revcount + 1:
                break
            yield {"parity": parity.next(),
                   "author": ctx.user(),
                   "parent": webutil.parents(ctx, i - 1),
                   "child": webutil.children(ctx, i + 1),
                   "changelogtag": showtags,
                   "desc": ctx.description(),
                   "extra": ctx.extra(),
                   "date": ctx.date(),
                   "files": files,
                   "rev": i,
                   "node": hex(n),
                   "tags": webutil.nodetagsdict(web.repo, n),
                   "bookmarks": webutil.nodebookmarksdict(web.repo, n),
                   "inbranch": webutil.nodeinbranch(web.repo, ctx),
                   "branches": webutil.nodebranchdict(web.repo, ctx)
            }

    revcount = shortlog and web.maxshortchanges or web.maxchanges
    if 'revcount' in req.form:
        try:
            revcount = int(req.form.get('revcount', [revcount])[0])
            revcount = max(revcount, 1)
            tmpl.defaults['sessionvars']['revcount'] = revcount
        except ValueError:
            pass

    lessvars = copy.copy(tmpl.defaults['sessionvars'])
    lessvars['revcount'] = max(revcount / 2, 1)
    morevars = copy.copy(tmpl.defaults['sessionvars'])
    morevars['revcount'] = revcount * 2

    count = len(web.repo)
    pos = ctx.rev()
    parity = paritygen(web.stripecount)

    changenav = webutil.revnav(web.repo).gen(pos, revcount, count)

    entries = list(changelist())
    latestentry = entries[:1]
    if len(entries) > revcount:
        nextentry = entries[-1:]
        entries = entries[:-1]
    else:
        nextentry = []

    return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav,
                node=ctx.hex(), rev=pos, changesets=count,
                entries=entries,
                latestentry=latestentry, nextentry=nextentry,
                archives=web.archivelist("tip"), revcount=revcount,
                morevars=morevars, lessvars=lessvars, query=query)
Пример #12
0
def changelog(web, req, tmpl, shortlog=False):
    """
    /changelog[/{revision}]
    -----------------------

    Show information about multiple changesets.

    If the optional ``revision`` URL argument is absent, information about
    all changesets starting at ``tip`` will be rendered. If the ``revision``
    argument is present, changesets will be shown starting from the specified
    revision.

    If ``revision`` is absent, the ``rev`` query string argument may be
    defined. This will perform a search for changesets.

    The argument for ``rev`` can be a single revision, a revision set,
    or a literal keyword to search for in changeset data (equivalent to
    :hg:`log -k`).

    The ``revcount`` query string argument defines the maximum numbers of
    changesets to render.

    For non-searches, the ``changelog`` template will be rendered.
    """

    query = ''
    if 'node' in req.form:
        ctx = webutil.changectx(web.repo, req)
    elif 'rev' in req.form:
        return _search(web, req, tmpl)
    else:
        ctx = web.repo['tip']

    def changelist():
        revs = []
        if pos != -1:
            revs = web.repo.changelog.revs(pos, 0)
        curcount = 0
        for rev in revs:
            curcount += 1
            if curcount > revcount + 1:
                break

            entry = webutil.changelistentry(web, web.repo[rev], tmpl)
            entry['parity'] = parity.next()
            yield entry

    if shortlog:
        revcount = web.maxshortchanges
    else:
        revcount = web.maxchanges

    if 'revcount' in req.form:
        try:
            revcount = int(req.form.get('revcount', [revcount])[0])
            revcount = max(revcount, 1)
            tmpl.defaults['sessionvars']['revcount'] = revcount
        except ValueError:
            pass

    lessvars = copy.copy(tmpl.defaults['sessionvars'])
    lessvars['revcount'] = max(revcount / 2, 1)
    morevars = copy.copy(tmpl.defaults['sessionvars'])
    morevars['revcount'] = revcount * 2

    count = len(web.repo)
    pos = ctx.rev()
    parity = paritygen(web.stripecount)

    changenav = webutil.revnav(web.repo).gen(pos, revcount, count)

    entries = list(changelist())
    latestentry = entries[:1]
    if len(entries) > revcount:
        nextentry = entries[-1:]
        entries = entries[:-1]
    else:
        nextentry = []

    return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav,
                node=ctx.hex(), rev=pos, changesets=count,
                entries=entries,
                latestentry=latestentry, nextentry=nextentry,
                archives=web.archivelist("tip"), revcount=revcount,
                morevars=morevars, lessvars=lessvars, query=query)