~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
import types
37
37
 
38
38
import bzrlib
 
39
from bzrlib import errors, osutils
39
40
from bzrlib.osutils import (pumpfile, quotefn, splitpath, joinpath,
40
41
                            pathjoin, sha_strings)
41
42
from bzrlib.errors import (NotVersionedError, InvalidEntryName,
80
81
    InventoryDirectory('123', 'src', parent_id='TREE_ROOT', revision=None)
81
82
    >>> i.add(InventoryFile('2323', 'hello.c', parent_id='123'))
82
83
    InventoryFile('2323', 'hello.c', parent_id='123', sha1=None, len=None)
83
 
    >>> shouldbe = {0: 'src', 1: pathjoin('src','hello.c')}
 
84
    >>> shouldbe = {0: '', 1: 'src', 2: pathjoin('src','hello.c')}
84
85
    >>> for ix, j in enumerate(i.iter_entries()):
85
86
    ...   print (j[0] == shouldbe[ix], j[1])
86
87
    ... 
 
88
    (True, InventoryDirectory('TREE_ROOT', '', parent_id=None, revision=None))
87
89
    (True, InventoryDirectory('123', 'src', parent_id='TREE_ROOT', revision=None))
88
90
    (True, InventoryFile('2323', 'hello.c', parent_id='123', sha1=None, len=None))
89
91
    >>> i.add(InventoryFile('2323', 'bye.c', '123'))
106
108
    ...     print path
107
109
    ...     assert i.path2id(path)
108
110
    ... 
 
111
    <BLANKLINE>
109
112
    src
110
113
    src/bye.c
111
114
    src/hello.c
309
312
        """
310
313
        fullpath = pathjoin(dest, dp)
311
314
        self._put_on_disk(fullpath, tree)
312
 
        mutter("  export {%s} kind %s to %s", self.file_id,
313
 
                self.kind, fullpath)
 
315
        # mutter("  export {%s} kind %s to %s", self.file_id,
 
316
        #         self.kind, fullpath)
314
317
 
315
318
    def _put_on_disk(self, fullpath, tree):
316
319
        """Put this entry onto disk at fullpath, from tree tree."""
407
410
        This means that all its fields are populated, that it has its
408
411
        text stored in the text store or weave.
409
412
        """
410
 
        mutter('new parents of %s are %r', path, previous_entries)
 
413
        # mutter('new parents of %s are %r', path, previous_entries)
411
414
        self._read_tree_state(path, work_tree)
412
415
        # TODO: Where should we determine whether to reuse a
413
416
        # previous revision id or create a new revision? 20060606
415
418
            # cannot be unchanged unless there is only one parent file rev.
416
419
            parent_ie = previous_entries.values()[0]
417
420
            if self._unchanged(parent_ie):
418
 
                mutter("found unchanged entry")
 
421
                # mutter("found unchanged entry")
419
422
                self.revision = parent_ie.revision
420
423
                return "unchanged"
421
424
        return self._snapshot_into_revision(revision, previous_entries, 
432
435
 
433
436
        :returns: String description of the commit (e.g. "merged", "modified"), etc.
434
437
        """
435
 
        mutter('new revision {%s} for {%s}', revision, self.file_id)
 
438
        # mutter('new revision {%s} for {%s}', revision, self.file_id)
436
439
        self.revision = revision
437
440
        self._snapshot_text(previous_entries, work_tree, commit_builder)
438
441
 
814
817
    May also look up by name:
815
818
 
816
819
    >>> [x[0] for x in inv.iter_entries()]
817
 
    [u'hello.c']
 
820
    ['', u'hello.c']
818
821
    >>> inv = Inventory('TREE_ROOT-12345678-12345678')
819
822
    >>> inv.add(InventoryFile('123-123', 'hello.c', ROOT_ID))
820
823
    InventoryFile('123-123', 'hello.c', parent_id='TREE_ROOT-12345678-12345678', sha1=None, len=None)
839
842
 
840
843
    def copy(self):
841
844
        # TODO: jam 20051218 Should copy also copy the revision_id?
842
 
        other = Inventory(self.root.file_id)
 
845
        entries = self.iter_entries()
 
846
        other = Inventory(entries.next()[1].file_id)
843
847
        # copy recursively so we know directories will be added before
844
848
        # their children.  There are more efficient ways than this...
845
 
        for path, entry in self.iter_entries():
846
 
            if entry == self.root:
847
 
                continue
 
849
        for path, entry in entries():
848
850
            other.add(entry.copy())
849
851
        return other
850
852
 
861
863
            if self.root is None:
862
864
                return
863
865
            from_dir = self.root
 
866
            yield '', self.root
864
867
        elif isinstance(from_dir, basestring):
865
868
            from_dir = self._byid[from_dir]
866
869
            
913
916
        if from_dir is None:
914
917
            assert self.root
915
918
            from_dir = self.root
 
919
            yield '', self.root
916
920
        elif isinstance(from_dir, basestring):
917
921
            from_dir = self._byid[from_dir]
918
922
            
1035
1039
 
1036
1040
        Returns the new entry object."""
1037
1041
        
1038
 
        parts = bzrlib.osutils.splitpath(relpath)
 
1042
        parts = osutils.splitpath(relpath)
1039
1043
 
1040
1044
        if len(parts) == 0:
1041
1045
            if file_id is None:
1216
1220
    """
1217
1221
    if file_id is None:
1218
1222
        file_id = bzrlib.workingtree.gen_file_id(name)
 
1223
 
 
1224
    norm_name, can_access = osutils.normalized_filename(name)
 
1225
    if norm_name != name:
 
1226
        if can_access:
 
1227
            name = norm_name
 
1228
        else:
 
1229
            # TODO: jam 20060701 This would probably be more useful
 
1230
            #       if the error was raised with the full path
 
1231
            raise errors.InvalidNormalization(name)
 
1232
 
1219
1233
    if kind == 'directory':
1220
1234
        return InventoryDirectory(file_id, name, parent_id)
1221
1235
    elif kind == 'file':
1226
1240
        raise BzrError("unknown kind %r" % kind)
1227
1241
 
1228
1242
 
1229
 
 
1230
1243
_NAME_RE = None
1231
1244
 
1232
1245
def is_valid_name(name):