~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-10 00:43:37 UTC
  • mto: This revision was merged to the branch mainline in revision 1926.
  • Revision ID: john@arbash-meinel.com-20060810004337-6aa4d7ea80e85093
Moving everything into a new location so that we can cache more than just revision ids

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
import sys
35
35
import tarfile
36
36
import types
 
37
from warnings import warn
37
38
 
38
39
import bzrlib
39
40
from bzrlib import errors, osutils
81
82
    InventoryDirectory('123', 'src', parent_id='TREE_ROOT', revision=None)
82
83
    >>> i.add(InventoryFile('2323', 'hello.c', parent_id='123'))
83
84
    InventoryFile('2323', 'hello.c', parent_id='123', sha1=None, len=None)
84
 
    >>> shouldbe = {0: 'src', 1: pathjoin('src','hello.c')}
 
85
    >>> shouldbe = {0: '', 1: 'src', 2: pathjoin('src','hello.c')}
85
86
    >>> for ix, j in enumerate(i.iter_entries()):
86
87
    ...   print (j[0] == shouldbe[ix], j[1])
87
88
    ... 
 
89
    (True, InventoryDirectory('TREE_ROOT', '', parent_id=None, revision=None))
88
90
    (True, InventoryDirectory('123', 'src', parent_id='TREE_ROOT', revision=None))
89
91
    (True, InventoryFile('2323', 'hello.c', parent_id='123', sha1=None, len=None))
90
92
    >>> i.add(InventoryFile('2323', 'bye.c', '123'))
107
109
    ...     print path
108
110
    ...     assert i.path2id(path)
109
111
    ... 
 
112
    <BLANKLINE>
110
113
    src
111
114
    src/bye.c
112
115
    src/hello.c
293
296
        """Return a short kind indicator useful for appending to names."""
294
297
        raise BzrError('unknown kind %r' % self.kind)
295
298
 
296
 
    known_kinds = ('file', 'directory', 'symlink', 'root_directory')
 
299
    known_kinds = ('file', 'directory', 'symlink')
297
300
 
298
301
    def _put_in_tar(self, item, tree):
299
302
        """populate item for stashing in a tar, and return the content stream.
310
313
        """
311
314
        fullpath = pathjoin(dest, dp)
312
315
        self._put_on_disk(fullpath, tree)
313
 
        mutter("  export {%s} kind %s to %s", self.file_id,
314
 
                self.kind, fullpath)
 
316
        # mutter("  export {%s} kind %s to %s", self.file_id,
 
317
        #         self.kind, fullpath)
315
318
 
316
319
    def _put_on_disk(self, fullpath, tree):
317
320
        """Put this entry onto disk at fullpath, from tree tree."""
408
411
        This means that all its fields are populated, that it has its
409
412
        text stored in the text store or weave.
410
413
        """
411
 
        mutter('new parents of %s are %r', path, previous_entries)
 
414
        # mutter('new parents of %s are %r', path, previous_entries)
412
415
        self._read_tree_state(path, work_tree)
413
416
        # TODO: Where should we determine whether to reuse a
414
417
        # previous revision id or create a new revision? 20060606
416
419
            # cannot be unchanged unless there is only one parent file rev.
417
420
            parent_ie = previous_entries.values()[0]
418
421
            if self._unchanged(parent_ie):
419
 
                mutter("found unchanged entry")
 
422
                # mutter("found unchanged entry")
420
423
                self.revision = parent_ie.revision
421
424
                return "unchanged"
422
425
        return self._snapshot_into_revision(revision, previous_entries, 
433
436
 
434
437
        :returns: String description of the commit (e.g. "merged", "modified"), etc.
435
438
        """
436
 
        mutter('new revision {%s} for {%s}', revision, self.file_id)
 
439
        # mutter('new revision {%s} for {%s}', revision, self.file_id)
437
440
        self.revision = revision
438
441
        self._snapshot_text(previous_entries, work_tree, commit_builder)
439
442
 
507
510
    def __init__(self, file_id):
508
511
        self.file_id = file_id
509
512
        self.children = {}
510
 
        self.kind = 'root_directory'
 
513
        self.kind = 'directory'
511
514
        self.parent_id = None
512
515
        self.name = u''
513
516
        self.revision = None
 
517
        warn('RootEntry is deprecated as of bzr 0.10.  Please use '
 
518
             'InventoryDirectory instead.',
 
519
            DeprecationWarning, stacklevel=2)
514
520
 
515
521
    def __eq__(self, other):
516
522
        if not isinstance(other, RootEntry):
840
846
    May also look up by name:
841
847
 
842
848
    >>> [x[0] for x in inv.iter_entries()]
843
 
    [u'hello.c']
 
849
    ['', u'hello.c']
844
850
    >>> inv = Inventory('TREE_ROOT-12345678-12345678')
845
851
    >>> inv.add(InventoryFile('123-123', 'hello.c', ROOT_ID))
846
852
    InventoryFile('123-123', 'hello.c', parent_id='TREE_ROOT-12345678-12345678', sha1=None, len=None)
859
865
        # root id. Rather than generating a random one here.
860
866
        #if root_id is None:
861
867
        #    root_id = bzrlib.branch.gen_file_id('TREE_ROOT')
862
 
        self.root = RootEntry(root_id)
 
868
        self.root = InventoryDirectory(root_id, '', None)
863
869
        # FIXME: this isn't ever used, changing it to self.revision may break
864
870
        # things. TODO make everything use self.revision_id
865
871
        self.revision_id = revision_id
867
873
 
868
874
    def copy(self):
869
875
        # TODO: jam 20051218 Should copy also copy the revision_id?
870
 
        other = Inventory(self.root.file_id)
 
876
        entries = self.iter_entries()
 
877
        other = Inventory(entries.next()[1].file_id)
871
878
        # copy recursively so we know directories will be added before
872
879
        # their children.  There are more efficient ways than this...
873
 
        for path, entry in self.iter_entries():
874
 
            if entry == self.root:
875
 
                continue
 
880
        for path, entry in entries():
876
881
            other.add(entry.copy())
877
882
        return other
878
883
 
888
893
        if from_dir is None:
889
894
            assert self.root
890
895
            from_dir = self.root
 
896
            yield '', self.root
891
897
        elif isinstance(from_dir, basestring):
892
898
            from_dir = self._byid[from_dir]
893
899
            
940
946
        if from_dir is None:
941
947
            assert self.root
942
948
            from_dir = self.root
 
949
            yield '', self.root
943
950
        elif isinstance(from_dir, basestring):
944
951
            from_dir = self._byid[from_dir]
945
952
            
1067
1074
        if len(parts) == 0:
1068
1075
            if file_id is None:
1069
1076
                file_id = bzrlib.workingtree.gen_root_id()
1070
 
            self.root = RootEntry(file_id)
 
1077
            self.root = InventoryDirectory(file_id, '', None)
1071
1078
            self._byid = {self.root.file_id: self.root}
1072
1079
            return
1073
1080
        else: