def remoteparent(ui, repo, rev, upstream=None):
    if upstream:
        remotepath = ui.expandpath(upstream)
    else:
        remotepath = ui.expandpath('default-push', 'default')
    remoterepo = hg.repository(ui, remotepath)
    out = repo.findoutgoing(remoterepo)
    ancestors = repo.changelog.ancestors([repo.lookup(rev)])
    for o in out:
        orev = repo[o]
        a, b, c = repo.changelog.nodesbetween([orev.node()], [repo[rev].node()])
        if a:
            return orev.parents()[0]
Exemple #2
0
def get_repo(alias, url):
    """Returns a hg.repository object initialized for usage.
    """

    try:
        from mercurial import hg, ui
    except ImportError:
        die("Mercurial python libraries not installed")

    ui = ui.ui()
    source, revs = hg.parseurl(ui.expandpath(url), ['tip'])
    repo = hg.repository(ui, source)

    prefix = 'refs/hg/%s/' % alias
    debug("prefix: '%s'", prefix)

    repo.hg = hg
    repo.gitdir = ""
    repo.alias = alias
    repo.prefix = prefix
    repo.revs = revs

    repo.git_hg = GitHg(warn)
    exporter = GitExporter(repo.git_hg, repo, 'hg.marks', 'git.marks', prefix)
    non_local = NonLocalHg(repo, alias)

    repo.exporter = exporter
    repo.non_local = non_local

    return repo
Exemple #3
0
def remoteparent(ui, repo, opts, rev, upstream=None):
    if upstream:
        remotepath = ui.expandpath(upstream)
    else:
        remotepath = ui.expandpath(
            ui.expandpath('reviewboard', 'default-push'), 'default')
    remoterepo = hg.peer(repo, opts, remotepath)
    out = findoutgoing(repo, remoterepo)
    ancestors = repo.changelog.ancestors(
        [repo.changelog.rev(repo.lookup(rev))])
    for o in out:
        orev = repo[o]
        a, b, c = repo.changelog.nodesbetween([orev.node()],
                                              [repo[rev].node()])
        if a:
            return orev.parents()[0]
Exemple #4
0
    def get_repo(self, alias, url):
        """Returns a hg.repository object initialized for usage.
        """

        try:
            from mercurial import hg, ui
        except ImportError:
            die("Mercurial python libraries not installed")

        remote = False

        if url.startswith("remote://"):
            remote = True
            url = "file://%s" % url[9:]

        ui = ui.ui()
        source, revs, checkout = util.parseurl(ui.expandpath(url), ['default'])
        repo = hg.repository(ui, source)
        if repo.capable('branchmap'):
            revs += repo.branchmap().keys()
            revs = set(revs)

        prefix = 'refs/hg/%s/' % alias
        debug("prefix: '%s'", prefix)

        repo.marksfile = 'git.marks'
        repo.hg = hg
        repo.prefix = prefix
        repo.revs_ = revs # must not override repo.revs()

        self.setup_repo(repo, alias)

        repo.git_hg = GitHg(warn)
        repo.exporter = GitExporter(repo)
        repo.importer = GitImporter(repo)
        repo.non_local = NonLocalHg(repo)

        repo.is_local = not remote and repo.local()

        return repo
Exemple #5
0
    def get_repo(self, alias, url):
        """Returns a hg.repository object initialized for usage.
        """

        try:
            from mercurial import hg, ui
        except ImportError:
            die("Mercurial python libraries not installed")

        remote = False

        if url.startswith("remote://"):
            remote = True
            url = "file://%s" % url[9:]

        ui = ui.ui()
        source, revs, checkout = util.parseurl(ui.expandpath(url), ['default'])
        repo = hg.repository(ui, source)
        if repo.capable('branchmap'):
            revs += repo.branchmap().keys()
            revs = set(revs)

        prefix = 'refs/hg/%s/' % alias
        debug("prefix: '%s'", prefix)

        repo.marksfile = 'git.marks'
        repo.hg = hg
        repo.prefix = prefix
        repo.revs_ = revs  # must not override repo.revs()

        self.setup_repo(repo, alias)

        repo.git_hg = GitHg(warn)
        repo.exporter = GitExporter(repo)
        repo.importer = GitImporter(repo)
        repo.non_local = NonLocalHg(repo)

        repo.is_local = not remote and repo.local()

        return repo
Exemple #6
0
def expandpath(ui, upstream):
    if upstream:
        return ui.expandpath(upstream)
    else:
        return ui.expandpath(ui.expandpath('reviewboard', 'default-push'),
            'default')
Exemple #7
0
def thgdispatch(ui, path=None, args=[]):
    '''
    Replicate functionality of mercurial dispatch but force the use
    of the passed in ui for all purposes
    '''
    # read --config before doing anything else
    # (e.g. to change trust settings for reading .hg/hgrc)
    config = _earlygetopt(['--config'], args)
    if config:
        ui.updateopts(config=_parseconfig(config))

    # check for cwd
    cwd = _earlygetopt(['--cwd'], args)
    if cwd:
        os.chdir(cwd[-1])

    # read the local repository .hgrc into a local ui object
    path = rootpath(path) or ""
    if path:
        try:
            ui.readconfig(os.path.join(path, ".hg", "hgrc"))
        except IOError:
            pass

    # now we can expand paths, even ones in .hg/hgrc
    rpath = _earlygetopt(["-R", "--repository", "--repo"], args)
    if rpath:
        path = ui.expandpath(rpath[-1])

    extensions.loadall(ui)
    if not hasattr(extensions, 'extensions'):
        extensions.extensions = lambda: () # pre-0.9.5, loadall did below
    for name, module in extensions.extensions():
        if name in _loaded:
            continue

        # setup extensions
        extsetup = getattr(module, 'extsetup', None)
        if extsetup:
            extsetup()

        cmdtable = getattr(module, 'cmdtable', {})
        overrides = [cmd for cmd in cmdtable if cmd in commands.table]
        if overrides:
            ui.warn(_("extension '%s' overrides commands: %s\n")
                    % (name, " ".join(overrides)))
        commands.table.update(cmdtable)
        _loaded[name] = 1

    # check for fallback encoding
    fallback = ui.config('ui', 'fallbackencoding')
    if fallback:
        util._fallbackencoding = fallback

    fullargs = args
    cmd, func, args, options, cmdoptions = parse(ui, args)

    if options["encoding"]:
        util._encoding = options["encoding"]
    if options["encodingmode"]:
        util._encodingmode = options["encodingmode"]
    ui.updateopts(options["verbose"], options["debug"], options["quiet"],
                 not options["noninteractive"], options["traceback"])

    if options['help']:
        return commands.help_(ui, cmd, options['version'])
    elif options['version']:
        return commands.version_(ui)
    elif not cmd:
        return commands.help_(ui, 'shortlist')

    repo = None
    if cmd not in commands.norepo.split():
        try:
            repo = hg.repository(ui, path=path)
            repo.ui = ui
            ui.setconfig("bundle", "mainreporoot", repo.root)
            if not repo.local():
                raise util.Abort(_("repository '%s' is not local") % path)
        except RepoError:
            if cmd not in commands.optionalrepo.split():
                if not path:
                    raise RepoError(_("There is no Mercurial repository here"
                                         " (.hg not found)"))
                raise
        d = lambda: func(ui, repo, *args, **cmdoptions)
    else:
        d = lambda: func(ui, *args, **cmdoptions)

    # run pre-hook, and abort if it fails
    ret = hook.hook(ui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs))
    if ret:
        return ret

    # Run actual command
    try:
        ret = d()
    except TypeError, inst:
        # was this an argument error?
        tb = traceback.extract_tb(sys.exc_info()[2])
        if len(tb) != 2: # no
            raise
        raise ParseError(cmd, _("invalid arguments"))