~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Jelmer Vernooij
  • Date: 2007-09-16 19:29:00 UTC
  • mfrom: (2823 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2824.
  • Revision ID: jelmer@samba.org-20070916192900-fph1i2wsytberyyl
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
    BzrCheckError,
51
51
    BzrError,
52
52
    )
 
53
from bzrlib.symbol_versioning import deprecated_method, zero_ninetyone
53
54
from bzrlib.trace import mutter
54
55
 
55
56
 
161
162
    def _diff(self, text_diff, from_label, tree, to_label, to_entry, to_tree,
162
163
             output_to, reverse=False):
163
164
        """Perform a diff between two entries of the same kind."""
164
 
 
165
 
    def find_previous_heads(self, previous_inventories,
166
 
                            versioned_file_store,
167
 
                            transaction,
168
 
                            entry_vf=None):
169
 
        """Return the revisions and entries that directly precede this.
170
 
 
171
 
        Returned as a map from revision to inventory entry.
172
 
 
173
 
        This is a map containing the file revisions in all parents
174
 
        for which the file exists, and its revision is not a parent of
175
 
        any other. If the file is new, the set will be empty.
176
 
 
177
 
        :param versioned_file_store: A store where ancestry data on this
178
 
                                     file id can be queried.
179
 
        :param transaction: The transaction that queries to the versioned 
180
 
                            file store should be completed under.
181
 
        :param entry_vf: The entry versioned file, if its already available.
 
165
    
 
166
    def parent_candidates(self, previous_inventories):
 
167
        """Find possible per-file graph parents.
 
168
 
 
169
        This is currently defined by:
 
170
         - Select the last changed revision in the parent inventory.
 
171
         - Do deal with a short lived bug in bzr 0.8's development two entries
 
172
           that have the same last changed but different 'x' bit settings are
 
173
           changed in-place.
182
174
        """
183
 
        def get_ancestors(weave, entry):
184
 
            return set(weave.get_ancestry(entry.revision, topo_sorted=False))
185
175
        # revision:ie mapping for each ie found in previous_inventories.
186
176
        candidates = {}
187
 
        # revision:ie mapping with one revision for each head.
188
 
        heads = {}
189
 
        # revision: ancestor list for each head
190
 
        head_ancestors = {}
191
177
        # identify candidate head revision ids.
192
178
        for inv in previous_inventories:
193
179
            if self.file_id in inv:
194
180
                ie = inv[self.file_id]
195
181
                assert ie.file_id == self.file_id
196
 
                if ie.kind != self.kind:
197
 
                    # Can't be a candidate if the kind has changed.
198
 
                    continue
199
182
                if ie.revision in candidates:
200
183
                    # same revision value in two different inventories:
201
184
                    # correct possible inconsistencies:
212
195
                else:
213
196
                    # add this revision as a candidate.
214
197
                    candidates[ie.revision] = ie
215
 
 
 
198
        return candidates
 
199
 
 
200
    @deprecated_method(zero_ninetyone)
 
201
    def find_previous_heads(self, previous_inventories,
 
202
                            versioned_file_store,
 
203
                            transaction,
 
204
                            entry_vf=None):
 
205
        """Return the revisions and entries that directly precede this.
 
206
 
 
207
        Returned as a map from revision to inventory entry.
 
208
 
 
209
        This is a map containing the file revisions in all parents
 
210
        for which the file exists, and its revision is not a parent of
 
211
        any other. If the file is new, the set will be empty.
 
212
 
 
213
        :param versioned_file_store: A store where ancestry data on this
 
214
                                     file id can be queried.
 
215
        :param transaction: The transaction that queries to the versioned 
 
216
                            file store should be completed under.
 
217
        :param entry_vf: The entry versioned file, if its already available.
 
218
        """
 
219
        candidates = self.parent_candidates(previous_inventories)
 
220
 
 
221
        # revision:ie mapping with one revision for each head.
 
222
        heads = {}
216
223
        # common case optimisation
217
224
        if len(candidates) == 1:
218
225
            # if there is only one candidate revision found
219
 
            # then we can opening the versioned file to access ancestry:
 
226
            # then we can avoid opening the versioned file to access ancestry:
220
227
            # there cannot be any ancestors to eliminate when there is 
221
228
            # only one revision available.
222
 
            heads[ie.revision] = ie
223
 
            return heads
 
229
            return candidates
 
230
        
 
231
        # --- what follows is now encapsulated in repository.get_graph.heads(), 
 
232
        #     but that is not accessible from here as we have no repository
 
233
        #     pointer. Note that the repository.get_graph.heads() call can return
 
234
        #     different results *at the moment* because of the kind-changing check
 
235
        #     we have in parent_candidates().
224
236
 
225
237
        # eliminate ancestors amongst the available candidates:
226
238
        # heads are those that are not an ancestor of any other candidate
227
239
        # - this provides convergence at a per-file level.
 
240
        def get_ancestors(weave, entry):
 
241
            return set(weave.get_ancestry(entry.revision, topo_sorted=False))
 
242
        # revision: ancestor list for each head
 
243
        head_ancestors = {}
228
244
        for ie in candidates.values():
229
245
            # may be an ancestor of a known head:
230
246
            already_present = 0 != len(