예제 #1
0
    def __init__(self, store, remote, stdin=sys.stdin, stdout=sys.stdout):
        super(GitRemoteHelper, self).__init__(stdin, stdout)
        self._store = store
        self._repo = get_repo(remote)
        if isinstance(self._repo, bundlerepo):
            self._repo.init(self._store)
        self._remote = remote

        self._branchmap = None
        self._bookmarks = {}
        self._HEAD = 'branches/default/tip'
        self._has_unknown_heads = False

        GRAFT = {
            None: False,
            'false': False,
            'true': True,
        }
        try:
            self._graft = Git.config('cinnabar.graft',
                                     remote=remote.name,
                                     values=GRAFT)
        except InvalidConfig as e:
            logging.error(e.message)
            return 1
        if Git.config('cinnabar.graft-refs') is not None:
            logging.warn(
                'The cinnabar.graft-refs configuration is deprecated.\n'
                'Please unset it.')
예제 #2
0
def fetch(args):
    '''fetch a changeset from a mercurial remote'''

    remote = args.remote
    revs = args.revs
    full_revs = []
    for rev in revs:
        if not re.match('[0-9a-f]{40}$', rev.lower()):
            if remote.startswith('hg:'):
                url = remote
            else:
                url = Git.config('remote.%s.url' % remote)
            if not url:
                print >> sys.stderr, "Unknown remote:", remote
                return 1
            if url.startswith('hg::'):
                url = url[4:]
            repo = get_repo(Remote(remote, url))
            if repo.capable('lookup'):
                rev = hexlify(repo.lookup(rev))
            else:
                print >> sys.stderr, (
                    'Remote repository does not support the "lookup" command. '
                    'Please use a non-abbreviated mercurial revision.')
                return 1
        full_revs.append(rev)

    refs = ['hg/revs/%s' % r for r in full_revs]

    proc = GitProcess('fetch',
                      remote,
                      *refs,
                      stdout=sys.stdout,
                      config={'cinnabar.fetch': ' '.join(full_revs)})
    return proc.wait()
예제 #3
0
def fetch(args):
    '''fetch a changeset from a mercurial remote'''

    remote = args.remote
    revs = args.revs
    full_revs = []
    for rev in revs:
        if not re.match('[0-9a-f]{40}$', rev.lower()):
            if remote.startswith('hg:'):
                url = remote
            else:
                url = Git.config('remote.%s.url' % remote)
            if not url:
                print >>sys.stderr, "Unknown remote:", remote
                return 1
            if url.startswith('hg::'):
                url = url[4:]
            repo = get_repo(Remote(remote, url))
            if repo.capable('lookup'):
                rev = hexlify(repo.lookup(rev))
            else:
                print >>sys.stderr, (
                    'Remote repository does not support the "lookup" command. '
                    'Please use a non-abbreviated mercurial revision.')
                return 1
        full_revs.append(rev)

    refs = ['hg/revs/%s' % r for r in full_revs]

    proc = GitProcess('fetch', remote, *refs, stdout=sys.stdout,
                      config={'cinnabar.fetch': ' '.join(full_revs)})
    return proc.wait()
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('url', help='URL of Mercurial repo to push to')
    parser.add_argument('commit', help='Git commit to push')
    parser.add_argument('--config-file', action='append',
                        help='Extra Mercurial config file to load')

    args = parser.parse_args(args)

    url = args.url
    commit = args.commit

    init_logging()

    if passwordmgr:
        repo = get_repo(Remote('hg::%s' % url, url))
    else:
        from mercurial import hg

        ui = get_ui()

        for p in args.config_file or []:
            ui.readconfig(p, trust=True)

        repo = hg.peer(ui, {}, url)

    heads = (hexlify(h) for h in repo.heads())
    store = PushStore()
    try:
        pushed = push(repo, store, {commit: (None, False)}, heads, ())
    except Exception as e:
        # This is a common error. So rather than display the entire stack to
        # the user, exit with a well-defined exit code so the caller can
        # display a nice error message.
        if any(arg.startswith('Pushing merges is not supported yet')
               for arg in getattr(e, 'args', ())[:1]):
            return 127
        raise

    commits = []
    if pushed:
        for commit in pushed.iternodes():
            changeset = store.hg_changeset(commit)
            ref = store.changeset_ref(changeset)
            new_data = type(ref) != str

            commits.append([commit, changeset, new_data])

    # By now, cinnabar or its subprocesses should not be writing anything to
    # either stdout or stderr. Ensure stderr is flushed for _this_ process,
    # since git-mozreview uses the same file descriptor for both stdout and
    # stderr, and we want to try to avoid mixed output.
    sys.stderr.flush()
    for commit, changeset, new_data in commits:
        print('>result>', commit, changeset, new_data)
    sys.stdout.flush()

    return 0
예제 #5
0
def unbundle(args):
    '''apply a mercurial bundle to the repository'''
    # Make git emit its error when the current directory is not in a git repo.
    proc = GitProcess('rev-parse')
    ret = proc.wait()
    if ret:
        return ret
    remote = Remote(b'', fsencode(args.url))
    if remote.parsed_url.scheme not in (b'file', b'http', b'https'):
        logging.error('%s urls are not supported.' % remote.parsed_url.scheme)
        return 1
    if args.clonebundle:
        repo = get_repo(remote)
        if not repo.capable(b'clonebundles'):
            logging.error('Repository does not support clonebundles')
            return 1
        bundle = get_clonebundle(repo)
    else:
        bundle = get_bundle(remote.url)

    store = GitHgStore()
    GRAFT = {
        None: False,
        b'false': False,
        b'true': True,
    }
    try:
        graft = Git.config('cinnabar.graft', values=GRAFT)
    except InvalidConfig as e:
        logging.error(str(e))
        return 1
    if graft:
        store.prepare_graft()
    bundle = unbundler(bundle)
    apply_bundle = BundleApplier(bundle)
    del bundle
    apply_bundle(store)
    store.close()