/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/__init__.py

Remove all remaining dependencies on C git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""The basic test suite for bzr-git."""
18
18
 
19
 
import subprocess
 
19
from cStringIO import StringIO
 
20
 
20
21
import time
21
22
 
22
23
from bzrlib import (
23
24
    errors as bzr_errors,
24
 
    osutils,
25
25
    tests,
26
 
    trace,
27
26
    )
28
27
from bzrlib.plugins.git import (
29
 
    errors,
30
28
    import_dulwich,
31
29
    )
32
30
 
55
53
 
56
54
    def __init__(self, stream=None):
57
55
        self.commit_info = []
58
 
        self.stream = stream
59
 
        self._process = None
 
56
        self.orig_stream = stream
 
57
        if stream is None:
 
58
            self.stream = StringIO()
 
59
        else:
 
60
            self.stream = stream
60
61
        self._counter = 0
61
62
        self._branch = 'refs/heads/master'
62
 
        if stream is None:
63
 
            # Write the marks file into the git sandbox.
64
 
            self._marks_file_name = osutils.abspath('marks')
65
 
            self._process = subprocess.Popen(
66
 
                ['git', 'fast-import', '--quiet',
67
 
                 # GIT doesn't support '--export-marks foo'
68
 
                 # it only supports '--export-marks=foo'
69
 
                 # And gives a 'unknown option' otherwise.
70
 
                 '--export-marks=' + self._marks_file_name,
71
 
                ],
72
 
                stdout=subprocess.PIPE,
73
 
                stderr=subprocess.PIPE,
74
 
                stdin=subprocess.PIPE,
75
 
                )
76
 
            self.stream = self._process.stdin
77
 
        else:
78
 
            self._process = None
79
63
 
80
64
    def set_branch(self, branch):
81
65
        """Set the branch we are committing."""
82
66
        self._branch = branch
83
67
 
84
68
    def _write(self, text):
85
 
        try:
86
 
            self.stream.write(text)
87
 
        except IOError, e:
88
 
            if self._process is None:
89
 
                raise
90
 
            raise errors.GitCommandError(self._process.returncode,
91
 
                                         'git fast-import',
92
 
                                         self._process.stderr.read())
 
69
        self.stream.write(text)
93
70
 
94
71
    def _writelines(self, lines):
95
 
        try:
96
 
            self.stream.writelines(lines)
97
 
        except IOError, e:
98
 
            if self._process is None:
99
 
                raise
100
 
            raise errors.GitCommandError(self._process.returncode,
101
 
                                         'git fast-import',
102
 
                                         self._process.stderr.read())
 
72
        self.stream.writelines(lines)
103
73
 
104
74
    def _create_blob(self, content):
105
75
        self._counter += 1
202
172
 
203
173
    def finish(self):
204
174
        """We are finished building, close the stream, get the id mapping"""
205
 
        self.stream.close()
206
 
        if self._process is None:
207
 
            return {}
208
 
        if self._process.wait() != 0:
209
 
            raise errors.GitCommandError(self._process.returncode,
210
 
                                         'git fast-import',
211
 
                                         self._process.stderr.read())
212
 
        marks_file = open(self._marks_file_name)
213
 
        mapping = {}
214
 
        for line in marks_file:
215
 
            mark, shasum = line.split()
216
 
            assert mark.startswith(':')
217
 
            mapping[int(mark[1:])] = shasum
218
 
        marks_file.close()
219
 
        return mapping
 
175
        self.stream.seek(0)
 
176
        if self.orig_stream is None:
 
177
            from dulwich.repo import Repo
 
178
            r = Repo(".")
 
179
            from dulwich.fastexport import FastImporter
 
180
            importer = FastImporter(r)
 
181
            return importer.import_stream(self.stream)
220
182
 
221
183
 
222
184
def test_suite():