Beispiel #1
0
def test_no_initial_commit():
    tmp = maketemp()
    commands.init_bare(tmp)

    r = repo.Repository(path=tmp)
    with r.transaction() as p:
        eq(list(p), [])

        with p.child('bar').open('w') as f:
            f.write('THUD')

    # transaction committed, now the content has changed
    got = commands.ls_tree(
        repo=tmp,
        path='bar',
        )
    got = list(got)
    eq(len(got), 1)
    got = got[0]
    object = got['object']
    content = commands.cat_file(
        repo=tmp,
        object=object,
        )
    eq(content, 'THUD')
Beispiel #2
0
def test_cat_file():
    tmp = maketemp()
    commands.init_bare(tmp)
    sha1 = commands.write_object(repo=tmp, content='FOO')
    eq(sha1, 'd96c7efbfec2814ae0301ad054dc8d9fc416c9b5')
    got = commands.cat_file(repo=tmp, object=sha1)
    eq(got, 'FOO')
Beispiel #3
0
 def open(self, mode='r'):
     if mode not in ['r', 'rb']:
         raise IOError(
             errno.EROFS,
             os.strerror(errno.EROFS),
             )
     # TODO don't read big files fully into RAM
     data = commands.cat_file(
         repo=self.repo,
         type_='blob',
         object='%s:%s' % (self.rev, self.path),
         )
     return ContextManagedFile(data)
Beispiel #4
0
def test_TemporaryIndexFS_simple():
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    commands.init_bare(repo)
    t = indexfs.TemporaryIndexFS(repo=repo)
    with t as root:
        with root.child('bar').open('w') as f:
            f.write('hello')
    eq(t.tree, '4d9fa708931786c374d879e71f89f97a68e73f94')
    got = commands.cat_file(
        repo=repo,
        object='4d9fa708931786c374d879e71f89f97a68e73f94:bar',
        )
    eq(got, 'hello')
Beispiel #5
0
    def open(self, mode="r"):
        path_sha = hashlib.sha1(self.path).hexdigest()
        work = os.path.extsep.join([self.index, path_sha, "work"])

        current_users = self.open_files.get(self.path)
        if current_users is None:

            try:
                object = self.git_get_sha1()
            except OSError, e:
                if e.errno == errno.ENOENT:
                    content = ""
                else:
                    raise
            else:
                # it exists
                content = commands.cat_file(repo=self.repo, object=object)
            tmp = os.path.extsep.join([self.index, path_sha, "tmp"])
            with file(tmp, "wb") as f:
                f.write(content)
            os.rename(tmp, work)
            current_users = self.open_files[self.path] = dict(users=set(), writable=False)
Beispiel #6
0
def test_commit_race():
    tmp = maketemp()
    commands.init_bare(tmp)
    commands.fast_import(
        repo=tmp,
        commits=[
            dict(
                message='one',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='quux/foo',
                        content='FOO',
                        ),
                    dict(
                        path='bar',
                        content='orig\n',
                        mode='100755',
                        ),
                    ],
                ),
            ],
        )

    r = repo.Repository(path=tmp)
    racecount = 0
    tries = 1
    MAX_RETRIES = 3
    success = False
    while tries <= MAX_RETRIES:
        try:
            with r.transaction() as p:

                if racecount < 2:
                    racecount += 1
                    r2 = repo.Repository(path=tmp)
                    with r2.transaction() as p2:
                        with p2.child('bar').open('a') as f:
                            f.write('racer %d\n' % racecount)

                with p.child('bar').open('a') as f:
                    f.write('loser %d\n' % tries)
        except repo.TransactionRaceLostError:
            tries += 1
        else:
            success = True
            break

    assert success

    # transaction committed, now the content has changed
    got = commands.ls_tree(
        repo=tmp,
        path='bar',
        )
    got = list(got)
    eq(len(got), 1)
    got = got[0]
    object = got['object']
    content = commands.cat_file(
        repo=tmp,
        object=object,
        )
    eq(content, 'orig\nracer 1\nracer 2\nloser 3\n')
Beispiel #7
0
def test_simple():
    tmp = maketemp()
    commands.init_bare(tmp)
    commands.fast_import(
        repo=tmp,
        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',
                        ),
                    ],
                ),
            ],
        )

    r = repo.Repository(path=tmp)
    with r.transaction() as p:
        assert type(p) == indexfs.IndexFS
        eq(p.path, '')
        eq(list(p), [p.child('bar'), p.child('quux')])

        with p.child('bar').open('w') as f:
            f.write('THUD')

        # the committed tree has not changed yet, because transaction
        # is still open
        got = commands.ls_tree(
            repo=tmp,
            path='bar',
            )
        got = list(got)
        eq(len(got), 1)
        got = got[0]
        object = got['object']
        content = commands.cat_file(
            repo=tmp,
            object=object,
            )
        eq(content, 'BAR')

    # transaction committed, now the content has changed
    got = commands.ls_tree(
        repo=tmp,
        path='bar',
        )
    got = list(got)
    eq(len(got), 1)
    got = got[0]
    object = got['object']
    content = commands.cat_file(
        repo=tmp,
        object=object,
        )
    eq(content, 'THUD')