121
121
def _add_text_to_weave(self, new_lines, parents, weave_store, transaction):
122
versionedfile = weave_store.get_weave_or_empty(self.file_id,
122
versionedfile = weave_store.get_weave(self.file_id, transaction)
124
123
versionedfile.add_lines(self.revision, parents, new_lines)
125
versionedfile.clear_cache()
127
125
def detect_changes(self, old_entry):
128
126
"""Return a (text_modified, meta_modified) from this to old_entry.
164
159
This is a map containing the file revisions in all parents
165
160
for which the file exists, and its revision is not a parent of
166
161
any other. If the file is new, the set will be empty.
168
:param versioned_file_store: A store where ancestry data on this
169
file id can be queried.
170
:param transaction: The transaction that queries to the versioned
171
file store should be completed under.
172
:param entry_vf: The entry versioned file, if its already available.
174
163
def get_ancestors(weave, entry):
175
164
return set(weave.get_ancestry(entry.revision))
176
# revision:ie mapping for each ie found in previous_inventories.
178
# revision:ie mapping with one revision for each head.
180
# revision: ancestor list for each head
181
166
head_ancestors = {}
182
# identify candidate head revision ids.
183
167
for inv in previous_inventories:
184
168
if self.file_id in inv:
185
169
ie = inv[self.file_id]
186
170
assert ie.file_id == self.file_id
187
if ie.revision in candidates:
188
# same revision value in two different inventories:
189
# correct possible inconsistencies:
190
# * there was a bug in revision updates with 'x' bit
171
if ie.revision in heads:
172
# fixup logic, there was a bug in revision updates.
173
# with x bit support.
193
if candidates[ie.revision].executable != ie.executable:
194
candidates[ie.revision].executable = False
175
if heads[ie.revision].executable != ie.executable:
176
heads[ie.revision].executable = False
195
177
ie.executable = False
196
178
except AttributeError:
198
# must now be the same.
199
assert candidates[ie.revision] == ie
180
assert heads[ie.revision] == ie
201
# add this revision as a candidate.
202
candidates[ie.revision] = ie
204
# common case optimisation
205
if len(candidates) == 1:
206
# if there is only one candidate revision found
207
# then we can opening the versioned file to access ancestry:
208
# there cannot be any ancestors to eliminate when there is
209
# only one revision available.
210
heads[ie.revision] = ie
213
# eliminate ancestors amongst the available candidates:
214
# heads are those that are not an ancestor of any other candidate
215
# - this provides convergence at a per-file level.
216
for ie in candidates.values():
217
# may be an ancestor of a known head:
218
already_present = 0 != len(
219
[head for head in heads
220
if ie.revision in head_ancestors[head]])
222
# an ancestor of an analyzed candidate.
224
# not an ancestor of a known head:
225
# load the versioned file for this file id if needed
227
entry_vf = versioned_file_store.get_weave_or_empty(
228
self.file_id, transaction)
229
ancestors = get_ancestors(entry_vf, ie)
230
# may knock something else out:
231
check_heads = list(heads.keys())
232
for head in check_heads:
233
if head in ancestors:
234
# this previously discovered 'head' is not
235
# really a head - its an ancestor of the newly
238
head_ancestors[ie.revision] = ancestors
239
heads[ie.revision] = ie
182
# may want to add it.
183
# may already be covered:
184
already_present = 0 != len(
185
[head for head in heads
186
if ie.revision in head_ancestors[head]])
188
# an ancestor of a known head.
191
ancestors = get_ancestors(entry_weave, ie)
192
# may knock something else out:
193
check_heads = list(heads.keys())
194
for head in check_heads:
195
if head in ancestors:
196
# this head is not really a head
198
head_ancestors[ie.revision] = ancestors
199
heads[ie.revision] = ie
242
202
def get_tar_item(self, root, dp, now, tree):
349
301
raise BzrCheckError('unknown entry kind %r in revision {%s}' %
350
302
(self.kind, rev_id))
353
306
"""Clone this inventory entry."""
354
307
raise NotImplementedError
356
def _describe_snapshot_change(self, previous_entries):
357
"""Describe how this entry will have changed in a new commit.
359
:param previous_entries: Dictionary from revision_id to inventory entry.
361
:returns: One-word description: "merged", "added", "renamed", "modified".
363
# XXX: This assumes that the file *has* changed -- it should probably
364
# be fused with whatever does that detection. Why not just a single
365
# thing to compare the entries?
367
# TODO: Return some kind of object describing all the possible
368
# dimensions that can change, not just a string. That can then give
369
# both old and new names for renames, etc.
309
def _get_snapshot_change(self, previous_entries):
371
310
if len(previous_entries) > 1:
373
312
elif len(previous_entries) == 0:
375
the_parent, = previous_entries.values()
376
if self.parent_id != the_parent.parent_id:
377
# actually, moved to another directory
379
elif self.name != the_parent.name:
315
return 'modified/renamed/reparented'
383
317
def __repr__(self):
384
318
return ("%s(%r, %r, parent_id=%r)"
403
337
mutter("found unchanged entry")
404
338
self.revision = parent_ie.revision
405
339
return "unchanged"
406
return self._snapshot_into_revision(revision, previous_entries,
407
work_tree, weave_store, transaction)
409
def _snapshot_into_revision(self, revision, previous_entries, work_tree,
410
weave_store, transaction):
411
"""Record this revision unconditionally into a store.
413
The entry's last-changed revision property (`revision`) is updated to
414
that of the new revision.
416
:param revision: id of the new revision that is being recorded.
418
:returns: String description of the commit (e.g. "merged", "modified"), etc.
420
mutter('new revision {%s} for {%s}', revision, self.file_id)
340
return self.snapshot_revision(revision, previous_entries,
341
work_tree, weave_store, transaction)
343
def snapshot_revision(self, revision, previous_entries, work_tree,
344
weave_store, transaction):
345
"""Record this revision unconditionally."""
346
mutter('new revision for {%s}', self.file_id)
421
347
self.revision = revision
422
change = self._describe_snapshot_change(previous_entries)
348
change = self._get_snapshot_change(previous_entries)
423
349
self._snapshot_text(previous_entries, work_tree, weave_store,
546
472
class InventoryFile(InventoryEntry):
547
473
"""A file in an inventory."""
549
def _check(self, checker, tree_revision_id, tree):
475
def _check(self, checker, rev_id, tree):
550
476
"""See InventoryEntry._check"""
551
t = (self.file_id, self.revision)
477
revision = self.revision
478
t = (self.file_id, revision)
552
479
if t in checker.checked_texts:
553
prev_sha = checker.checked_texts[t]
480
prev_sha = checker.checked_texts[t]
554
481
if prev_sha != self.text_sha1:
555
482
raise BzrCheckError('mismatched sha1 on {%s} in {%s}' %
556
(self.file_id, tree_revision_id))
483
(self.file_id, rev_id))
558
485
checker.repeated_text_cnt += 1
570
497
w = tree.get_weave(self.file_id)
572
mutter('check version {%s} of {%s}', tree_revision_id, self.file_id)
573
checker.checked_text_cnt += 1
499
mutter('check version {%s} of {%s}', rev_id, self.file_id)
500
checker.checked_text_cnt += 1
574
501
# We can't check the length, because Weave doesn't store that
575
502
# information, and the whole point of looking at the weave's
576
503
# sha1sum is that we don't have to extract the text.
599
526
def _diff(self, text_diff, from_label, tree, to_label, to_entry, to_tree,
600
527
output_to, reverse=False):
601
528
"""See InventoryEntry._diff."""
603
from_text = tree.get_file(self.file_id).readlines()
605
to_text = to_tree.get_file(to_entry.file_id).readlines()
609
text_diff(from_label, from_text,
610
to_label, to_text, output_to)
612
text_diff(to_label, to_text,
613
from_label, from_text, output_to)
616
label_pair = (to_label, from_label)
618
label_pair = (from_label, to_label)
619
print >> output_to, "Binary files %s and %s differ" % label_pair
529
from_text = tree.get_file(self.file_id).readlines()
531
to_text = to_tree.get_file(to_entry.file_id).readlines()
535
text_diff(from_label, from_text,
536
to_label, to_text, output_to)
538
text_diff(to_label, to_text,
539
from_label, from_text, output_to)
621
541
def has_text(self):
622
542
"""See InventoryEntry.has_text."""