65
65
for parent_id in parent_ids:
66
66
parent_trees.append(tree.branch.repository.revision_tree(parent_id))
68
lines.append(result._get_parents_line(parent_ids))
68
69
# FIXME: is this utf8 safe?
69
lines.append('\0'.join([str(num_parents)] + parent_ids))
71
71
to_minikind = DirState._kind_to_minikind
72
72
to_yesno = {True:'y', False: 'n'}
152
152
for entry in to_remove:
153
153
block.remove(entry)
155
result.lines = result._get_output_lines(lines)
159
"""Serialise the entire dirstate to a sequence of lines."""
162
def _get_parents_line(self, parent_ids):
163
"""Create a line for the state file for parents information."""
164
return '\0'.join([str(len(parent_ids))] + parent_ids)
166
def get_parent_ids(self):
167
"""Return a list of the parent tree ids for the directory state."""
172
def initialize(path):
173
"""Create a new dirstate on path."""
176
lines.append(result._get_parents_line([]))
177
result.lines = result._get_output_lines(lines)
178
state_file = open(path, 'wb+')
180
state_file.write(''.join(result.lines))
185
def _get_output_lines(self, lines):
186
"""format lines for final output.
188
:param lines: A sequece of lines containing the parents list and the
155
191
output_lines = ['#bzr dirstate flat format 1\n']
157
192
lines.append('') # a final newline
158
193
inventory_text = '\0\n\0'.join(lines)
159
194
output_lines.append('adler32: %s\n' % (zlib.adler32(inventory_text),))
161
196
num_entries = len(lines)-2
162
197
output_lines.append('num_entries: %s\n' % (num_entries,))
163
198
output_lines.append(inventory_text)
165
result.lines = output_lines
203
"""Construct a DirState on the file at path path."""
205
result.state_file = open(path, 'rb')
169
"""Serialise the entire dirstate to a sequence of lines."""
172
'#bzr dirstate flat format 1\n',
176
'\x00\x00\x00d\x00TREE_ROOT\x004096\x00AAAQAETIF65EyBeuAAADAQAQQxsAAEHt\x00\x00\n',
209
"""Read the entire state."""
212
def _read_header(self):
213
"""This reads in the metadata header, and the parent ids.
215
After reading in, the file should be positioned at the null
216
just before the start of the first record in the file.
218
:return: (expected adler checksum, number of entries, parent list)
221
parent_line = self.state_file.readline()
222
info = parent_line.split('\0')
223
num_parents = int(info[0])
224
assert num_parents == len(info)-2, 'incorrect parent info line'
226
self._parents = [p.decode('utf8') for p in info[1:-1]]
228
def _read_prelude(self):
229
"""Read in the prelude header of the dirstate file
231
This only reads in the stuff that is not connected to the adler
232
checksum. The position will be correct to read in the rest of
233
the file and check the checksum after this point.
234
The next entry in the file should be the number of parents,
235
and their ids. Followed by a newline.
237
header = self.state_file.readline()
238
assert header == '#bzr dirstate flat format 1\n', \
239
'invalid header line: %r' % (header,)
240
adler_line = self.state_file.readline()
241
assert adler_line.startswith('adler32: '), 'missing adler32 checksum'
242
self.adler_expected = int(adler_line[len('adler32: '):-1])
243
num_entries_line = self.state_file.readline()
244
assert num_entries_line.startswith('num_entries: '), 'missing num_entries line'
245
self.num_entries = int(num_entries_line[len('num_entries: '):-1])
180
248
def pack_stat(st, _encode=base64.encodestring, _pack=struct.pack):
181
249
"""Convert stat values into a packed representation."""