~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

- refactor handling of short option names

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):
136
133
        text_diff will be used for textual difference calculation.
137
134
        This is a template method, override _diff in child classes.
138
135
        """
139
 
        self._read_tree_state(tree.id2path(self.file_id), tree)
 
136
        self._read_tree_state(tree)
140
137
        if to_entry:
141
138
            # cannot diff from one kind to another - you must do a removal
142
139
            # and an addif they do not match.
143
140
            assert self.kind == to_entry.kind
144
 
            to_entry._read_tree_state(to_tree.id2path(to_entry.file_id),
145
 
                                      to_tree)
 
141
            to_entry._read_tree_state(to_tree)
146
142
        self._diff(text_diff, from_label, tree, to_label, to_entry, to_tree,
147
143
                   output_to, reverse)
148
144
 
232
228
        '123'
233
229
        >>> e = InventoryFile('123', 'src/hello.c', ROOT_ID)
234
230
        Traceback (most recent call last):
235
 
        InvalidEntryName: Invalid entry name: src/hello.c
 
231
        BzrCheckError: InventoryEntry name 'src/hello.c' is invalid
236
232
        """
237
233
        assert isinstance(name, basestring), name
238
234
        if '/' in name or '\\' in name:
239
 
            raise InvalidEntryName(name=name)
 
235
            raise BzrCheckError('InventoryEntry name %r is invalid' % name)
 
236
        
240
237
        self.executable = False
241
238
        self.revision = None
242
239
        self.text_sha1 = None
328
325
        text stored in the text store or weave.
329
326
        """
330
327
        mutter('new parents of %s are %r', path, previous_entries)
331
 
        self._read_tree_state(path, work_tree)
 
328
        self._read_tree_state(work_tree)
332
329
        if len(previous_entries) == 1:
333
330
            # cannot be unchanged unless there is only one parent file rev.
334
331
            parent_ie = previous_entries.values()[0]
394
391
            compatible = False
395
392
        return compatible
396
393
 
397
 
    def _read_tree_state(self, path, work_tree):
 
394
    def _read_tree_state(self, work_tree):
398
395
        """Populate fields in the inventory entry from the given tree.
399
396
        
400
397
        Note that this should be modified to be a noop on virtual trees
550
547
        if tree.is_executable(self.file_id):
551
548
            os.chmod(fullpath, 0755)
552
549
 
553
 
    def _read_tree_state(self, path, work_tree):
 
550
    def _read_tree_state(self, work_tree):
554
551
        """See InventoryEntry._read_tree_state."""
555
552
        self.text_sha1 = work_tree.get_file_sha1(self.file_id)
556
553
        self.executable = work_tree.is_executable(self.file_id)
660
657
        except OSError,e:
661
658
            raise BzrError("Failed to create symlink %r -> %r, error: %s" % (fullpath, self.symlink_target, e))
662
659
 
663
 
    def _read_tree_state(self, path, work_tree):
 
660
    def _read_tree_state(self, work_tree):
664
661
        """See InventoryEntry._read_tree_state."""
665
662
        self.symlink_target = work_tree.get_symlink_target(self.file_id)
666
663
 
887
884
        parent_path = parts[:-1]
888
885
        parent_id = self.path2id(parent_path)
889
886
        if parent_id == None:
890
 
            raise NotVersionedError(path=parent_path)
 
887
            raise NotVersionedError(parent_path)
 
888
 
891
889
        if kind == 'directory':
892
890
            ie = InventoryDirectory(file_id, parts[-1], parent_id)
893
891
        elif kind == 'file':