56
54
def __init__(self, stream=None):
57
55
self.commit_info = []
56
self.orig_stream = stream
58
self.stream = StringIO()
61
62
self._branch = 'refs/heads/master'
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,
72
stdout=subprocess.PIPE,
73
stderr=subprocess.PIPE,
74
stdin=subprocess.PIPE,
76
self.stream = self._process.stdin
80
64
def set_branch(self, branch):
81
65
"""Set the branch we are committing."""
82
66
self._branch = branch
84
68
def _write(self, text):
86
self.stream.write(text)
88
if self._process is None:
90
raise errors.GitCommandError(self._process.returncode,
92
self._process.stderr.read())
69
self.stream.write(text)
94
71
def _writelines(self, lines):
96
self.stream.writelines(lines)
98
if self._process is None:
100
raise errors.GitCommandError(self._process.returncode,
102
self._process.stderr.read())
72
self.stream.writelines(lines)
104
74
def _create_blob(self, content):
105
75
self._counter += 1
203
173
def finish(self):
204
174
"""We are finished building, close the stream, get the id mapping"""
206
if self._process is None:
208
if self._process.wait() != 0:
209
raise errors.GitCommandError(self._process.returncode,
211
self._process.stderr.read())
212
marks_file = open(self._marks_file_name)
214
for line in marks_file:
215
mark, shasum = line.split()
216
assert mark.startswith(':')
217
mapping[int(mark[1:])] = shasum
176
if self.orig_stream is None:
177
from dulwich.repo import Repo
179
from dulwich.fastexport import FastImporter
180
importer = FastImporter(r)
181
return importer.import_stream(self.stream)
222
184
def test_suite():