120
119
self.parent_ids = rev.parent_ids[:]
121
120
if not isinstance(tree, Tree):
122
121
raise TypeError("As of bzr 2.4 Testament.__init__() takes a "
123
"Revision and a Tree.")
122
"Revision and a Tree.")
125
124
self.revprops = copy(rev.properties)
126
125
if contains_whitespace(self.revision_id):
139
138
a(self.long_header)
140
a('revision-id: %s\n' % self.revision_id.decode('utf-8'))
139
a('revision-id: %s\n' % self.revision_id)
141
140
a('committer: %s\n' % self.committer)
142
141
a('timestamp: %d\n' % self.timestamp)
143
142
a('timezone: %d\n' % self.timezone)
146
145
for parent_id in sorted(self.parent_ids):
147
146
if contains_whitespace(parent_id):
148
147
raise ValueError(parent_id)
149
a(' %s\n' % parent_id.decode('utf-8'))
148
a(' %s\n' % parent_id)
151
150
for l in self.message.splitlines():
157
156
return [line.encode('utf-8') for line in r]
159
158
def _get_entries(self):
160
return ((path, ie) for (path, file_class, kind, ie) in
159
return ((path, ie) for (path, versioned, kind, file_id, ie) in
161
160
self.tree.list_files(include_root=self.include_root))
163
162
def _escape_path(self, path):
164
163
if contains_linebreaks(path):
165
164
raise ValueError(path)
166
if not isinstance(path, text_type):
167
# TODO(jelmer): Clean this up for pad.lv/1696545
168
path = path.decode('ascii')
169
return path.replace(u'\\', u'/').replace(u' ', u'\\ ')
165
return unicode(path.replace('\\', '/').replace(' ', '\\ '))
171
167
def _entry_to_line(self, path, ie):
172
168
"""Turn an inventory entry into a testament line"""
173
169
if contains_whitespace(ie.file_id):
174
170
raise ValueError(ie.file_id)
177
173
if ie.kind == 'file':
178
174
# TODO: avoid switching on kind
179
175
if not ie.text_sha1:
180
176
raise AssertionError()
181
content = ie.text_sha1.decode('ascii')
177
content = ie.text_sha1
182
178
content_spacer = ' '
183
179
elif ie.kind == 'symlink':
184
180
if not ie.symlink_target:
194
190
def as_text(self):
195
return b''.join(self.as_text_lines())
191
return ''.join(self.as_text_lines())
197
193
def as_short_text(self):
198
194
"""Return short digest-based testament."""
199
return (self.short_header.encode('ascii') +
195
return (self.short_header +
202
198
% (self.revision_id, self.as_sha1()))
204
200
def _revprops_to_lines(self):
224
220
long_header = 'bazaar-ng testament version 2.1\n'
225
221
short_header = 'bazaar-ng testament short form 2.1\n'
226
222
include_root = False
228
223
def _entry_to_line(self, path, ie):
229
224
l = Testament._entry_to_line(self, path, ie)[:-1]
230
l += ' ' + ie.revision.decode('utf-8')
225
l += ' ' + ie.revision
231
226
l += {True: ' yes\n', False: ' no\n'}[ie.executable]
245
240
def _escape_path(self, path):
246
241
if contains_linebreaks(path):
247
242
raise ValueError(path)
248
if not isinstance(path, text_type):
249
# TODO(jelmer): Clean this up for pad.lv/1696545
250
path = path.decode('ascii')
253
return path.replace(u'\\', u'/').replace(u' ', u'\\ ')
245
return unicode(path.replace('\\', '/').replace(' ', '\\ '))