38
38
from bzrlib.osutils import (pumpfile, quotefn, splitpath, joinpath,
39
pathjoin, sha_strings)
39
appendpath, 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: pathjoin('src','hello.c')}
83
>>> for ix, j in enumerate(i.iter_entries()):
84
... print (j[0] == shouldbe[ix], j[1])
82
>>> for j in i.iter_entries():
86
(True, InventoryDirectory('123', 'src', parent_id='TREE_ROOT'))
87
(True, InventoryFile('2323', 'hello.c', parent_id='123'))
85
('src', InventoryDirectory('123', 'src', parent_id='TREE_ROOT'))
86
('src/hello.c', InventoryFile('2323', 'hello.c', parent_id='123'))
88
87
>>> i.add(InventoryFile('2323', 'bye.c', '123'))
89
88
Traceback (most recent call last):
103
102
InventoryFile('2326', 'wibble.c', parent_id='2325')
104
103
>>> for path, entry in i.iter_entries():
104
... print path.replace('\\\\', '/') # for win32 os.sep
106
105
... assert i.path2id(path)
203
202
def get_tar_item(self, root, dp, now, tree):
204
203
"""Get a tarfile item and a file stream for its content."""
205
item = tarfile.TarInfo(pathjoin(root, dp))
204
item = tarfile.TarInfo(os.path.join(root, dp))
206
205
# TODO: would be cool to actually set it to the timestamp of the
207
206
# revision it was last changed
268
267
This is a template method - implement _put_on_disk in subclasses.
270
fullpath = pathjoin(dest, dp)
269
fullpath = appendpath(dest, dp)
271
270
self._put_on_disk(fullpath, tree)
272
mutter(" export {%s} kind %s to %s", self.file_id,
271
mutter(" export {%s} kind %s to %s" % (self.file_id, self.kind, fullpath))
275
273
def _put_on_disk(self, fullpath, tree):
276
274
"""Put this entry onto disk at fullpath, from tree tree."""
483
481
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)
497
483
mutter('check version {%s} of {%s}', rev_id, self.file_id)
484
file_lines = tree.get_file_lines(self.file_id)
498
485
checker.checked_text_cnt += 1
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))
486
if self.text_size != sum(map(len, file_lines)):
487
raise BzrCheckError('text {%s} wrong size' % self.text_id)
488
if self.text_sha1 != sha_strings(file_lines):
489
raise BzrCheckError('text {%s} wrong sha1' % self.text_id)
505
490
checker.checked_texts[t] = self.text_sha1
662
647
def _put_in_tar(self, item, tree):
663
648
"""See InventoryEntry._put_in_tar."""
664
item.type = tarfile.SYMTYPE
649
iterm.type = tarfile.SYMTYPE
778
763
if ie.kind == 'directory':
779
764
for cn, cie in self.iter_entries(from_dir=ie.file_id):
780
yield pathjoin(name, cn), cie
765
yield os.path.join(name, cn), cie
783
768
def entries(self):
790
775
kids = dir_ie.children.items()
792
777
for name, ie in kids:
793
child_path = pathjoin(dir_path, name)
778
child_path = os.path.join(dir_path, name)
794
779
accum.append((child_path, ie))
795
780
if ie.kind == 'directory':
796
781
descend(ie, child_path)
798
descend(self.root, u'')
783
descend(self.root, '')
812
797
for name, child_ie in kids:
813
child_path = pathjoin(parent_path, name)
798
child_path = os.path.join(parent_path, name)
814
799
descend(child_ie, child_path)
815
descend(self.root, u'')
800
descend(self.root, '')
878
863
if parent.children.has_key(entry.name):
879
864
raise BzrError("%s is already versioned" %
880
pathjoin(self.id2path(parent.file_id), entry.name))
865
appendpath(self.id2path(parent.file_id), entry.name))
882
867
self._byid[entry.file_id] = entry
883
868
parent.children[entry.name] = entry
890
875
The immediate parent must already be versioned.
892
877
Returns the new entry object."""
893
from bzrlib.workingtree import gen_file_id
878
from bzrlib.branch import gen_file_id
895
880
parts = bzrlib.osutils.splitpath(relpath)
896
881
if len(parts) == 0:
1000
985
>>> i = Inventory()
1001
986
>>> e = i.add(InventoryDirectory('src-id', 'src', ROOT_ID))
1002
987
>>> e = i.add(InventoryFile('foo-id', 'foo.c', parent_id='src-id'))
1003
>>> print i.id2path('foo-id')
988
>>> print i.id2path('foo-id').replace(os.sep, '/')
1006
991
# get all names, skipping root
1007
992
p = [self._byid[fid].name for fid in self.get_idpath(file_id)[1:]]
993
return os.sep.join(p)