~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

Handled more pipe errors for display commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
import bzrlib
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():
 
83
    ...   print j
85
84
    ... 
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):
90
89
    ...
102
101
    >>> i['2326']
103
102
    InventoryFile('2326', 'wibble.c', parent_id='2325')
104
103
    >>> for path, entry in i.iter_entries():
105
 
    ...     print path
 
104
    ...     print path.replace('\\\\', '/')     # for win32 os.sep
106
105
    ...     assert i.path2id(path)
107
106
    ... 
108
107
    src
110
109
    src/hello.c
111
110
    src/wibble
112
111
    src/wibble/wibble.c
113
 
    >>> i.id2path('2326')
 
112
    >>> i.id2path('2326').replace('\\\\', '/')
114
113
    'src/wibble/wibble.c'
115
114
    """
116
115
    
202
201
 
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
208
207
        item.mtime = now
267
266
        
268
267
        This is a template method - implement _put_on_disk in subclasses.
269
268
        """
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,
273
 
                self.kind, fullpath)
 
271
        mutter("  export {%s} kind %s to %s" % (self.file_id, self.kind, fullpath))
274
272
 
275
273
    def _put_on_disk(self, fullpath, tree):
276
274
        """Put this entry onto disk at fullpath, from tree tree."""
418
416
        self.children = {}
419
417
        self.kind = 'root_directory'
420
418
        self.parent_id = None
421
 
        self.name = u''
 
419
        self.name = ''
422
420
 
423
421
    def __eq__(self, other):
424
422
        if not isinstance(other, RootEntry):
482
480
            else:
483
481
                checker.repeated_text_cnt += 1
484
482
                return
485
 
 
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
492
 
            w.check()
493
 
            checker.checked_weaves[self.file_id] = True
494
 
        else:
495
 
            w = tree.get_weave_prelude(self.file_id)
496
 
 
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
506
491
 
507
492
    def copy(self):
661
646
 
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
665
650
        fileobj = None
666
651
        item.size = 0
667
652
        item.mode = 0755
777
762
            yield name, ie
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
781
766
 
782
767
 
783
768
    def entries(self):
790
775
            kids = dir_ie.children.items()
791
776
            kids.sort()
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)
797
782
 
798
 
        descend(self.root, u'')
 
783
        descend(self.root, '')
799
784
        return accum
800
785
 
801
786
 
810
795
            kids.sort()
811
796
 
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, '')
816
801
        return accum
817
802
        
818
803
 
877
862
 
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))
881
866
 
882
867
        self._byid[entry.file_id] = entry
883
868
        parent.children[entry.name] = entry
890
875
        The immediate parent must already be versioned.
891
876
 
892
877
        Returns the new entry object."""
893
 
        from bzrlib.workingtree import gen_file_id
 
878
        from bzrlib.branch import gen_file_id
894
879
        
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, '/')
1004
989
        src/foo.c
1005
990
        """
1006
991
        # get all names, skipping root
1007
992
        p = [self._byid[fid].name for fid in self.get_idpath(file_id)[1:]]
1008
 
        if p:
1009
 
            return pathjoin(*p)
1010
 
        else:
1011
 
            return ''
 
993
        return os.sep.join(p)
1012
994
            
1013
995
 
1014
996