~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Robert Collins
  • Date: 2005-10-03 03:30:02 UTC
  • mto: (1393.1.30)
  • mto: This revision was merged to the branch mainline in revision 1400.
  • Revision ID: robertc@robertcollins.net-20051003033002-3cea87a4505b9356
move change detection for text and metadata from delta to entry.detect_changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
122
122
    def _add_text_to_weave(self, new_lines, parents, weave_store):
123
123
        weave_store.add_text(self.file_id, self.revision, new_lines, parents)
124
124
 
 
125
    def detect_changes(self, old_entry):
 
126
        """Return a (text_modified, meta_modified) from this to old_entry.
 
127
        
 
128
        _read_tree_state must have been called on self and old_entry prior to 
 
129
        calling detect_changes.
 
130
        """
 
131
        if self.kind == 'file':
 
132
            assert self.text_sha1 != None
 
133
            assert old_entry.text_sha1 != None
 
134
            text_modified = (self.text_sha1 != old_entry.text_sha1)
 
135
            meta_modified = (self.executable != old_entry.executable)
 
136
        elif self.kind == 'symlink':
 
137
            # FIXME: which _modified field should we use ? RBC 20051003
 
138
            text_modified = (self.symlink_target != old_entry.symlink_target)
 
139
            if text_modified:
 
140
                mutter("    symlink target changed")
 
141
            meta_modified = False
 
142
        else:
 
143
            text_modified = False
 
144
            meta_modified = False
 
145
        return text_modified, meta_modified
 
146
 
125
147
    def __init__(self, file_id, name, kind, parent_id, text_id=None):
126
148
        """Create an InventoryEntry
127
149
        
170
192
            return ''
171
193
        raise RuntimeError('unreachable code')
172
194
 
173
 
    def read_symlink_target(self, path):
174
 
        if self.kind == 'symlink':
175
 
            try:
176
 
                self.symlink_target = os.readlink(path)
177
 
            except OSError,e:
178
 
                raise BzrError("os.readlink error, %s" % e)
 
195
    known_kinds = ('file', 'directory', 'symlink', 'root_directory')
179
196
 
180
197
    def sorted_children(self):
181
198
        l = self.children.items()
343
360
 
344
361
    def _read_tree_state(self, path, work_tree):
345
362
        if self.kind == 'symlink':
346
 
            self.read_symlink_target(work_tree.abspath(path))
 
363
            self.symlink_target = work_tree.get_symlink_target(self.file_id)
347
364
        if self.kind == 'file':
348
365
            self.text_sha1 = work_tree.get_file_sha1(self.file_id)
349
366
            self.executable = work_tree.is_executable(self.file_id)