~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

Merge from integration.

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
 
                            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])
85
85
    ... 
102
102
    >>> i['2326']
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
 
105
    ...     print path
106
106
    ...     assert i.path2id(path)
107
107
    ... 
108
108
    src
110
110
    src/hello.c
111
111
    src/wibble
112
112
    src/wibble/wibble.c
113
 
    >>> i.id2path('2326').replace('\\\\', '/')
 
113
    >>> i.id2path('2326')
114
114
    'src/wibble/wibble.c'
115
115
    """
116
116
    
202
202
 
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
208
208
        item.mtime = now
267
267
        
268
268
        This is a template method - implement _put_on_disk in subclasses.
269
269
        """
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)
418
418
        self.children = {}
419
419
        self.kind = 'root_directory'
420
420
        self.parent_id = None
421
 
        self.name = ''
 
421
        self.name = u''
422
422
 
423
423
    def __eq__(self, other):
424
424
        if not isinstance(other, RootEntry):
482
482
            else:
483
483
                checker.repeated_text_cnt += 1
484
484
                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
 
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
493
506
 
494
507
    def copy(self):
764
777
            yield name, ie
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
768
781
 
769
782
 
770
783
    def entries(self):
777
790
            kids = dir_ie.children.items()
778
791
            kids.sort()
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)
784
797
 
785
 
        descend(self.root, '')
 
798
        descend(self.root, u'')
786
799
        return accum
787
800
 
788
801
 
797
810
            kids.sort()
798
811
 
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
 
        descend(self.root, '')
 
815
        descend(self.root, u'')
803
816
        return accum
804
817
        
805
818
 
864
877
 
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))
868
881
 
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')
991
1004
        src/foo.c
992
1005
        """
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)
 
1008
        if p:
 
1009
            return pathjoin(*p)
 
1010
        else:
 
1011
            return ''
996
1012
            
997
1013
 
998
1014