예제 #1
0
파일: indexfs.py 프로젝트: jisqyv/pygitfs
        def g():
            for data in commands.ls_files(repo=self.repo, index=self.index, path=self.path, children=False):
                if data["path"] == self.path:
                    # delete the old one
                    delete = {}
                    delete.update(data)
                    delete["mode"] = "0"
                    yield delete

                    # add the new one
                    data["path"] = new_path.path
                    yield data
                else:
                    prefix = self.path + "/"
                    assert data["path"][: len(prefix)] == prefix

                    # delete the old one
                    delete = {}
                    delete.update(data)
                    delete["mode"] = "0"
                    yield delete

                    # add the new one
                    data["path"] = new_path.path + "/" + data["path"][len(prefix) :]
                    yield data
예제 #2
0
파일: indexfs.py 프로젝트: jisqyv/pygitfs
    def isdir(self):
        if self.path == "":
            return True
        for data in commands.ls_files(repo=self.repo, index=self.index, path=self.path):
            return True

        # i have no children, therefore i am not a directory
        return False
예제 #3
0
파일: indexfs.py 프로젝트: jisqyv/pygitfs
 def exists(self):
     if self.path == "":
         # root directory always exists
         return True
     for data in commands.ls_files(repo=self.repo, index=self.index, path=self.path, children=False):
         # doesn't matter if it matches the file itself, or files
         # in a subdirectory; anyway, current path exists
         return True
     return False
예제 #4
0
def test_ls_files():
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    os.mkdir(repo)
    commands.init_bare(repo)
    index = os.path.join(tmp, 'index')
    commands.fast_import(
        repo=repo,
        commits=[
            dict(
                message='one',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='quux/foo',
                        content='FOO',
                        ),
                    dict(
                        path='bar',
                        content='BAR',
                        mode='100755',
                        ),
                    ],
                ),
            ],
        )
    commands.read_tree(
        repo=repo,
        treeish='HEAD',
        index=index,
        )
    g = commands.ls_files(
        repo=repo,
        index=index,
        )
    eq(
        g.next(),
        dict(
            mode='100755',
            object='add8373108657cb230a5379a6fcdaab73f330642',
            path='bar',
            ),
        )
    eq(
        g.next(),
        dict(
            mode='100644',
            object='d96c7efbfec2814ae0301ad054dc8d9fc416c9b5',
            path='quux/foo',
            ),
        )
    assert_raises(StopIteration, g.next)
예제 #5
0
파일: indexfs.py 프로젝트: jisqyv/pygitfs
    def git_get_sha1(self):
        """
        Get the git sha1 for the object.

        Does not work on ope
        """
        for data in commands.ls_files(repo=self.repo, index=self.index, path=self.path, children=False):
            if data["path"] != self.path:
                continue
            return data["object"]

        # not found
        raise OSError(errno.ENOENT, os.strerror(errno.ENOENT))
예제 #6
0
파일: indexfs.py 프로젝트: jisqyv/pygitfs
    def islink(self):
        if self.path == "":
            # root directory is never a link
            return False
        for data in commands.ls_files(repo=self.repo, index=self.index, path=self.path, children=False):
            if data["path"] == self.path:
                return data["mode"] == "120000"
            else:
                # if current path has children, it can't be a symlink
                assert data["path"].startswith(self.path + "/")
                return False

        # didn't match anything -> don't even exist
        return False
예제 #7
0
파일: indexfs.py 프로젝트: jisqyv/pygitfs
    def stat(self):
        if self.path == "":
            return posix.stat_result([stat.S_IFDIR + 0777, 0, 0, 0, 0, 0, 0, 0, 0, 0])
        for data in commands.ls_files(repo=self.repo, index=self.index, path=self.path, children=False):
            if data["path"] == self.path:
                mode = int(data["mode"], 8)
                size = commands.get_object_size(repo=self.repo, object=data["object"])
                return posix.stat_result([mode, 0, 0, 0, 0, 0, size, 0, 0, 0])
            else:
                # if current path has children, it must be a dir
                assert data["path"].startswith(self.path + "/")
                return posix.stat_result([stat.S_IFDIR + 0777, 0, 0, 0, 0, 0, 0, 0, 0, 0])

        # not found
        raise OSError(errno.ENOENT, os.strerror(errno.ENOENT))
예제 #8
0
파일: indexfs.py 프로젝트: jisqyv/pygitfs
    def __iter__(self):
        last_subdir = None
        saw_children = False
        for data in commands.ls_files(repo=self.repo, index=self.index, path=self.path, children=True):
            saw_children = True

            # TODO OMG THIS IS STUPID, always retrieves full subtree
            # (so for root, always dumps whole index)
            if self.path == "":
                prefix = ""
            else:
                prefix = self.path + "/"
                assert data["path"][: len(prefix)] == prefix
            relative = data["path"][len(prefix) :]

            if relative == ".gitfs-placeholder":
                # hide the magic
                continue

            if "/" in relative:
                # it's a subdir, really; combine multiple files into
                # one dir entry
                head = relative.split(os.path.sep, 1)[0]
                if head == last_subdir:
                    # already handled this one
                    continue
                else:
                    last_subdir = head
                    yield self.child(head)
            else:
                yield self.child(relative)

        if not saw_children:
            # it's either not a dir or it doesn't exist..
            # TODO make tests differentiate between those
            if self.path == "":
                # except root always exists
                return
            raise OSError(errno.ENOENT, os.strerror(errno.ENOENT))
예제 #9
0
def test_read_tree_merge3():
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    os.mkdir(repo)
    commands.init_bare(repo)
    commands.fast_import(
        repo=repo,
        commits=[
            dict(
                message='one',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    ],
                ),
            dict(
                message='two',
                committer='Jack Smith <*****@*****.**>',
                commit_time='1216235940 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    dict(
                        path='bar',
                        content='BAR',
                        ),
                    ],
                ),
            ],
        )
    one = commands.rev_parse(repo=repo, rev='HEAD~1')
    commands.fast_import(
        repo=repo,
        ref='refs/heads/bar',
        commits=[
            dict(
                parent=one,
                message='three',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235942 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    dict(
                        path='quux',
                        content='QUUX',
                        ),
                    ],
                ),
            ],
        )

    index = os.path.join(tmp, 'index')
    commands.read_tree(
        repo=repo,
        treeish='HEAD',
        index=index,
        )
    commands.read_tree_merge3(
        repo=repo,
        index=index,
        ancestor=one,
        local='HEAD',
        remote='refs/heads/bar',
        trivial=True,
        )
    g = commands.ls_files(
        repo=repo,
        index=index,
        )
    eq(
        g.next(),
        dict(
            mode='100644',
            object='add8373108657cb230a5379a6fcdaab73f330642',
            path='bar',
            ),
        )
    eq(
        g.next(),
        dict(
            mode='100644',
            object='d96c7efbfec2814ae0301ad054dc8d9fc416c9b5',
            path='foo',
            ),
        )
    eq(
        g.next(),
        dict(
            mode='100644',
            object='b9d4f2faa83cc1ad83ef7493ad6cbf08b086e4c1',
            path='quux',
            ),
        )
    assert_raises(StopIteration, g.next)