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
17
from binascii import hexlify
18
17
from copy import deepcopy
19
18
from cStringIO import StringIO
22
19
from unittest import TestSuite
24
from bzrlib import bzrdir, check, delta, gpg, errors, xml5, ui, transactions, osutils
20
import xml.sax.saxutils
25
23
from bzrlib.decorators import needs_read_lock, needs_write_lock
24
import bzrlib.errors as errors
26
25
from bzrlib.errors import InvalidRevisionId
27
from bzrlib.graph import Graph
28
from bzrlib.inter import InterObject
29
from bzrlib.inventory import Inventory
30
from bzrlib.knit import KnitVersionedFile, KnitPlainFactory
31
from bzrlib.lockable_files import LockableFiles, TransportLock
32
from bzrlib.lockdir import LockDir
33
from bzrlib.osutils import (safe_unicode, rand_bytes, compact_date,
35
from bzrlib.revision import NULL_REVISION, Revision
36
from bzrlib.store.versioned import VersionedFileStore, WeaveStore
26
from bzrlib.lockable_files import LockableFiles
27
from bzrlib.osutils import safe_unicode
28
from bzrlib.revision import NULL_REVISION
29
from bzrlib.store import copy_all
30
from bzrlib.store.weave import WeaveStore
37
31
from bzrlib.store.text import TextStore
38
from bzrlib.symbol_versioning import (deprecated_method,
41
from bzrlib.trace import mutter, note
42
from bzrlib.tree import RevisionTree, EmptyTree
43
from bzrlib.tsort import topo_sort
32
from bzrlib.symbol_versioning import *
33
from bzrlib.trace import mutter
34
from bzrlib.tree import RevisionTree
44
35
from bzrlib.testament import Testament
45
36
from bzrlib.tree import EmptyTree
46
from bzrlib.weave import WeaveFile
49
41
class Repository(object):
62
def add_inventory(self, revid, inv, parents):
63
"""Add the inventory inv to the repository as revid.
65
:param parents: The revision ids of the parents that revid
66
is known to have and are in the repository already.
68
returns the sha1 of the serialized inventory.
70
assert inv.revision_id is None or inv.revision_id == revid, \
71
"Mismatch between inventory revision" \
72
" id and insertion revid (%r, %r)" % (inv.revision_id, revid)
73
inv_text = xml5.serializer_v5.write_inventory_to_string(inv)
74
inv_sha1 = osutils.sha_string(inv_text)
75
inv_vf = self.control_weaves.get_weave('inventory',
76
self.get_transaction())
77
self._inventory_add_lines(inv_vf, revid, parents, osutils.split_lines(inv_text))
80
def _inventory_add_lines(self, inv_vf, revid, parents, lines):
82
for parent in parents:
84
final_parents.append(parent)
86
inv_vf.add_lines(revid, final_parents, lines)
89
def add_revision(self, rev_id, rev, inv=None, config=None):
90
"""Add rev to the revision store as rev_id.
92
:param rev_id: the revision id to use.
93
:param rev: The revision object.
94
:param inv: The inventory for the revision. if None, it will be looked
95
up in the inventory storer
96
:param config: If None no digital signature will be created.
97
If supplied its signature_needed method will be used
98
to determine if a signature should be made.
100
if config is not None and config.signature_needed():
102
inv = self.get_inventory(rev_id)
103
plaintext = Testament(rev, inv).as_short_text()
104
self.store_revision_signature(
105
gpg.GPGStrategy(config), plaintext, rev_id)
106
if not rev_id in self.get_inventory_weave():
108
raise errors.WeaveRevisionNotPresent(rev_id,
109
self.get_inventory_weave())
111
# yes, this is not suitable for adding with ghosts.
112
self.add_inventory(rev_id, inv, rev.parent_ids)
113
self._revision_store.add_revision(rev, self.get_transaction())
116
54
def _all_possible_ids(self):
117
55
"""Return all the possible revisions that we could find."""
118
return self.get_inventory_weave().versions()
56
return self.get_inventory_weave().names()
120
59
def all_revision_ids(self):
121
60
"""Returns a list of all the revision ids in the repository.
123
This is deprecated because code should generally work on the graph
124
reachable from a particular revision, and ignore any other revisions
125
that might be present. There is no direct replacement method.
127
return self._all_revision_ids()
130
def _all_revision_ids(self):
131
"""Returns a list of all the revision ids in the repository.
133
62
These are in as much topological order as the underlying store can
134
63
present: for weaves ghosts may lead to a lack of correctness until
135
64
the reweave updates the parents list.
137
if self._revision_store.text_store.listable():
138
return self._revision_store.all_revision_ids(self.get_transaction())
139
66
result = self._all_possible_ids()
140
67
return self._eliminate_revisions_not_present(result)
142
def break_lock(self):
143
"""Break a lock if one is present from another instance.
145
Uses the ui factory to ask for confirmation if the lock may be from
148
self.control_files.break_lock()
151
70
def _eliminate_revisions_not_present(self, revision_ids):
152
71
"""Check every revision id in revision_ids to see if we have it.
274
157
result = a_bzrdir.create_repository()
275
158
# FIXME RBC 20060209 split out the repository type to avoid this check ?
276
159
elif isinstance(a_bzrdir._format,
277
(bzrdir.BzrDirFormat4,
278
bzrdir.BzrDirFormat5,
279
bzrdir.BzrDirFormat6)):
160
(bzrlib.bzrdir.BzrDirFormat4,
161
bzrlib.bzrdir.BzrDirFormat5,
162
bzrlib.bzrdir.BzrDirFormat6)):
280
163
result = a_bzrdir.open_repository()
282
165
result = self._format.initialize(a_bzrdir, shared=self.is_shared())
283
166
self.copy_content_into(result, revision_id, basis)
287
169
def has_revision(self, revision_id):
288
"""True if this repository has a copy of the revision."""
289
return self._revision_store.has_revision_id(revision_id,
290
self.get_transaction())
170
"""True if this branch has a copy of the revision.
172
This does not necessarily imply the revision is merge
173
or on the mainline."""
174
return (revision_id is None
175
or self.revision_store.has_id(revision_id))
293
def get_revision_reconcile(self, revision_id):
294
"""'reconcile' helper routine that allows access to a revision always.
296
This variant of get_revision does not cross check the weave graph
297
against the revision one as get_revision does: but it should only
298
be used by reconcile, or reconcile-alike commands that are correcting
299
or testing the revision graph.
178
def get_revision_xml_file(self, revision_id):
179
"""Return XML file object for revision object."""
301
180
if not revision_id or not isinstance(revision_id, basestring):
302
181
raise InvalidRevisionId(revision_id=revision_id, branch=self)
303
return self._revision_store.get_revisions([revision_id],
304
self.get_transaction())[0]
306
def get_revisions(self, revision_ids):
307
return self._revision_store.get_revisions(revision_ids,
308
self.get_transaction())
183
return self.revision_store.get(revision_id)
184
except (IndexError, KeyError):
185
raise bzrlib.errors.NoSuchRevision(self, revision_id)
311
188
def get_revision_xml(self, revision_id):
312
rev = self.get_revision(revision_id)
314
# the current serializer..
315
self._revision_store._serializer.write_revision(rev, rev_tmp)
317
return rev_tmp.getvalue()
189
return self.get_revision_xml_file(revision_id).read()
320
192
def get_revision(self, revision_id):
321
193
"""Return the Revision object for a named revision"""
322
r = self.get_revision_reconcile(revision_id)
323
# weave corruption can lead to absent revision markers that should be
325
# the following test is reasonably cheap (it needs a single weave read)
326
# and the weave is cached in read transactions. In write transactions
327
# it is not cached but typically we only read a small number of
328
# revisions. For knits when they are introduced we will probably want
329
# to ensure that caching write transactions are in use.
330
inv = self.get_inventory_weave()
331
self._check_revision_parents(r, inv)
194
xml_file = self.get_revision_xml_file(revision_id)
197
r = bzrlib.xml5.serializer_v5.read_revision(xml_file)
198
except SyntaxError, e:
199
raise bzrlib.errors.BzrError('failed to unpack revision_xml',
203
assert r.revision_id == revision_id
335
def get_deltas_for_revisions(self, revisions):
336
"""Produce a generator of revision deltas.
338
Note that the input is a sequence of REVISIONS, not revision_ids.
339
Trees will be held in memory until the generator exits.
340
Each delta is relative to the revision's lefthand predecessor.
342
required_trees = set()
343
for revision in revisions:
344
required_trees.add(revision.revision_id)
345
required_trees.update(revision.parent_ids[:1])
346
trees = dict((t.get_revision_id(), t) for
347
t in self.revision_trees(required_trees))
348
for revision in revisions:
349
if not revision.parent_ids:
350
old_tree = EmptyTree()
352
old_tree = trees[revision.parent_ids[0]]
353
yield delta.compare_trees(old_tree, trees[revision.revision_id])
356
def get_revision_delta(self, revision_id):
357
"""Return the delta for one revision.
359
The delta is relative to the left-hand predecessor of the
362
r = self.get_revision(revision_id)
363
return list(self.get_deltas_for_revisions([r]))[0]
365
def _check_revision_parents(self, revision, inventory):
366
"""Private to Repository and Fetch.
368
This checks the parentage of revision in an inventory weave for
369
consistency and is only applicable to inventory-weave-for-ancestry
370
using repository formats & fetchers.
372
weave_parents = inventory.get_parents(revision.revision_id)
373
weave_names = inventory.versions()
374
for parent_id in revision.parent_ids:
375
if parent_id in weave_names:
376
# this parent must not be a ghost.
377
if not parent_id in weave_parents:
379
raise errors.CorruptRepository(self)
207
def get_revision_sha1(self, revision_id):
208
"""Hash the stored value of a revision, and return it."""
209
# In the future, revision entries will be signed. At that
210
# point, it is probably best *not* to include the signature
211
# in the revision hash. Because that lets you re-sign
212
# the revision, (add signatures/remove signatures) and still
213
# have all hash pointers stay consistent.
214
# But for now, just hash the contents.
215
return bzrlib.osutils.sha_file(self.get_revision_xml_file(revision_id))
381
217
@needs_write_lock
382
218
def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
383
signature = gpg_strategy.sign(plaintext)
384
self._revision_store.add_revision_signature_text(revision_id,
386
self.get_transaction())
388
def fileids_altered_by_revision_ids(self, revision_ids):
389
"""Find the file ids and versions affected by revisions.
391
:param revisions: an iterable containing revision ids.
392
:return: a dictionary mapping altered file-ids to an iterable of
393
revision_ids. Each altered file-ids has the exact revision_ids that
394
altered it listed explicitly.
219
self.revision_store.add(StringIO(gpg_strategy.sign(plaintext)),
222
def fileid_involved_between_revs(self, from_revid, to_revid):
223
"""Find file_id(s) which are involved in the changes between revisions.
225
This determines the set of revisions which are involved, and then
226
finds all file ids affected by those revisions.
228
# TODO: jam 20060119 This code assumes that w.inclusions will
229
# always be correct. But because of the presence of ghosts
230
# it is possible to be wrong.
231
# One specific example from Robert Collins:
232
# Two branches, with revisions ABC, and AD
233
# C is a ghost merge of D.
234
# Inclusions doesn't recognize D as an ancestor.
235
# If D is ever merged in the future, the weave
236
# won't be fixed, because AD never saw revision C
237
# to cause a conflict which would force a reweave.
238
w = self.get_inventory_weave()
239
from_set = set(w.inclusions([w.lookup(from_revid)]))
240
to_set = set(w.inclusions([w.lookup(to_revid)]))
241
included = to_set.difference(from_set)
242
changed = map(w.idx_to_name, included)
243
return self._fileid_involved_by_set(changed)
245
def fileid_involved(self, last_revid=None):
246
"""Find all file_ids modified in the ancestry of last_revid.
248
:param last_revid: If None, last_revision() will be used.
250
w = self.get_inventory_weave()
252
changed = set(w._names)
254
included = w.inclusions([w.lookup(last_revid)])
255
changed = map(w.idx_to_name, included)
256
return self._fileid_involved_by_set(changed)
258
def fileid_involved_by_set(self, changes):
259
"""Find all file_ids modified by the set of revisions passed in.
261
:param changes: A set() of revision ids
263
# TODO: jam 20060119 This line does *nothing*, remove it.
264
# or better yet, change _fileid_involved_by_set so
265
# that it takes the inventory weave, rather than
266
# pulling it out by itself.
267
return self._fileid_involved_by_set(changes)
269
def _fileid_involved_by_set(self, changes):
270
"""Find the set of file-ids affected by the set of revisions.
272
:param changes: A set() of revision ids.
273
:return: A set() of file ids.
275
This peaks at the Weave, interpreting each line, looking to
276
see if it mentions one of the revisions. And if so, includes
277
the file id mentioned.
278
This expects both the Weave format, and the serialization
279
to have a single line per file/directory, and to have
280
fileid="" and revision="" on that line.
396
282
assert isinstance(self._format, (RepositoryFormat5,
397
283
RepositoryFormat6,
398
284
RepositoryFormat7,
399
285
RepositoryFormatKnit1)), \
400
("fileids_altered_by_revision_ids only supported for branches "
401
"which store inventory as unnested xml, not on %r" % self)
402
selected_revision_ids = set(revision_ids)
286
"fileid_involved only supported for branches which store inventory as unnested xml"
403
288
w = self.get_inventory_weave()
406
# this code needs to read every new line in every inventory for the
407
# inventories [revision_ids]. Seeing a line twice is ok. Seeing a line
408
# not present in one of those inventories is unnecessary but not
409
# harmful because we are filtering by the revision id marker in the
410
# inventory lines : we only select file ids altered in one of those
411
# revisions. We don't need to see all lines in the inventory because
412
# only those added in an inventory in rev X can contain a revision=X
414
for line in w.iter_lines_added_or_present_in_versions(selected_revision_ids):
290
for line in w._weave:
292
# it is ugly, but it is due to the weave structure
293
if not isinstance(line, basestring): continue
415
295
start = line.find('file_id="')+9
416
296
if start < 9: continue
417
297
end = line.find('"', start)
419
file_id = _unescape_xml(line[start:end])
299
file_id = xml.sax.saxutils.unescape(line[start:end])
301
# check if file_id is already present
302
if file_id in file_ids: continue
421
304
start = line.find('revision="')+10
422
305
if start < 10: continue
423
306
end = line.find('"', start)
425
revision_id = _unescape_xml(line[start:end])
426
if revision_id in selected_revision_ids:
427
result.setdefault(file_id, set()).add(revision_id)
308
revision_id = xml.sax.saxutils.unescape(line[start:end])
310
if revision_id in changes:
311
file_ids.add(file_id)
431
315
def get_inventory_weave(self):
463
339
return self.get_revision(revision_id).inventory_sha1
466
def get_revision_graph(self, revision_id=None):
467
"""Return a dictionary containing the revision graph.
469
:param revision_id: The revision_id to get a graph from. If None, then
470
the entire revision graph is returned. This is a deprecated mode of
471
operation and will be removed in the future.
472
:return: a dictionary of revision_id->revision_parents_list.
474
# special case NULL_REVISION
475
if revision_id == NULL_REVISION:
477
weave = self.get_inventory_weave()
478
all_revisions = self._eliminate_revisions_not_present(weave.versions())
479
entire_graph = dict([(node, weave.get_parents(node)) for
480
node in all_revisions])
481
if revision_id is None:
483
elif revision_id not in entire_graph:
484
raise errors.NoSuchRevision(self, revision_id)
486
# add what can be reached from revision_id
488
pending = set([revision_id])
489
while len(pending) > 0:
491
result[node] = entire_graph[node]
492
for revision_id in result[node]:
493
if revision_id not in result:
494
pending.add(revision_id)
498
def get_revision_graph_with_ghosts(self, revision_ids=None):
499
"""Return a graph of the revisions with ghosts marked as applicable.
501
:param revision_ids: an iterable of revisions to graph or None for all.
502
:return: a Graph object with the graph reachable from revision_ids.
506
pending = set(self.all_revision_ids())
509
pending = set(revision_ids)
510
# special case NULL_REVISION
511
if NULL_REVISION in pending:
512
pending.remove(NULL_REVISION)
513
required = set(pending)
516
revision_id = pending.pop()
518
rev = self.get_revision(revision_id)
519
except errors.NoSuchRevision:
520
if revision_id in required:
523
result.add_ghost(revision_id)
525
for parent_id in rev.parent_ids:
526
# is this queued or done ?
527
if (parent_id not in pending and
528
parent_id not in done):
530
pending.add(parent_id)
531
result.add_node(revision_id, rev.parent_ids)
532
done.add(revision_id)
536
342
def get_revision_inventory(self, revision_id):
537
343
"""Return inventory of a past revision."""
538
344
# TODO: Unify this with get_inventory()
639
426
:param new_value: True to restore the default, False to disable making
642
raise NotImplementedError(self.set_make_working_trees)
429
# FIXME: split out into a new class/strategy ?
430
if isinstance(self._format, (RepositoryFormat4,
433
raise NotImplementedError(self.set_make_working_trees)
436
self.control_files._transport.delete('no-working-trees')
437
except errors.NoSuchFile:
440
self.control_files.put_utf8('no-working-trees', '')
644
442
def make_working_trees(self):
645
443
"""Returns the policy for making working trees on new branches."""
646
raise NotImplementedError(self.make_working_trees)
444
# FIXME: split out into a new class/strategy ?
445
if isinstance(self._format, (RepositoryFormat4,
449
return not self.control_files._transport.has('no-working-trees')
648
451
@needs_write_lock
649
452
def sign_revision(self, revision_id, gpg_strategy):
650
453
plaintext = Testament.from_revision(self, revision_id).as_short_text()
651
454
self.store_revision_signature(gpg_strategy, plaintext, revision_id)
654
def has_signature_for_revision_id(self, revision_id):
655
"""Query for a revision signature for revision_id in the repository."""
656
return self._revision_store.has_signature(revision_id,
657
self.get_transaction())
660
def get_signature_text(self, revision_id):
661
"""Return the text for a signature."""
662
return self._revision_store.get_signature_text(revision_id,
663
self.get_transaction())
666
def check(self, revision_ids):
667
"""Check consistency of all history of given revision_ids.
669
Different repository implementations should override _check().
671
:param revision_ids: A non-empty list of revision_ids whose ancestry
672
will be checked. Typically the last revision_id of a branch.
675
raise ValueError("revision_ids must be non-empty in %s.check"
677
return self._check(revision_ids)
679
def _check(self, revision_ids):
680
result = check.Check(self)
685
457
class AllInOneRepository(Repository):
686
458
"""Legacy support - the repository behaviour for all-in-one branches."""
688
def __init__(self, _format, a_bzrdir, _revision_store, control_store, text_store):
460
def __init__(self, _format, a_bzrdir, revision_store):
689
461
# we reuse one control files instance.
690
462
dir_mode = a_bzrdir._control_files._dir_mode
691
463
file_mode = a_bzrdir._control_files._file_mode
465
def get_weave(name, prefixed=False):
467
name = safe_unicode(name)
470
relpath = a_bzrdir._control_files._escape(name)
471
weave_transport = a_bzrdir._control_files._transport.clone(relpath)
472
ws = WeaveStore(weave_transport, prefixed=prefixed,
475
if a_bzrdir._control_files._transport.should_cache():
476
ws.enable_cache = True
693
479
def get_store(name, compressed=True, prefixed=False):
694
480
# FIXME: This approach of assuming stores are all entirely compressed
695
481
# or entirely uncompressed is tidy, but breaks upgrade from
709
495
# not broken out yet because the controlweaves|inventory_store
710
496
# and text_store | weave_store bits are still different.
711
497
if isinstance(_format, RepositoryFormat4):
712
# cannot remove these - there is still no consistent api
713
# which allows access to this old info.
714
498
self.inventory_store = get_store('inventory-store')
715
text_store = get_store('text-store')
716
super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, _revision_store, control_store, text_store)
720
"""AllInOne repositories cannot be shared."""
724
def set_make_working_trees(self, new_value):
725
"""Set the policy flag for making working trees when creating branches.
727
This only applies to branches that use this repository.
729
The default is 'True'.
730
:param new_value: True to restore the default, False to disable making
733
raise NotImplementedError(self.set_make_working_trees)
735
def make_working_trees(self):
736
"""Returns the policy for making working trees on new branches."""
740
def install_revision(repository, rev, revision_tree):
741
"""Install all revision data into a repository."""
744
for p_id in rev.parent_ids:
745
if repository.has_revision(p_id):
746
present_parents.append(p_id)
747
parent_trees[p_id] = repository.revision_tree(p_id)
499
self.text_store = get_store('text-store')
500
elif isinstance(_format, RepositoryFormat5):
501
self.control_weaves = get_weave('')
502
self.weave_store = get_weave('weaves')
503
elif isinstance(_format, RepositoryFormat6):
504
self.control_weaves = get_weave('')
505
self.weave_store = get_weave('weaves', prefixed=True)
749
parent_trees[p_id] = EmptyTree()
751
inv = revision_tree.inventory
753
# Add the texts that are not already present
754
for path, ie in inv.iter_entries():
755
w = repository.weave_store.get_weave_or_empty(ie.file_id,
756
repository.get_transaction())
757
if ie.revision not in w:
759
# FIXME: TODO: The following loop *may* be overlapping/duplicate
760
# with InventoryEntry.find_previous_heads(). if it is, then there
761
# is a latent bug here where the parents may have ancestors of each
763
for revision, tree in parent_trees.iteritems():
764
if ie.file_id not in tree:
766
parent_id = tree.inventory[ie.file_id].revision
767
if parent_id in text_parents:
769
text_parents.append(parent_id)
771
vfile = repository.weave_store.get_weave_or_empty(ie.file_id,
772
repository.get_transaction())
773
lines = revision_tree.get_file(ie.file_id).readlines()
774
vfile.add_lines(rev.revision_id, text_parents, lines)
776
# install the inventory
777
repository.add_inventory(rev.revision_id, inv, present_parents)
778
except errors.RevisionAlreadyPresent:
780
repository.add_revision(rev.revision_id, rev, inv)
507
raise errors.BzrError('unreachable code: unexpected repository'
509
revision_store.register_suffix('sig')
510
super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, revision_store)
783
513
class MetaDirRepository(Repository):
784
514
"""Repositories in the new meta-dir layout."""
786
def __init__(self, _format, a_bzrdir, control_files, _revision_store, control_store, text_store):
516
def __init__(self, _format, a_bzrdir, control_files, revision_store):
787
517
super(MetaDirRepository, self).__init__(_format,
794
522
dir_mode = self.control_files._dir_mode
795
523
file_mode = self.control_files._file_mode
799
"""Return True if this repository is flagged as a shared repository."""
800
return self.control_files._transport.has('shared-storage')
803
def set_make_working_trees(self, new_value):
804
"""Set the policy flag for making working trees when creating branches.
806
This only applies to branches that use this repository.
808
The default is 'True'.
809
:param new_value: True to restore the default, False to disable making
814
self.control_files._transport.delete('no-working-trees')
815
except errors.NoSuchFile:
818
self.control_files.put_utf8('no-working-trees', '')
820
def make_working_trees(self):
821
"""Returns the policy for making working trees on new branches."""
822
return not self.control_files._transport.has('no-working-trees')
825
class KnitRepository(MetaDirRepository):
826
"""Knit format repository."""
828
def _inventory_add_lines(self, inv_vf, revid, parents, lines):
829
inv_vf.add_lines_with_ghosts(revid, parents, lines)
832
def _all_revision_ids(self):
833
"""See Repository.all_revision_ids()."""
834
# Knits get the revision graph from the index of the revision knit, so
835
# it's always possible even if they're on an unlistable transport.
836
return self._revision_store.all_revision_ids(self.get_transaction())
838
def fileid_involved_between_revs(self, from_revid, to_revid):
839
"""Find file_id(s) which are involved in the changes between revisions.
841
This determines the set of revisions which are involved, and then
842
finds all file ids affected by those revisions.
844
vf = self._get_revision_vf()
845
from_set = set(vf.get_ancestry(from_revid))
846
to_set = set(vf.get_ancestry(to_revid))
847
changed = to_set.difference(from_set)
848
return self._fileid_involved_by_set(changed)
850
def fileid_involved(self, last_revid=None):
851
"""Find all file_ids modified in the ancestry of last_revid.
853
:param last_revid: If None, last_revision() will be used.
856
changed = set(self.all_revision_ids())
858
changed = set(self.get_ancestry(last_revid))
861
return self._fileid_involved_by_set(changed)
864
def get_ancestry(self, revision_id):
865
"""Return a list of revision-ids integrated by a revision.
867
This is topologically sorted.
869
if revision_id is None:
871
vf = self._get_revision_vf()
873
return [None] + vf.get_ancestry(revision_id)
874
except errors.RevisionNotPresent:
875
raise errors.NoSuchRevision(self, revision_id)
878
def get_revision(self, revision_id):
879
"""Return the Revision object for a named revision"""
880
return self.get_revision_reconcile(revision_id)
883
def get_revision_graph(self, revision_id=None):
884
"""Return a dictionary containing the revision graph.
886
:param revision_id: The revision_id to get a graph from. If None, then
887
the entire revision graph is returned. This is a deprecated mode of
888
operation and will be removed in the future.
889
:return: a dictionary of revision_id->revision_parents_list.
891
# special case NULL_REVISION
892
if revision_id == NULL_REVISION:
894
weave = self._get_revision_vf()
895
entire_graph = weave.get_graph()
896
if revision_id is None:
897
return weave.get_graph()
898
elif revision_id not in weave:
899
raise errors.NoSuchRevision(self, revision_id)
901
# add what can be reached from revision_id
903
pending = set([revision_id])
904
while len(pending) > 0:
906
result[node] = weave.get_parents(node)
907
for revision_id in result[node]:
908
if revision_id not in result:
909
pending.add(revision_id)
913
def get_revision_graph_with_ghosts(self, revision_ids=None):
914
"""Return a graph of the revisions with ghosts marked as applicable.
916
:param revision_ids: an iterable of revisions to graph or None for all.
917
:return: a Graph object with the graph reachable from revision_ids.
920
vf = self._get_revision_vf()
921
versions = set(vf.versions())
923
pending = set(self.all_revision_ids())
926
pending = set(revision_ids)
927
# special case NULL_REVISION
928
if NULL_REVISION in pending:
929
pending.remove(NULL_REVISION)
930
required = set(pending)
933
revision_id = pending.pop()
934
if not revision_id in versions:
935
if revision_id in required:
936
raise errors.NoSuchRevision(self, revision_id)
938
result.add_ghost(revision_id)
939
# mark it as done so we don't try for it again.
940
done.add(revision_id)
942
parent_ids = vf.get_parents_with_ghosts(revision_id)
943
for parent_id in parent_ids:
944
# is this queued or done ?
945
if (parent_id not in pending and
946
parent_id not in done):
948
pending.add(parent_id)
949
result.add_node(revision_id, parent_ids)
950
done.add(revision_id)
953
def _get_revision_vf(self):
954
""":return: a versioned file containing the revisions."""
955
vf = self._revision_store.get_revision_file(self.get_transaction())
959
def reconcile(self, other=None, thorough=False):
960
"""Reconcile this repository."""
961
from bzrlib.reconcile import KnitReconciler
962
reconciler = KnitReconciler(self, thorough=thorough)
963
reconciler.reconcile()
966
def revision_parents(self, revision_id):
967
return self._get_revision_vf().get_parents(revision_id)
525
def get_weave(name, prefixed=False):
527
name = safe_unicode(name)
530
relpath = self.control_files._escape(name)
531
weave_transport = self.control_files._transport.clone(relpath)
532
ws = WeaveStore(weave_transport, prefixed=prefixed,
535
if self.control_files._transport.should_cache():
536
ws.enable_cache = True
539
if isinstance(self._format, RepositoryFormat7):
540
self.control_weaves = get_weave('')
541
self.weave_store = get_weave('weaves', prefixed=True)
542
elif isinstance(self._format, RepositoryFormatKnit1):
543
self.control_weaves = get_weave('')
544
self.weave_store = get_weave('knits', prefixed=True)
546
raise errors.BzrError('unreachable code: unexpected repository'
970
550
class RepositoryFormat(object):
1280
798
def __init__(self):
1281
799
super(RepositoryFormat6, self).__init__()
1282
self._matchingbzrdir = bzrdir.BzrDirFormat6()
1284
def get_format_description(self):
1285
"""See RepositoryFormat.get_format_description()."""
1286
return "Weave repository format 6"
800
self._matchingbzrdir = bzrlib.bzrdir.BzrDirFormat6()
1288
802
def _get_revision_store(self, repo_transport, control_files):
1289
803
"""See RepositoryFormat._get_revision_store()."""
1290
return self._get_text_rev_store(repo_transport,
1296
def _get_text_store(self, transport, control_files):
1297
"""See RepositoryFormat._get_text_store()."""
1298
return self._get_versioned_file_store('weaves', transport, control_files)
804
return self._get_rev_store(repo_transport,
1301
811
class MetaDirRepositoryFormat(RepositoryFormat):
1302
"""Common base class for the new repositories using the metadir layout."""
812
"""Common base class for the new repositories using the metadir layour."""
1304
814
def __init__(self):
1305
815
super(MetaDirRepositoryFormat, self).__init__()
1306
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
816
self._matchingbzrdir = bzrlib.bzrdir.BzrDirMetaFormat1()
1308
818
def _create_control_files(self, a_bzrdir):
1309
819
"""Create the required files and the initial control_files object."""
1310
# FIXME: RBC 20060125 don't peek under the covers
820
# FIXME: RBC 20060125 dont peek under the covers
1311
821
# NB: no need to escape relative paths that are url safe.
1312
823
repository_transport = a_bzrdir.get_repository_transport(self)
1313
control_files = LockableFiles(repository_transport, 'lock', LockDir)
1314
control_files.create_lock()
824
repository_transport.put(lock_file, StringIO()) # TODO get the file mode from the bzrdir lock files., mode=file_mode)
825
control_files = LockableFiles(repository_transport, 'lock')
1315
826
return control_files
828
def _get_revision_store(self, repo_transport, control_files):
829
"""See RepositoryFormat._get_revision_store()."""
830
return self._get_rev_store(repo_transport,
837
def open(self, a_bzrdir, _found=False, _override_transport=None):
838
"""See RepositoryFormat.open().
840
:param _override_transport: INTERNAL USE ONLY. Allows opening the
841
repository at a slightly different url
842
than normal. I.e. during 'upgrade'.
845
format = RepositoryFormat.find_format(a_bzrdir)
846
assert format.__class__ == self.__class__
847
if _override_transport is not None:
848
repo_transport = _override_transport
850
repo_transport = a_bzrdir.get_repository_transport(None)
851
control_files = LockableFiles(repo_transport, 'lock')
852
revision_store = self._get_revision_store(repo_transport, control_files)
853
return MetaDirRepository(_format=self,
855
control_files=control_files,
856
revision_store=revision_store)
1317
858
def _upload_blank_content(self, a_bzrdir, dirs, files, utf8_files, shared):
1318
859
"""Upload the initial blank content."""
1319
860
control_files = self._create_control_files(a_bzrdir)
1320
861
control_files.lock_write()
862
control_files._transport.mkdir_multi(dirs,
863
mode=control_files._dir_mode)
1322
control_files._transport.mkdir_multi(dirs,
1323
mode=control_files._dir_mode)
1324
865
for file, content in files:
1325
866
control_files.put(file, content)
1326
867
for file, content in utf8_files:
1433
923
- a format marker of its own
1434
924
- an optional 'shared-storage' flag
1435
925
- an optional 'no-working-trees' flag
1438
This format was introduced in bzr 0.8.
1441
def _get_control_store(self, repo_transport, control_files):
1442
"""Return the control store for this repository."""
1443
return VersionedFileStore(
1446
file_mode=control_files._file_mode,
1447
versionedfile_class=KnitVersionedFile,
1448
versionedfile_kwargs={'factory':KnitPlainFactory()},
1451
928
def get_format_string(self):
1452
929
"""See RepositoryFormat.get_format_string()."""
1453
930
return "Bazaar-NG Knit Repository Format 1"
1455
def get_format_description(self):
1456
"""See RepositoryFormat.get_format_description()."""
1457
return "Knit repository format 1"
1459
def _get_revision_store(self, repo_transport, control_files):
1460
"""See RepositoryFormat._get_revision_store()."""
1461
from bzrlib.store.revision.knit import KnitRevisionStore
1462
versioned_file_store = VersionedFileStore(
1464
file_mode=control_files._file_mode,
1467
versionedfile_class=KnitVersionedFile,
1468
versionedfile_kwargs={'delta':False, 'factory':KnitPlainFactory()},
1471
return KnitRevisionStore(versioned_file_store)
1473
def _get_text_store(self, transport, control_files):
1474
"""See RepositoryFormat._get_text_store()."""
1475
return self._get_versioned_file_store('knits',
1478
versionedfile_class=KnitVersionedFile,
1481
932
def initialize(self, a_bzrdir, shared=False):
1482
933
"""Create a knit format 1 repository.
1484
:param a_bzrdir: bzrdir to contain the new repository; must already
1486
935
:param shared: If true the repository will be initialized as a shared
937
XXX NOTE that this current uses a Weave for testing and will become
938
A Knit in due course.
940
from bzrlib.weavefile import write_weave_v5
941
from bzrlib.weave import Weave
943
# Create an empty weave
945
bzrlib.weavefile.write_weave_v5(Weave(), sio)
946
empty_weave = sio.getvalue()
1489
948
mutter('creating repository in %s.', a_bzrdir.transport.base)
1490
949
dirs = ['revision-store', 'knits']
950
files = [('inventory.weave', StringIO(empty_weave)),
1492
952
utf8_files = [('format', self.get_format_string())]
1494
954
self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
1495
repo_transport = a_bzrdir.get_repository_transport(None)
1496
control_files = LockableFiles(repo_transport, 'lock', LockDir)
1497
control_store = self._get_control_store(repo_transport, control_files)
1498
transaction = transactions.WriteTransaction()
1499
# trigger a write of the inventory store.
1500
control_store.get_weave_or_empty('inventory', transaction)
1501
_revision_store = self._get_revision_store(repo_transport, control_files)
1502
_revision_store.has_revision_id('A', transaction)
1503
_revision_store.get_signature_file(transaction)
1504
955
return self.open(a_bzrdir=a_bzrdir, _found=True)
1506
def open(self, a_bzrdir, _found=False, _override_transport=None):
1507
"""See RepositoryFormat.open().
1509
:param _override_transport: INTERNAL USE ONLY. Allows opening the
1510
repository at a slightly different url
1511
than normal. I.e. during 'upgrade'.
1514
format = RepositoryFormat.find_format(a_bzrdir)
1515
assert format.__class__ == self.__class__
1516
if _override_transport is not None:
1517
repo_transport = _override_transport
1519
repo_transport = a_bzrdir.get_repository_transport(None)
1520
control_files = LockableFiles(repo_transport, 'lock', LockDir)
1521
text_store = self._get_text_store(repo_transport, control_files)
1522
control_store = self._get_control_store(repo_transport, control_files)
1523
_revision_store = self._get_revision_store(repo_transport, control_files)
1524
return KnitRepository(_format=self,
1526
control_files=control_files,
1527
_revision_store=_revision_store,
1528
control_store=control_store,
1529
text_store=text_store)
1532
958
# formats which have no format string are not discoverable
1533
959
# and not independently creatable, so are not registered.
1534
RepositoryFormat.register_format(RepositoryFormat7())
1535
_default_format = RepositoryFormatKnit1()
960
_default_format = RepositoryFormat7()
1536
961
RepositoryFormat.register_format(_default_format)
962
RepositoryFormat.register_format(RepositoryFormatKnit1())
1537
963
RepositoryFormat.set_default_format(_default_format)
1538
964
_legacy_formats = [RepositoryFormat4(),
1539
965
RepositoryFormat5(),
1540
966
RepositoryFormat6()]
1543
class InterRepository(InterObject):
969
class InterRepository(object):
1544
970
"""This class represents operations taking place between two repositories.
1546
972
Its instances have methods like copy_content and fetch, and contain
1705
1170
# FIXME do not peek!
1706
1171
if self.source.control_files._transport.listable():
1707
pb = ui.ui_factory.nested_progress_bar()
1709
self.target.weave_store.copy_all_ids(
1710
self.source.weave_store,
1712
from_transaction=self.source.get_transaction(),
1713
to_transaction=self.target.get_transaction())
1714
pb.update('copying inventory', 0, 1)
1715
self.target.control_weaves.copy_multi(
1716
self.source.control_weaves, ['inventory'],
1717
from_transaction=self.source.get_transaction(),
1718
to_transaction=self.target.get_transaction())
1719
self.target._revision_store.text_store.copy_all_ids(
1720
self.source._revision_store.text_store,
1172
pb = bzrlib.ui.ui_factory.progress_bar()
1173
copy_all(self.source.weave_store,
1174
self.target.weave_store, pb=pb)
1175
pb.update('copying inventory', 0, 1)
1176
self.target.control_weaves.copy_multi(
1177
self.source.control_weaves, ['inventory'])
1178
copy_all(self.source.revision_store,
1179
self.target.revision_store, pb=pb)
1725
1181
self.target.fetch(self.source, revision_id=revision_id)
1727
1183
@needs_write_lock
1728
1184
def fetch(self, revision_id=None, pb=None):
1729
1185
"""See InterRepository.fetch()."""
1730
from bzrlib.fetch import GenericRepoFetcher
1186
from bzrlib.fetch import RepoFetcher
1731
1187
mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
1732
1188
self.source, self.source._format, self.target, self.target._format)
1733
f = GenericRepoFetcher(to_repository=self.target,
1734
from_repository=self.source,
1735
last_revision=revision_id,
1189
f = RepoFetcher(to_repository=self.target,
1190
from_repository=self.source,
1191
last_revision=revision_id,
1737
1193
return f.count_copied, f.failed_revisions
1739
1195
@needs_read_lock
1740
1196
def missing_revision_ids(self, revision_id=None):
1741
1197
"""See InterRepository.missing_revision_ids()."""
1742
1198
# we want all revisions to satisfy revision_id in source.
1743
# but we don't want to stat every file here and there.
1199
# but we dont want to stat every file here and there.
1744
1200
# we want then, all revisions other needs to satisfy revision_id
1745
1201
# checked, but not those that we have locally.
1746
1202
# so the first thing is to get a subset of the revisions to
1752
1208
# - RBC 20060209
1753
1209
if revision_id is not None:
1754
1210
source_ids = self.source.get_ancestry(revision_id)
1755
assert source_ids[0] == None
1758
source_ids = self.source._all_possible_ids()
1759
source_ids_set = set(source_ids)
1760
# source_ids is the worst possible case we may need to pull.
1761
# now we want to filter source_ids against what we actually
1762
# have in target, but don't try to check for existence where we know
1763
# we do not have a revision as that would be pointless.
1764
target_ids = set(self.target._all_possible_ids())
1765
possibly_present_revisions = target_ids.intersection(source_ids_set)
1766
actually_present_revisions = set(self.target._eliminate_revisions_not_present(possibly_present_revisions))
1767
required_revisions = source_ids_set.difference(actually_present_revisions)
1768
required_topo_revisions = [rev_id for rev_id in source_ids if rev_id in required_revisions]
1769
if revision_id is not None:
1770
# we used get_ancestry to determine source_ids then we are assured all
1771
# revisions referenced are present as they are installed in topological order.
1772
# and the tip revision was validated by get_ancestry.
1773
return required_topo_revisions
1775
# if we just grabbed the possibly available ids, then
1776
# we only have an estimate of whats available and need to validate
1777
# that against the revision records.
1778
return self.source._eliminate_revisions_not_present(required_topo_revisions)
1781
class InterKnitRepo(InterRepository):
1782
"""Optimised code paths between Knit based repositories."""
1784
_matching_repo_format = RepositoryFormatKnit1()
1785
"""Repository format for testing with."""
1788
def is_compatible(source, target):
1789
"""Be compatible with known Knit formats.
1791
We don't test for the stores being of specific types because that
1792
could lead to confusing results, and there is no need to be
1796
return (isinstance(source._format, (RepositoryFormatKnit1)) and
1797
isinstance(target._format, (RepositoryFormatKnit1)))
1798
except AttributeError:
1802
def fetch(self, revision_id=None, pb=None):
1803
"""See InterRepository.fetch()."""
1804
from bzrlib.fetch import KnitRepoFetcher
1805
mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
1806
self.source, self.source._format, self.target, self.target._format)
1807
f = KnitRepoFetcher(to_repository=self.target,
1808
from_repository=self.source,
1809
last_revision=revision_id,
1811
return f.count_copied, f.failed_revisions
1814
def missing_revision_ids(self, revision_id=None):
1815
"""See InterRepository.missing_revision_ids()."""
1816
if revision_id is not None:
1817
source_ids = self.source.get_ancestry(revision_id)
1818
assert source_ids[0] == None
1821
source_ids = self.source._all_possible_ids()
1822
source_ids_set = set(source_ids)
1823
# source_ids is the worst possible case we may need to pull.
1824
# now we want to filter source_ids against what we actually
1825
# have in target, but don't try to check for existence where we know
1826
# we do not have a revision as that would be pointless.
1827
target_ids = set(self.target._all_possible_ids())
1828
possibly_present_revisions = target_ids.intersection(source_ids_set)
1829
actually_present_revisions = set(self.target._eliminate_revisions_not_present(possibly_present_revisions))
1830
required_revisions = source_ids_set.difference(actually_present_revisions)
1831
required_topo_revisions = [rev_id for rev_id in source_ids if rev_id in required_revisions]
1832
if revision_id is not None:
1833
# we used get_ancestry to determine source_ids then we are assured all
1834
# revisions referenced are present as they are installed in topological order.
1835
# and the tip revision was validated by get_ancestry.
1836
return required_topo_revisions
1838
# if we just grabbed the possibly available ids, then
1839
# we only have an estimate of whats available and need to validate
1840
# that against the revision records.
1841
return self.source._eliminate_revisions_not_present(required_topo_revisions)
1211
assert source_ids.pop(0) == None
1213
source_ids = self.source._all_possible_ids()
1214
source_ids_set = set(source_ids)
1215
# source_ids is the worst possible case we may need to pull.
1216
# now we want to filter source_ids against what we actually
1217
# have in target, but dont try to check for existence where we know
1218
# we do not have a revision as that would be pointless.
1219
target_ids = set(self.target._all_possible_ids())
1220
possibly_present_revisions = target_ids.intersection(source_ids_set)
1221
actually_present_revisions = set(self.target._eliminate_revisions_not_present(possibly_present_revisions))
1222
required_revisions = source_ids_set.difference(actually_present_revisions)
1223
required_topo_revisions = [rev_id for rev_id in source_ids if rev_id in required_revisions]
1224
if revision_id is not None:
1225
# we used get_ancestry to determine source_ids then we are assured all
1226
# revisions referenced are present as they are installed in topological order.
1227
# and the tip revision was validated by get_ancestry.
1228
return required_topo_revisions
1230
# if we just grabbed the possibly available ids, then
1231
# we only have an estimate of whats available and need to validate
1232
# that against the revision records.
1233
return self.source._eliminate_revisions_not_present(required_topo_revisions)
1843
1236
InterRepository.register_optimiser(InterWeaveRepo)
1844
InterRepository.register_optimiser(InterKnitRepo)
1847
1239
class RepositoryTestProviderAdapter(object):
1974
1366
"""Update the pb by a step."""
1976
1368
self.pb.update(message, self.count, self.total)
1979
class CommitBuilder(object):
1980
"""Provides an interface to build up a commit.
1982
This allows describing a tree to be committed without needing to
1983
know the internals of the format of the repository.
1985
def __init__(self, repository, parents, config, timestamp=None,
1986
timezone=None, committer=None, revprops=None,
1988
"""Initiate a CommitBuilder.
1990
:param repository: Repository to commit to.
1991
:param parents: Revision ids of the parents of the new revision.
1992
:param config: Configuration to use.
1993
:param timestamp: Optional timestamp recorded for commit.
1994
:param timezone: Optional timezone for timestamp.
1995
:param committer: Optional committer to set for commit.
1996
:param revprops: Optional dictionary of revision properties.
1997
:param revision_id: Optional revision id.
1999
self._config = config
2001
if committer is None:
2002
self._committer = self._config.username()
2004
assert isinstance(committer, basestring), type(committer)
2005
self._committer = committer
2007
self.new_inventory = Inventory()
2008
self._new_revision_id = revision_id
2009
self.parents = parents
2010
self.repository = repository
2013
if revprops is not None:
2014
self._revprops.update(revprops)
2016
if timestamp is None:
2017
self._timestamp = time.time()
2019
self._timestamp = long(timestamp)
2021
if timezone is None:
2022
self._timezone = local_time_offset()
2024
self._timezone = int(timezone)
2026
self._generate_revision_if_needed()
2028
def commit(self, message):
2029
"""Make the actual commit.
2031
:return: The revision id of the recorded revision.
2033
rev = Revision(timestamp=self._timestamp,
2034
timezone=self._timezone,
2035
committer=self._committer,
2037
inventory_sha1=self.inv_sha1,
2038
revision_id=self._new_revision_id,
2039
properties=self._revprops)
2040
rev.parent_ids = self.parents
2041
self.repository.add_revision(self._new_revision_id, rev,
2042
self.new_inventory, self._config)
2043
return self._new_revision_id
2045
def finish_inventory(self):
2046
"""Tell the builder that the inventory is finished."""
2047
self.new_inventory.revision_id = self._new_revision_id
2048
self.inv_sha1 = self.repository.add_inventory(
2049
self._new_revision_id,
2054
def _gen_revision_id(self):
2055
"""Return new revision-id."""
2056
s = '%s-%s-' % (self._config.user_email(),
2057
compact_date(self._timestamp))
2058
s += hexlify(rand_bytes(8))
2061
def _generate_revision_if_needed(self):
2062
"""Create a revision id if None was supplied.
2064
If the repository can not support user-specified revision ids
2065
they should override this function and raise UnsupportedOperation
2066
if _new_revision_id is not None.
2068
:raises: UnsupportedOperation
2070
if self._new_revision_id is None:
2071
self._new_revision_id = self._gen_revision_id()
2073
def record_entry_contents(self, ie, parent_invs, path, tree):
2074
"""Record the content of ie from tree into the commit if needed.
2076
:param ie: An inventory entry present in the commit.
2077
:param parent_invs: The inventories of the parent revisions of the
2079
:param path: The path the entry is at in the tree.
2080
:param tree: The tree which contains this entry and should be used to
2083
self.new_inventory.add(ie)
2085
# ie.revision is always None if the InventoryEntry is considered
2086
# for committing. ie.snapshot will record the correct revision
2087
# which may be the sole parent if it is untouched.
2088
if ie.revision is not None:
2090
previous_entries = ie.find_previous_heads(
2092
self.repository.weave_store,
2093
self.repository.get_transaction())
2094
# we are creating a new revision for ie in the history store
2096
ie.snapshot(self._new_revision_id, path, previous_entries, tree, self)
2098
def modified_directory(self, file_id, file_parents):
2099
"""Record the presence of a symbolic link.
2101
:param file_id: The file_id of the link to record.
2102
:param file_parents: The per-file parent revision ids.
2104
self._add_text_to_weave(file_id, [], file_parents.keys())
2106
def modified_file_text(self, file_id, file_parents,
2107
get_content_byte_lines, text_sha1=None,
2109
"""Record the text of file file_id
2111
:param file_id: The file_id of the file to record the text of.
2112
:param file_parents: The per-file parent revision ids.
2113
:param get_content_byte_lines: A callable which will return the byte
2115
:param text_sha1: Optional SHA1 of the file contents.
2116
:param text_size: Optional size of the file contents.
2118
mutter('storing text of file {%s} in revision {%s} into %r',
2119
file_id, self._new_revision_id, self.repository.weave_store)
2120
# special case to avoid diffing on renames or
2122
if (len(file_parents) == 1
2123
and text_sha1 == file_parents.values()[0].text_sha1
2124
and text_size == file_parents.values()[0].text_size):
2125
previous_ie = file_parents.values()[0]
2126
versionedfile = self.repository.weave_store.get_weave(file_id,
2127
self.repository.get_transaction())
2128
versionedfile.clone_text(self._new_revision_id,
2129
previous_ie.revision, file_parents.keys())
2130
return text_sha1, text_size
2132
new_lines = get_content_byte_lines()
2133
# TODO: Rather than invoking sha_strings here, _add_text_to_weave
2134
# should return the SHA1 and size
2135
self._add_text_to_weave(file_id, new_lines, file_parents.keys())
2136
return osutils.sha_strings(new_lines), \
2137
sum(map(len, new_lines))
2139
def modified_link(self, file_id, file_parents, link_target):
2140
"""Record the presence of a symbolic link.
2142
:param file_id: The file_id of the link to record.
2143
:param file_parents: The per-file parent revision ids.
2144
:param link_target: Target location of this link.
2146
self._add_text_to_weave(file_id, [], file_parents.keys())
2148
def _add_text_to_weave(self, file_id, new_lines, parents):
2149
versionedfile = self.repository.weave_store.get_weave_or_empty(
2150
file_id, self.repository.get_transaction())
2151
versionedfile.add_lines(self._new_revision_id, parents, new_lines)
2152
versionedfile.clear_cache()
2164
def _unescaper(match, _map=_unescape_map):
2165
return _map[match.group(1)]
2171
def _unescape_xml(data):
2172
"""Unescape predefined XML entities in a string of data."""
2174
if _unescape_re is None:
2175
_unescape_re = re.compile('\&([^;]*);')
2176
return _unescape_re.sub(_unescaper, data)