~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Robert Collins
  • Date: 2005-10-06 02:51:02 UTC
  • Revision ID: robertc@robertcollins.net-20051006025102-91f3a5a8d9283752
use weave ancestry to determine inventory entry previous heads, prevent propogating 'I did a merge' merges.

Show diffs side-by-side

added added

removed removed

Lines of Context:
146
146
             output_to, reverse=False):
147
147
        """Perform a diff between two entries of the same kind."""
148
148
 
149
 
    def find_previous_heads(self, previous_inventories):
 
149
    def find_previous_heads(self, previous_inventories, entry_weave):
150
150
        """Return the revisions and entries that directly preceed this.
151
151
 
152
152
        Returned as a map from revision to inventory entry.
155
155
        for which the file exists, and its revision is not a parent of
156
156
        any other. If the file is new, the set will be empty.
157
157
        """
 
158
        def get_ancestors(weave, entry):
 
159
            return set(map(weave.idx_to_name,
 
160
                           weave.inclusions([weave.lookup(entry.revision)])))
158
161
        heads = {}
 
162
        head_ancestors = {}
159
163
        for inv in previous_inventories:
160
164
            if self.file_id in inv:
161
165
                ie = inv[self.file_id]
163
167
                if ie.revision in heads:
164
168
                    assert heads[ie.revision] == ie
165
169
                else:
 
170
                    # may want to add it.
 
171
                    # may already be covered:
 
172
                    already_present = 0 != len(
 
173
                        [head for head in heads 
 
174
                         if ie.revision in head_ancestors[head]])
 
175
                    if already_present:
 
176
                        # an ancestor of a known head.
 
177
                        continue
 
178
                    # definately a head:
 
179
                    ancestors = get_ancestors(entry_weave, ie)
 
180
                    # may knock something else out:
 
181
                    check_heads = list(heads.keys())
 
182
                    for head in check_heads:
 
183
                        if head in ancestors:
 
184
                            # this head is not really a head
 
185
                            heads.pop(head)
 
186
                    head_ancestors[ie.revision] = ancestors
166
187
                    heads[ie.revision] = ie
167
188
        return heads
168
189
 
288
309
                   self.name,
289
310
                   self.parent_id))
290
311
 
291
 
    def snapshot(self, revision, path, previous_entries, work_tree, 
292
 
                 weave_store):
 
312
    def snapshot(self, revision, path, previous_entries,
 
313
                 work_tree, weave_store):
293
314
        """Make a snapshot of this entry which may or may not have changed.
294
315
        
295
316
        This means that all its fields are populated, that it has its