~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Robert Collins
  • Date: 2005-10-16 08:29:16 UTC
  • mto: This revision was merged to the branch mainline in revision 1459.
  • Revision ID: robertc@lifelesslap.robertcollins.net-20051016082916-dae075fdf18af47e
unify has() implementations for TransportStore classes

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
# FIXME: This refactoring of the workingtree code doesn't seem to keep 
18
 
# the WorkingTree's copy of the inventory in sync with the branch.  The
19
 
# branch modifies its working inventory when it does a commit to make
20
 
# missing files permanently removed.
21
17
 
22
18
# TODO: Maybe also keep the full path of the entry, and the children?
23
19
# But those depend on its position within a particular inventory, and
35
31
import types
36
32
 
37
33
import bzrlib
 
34
from bzrlib.errors import BzrError, BzrCheckError
 
35
 
38
36
from bzrlib.osutils import (pumpfile, quotefn, splitpath, joinpath,
39
37
                            appendpath, sha_strings)
40
38
from bzrlib.trace import mutter
41
 
from bzrlib.errors import (NotVersionedError, InvalidEntryName,
42
 
                           BzrError, BzrCheckError)
 
39
from bzrlib.errors import NotVersionedError
43
40
 
44
41
 
45
42
class InventoryEntry(object):
79
76
    InventoryDirectory('123', 'src', parent_id='TREE_ROOT')
80
77
    >>> i.add(InventoryFile('2323', 'hello.c', parent_id='123'))
81
78
    InventoryFile('2323', 'hello.c', parent_id='123')
82
 
    >>> shouldbe = {0: 'src', 1: os.path.join('src','hello.c')}
83
 
    >>> for ix, j in enumerate(i.iter_entries()):
84
 
    ...   print (j[0] == shouldbe[ix], j[1])
 
79
    >>> for j in i.iter_entries():
 
80
    ...   print j
85
81
    ... 
86
 
    (True, InventoryDirectory('123', 'src', parent_id='TREE_ROOT'))
87
 
    (True, InventoryFile('2323', 'hello.c', parent_id='123'))
 
82
    ('src', InventoryDirectory('123', 'src', parent_id='TREE_ROOT'))
 
83
    ('src/hello.c', InventoryFile('2323', 'hello.c', parent_id='123'))
88
84
    >>> i.add(InventoryFile('2323', 'bye.c', '123'))
89
85
    Traceback (most recent call last):
90
86
    ...
137
133
        text_diff will be used for textual difference calculation.
138
134
        This is a template method, override _diff in child classes.
139
135
        """
140
 
        self._read_tree_state(tree.id2path(self.file_id), tree)
 
136
        self._read_tree_state(tree)
141
137
        if to_entry:
142
138
            # cannot diff from one kind to another - you must do a removal
143
139
            # and an addif they do not match.
144
140
            assert self.kind == to_entry.kind
145
 
            to_entry._read_tree_state(to_tree.id2path(to_entry.file_id),
146
 
                                      to_tree)
 
141
            to_entry._read_tree_state(to_tree)
147
142
        self._diff(text_diff, from_label, tree, to_label, to_entry, to_tree,
148
143
                   output_to, reverse)
149
144
 
233
228
        '123'
234
229
        >>> e = InventoryFile('123', 'src/hello.c', ROOT_ID)
235
230
        Traceback (most recent call last):
236
 
        InvalidEntryName: Invalid entry name: src/hello.c
 
231
        BzrCheckError: InventoryEntry name 'src/hello.c' is invalid
237
232
        """
238
233
        assert isinstance(name, basestring), name
239
234
        if '/' in name or '\\' in name:
240
 
            raise InvalidEntryName(name=name)
 
235
            raise BzrCheckError('InventoryEntry name %r is invalid' % name)
 
236
        
241
237
        self.executable = False
242
238
        self.revision = None
243
239
        self.text_sha1 = None
269
265
        """
270
266
        fullpath = appendpath(dest, dp)
271
267
        self._put_on_disk(fullpath, tree)
272
 
        mutter("  export {%s} kind %s to %s", self.file_id,
273
 
                self.kind, fullpath)
 
268
        mutter("  export {%s} kind %s to %s" % (self.file_id, self.kind, fullpath))
274
269
 
275
270
    def _put_on_disk(self, fullpath, tree):
276
271
        """Put this entry onto disk at fullpath, from tree tree."""
330
325
        text stored in the text store or weave.
331
326
        """
332
327
        mutter('new parents of %s are %r', path, previous_entries)
333
 
        self._read_tree_state(path, work_tree)
 
328
        self._read_tree_state(work_tree)
334
329
        if len(previous_entries) == 1:
335
330
            # cannot be unchanged unless there is only one parent file rev.
336
331
            parent_ie = previous_entries.values()[0]
396
391
            compatible = False
397
392
        return compatible
398
393
 
399
 
    def _read_tree_state(self, path, work_tree):
 
394
    def _read_tree_state(self, work_tree):
400
395
        """Populate fields in the inventory entry from the given tree.
401
396
        
402
397
        Note that this should be modified to be a noop on virtual trees
552
547
        if tree.is_executable(self.file_id):
553
548
            os.chmod(fullpath, 0755)
554
549
 
555
 
    def _read_tree_state(self, path, work_tree):
 
550
    def _read_tree_state(self, work_tree):
556
551
        """See InventoryEntry._read_tree_state."""
557
552
        self.text_sha1 = work_tree.get_file_sha1(self.file_id)
558
553
        self.executable = work_tree.is_executable(self.file_id)
648
643
 
649
644
    def _put_in_tar(self, item, tree):
650
645
        """See InventoryEntry._put_in_tar."""
651
 
        item.type = tarfile.SYMTYPE
 
646
        iterm.type = tarfile.SYMTYPE
652
647
        fileobj = None
653
648
        item.size = 0
654
649
        item.mode = 0755
662
657
        except OSError,e:
663
658
            raise BzrError("Failed to create symlink %r -> %r, error: %s" % (fullpath, self.symlink_target, e))
664
659
 
665
 
    def _read_tree_state(self, path, work_tree):
 
660
    def _read_tree_state(self, work_tree):
666
661
        """See InventoryEntry._read_tree_state."""
667
662
        self.symlink_target = work_tree.get_symlink_target(self.file_id)
668
663
 
877
872
        The immediate parent must already be versioned.
878
873
 
879
874
        Returns the new entry object."""
880
 
        from bzrlib.workingtree import gen_file_id
 
875
        from bzrlib.branch import gen_file_id
881
876
        
882
877
        parts = bzrlib.osutils.splitpath(relpath)
883
878
        if len(parts) == 0:
889
884
        parent_path = parts[:-1]
890
885
        parent_id = self.path2id(parent_path)
891
886
        if parent_id == None:
892
 
            raise NotVersionedError(path=parent_path)
 
887
            raise NotVersionedError(parent_path)
 
888
 
893
889
        if kind == 'directory':
894
890
            ie = InventoryDirectory(file_id, parts[-1], parent_id)
895
891
        elif kind == 'file':