예제 #1
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()
예제 #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 run(self):
     from cinnabar import VERSION
     from cinnabar.git import Git, GitProcess
     from distutils.version import StrictVersion
     parent_dir = os.path.dirname(os.path.dirname(__file__))
     if not os.path.exists(os.path.join(parent_dir, '.git')) or \
             check_enabled('no-version-check') or \
             not interval_expired('version-check', 86400):
         return
     REPO = 'https://github.com/glandium/git-cinnabar'
     devnull = open(os.devnull, 'wb')
     if VERSION.endswith('a'):
         _, _, extra = StrictVersion(VERSION[:-1]).version
         ref = 'refs/heads/next' if extra == 0 else 'refs/heads/master'
         for line in Git.iter('ls-remote', REPO, ref, stderr=devnull):
             sha1, head = line.split()
             if head != ref:
                 continue
             proc = GitProcess(
                 '-C', parent_dir, 'merge-base', '--is-ancestor', sha1,
                 'HEAD', stdout=devnull, stderr=devnull)
             if proc.wait() != 0:
                 self.message = (
                     'The `{}` branch of git-cinnabar was updated. '
                     'Please update your copy.\n'
                     'You can switch to the `release` branch if you want '
                     'to reduce these update notifications.'
                     .format(ref.partition('refs/heads/')[-1]))
                 break
     else:
         version = StrictVersion(VERSION)
         newer_version = version
         for line in Git.iter('ls-remote', REPO, 'refs/tags/*',
                              stderr=devnull):
             sha1, tag = line.split()
             tag = tag.partition('refs/tags/')[-1]
             try:
                 v = StrictVersion(tag)
             except ValueError:
                 continue
             if v > newer_version:
                 newer_version = v
         if newer_version != version:
             self.message = (
                 'New version available: {} (current version: {})'
                 .format(newer_version, version))
예제 #4
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()