78
78
fp = fingerprint_file(f)
81
if ie.text_size != None:
81
if ie.text_size is not None:
82
82
if ie.text_size != fp['size']:
83
83
bailout("mismatched size for file %r in %r" % (ie.file_id, self._store),
84
84
["inventory expects %d bytes" % ie.text_size,
92
92
"store is probably damaged/corrupt"])
95
def print_file(self, fileid):
96
"""Print file with id `fileid` to stdout."""
98
pumpfile(self.get_file(fileid), sys.stdout)
101
def export(self, dest):
95
def export(self, dest):
102
96
"""Export this tree to a new directory.
104
98
`dest` should not exist, and will be created holding the
105
99
contents of this tree.
107
TODO: To handle subdirectories we need to create the
101
:todo: To handle subdirectories we need to create the
108
102
directories first.
110
104
:note: If the export fails, the destination directory will be
121
115
elif kind == 'file':
122
116
pumpfile(self.get_file(ie.file_id), file(fullpath, 'wb'))
124
bailout("don't know how to export {%s} of kind %r" % (fid, kind))
118
bailout("don't know how to export {%s} of kind %r", fid, kind)
125
119
mutter(" export {%s} kind %s to %s" % (ie.file_id, kind, fullpath))
157
151
return file(self.abspath(filename), 'rb')
159
153
def _get_store_filename(self, file_id):
160
## XXX: badly named; this isn't in the store at all
161
154
return self.abspath(self.id2path(file_id))
163
156
def has_id(self, file_id):
238
231
for ff in descend(fp, f_ie.file_id, fap):
241
for f in descend('', inv.root.file_id, self.basedir):
234
for f in descend('', None, self.basedir):
306
299
def is_ignored(self, filename):
307
r"""Check whether the filename matches an ignore pattern.
300
"""Check whether the filename matches an ignore pattern.
309
Patterns containing '/' or '\' need to match the whole path;
310
others match against only the last component.
302
Patterns containing '/' need to match the whole path; others
303
match against only the last component.
312
305
If the file is ignored, returns the pattern which caused it to
313
306
be ignored, otherwise None. So this can simply be used as a
314
307
boolean if desired."""
316
# TODO: Use '**' to match directories, and other extended
317
# globbing stuff from cvs/rsync.
319
# XXX: fnmatch is actually not quite what we want: it's only
320
# approximately the same as real Unix fnmatch, and doesn't
321
# treat dotfiles correctly and allows * to match /.
322
# Eventually it should be replaced with something more
309
## TODO: Use '**' to match directories, and other extended globbing stuff from cvs/rsync.
325
311
for pat in self.get_ignore_list():
326
if '/' in pat or '\\' in pat:
328
# as a special case, you can put ./ at the start of a
329
# pattern; this is good to match in the top-level
332
if (pat[:2] == './') or (pat[:2] == '.\\'):
313
# as a special case, you can put ./ at the start of a pattern;
314
# this is good to match in the top-level only;
350
333
File text can be retrieved from the text store.
352
TODO: Some kind of `__repr__` method, but a good one
335
:todo: Some kind of `__repr__` method, but a good one
353
336
probably means knowing the branch and revision number,
354
337
or at least passing a description to the constructor.
452
def find_renames(old_inv, new_inv):
453
for file_id in old_inv:
454
if file_id not in new_inv:
456
old_name = old_inv.id2path(file_id)
457
new_name = new_inv.id2path(file_id)
458
if old_name != new_name:
459
yield (old_name, new_name)