38
38
from bzrlib.osutils import (pumpfile, quotefn, splitpath, joinpath,
39
appendpath, sha_strings)
39
pathjoin, sha_strings)
40
40
from bzrlib.trace import mutter
41
41
from bzrlib.errors import (NotVersionedError, InvalidEntryName,
42
42
BzrError, BzrCheckError)
79
79
InventoryDirectory('123', 'src', parent_id='TREE_ROOT')
80
80
>>> i.add(InventoryFile('2323', 'hello.c', parent_id='123'))
81
81
InventoryFile('2323', 'hello.c', parent_id='123')
82
>>> shouldbe = {0: 'src', 1: os.path.join('src','hello.c')}
82
>>> shouldbe = {0: 'src', 1: pathjoin('src','hello.c')}
83
83
>>> for ix, j in enumerate(i.iter_entries()):
84
84
... print (j[0] == shouldbe[ix], j[1])
103
103
InventoryFile('2326', 'wibble.c', parent_id='2325')
104
104
>>> for path, entry in i.iter_entries():
105
... print path.replace('\\\\', '/') # for win32 os.sep
106
106
... assert i.path2id(path)
203
203
def get_tar_item(self, root, dp, now, tree):
204
204
"""Get a tarfile item and a file stream for its content."""
205
item = tarfile.TarInfo(os.path.join(root, dp))
205
item = tarfile.TarInfo(pathjoin(root, dp))
206
206
# TODO: would be cool to actually set it to the timestamp of the
207
207
# revision it was last changed
268
268
This is a template method - implement _put_on_disk in subclasses.
270
fullpath = appendpath(dest, dp)
270
fullpath = pathjoin(dest, dp)
271
271
self._put_on_disk(fullpath, tree)
272
272
mutter(" export {%s} kind %s to %s", self.file_id,
273
273
self.kind, fullpath)
483
483
checker.repeated_text_cnt += 1
486
if self.file_id not in checker.checked_weaves:
487
mutter('check weave {%s}', self.file_id)
488
w = tree.get_weave(self.file_id)
489
# Not passing a progress bar, because it creates a new
490
# progress, which overwrites the current progress,
491
# and doesn't look nice
493
checker.checked_weaves[self.file_id] = True
495
w = tree.get_weave_prelude(self.file_id)
485
497
mutter('check version {%s} of {%s}', rev_id, self.file_id)
486
file_lines = tree.get_file_lines(self.file_id)
487
498
checker.checked_text_cnt += 1
488
if self.text_size != sum(map(len, file_lines)):
489
raise BzrCheckError('text {%s} wrong size' % self.text_id)
490
if self.text_sha1 != sha_strings(file_lines):
491
raise BzrCheckError('text {%s} wrong sha1' % self.text_id)
499
# We can't check the length, because Weave doesn't store that
500
# information, and the whole point of looking at the weave's
501
# sha1sum is that we don't have to extract the text.
502
if self.text_sha1 != w.get_sha1(self.revision):
503
raise BzrCheckError('text {%s} version {%s} wrong sha1'
504
% (self.file_id, self.revision))
492
505
checker.checked_texts[t] = self.text_sha1
765
778
if ie.kind == 'directory':
766
779
for cn, cie in self.iter_entries(from_dir=ie.file_id):
767
yield os.path.join(name, cn), cie
780
yield pathjoin(name, cn), cie
770
783
def entries(self):
777
790
kids = dir_ie.children.items()
779
792
for name, ie in kids:
780
child_path = os.path.join(dir_path, name)
793
child_path = pathjoin(dir_path, name)
781
794
accum.append((child_path, ie))
782
795
if ie.kind == 'directory':
783
796
descend(ie, child_path)
799
812
for name, child_ie in kids:
800
child_path = os.path.join(parent_path, name)
813
child_path = pathjoin(parent_path, name)
801
814
descend(child_ie, child_path)
802
815
descend(self.root, u'')
865
878
if parent.children.has_key(entry.name):
866
879
raise BzrError("%s is already versioned" %
867
appendpath(self.id2path(parent.file_id), entry.name))
880
pathjoin(self.id2path(parent.file_id), entry.name))
869
882
self._byid[entry.file_id] = entry
870
883
parent.children[entry.name] = entry
987
1000
>>> i = Inventory()
988
1001
>>> e = i.add(InventoryDirectory('src-id', 'src', ROOT_ID))
989
1002
>>> e = i.add(InventoryFile('foo-id', 'foo.c', parent_id='src-id'))
990
>>> print i.id2path('foo-id').replace(os.sep, '/')
1003
>>> print i.id2path('foo-id')
993
1006
# get all names, skipping root
994
1007
p = [self._byid[fid].name for fid in self.get_idpath(file_id)[1:]]
995
return os.sep.join(p)