def isancestorwebcommand(web):
    """Determine whether a changeset is an ancestor of another."""
    req = web.req
    for k in (b'head', b'node'):
        if k not in req.qsparams:
            raise ErrorResponse(HTTP_NOT_FOUND, b"missing parameter '%s'" % k)

    head = req.qsparams[b'head']
    node = req.qsparams[b'node']

    try:
        headctx = scmutil.revsingle(web.repo, head)
    except error.RepoLookupError:
        raise ErrorResponse(HTTP_NOT_FOUND, b'unknown head revision %s' % head)

    try:
        testctx = scmutil.revsingle(web.repo, node)
    except error.RepoLookupError:
        raise ErrorResponse(HTTP_NOT_FOUND, b'unknown node revision %s' % node)

    testrev = testctx.rev()
    isancestor = False

    for rev in web.repo.changelog.ancestors([headctx.rev()], inclusive=True):
        if rev == testrev:
            isancestor = True
            break

    return web.sendtemplate(b'isancestor',
                            headnode=headctx.hex(),
                            testnode=testctx.hex(),
                            isancestor=isancestor)
예제 #2
0
def isancestorwebcommand(web, req, tmpl):
    """Determine whether a changeset is an ancestor of another."""
    for k in ('head', 'node'):
        if k not in req.form:
            raise ErrorResponse(HTTP_NOT_FOUND, "missing parameter '%s'" % k)

    head = req.form['head'][0]
    node = req.form['node'][0]

    try:
        headctx = web.repo[head]
    except error.RepoLookupError:
        raise ErrorResponse(HTTP_NOT_FOUND, 'unknown head revision %s' % head)

    try:
        testctx = web.repo[node]
    except error.RepoLookupError:
        raise ErrorResponse(HTTP_NOT_FOUND, 'unknown node revision %s' % node)

    testrev = testctx.rev()
    isancestor = False

    for rev in web.repo.changelog.ancestors([headctx.rev()], inclusive=True):
        if rev == testrev:
            isancestor = True
            break

    return tmpl('isancestor',
                headnode=headctx.hex(),
                testnode=testctx.hex(),
                isancestor=isancestor)
예제 #3
0
def pushlog_setup(repo, req):
    """Given a repository object and a hgweb request object,
    build a PushlogQuery object and populate it with data from the request.
    The returned query object will have its query already run, and
    its entries member can be read."""
    try:
        page = int(req.qsparams.get(b'node', b'1'))
    except ValueError:
        page = 1

    tipsonly = req.qsparams.get(b'tipsonly', None) == b'1'

    urlbase = req.advertisedbaseurl

    query = PushlogQuery(urlbase=urlbase, repo=repo, tipsonly=tipsonly)
    query.page = page

    # find start component
    if b'startdate' in req.qsparams:
        startdate = do_parse_date(req.qsparams.get(b'startdate', None))
        query.querystart = QueryType.DATE
        query.querystart_value = startdate
    elif b'fromchange' in req.qsparams:
        query.querystart = QueryType.CHANGESET
        query.querystart_value = req.qsparams.get(b'fromchange', None)
    elif b'startID' in req.qsparams:
        query.querystart = QueryType.PUSHID
        query.querystart_value = req.qsparams.get(b'startID', None)
    else:
        # default is last 10 pushes
        query.querystart = QueryType.COUNT
        query.querystart_value = PUSHES_PER_PAGE

    if b'enddate' in req.qsparams:
        enddate = do_parse_date(req.qsparams.get(b'enddate', None))
        query.queryend = QueryType.DATE
        query.queryend_value = enddate
    elif b'tochange' in req.qsparams:
        query.queryend = QueryType.CHANGESET
        query.queryend_value = req.qsparams.get(b'tochange', None)
    elif b'endID' in req.qsparams:
        query.queryend = QueryType.PUSHID
        query.queryend_value = req.qsparams.get(b'endID', None)

    query.userquery = req.qsparams.getall(b'user')

    #TODO: use rev here, switch page to ?page=foo ?
    query.changesetquery = req.qsparams.getall(b'changeset')

    try:
        query.formatversion = int(req.qsparams.get(b'version', b'1'))
    except ValueError:
        raise ErrorResponse(500, b'version parameter must be an integer')
    if query.formatversion < 1 or query.formatversion > 2:
        raise ErrorResponse(500, b'version parameter must be 1 or 2')

    query.do_query()

    return query
예제 #4
0
def pushes(web, req, tmpl):
    """WebCommand to return a data structure containing pushes."""
    query = pushlogSetup(web.repo, req)
    data = pushes_worker(query, web.repo, 'full' in req.form)

    if query.formatversion == 1:
        return tmpl('pushes1', **data)
    elif query.formatversion == 2:
        return tmpl('pushes2', **data)

    raise ErrorResponse(500, 'unexpected formatversion')
예제 #5
0
def pushes(web):
    """WebCommand to return a data structure containing pushes."""
    req = web.req

    query = pushlog_setup(web.repo, req)
    data = pushes_worker(query, web.repo, 'full' in req.qsparams)

    if query.formatversion == 1:
        template = 'pushes1'
    elif query.formatversion == 2:
        template = 'pushes2'
    else:
        raise ErrorResponse(500, 'unexpected formatversion')

    return web.sendtemplate(template, **data)
예제 #6
0
def pushlogSetup(repo, req):
    """Given a repository object and a hgweb request object,
    build a PushlogQuery object and populate it with data from the request.
    The returned query object will have its query already run, and
    its entries member can be read."""
    repopath = os.path.dirname(repo.path)
    reponame = os.path.basename(repopath)
    if reponame == '.hg':
        reponame = os.path.basename(os.path.dirname(repopath))
    pushdb = os.path.join(repo.path, "pushlog2.db")
    # If the database doesn't already exist, don't try to open it.
    conn = None
    if os.path.isfile(pushdb):
        try:
            conn = sqlite3.connect(pushdb)
        except sqlite3.OperationalError:
            pass

    if 'node' in req.form:
        page = int(req.form['node'][0])
    else:
        page = 1

    # figure out the urlbase
    proto = req.env.get('wsgi.url_scheme')
    if proto == 'https':
        proto = 'https'
        default_port = "443"
    else:
        proto = 'http'
        default_port = "80"
    port = req.env["SERVER_PORT"]
    port = port != default_port and (":" + port) or ""

    tipsonly = False
    if 'tipsonly' in req.form and req.form['tipsonly'][0] == '1':
        tipsonly = True

    query = PushlogQuery(urlbase='%s://%s%s' % (proto, req.env['SERVER_NAME'], port),
                         repo=repo,
                         dbconn=conn,
                         tipsonly=tipsonly,
                         reponame=reponame)
    query.page = page

    # find start component
    if 'startdate' in req.form:
        startdate = doParseDate(req.form['startdate'][0])
        query.querystart = QueryType.DATE
        query.querystart_value = startdate
    elif 'fromchange' in req.form:
        query.querystart = QueryType.CHANGESET
        query.querystart_value = req.form.get('fromchange', ['null'])[0]
    elif 'startID' in req.form:
        query.querystart = QueryType.PUSHID
        query.querystart_value = req.form.get('startID', ['0'])[0]
    else:
        # default is last 10 pushes
        query.querystart = QueryType.COUNT
        query.querystart_value = PUSHES_PER_PAGE

    if 'enddate' in req.form:
        enddate = doParseDate(req.form['enddate'][0])
        query.queryend = QueryType.DATE
        query.queryend_value = enddate
    elif 'tochange' in req.form:
        query.queryend = QueryType.CHANGESET
        query.queryend_value = req.form.get('tochange', ['default'])[0]
    elif 'endID' in req.form:
        query.queryend = QueryType.PUSHID
        query.queryend_value = req.form.get('endID', [None])[0]

    if 'user' in req.form:
        query.userquery = req.form.get('user', [])

    #TODO: use rev here, switch page to ?page=foo ?
    if 'changeset' in req.form:
        query.changesetquery = req.form.get('changeset', [])

    try:
        query.formatversion = int(req.form.get('version', ['1'])[0])
    except ValueError:
        raise ErrorResponse(500, 'version parameter must be an integer')
    if query.formatversion < 1 or query.formatversion > 2:
        raise ErrorResponse(500, 'version parameter must be 1 or 2')

    query.DoQuery()
    return query