Пример #1
0
    def _proc(self):
        try:
            return self._real_proc
        except AttributeError:
            from .helper import GitHgHelper, NoHelperException
            # Ensure the helper is there.
            if GitHgHelper._helper is GitHgHelper:
                GitHgHelper._helper = False
            try:
                with GitHgHelper.query('feature', 'force'):
                    pass
                self._real_proc = GitHgHelper._helper
            except NoHelperException:
                self._real_proc = GitProcess(
                    'fast-import', '--quiet', stdin=subprocess.PIPE,
                    config={'core.ignorecase': 'false'})
            self.write(
                "feature force\n"
                "feature ls\n"
                "feature notes\n"
            )
            if self._done:
                self.write('feature done\n')

            return self._real_proc
Пример #2
0
    def ls_tree(self, treeish, path='', recursive=False):
        if (not isinstance(treeish, Mark) and
                treeish.startswith('refs/')):
            treeish = self.resolve_ref(treeish)
        normalize = False
        if recursive:
            assert not isinstance(treeish, Mark)
            iterator = self.iter('ls-tree', '--full-tree', '-r', treeish,
                                 '--', path)
            normalize = True
        elif isinstance(treeish, Mark) and self._fast_import:
            assert not path.endswith('/')
            ls = self._fast_import.ls(treeish, path)
            if any(l is not None for l in ls):
                yield ls
            return
        elif not isinstance(treeish, Mark):
            if path == '' or path.endswith('/'):
                from githg import GitHgHelper
                treeish = treeish + ':' + path
                typ, data = GitHgHelper.cat_file('auto', treeish)
                assert typ in ('tree', 'missing')
                while data:
                    null = data.index('\0')
                    mode, path = data[:null].split(' ', 1)
                    if mode == '160000':
                        typ = 'commit'
                    elif mode == '40000':
                        typ = 'tree'
                        mode = '040000'
                    else:
                        typ = 'blob'
                    sha1 = hexlify(data[null + 1:null + 21])
                    yield mode, typ, sha1, path
                    data = data[null + 21:]
            else:
                base = path.rsplit('/', 1)
                if len(base) == 1:
                    base = ''
                else:
                    base, path = base
                    base += '/'
                for mode, typ, sha1, p in self.ls_tree(treeish, base):
                    if p == path:
                        yield mode, typ, sha1, path
            return
        else:
            iterator = self.iter('ls-tree', '--full-tree', treeish, '--', path)
            normalize = True

        for line in iterator:
            if normalize:
                mode, typ, sha1, path = split_ls_tree(line)
                yield mode, typ, sha1, normalize_path(path)
            else:
                yield split_ls_tree(line)
Пример #3
0
    def ls_tree(self, treeish, path='', recursive=False):
        if (not isinstance(treeish, Mark) and treeish.startswith('refs/')):
            treeish = self.resolve_ref(treeish)
        normalize = False
        if recursive:
            assert not isinstance(treeish, Mark)
            iterator = self.iter('ls-tree', '--full-tree', '-r', treeish, '--',
                                 path)
            normalize = True
        elif isinstance(treeish, Mark) and self._fast_import:
            assert not path.endswith('/')
            ls = self._fast_import.ls(treeish, path)
            if any(l is not None for l in ls):
                yield ls
            return
        elif not isinstance(treeish, Mark):
            if path == '' or path.endswith('/'):
                from githg import GitHgHelper
                treeish = treeish + ':' + path
                typ, data = GitHgHelper.cat_file('auto', treeish)
                assert typ in ('tree', 'missing')
                while data:
                    null = data.index('\0')
                    mode, path = data[:null].split(' ', 1)
                    if mode == '160000':
                        typ = 'commit'
                    elif mode == '40000':
                        typ = 'tree'
                        mode = '040000'
                    else:
                        typ = 'blob'
                    sha1 = hexlify(data[null + 1:null + 21])
                    yield mode, typ, sha1, path
                    data = data[null + 21:]
            else:
                base = path.rsplit('/', 1)
                if len(base) == 1:
                    base = ''
                else:
                    base, path = base
                    base += '/'
                for mode, typ, sha1, p in self.ls_tree(treeish, base):
                    if p == path:
                        yield mode, typ, sha1, path
            return
        else:
            iterator = self.iter('ls-tree', '--full-tree', treeish, '--', path)
            normalize = True

        for line in iterator:
            if normalize:
                mode, typ, sha1, path = split_ls_tree(line)
                yield mode, typ, sha1, normalize_path(path)
            else:
                yield split_ls_tree(line)
Пример #4
0
    def ls_tree(self, treeish, path='', recursive=False):
        from githg import GitHgHelper
        if treeish.startswith('refs/'):
            treeish = self.resolve_ref(treeish)

        if path.endswith('/') or recursive or path == '':
            path = path.rstrip('/')
            for line in GitHgHelper.ls_tree('%s:%s' % (treeish, path),
                                            recursive):
                mode, typ, sha1, p = line
                if path:
                    yield mode, typ, sha1, posixpath.join(path, p)
                else:
                    yield mode, typ, sha1, p
        else:
            # self._fast_import might not be initialized, so use the ls command
            # through the helper instead.
            with GitHgHelper.query('ls', treeish, path) as stdout:
                line = stdout.readline()
                if not line.startswith('missing '):
                    yield split_ls_tree(line[:-1])
Пример #5
0
    def _proc(self):
        if self._real_proc is None:
            from .helper import GitHgHelper
            # Ensure the helper is there.
            if GitHgHelper._helper is GitHgHelper:
                GitHgHelper._helper = False
            with GitHgHelper.query('feature', 'force'):
                pass
            self._real_proc = GitHgHelper._helper

            atexit.register(self.close, rollback=True)

        return self._real_proc
Пример #6
0
    def _proc(self):
        try:
            return self._real_proc
        except AttributeError:
            from .helper import GitHgHelper
            # Ensure the helper is there.
            if GitHgHelper._helper is GitHgHelper:
                GitHgHelper._helper = False
            with GitHgHelper.query('feature', 'force'):
                pass
            self._real_proc = GitHgHelper._helper
            self.write("feature force\n" "feature ls\n" "feature notes\n")
            if self._done:
                self.write('feature done\n')

            return self._real_proc
Пример #7
0
    def diff_tree(self, treeish1, treeish2, path='', detect_copy=False):
        from githg import GitHgHelper
        if path:

            def one_sided_diff(treeish, status):
                for line in self.ls_tree(treeish, recursive=True):
                    mode, typ, sha1, path = line
                    if status == 'A':
                        yield '000000', mode, NULL_NODE_ID, sha1, status, path
                    elif status == 'D':
                        yield mode, '000000', sha1, NULL_NODE_ID, status, path

            treeish1 = '%s:%s' % (treeish1, path)
            treeish2 = '%s:%s' % (treeish2, path)

            if treeish1 is None:
                if treeish2 is None:
                    return ()
                return one_sided_diff(treeish2, 'A')
            if treeish2 is None:
                return one_sided_diff(treeish1, 'D')

        return GitHgHelper.diff_tree(treeish1, treeish2, detect_copy)
Пример #8
0
 def cat_file(self, typ, sha1):
     from githg import GitHgHelper
     return GitHgHelper.cat_file(typ, sha1)