20
20
from sets import Set
21
21
import os.path, os, fnmatch
23
from osutils import pumpfile, compare_files, filesize, quotefn, sha_file, \
24
joinpath, splitpath, appendpath, isdir, isfile, file_kind, fingerprint_file
26
from stat import S_ISREG, S_ISDIR, ST_MODE, ST_SIZE
23
28
from inventory import Inventory
24
29
from trace import mutter, note
25
from osutils import pumpfile, compare_files, filesize, quotefn, sha_file, \
26
joinpath, splitpath, appendpath, isdir, isfile, file_kind, fingerprint_file
27
30
from errors import bailout
29
from stat import S_ISREG, S_ISDIR, ST_MODE, ST_SIZE
76
78
fp = fingerprint_file(f)
79
if ie.text_size is not None:
81
if ie.text_size != None:
80
82
if ie.text_size != fp['size']:
81
83
bailout("mismatched size for file %r in %r" % (ie.file_id, self._store),
82
84
["inventory expects %d bytes" % ie.text_size,
90
92
"store is probably damaged/corrupt"])
93
def export(self, dest):
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):
94
102
"""Export this tree to a new directory.
96
104
`dest` should not exist, and will be created holding the
97
105
contents of this tree.
99
:todo: To handle subdirectories we need to create the
107
TODO: To handle subdirectories we need to create the
100
108
directories first.
102
110
:note: If the export fails, the destination directory will be
113
121
elif kind == 'file':
114
122
pumpfile(self.get_file(ie.file_id), file(fullpath, 'wb'))
116
bailout("don't know how to export {%s} of kind %r", fid, kind)
124
bailout("don't know how to export {%s} of kind %r" % (fid, kind))
117
125
mutter(" export {%s} kind %s to %s" % (ie.file_id, kind, fullpath))
149
157
return file(self.abspath(filename), 'rb')
151
159
def _get_store_filename(self, file_id):
160
## XXX: badly named; this isn't in the store at all
152
161
return self.abspath(self.id2path(file_id))
154
163
def has_id(self, file_id):
229
238
for ff in descend(fp, f_ie.file_id, fap):
232
for f in descend('', None, self.basedir):
241
for f in descend('', inv.root.file_id, self.basedir):
297
306
def is_ignored(self, filename):
298
"""Check whether the filename matches an ignore pattern.
307
r"""Check whether the filename matches an ignore pattern.
300
Patterns containing '/' need to match the whole path; others
301
match against only the last component.
309
Patterns containing '/' or '\' need to match the whole path;
310
others match against only the last component.
303
312
If the file is ignored, returns the pattern which caused it to
304
313
be ignored, otherwise None. So this can simply be used as a
305
314
boolean if desired."""
307
## TODO: Use '**' to match directories, and other extended globbing stuff from cvs/rsync.
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
325
for pat in self.get_ignore_list():
311
# as a special case, you can put ./ at the start of a pattern;
312
# this is good to match in the top-level only;
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] == '.\\'):
331
350
File text can be retrieved from the text store.
333
:todo: Some kind of `__repr__` method, but a good one
352
TODO: Some kind of `__repr__` method, but a good one
334
353
probably means knowing the branch and revision number,
335
354
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)