2241.1.1
by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary |
1 |
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
3 |
# This program is free software; you can redistribute it and/or modify
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
8 |
# This program is distributed in the hope that it will be useful,
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
12 |
#
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
13 |
# You should have received a copy of the GNU General Public License
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
1185.65.10
by Robert Collins
Rename Controlfiles to LockableFiles. |
16 |
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
17 |
from cStringIO import StringIO |
18 |
||
19 |
from bzrlib.lazy_import import lazy_import |
|
20 |
lazy_import(globals(), """ |
|
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
21 |
from binascii import hexlify
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
22 |
from copy import deepcopy
|
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
23 |
import re
|
24 |
import time
|
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
25 |
import unittest
|
26 |
||
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
27 |
from bzrlib import (
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
28 |
bzrdir,
|
29 |
check,
|
|
30 |
delta,
|
|
31 |
errors,
|
|
2116.4.1
by John Arbash Meinel
Update file and revision id generators. |
32 |
generate_ids,
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
33 |
gpg,
|
34 |
graph,
|
|
1996.3.5
by John Arbash Meinel
Cleanup, deprecated, and get the tests passing again. |
35 |
knit,
|
2163.2.1
by John Arbash Meinel
Speed up the fileids_altered_by_revision_ids processing |
36 |
lazy_regex,
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
37 |
lockable_files,
|
38 |
lockdir,
|
|
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
39 |
osutils,
|
2241.1.1
by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary |
40 |
registry,
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
41 |
revision as _mod_revision,
|
42 |
symbol_versioning,
|
|
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
43 |
transactions,
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
44 |
ui,
|
45 |
weave,
|
|
46 |
weavefile,
|
|
47 |
xml5,
|
|
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
48 |
xml6,
|
49 |
)
|
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
50 |
from bzrlib.osutils import (
|
51 |
rand_bytes,
|
|
52 |
compact_date,
|
|
53 |
local_time_offset,
|
|
54 |
)
|
|
55 |
from bzrlib.revisiontree import RevisionTree
|
|
56 |
from bzrlib.store.versioned import VersionedFileStore
|
|
57 |
from bzrlib.store.text import TextStore
|
|
58 |
from bzrlib.testament import Testament
|
|
59 |
""") |
|
60 |
||
1534.4.28
by Robert Collins
first cut at merge from integration. |
61 |
from bzrlib.decorators import needs_read_lock, needs_write_lock |
1563.2.12
by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile. |
62 |
from bzrlib.inter import InterObject |
1910.2.3
by Aaron Bentley
All tests pass |
63 |
from bzrlib.inventory import Inventory, InventoryDirectory, ROOT_ID |
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
64 |
from bzrlib.symbol_versioning import ( |
65 |
deprecated_method, |
|
66 |
zero_nine, |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
67 |
)
|
1904.2.3
by Martin Pool
Give a warning on access to old repository formats |
68 |
from bzrlib.trace import mutter, note, warning |
1185.70.3
by Martin Pool
Various updates to make storage branch mergeable: |
69 |
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
70 |
|
1904.2.5
by Martin Pool
Fix format warning inside test suite and add test |
71 |
# Old formats display a warning, but only once
|
72 |
_deprecation_warning_done = False |
|
73 |
||
74 |
||
1185.66.5
by Aaron Bentley
Renamed RevisionStorage to Repository |
75 |
class Repository(object): |
1185.70.3
by Martin Pool
Various updates to make storage branch mergeable: |
76 |
"""Repository holding history for one or more branches.
|
77 |
||
78 |
The repository holds and retrieves historical information including
|
|
79 |
revisions and file history. It's normally accessed only by the Branch,
|
|
80 |
which views a particular line of development through that history.
|
|
81 |
||
82 |
The Repository builds on top of Stores and a Transport, which respectively
|
|
83 |
describe the disk data format and the way of accessing the (possibly
|
|
84 |
remote) disk.
|
|
85 |
"""
|
|
1185.65.17
by Robert Collins
Merge from integration, mode-changes are broken. |
86 |
|
2163.2.1
by John Arbash Meinel
Speed up the fileids_altered_by_revision_ids processing |
87 |
_file_ids_altered_regex = lazy_regex.lazy_compile( |
88 |
r'file_id="(?P<file_id>[^"]+)"' |
|
89 |
r'.*revision="(?P<revision_id>[^"]+)"' |
|
90 |
)
|
|
91 |
||
1570.1.2
by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.' |
92 |
@needs_write_lock
|
93 |
def add_inventory(self, revid, inv, parents): |
|
94 |
"""Add the inventory inv to the repository as revid.
|
|
95 |
|
|
96 |
:param parents: The revision ids of the parents that revid
|
|
97 |
is known to have and are in the repository already.
|
|
98 |
||
99 |
returns the sha1 of the serialized inventory.
|
|
100 |
"""
|
|
2229.2.3
by Aaron Bentley
change reserved_id to is_reserved_id, add check_not_reserved for DRY |
101 |
_mod_revision.check_not_reserved_id(revid) |
1740.2.2
by Aaron Bentley
Add test for the basis inventory automatically adding the revision id. |
102 |
assert inv.revision_id is None or inv.revision_id == revid, \ |
103 |
"Mismatch between inventory revision" \
|
|
104 |
" id and insertion revid (%r, %r)" % (inv.revision_id, revid) |
|
1910.2.6
by Aaron Bentley
Update for merge review, handle deprecations |
105 |
assert inv.root is not None |
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
106 |
inv_text = self.serialise_inventory(inv) |
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
107 |
inv_sha1 = osutils.sha_string(inv_text) |
1563.2.25
by Robert Collins
Merge in upstream. |
108 |
inv_vf = self.control_weaves.get_weave('inventory', |
109 |
self.get_transaction()) |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
110 |
self._inventory_add_lines(inv_vf, revid, parents, osutils.split_lines(inv_text)) |
1570.1.2
by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.' |
111 |
return inv_sha1 |
112 |
||
1740.3.6
by Jelmer Vernooij
Move inventory writing to the commit builder. |
113 |
def _inventory_add_lines(self, inv_vf, revid, parents, lines): |
114 |
final_parents = [] |
|
115 |
for parent in parents: |
|
116 |
if parent in inv_vf: |
|
117 |
final_parents.append(parent) |
|
118 |
||
119 |
inv_vf.add_lines(revid, final_parents, lines) |
|
120 |
||
1570.1.2
by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.' |
121 |
@needs_write_lock
|
122 |
def add_revision(self, rev_id, rev, inv=None, config=None): |
|
123 |
"""Add rev to the revision store as rev_id.
|
|
124 |
||
125 |
:param rev_id: the revision id to use.
|
|
126 |
:param rev: The revision object.
|
|
127 |
:param inv: The inventory for the revision. if None, it will be looked
|
|
128 |
up in the inventory storer
|
|
129 |
:param config: If None no digital signature will be created.
|
|
130 |
If supplied its signature_needed method will be used
|
|
131 |
to determine if a signature should be made.
|
|
132 |
"""
|
|
2229.2.3
by Aaron Bentley
change reserved_id to is_reserved_id, add check_not_reserved for DRY |
133 |
_mod_revision.check_not_reserved_id(rev_id) |
1570.1.2
by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.' |
134 |
if config is not None and config.signature_needed(): |
135 |
if inv is None: |
|
136 |
inv = self.get_inventory(rev_id) |
|
137 |
plaintext = Testament(rev, inv).as_short_text() |
|
138 |
self.store_revision_signature( |
|
139 |
gpg.GPGStrategy(config), plaintext, rev_id) |
|
140 |
if not rev_id in self.get_inventory_weave(): |
|
141 |
if inv is None: |
|
142 |
raise errors.WeaveRevisionNotPresent(rev_id, |
|
143 |
self.get_inventory_weave()) |
|
144 |
else: |
|
145 |
# yes, this is not suitable for adding with ghosts.
|
|
146 |
self.add_inventory(rev_id, inv, rev.parent_ids) |
|
1608.2.1
by Martin Pool
[merge] Storage filename escaping |
147 |
self._revision_store.add_revision(rev, self.get_transaction()) |
1570.1.2
by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.' |
148 |
|
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
149 |
@needs_read_lock
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
150 |
def _all_possible_ids(self): |
151 |
"""Return all the possible revisions that we could find."""
|
|
1563.2.4
by Robert Collins
First cut at including the knit implementation of versioned_file. |
152 |
return self.get_inventory_weave().versions() |
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
153 |
|
1732.2.4
by Martin Pool
Split check into Branch.check and Repository.check |
154 |
def all_revision_ids(self): |
155 |
"""Returns a list of all the revision ids in the repository.
|
|
156 |
||
157 |
This is deprecated because code should generally work on the graph
|
|
158 |
reachable from a particular revision, and ignore any other revisions
|
|
159 |
that might be present. There is no direct replacement method.
|
|
160 |
"""
|
|
161 |
return self._all_revision_ids() |
|
162 |
||
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
163 |
@needs_read_lock
|
1732.2.4
by Martin Pool
Split check into Branch.check and Repository.check |
164 |
def _all_revision_ids(self): |
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
165 |
"""Returns a list of all the revision ids in the repository.
|
166 |
||
167 |
These are in as much topological order as the underlying store can
|
|
168 |
present: for weaves ghosts may lead to a lack of correctness until
|
|
169 |
the reweave updates the parents list.
|
|
170 |
"""
|
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
171 |
if self._revision_store.text_store.listable(): |
172 |
return self._revision_store.all_revision_ids(self.get_transaction()) |
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
173 |
result = self._all_possible_ids() |
174 |
return self._eliminate_revisions_not_present(result) |
|
175 |
||
1687.1.7
by Robert Collins
Teach Repository about break_lock. |
176 |
def break_lock(self): |
177 |
"""Break a lock if one is present from another instance.
|
|
178 |
||
179 |
Uses the ui factory to ask for confirmation if the lock may be from
|
|
180 |
an active process.
|
|
181 |
"""
|
|
182 |
self.control_files.break_lock() |
|
183 |
||
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
184 |
@needs_read_lock
|
185 |
def _eliminate_revisions_not_present(self, revision_ids): |
|
186 |
"""Check every revision id in revision_ids to see if we have it.
|
|
187 |
||
188 |
Returns a set of the present revisions.
|
|
189 |
"""
|
|
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
190 |
result = [] |
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
191 |
for id in revision_ids: |
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
192 |
if self.has_revision(id): |
193 |
result.append(id) |
|
194 |
return result |
|
195 |
||
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
196 |
@staticmethod
|
197 |
def create(a_bzrdir): |
|
198 |
"""Construct the current default format repository in a_bzrdir."""
|
|
199 |
return RepositoryFormat.get_default_format().initialize(a_bzrdir) |
|
200 |
||
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
201 |
def __init__(self, _format, a_bzrdir, control_files, _revision_store, control_store, text_store): |
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
202 |
"""instantiate a Repository.
|
203 |
||
204 |
:param _format: The format of the repository on disk.
|
|
205 |
:param a_bzrdir: The BzrDir of the repository.
|
|
206 |
||
207 |
In the future we will have a single api for all stores for
|
|
208 |
getting file texts, inventories and revisions, then
|
|
209 |
this construct will accept instances of those things.
|
|
210 |
"""
|
|
1608.2.1
by Martin Pool
[merge] Storage filename escaping |
211 |
super(Repository, self).__init__() |
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
212 |
self._format = _format |
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
213 |
# the following are part of the public API for Repository:
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
214 |
self.bzrdir = a_bzrdir |
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
215 |
self.control_files = control_files |
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
216 |
self._revision_store = _revision_store |
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
217 |
self.text_store = text_store |
1759.2.1
by Jelmer Vernooij
Fix some types (found using aspell). |
218 |
# backwards compatibility
|
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
219 |
self.weave_store = text_store |
1563.2.23
by Robert Collins
Add add_revision and get_revision methods to RevisionStore |
220 |
# not right yet - should be more semantically clear ?
|
221 |
#
|
|
222 |
self.control_store = control_store |
|
223 |
self.control_weaves = control_store |
|
1608.2.1
by Martin Pool
[merge] Storage filename escaping |
224 |
# TODO: make sure to construct the right store classes, etc, depending
|
225 |
# on whether escaping is required.
|
|
1904.2.3
by Martin Pool
Give a warning on access to old repository formats |
226 |
self._warn_if_deprecated() |
1910.2.48
by Aaron Bentley
Update from review comments |
227 |
self._serializer = xml5.serializer_v5 |
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
228 |
|
1668.1.3
by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959) |
229 |
def __repr__(self): |
230 |
return '%s(%r)' % (self.__class__.__name__, |
|
231 |
self.bzrdir.transport.base) |
|
232 |
||
1694.2.6
by Martin Pool
[merge] bzr.dev |
233 |
def is_locked(self): |
234 |
return self.control_files.is_locked() |
|
235 |
||
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
236 |
def lock_write(self): |
237 |
self.control_files.lock_write() |
|
238 |
||
239 |
def lock_read(self): |
|
1553.5.55
by Martin Pool
[revert] broken changes |
240 |
self.control_files.lock_read() |
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
241 |
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
242 |
def get_physical_lock_status(self): |
243 |
return self.control_files.get_physical_lock_status() |
|
1624.3.36
by Olaf Conradi
Rename is_transport_locked() to get_physical_lock_status() as the |
244 |
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
245 |
@needs_read_lock
|
246 |
def missing_revision_ids(self, other, revision_id=None): |
|
247 |
"""Return the revision ids that other has that this does not.
|
|
248 |
|
|
249 |
These are returned in topological order.
|
|
250 |
||
251 |
revision_id: only return revision ids included by revision_id.
|
|
252 |
"""
|
|
1534.1.34
by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method. |
253 |
return InterRepository.get(other, self).missing_revision_ids(revision_id) |
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
254 |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
255 |
@staticmethod
|
256 |
def open(base): |
|
257 |
"""Open the repository rooted at base.
|
|
258 |
||
259 |
For instance, if the repository is at URL/.bzr/repository,
|
|
260 |
Repository.open(URL) -> a Repository instance.
|
|
261 |
"""
|
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
262 |
control = bzrdir.BzrDir.open(base) |
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
263 |
return control.open_repository() |
264 |
||
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
265 |
def copy_content_into(self, destination, revision_id=None, basis=None): |
1534.6.6
by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient. |
266 |
"""Make a complete copy of the content in self into destination.
|
267 |
|
|
268 |
This is a destructive operation! Do not use it on existing
|
|
269 |
repositories.
|
|
270 |
"""
|
|
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
271 |
return InterRepository.get(self, destination).copy_content(revision_id, basis) |
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
272 |
|
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
273 |
def fetch(self, source, revision_id=None, pb=None): |
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
274 |
"""Fetch the content required to construct revision_id from source.
|
275 |
||
276 |
If revision_id is None all content is copied.
|
|
277 |
"""
|
|
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
278 |
return InterRepository.get(source, self).fetch(revision_id=revision_id, |
279 |
pb=pb) |
|
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
280 |
|
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
281 |
def get_commit_builder(self, branch, parents, config, timestamp=None, |
282 |
timezone=None, committer=None, revprops=None, |
|
283 |
revision_id=None): |
|
284 |
"""Obtain a CommitBuilder for this repository.
|
|
285 |
|
|
286 |
:param branch: Branch to commit to.
|
|
287 |
:param parents: Revision ids of the parents of the new revision.
|
|
288 |
:param config: Configuration to use.
|
|
289 |
:param timestamp: Optional timestamp recorded for commit.
|
|
290 |
:param timezone: Optional timezone for timestamp.
|
|
291 |
:param committer: Optional committer to set for commit.
|
|
292 |
:param revprops: Optional dictionary of revision properties.
|
|
293 |
:param revision_id: Optional revision id.
|
|
294 |
"""
|
|
1910.2.6
by Aaron Bentley
Update for merge review, handle deprecations |
295 |
return _CommitBuilder(self, parents, config, timestamp, timezone, |
296 |
committer, revprops, revision_id) |
|
1740.3.1
by Jelmer Vernooij
Introduce and use CommitBuilder objects. |
297 |
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
298 |
def unlock(self): |
299 |
self.control_files.unlock() |
|
300 |
||
1185.65.27
by Robert Collins
Tweak storage towards mergability. |
301 |
@needs_read_lock
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
302 |
def clone(self, a_bzrdir, revision_id=None, basis=None): |
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
303 |
"""Clone this repository into a_bzrdir using the current format.
|
304 |
||
305 |
Currently no check is made that the format of this repository and
|
|
306 |
the bzrdir format are compatible. FIXME RBC 20060201.
|
|
307 |
"""
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
308 |
if not isinstance(a_bzrdir._format, self.bzrdir._format.__class__): |
309 |
# use target default format.
|
|
310 |
result = a_bzrdir.create_repository() |
|
311 |
# FIXME RBC 20060209 split out the repository type to avoid this check ?
|
|
312 |
elif isinstance(a_bzrdir._format, |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
313 |
(bzrdir.BzrDirFormat4, |
314 |
bzrdir.BzrDirFormat5, |
|
315 |
bzrdir.BzrDirFormat6)): |
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
316 |
result = a_bzrdir.open_repository() |
317 |
else: |
|
1534.6.5
by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes. |
318 |
result = self._format.initialize(a_bzrdir, shared=self.is_shared()) |
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
319 |
self.copy_content_into(result, revision_id, basis) |
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
320 |
return result |
321 |
||
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
322 |
@needs_read_lock
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
323 |
def has_revision(self, revision_id): |
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
324 |
"""True if this repository has a copy of the revision."""
|
325 |
return self._revision_store.has_revision_id(revision_id, |
|
326 |
self.get_transaction()) |
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
327 |
|
1185.65.27
by Robert Collins
Tweak storage towards mergability. |
328 |
@needs_read_lock
|
1570.1.13
by Robert Collins
Check for incorrect revision parentage in the weave during revision access. |
329 |
def get_revision_reconcile(self, revision_id): |
330 |
"""'reconcile' helper routine that allows access to a revision always.
|
|
331 |
|
|
332 |
This variant of get_revision does not cross check the weave graph
|
|
333 |
against the revision one as get_revision does: but it should only
|
|
334 |
be used by reconcile, or reconcile-alike commands that are correcting
|
|
335 |
or testing the revision graph.
|
|
336 |
"""
|
|
1563.2.25
by Robert Collins
Merge in upstream. |
337 |
if not revision_id or not isinstance(revision_id, basestring): |
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
338 |
raise errors.InvalidRevisionId(revision_id=revision_id, |
339 |
branch=self) |
|
1756.1.2
by Aaron Bentley
Show logs using get_revisions |
340 |
return self._revision_store.get_revisions([revision_id], |
341 |
self.get_transaction())[0] |
|
342 |
@needs_read_lock
|
|
343 |
def get_revisions(self, revision_ids): |
|
344 |
return self._revision_store.get_revisions(revision_ids, |
|
345 |
self.get_transaction()) |
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
346 |
|
1185.65.27
by Robert Collins
Tweak storage towards mergability. |
347 |
@needs_read_lock
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
348 |
def get_revision_xml(self, revision_id): |
349 |
rev = self.get_revision(revision_id) |
|
350 |
rev_tmp = StringIO() |
|
351 |
# the current serializer..
|
|
352 |
self._revision_store._serializer.write_revision(rev, rev_tmp) |
|
353 |
rev_tmp.seek(0) |
|
354 |
return rev_tmp.getvalue() |
|
355 |
||
356 |
@needs_read_lock
|
|
1570.1.13
by Robert Collins
Check for incorrect revision parentage in the weave during revision access. |
357 |
def get_revision(self, revision_id): |
358 |
"""Return the Revision object for a named revision"""
|
|
359 |
r = self.get_revision_reconcile(revision_id) |
|
360 |
# weave corruption can lead to absent revision markers that should be
|
|
361 |
# present.
|
|
362 |
# the following test is reasonably cheap (it needs a single weave read)
|
|
363 |
# and the weave is cached in read transactions. In write transactions
|
|
364 |
# it is not cached but typically we only read a small number of
|
|
365 |
# revisions. For knits when they are introduced we will probably want
|
|
366 |
# to ensure that caching write transactions are in use.
|
|
367 |
inv = self.get_inventory_weave() |
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
368 |
self._check_revision_parents(r, inv) |
369 |
return r |
|
370 |
||
1756.3.19
by Aaron Bentley
Documentation and cleanups |
371 |
@needs_read_lock
|
1756.3.22
by Aaron Bentley
Tweaks from review |
372 |
def get_deltas_for_revisions(self, revisions): |
1756.3.19
by Aaron Bentley
Documentation and cleanups |
373 |
"""Produce a generator of revision deltas.
|
374 |
|
|
375 |
Note that the input is a sequence of REVISIONS, not revision_ids.
|
|
376 |
Trees will be held in memory until the generator exits.
|
|
377 |
Each delta is relative to the revision's lefthand predecessor.
|
|
378 |
"""
|
|
1756.3.3
by Aaron Bentley
More refactoring, introduce revision_trees. |
379 |
required_trees = set() |
380 |
for revision in revisions: |
|
381 |
required_trees.add(revision.revision_id) |
|
382 |
required_trees.update(revision.parent_ids[:1]) |
|
383 |
trees = dict((t.get_revision_id(), t) for |
|
384 |
t in self.revision_trees(required_trees)) |
|
385 |
for revision in revisions: |
|
386 |
if not revision.parent_ids: |
|
1852.5.1
by Robert Collins
Deprecate EmptyTree in favour of using Repository.revision_tree. |
387 |
old_tree = self.revision_tree(None) |
1756.3.3
by Aaron Bentley
More refactoring, introduce revision_trees. |
388 |
else: |
389 |
old_tree = trees[revision.parent_ids[0]] |
|
1852.10.3
by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib. |
390 |
yield trees[revision.revision_id].changes_from(old_tree) |
1756.3.3
by Aaron Bentley
More refactoring, introduce revision_trees. |
391 |
|
1756.3.19
by Aaron Bentley
Documentation and cleanups |
392 |
@needs_read_lock
|
1744.2.2
by Johan Rydberg
Add get_revision_delta to Repository; and make Branch.get_revision_delta use it. |
393 |
def get_revision_delta(self, revision_id): |
394 |
"""Return the delta for one revision.
|
|
395 |
||
396 |
The delta is relative to the left-hand predecessor of the
|
|
397 |
revision.
|
|
398 |
"""
|
|
1756.3.3
by Aaron Bentley
More refactoring, introduce revision_trees. |
399 |
r = self.get_revision(revision_id) |
1756.3.22
by Aaron Bentley
Tweaks from review |
400 |
return list(self.get_deltas_for_revisions([r]))[0] |
1744.2.2
by Johan Rydberg
Add get_revision_delta to Repository; and make Branch.get_revision_delta use it. |
401 |
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
402 |
def _check_revision_parents(self, revision, inventory): |
403 |
"""Private to Repository and Fetch.
|
|
404 |
|
|
405 |
This checks the parentage of revision in an inventory weave for
|
|
406 |
consistency and is only applicable to inventory-weave-for-ancestry
|
|
407 |
using repository formats & fetchers.
|
|
408 |
"""
|
|
1563.2.25
by Robert Collins
Merge in upstream. |
409 |
weave_parents = inventory.get_parents(revision.revision_id) |
410 |
weave_names = inventory.versions() |
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
411 |
for parent_id in revision.parent_ids: |
1570.1.13
by Robert Collins
Check for incorrect revision parentage in the weave during revision access. |
412 |
if parent_id in weave_names: |
413 |
# this parent must not be a ghost.
|
|
414 |
if not parent_id in weave_parents: |
|
415 |
# but it is a ghost
|
|
416 |
raise errors.CorruptRepository(self) |
|
417 |
||
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
418 |
@needs_write_lock
|
419 |
def store_revision_signature(self, gpg_strategy, plaintext, revision_id): |
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
420 |
signature = gpg_strategy.sign(plaintext) |
421 |
self._revision_store.add_revision_signature_text(revision_id, |
|
422 |
signature, |
|
423 |
self.get_transaction()) |
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
424 |
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
425 |
def fileids_altered_by_revision_ids(self, revision_ids): |
426 |
"""Find the file ids and versions affected by revisions.
|
|
427 |
||
428 |
:param revisions: an iterable containing revision ids.
|
|
429 |
:return: a dictionary mapping altered file-ids to an iterable of
|
|
430 |
revision_ids. Each altered file-ids has the exact revision_ids that
|
|
431 |
altered it listed explicitly.
|
|
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
432 |
"""
|
1910.2.48
by Aaron Bentley
Update from review comments |
433 |
assert self._serializer.support_altered_by_hack, \ |
1732.2.1
by Martin Pool
Remove obsolete fileid_involved from KnitRepository, fix error message. |
434 |
("fileids_altered_by_revision_ids only supported for branches " |
435 |
"which store inventory as unnested xml, not on %r" % self) |
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
436 |
selected_revision_ids = set(revision_ids) |
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
437 |
w = self.get_inventory_weave() |
1694.2.6
by Martin Pool
[merge] bzr.dev |
438 |
result = {} |
1563.2.35
by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too. |
439 |
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
440 |
# this code needs to read every new line in every inventory for the
|
441 |
# inventories [revision_ids]. Seeing a line twice is ok. Seeing a line
|
|
1759.2.1
by Jelmer Vernooij
Fix some types (found using aspell). |
442 |
# not present in one of those inventories is unnecessary but not
|
1594.2.6
by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved. |
443 |
# harmful because we are filtering by the revision id marker in the
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
444 |
# inventory lines : we only select file ids altered in one of those
|
1759.2.2
by Jelmer Vernooij
Revert some of my spelling fixes and fix some typos after review by Aaron. |
445 |
# revisions. We don't need to see all lines in the inventory because
|
1594.2.6
by Robert Collins
Introduce a api specifically for looking at lines in some versions of the inventory, for fileid_involved. |
446 |
# only those added in an inventory in rev X can contain a revision=X
|
447 |
# line.
|
|
2163.2.3
by John Arbash Meinel
Change to local variables to save another 300ms |
448 |
unescape_revid_cache = {} |
449 |
unescape_fileid_cache = {} |
|
450 |
||
2163.2.5
by John Arbash Meinel
Inline the cache lookup, and explain why |
451 |
# jam 20061218 In a big fetch, this handles hundreds of thousands
|
452 |
# of lines, so it has had a lot of inlining and optimizing done.
|
|
453 |
# Sorry that it is a little bit messy.
|
|
2163.2.3
by John Arbash Meinel
Change to local variables to save another 300ms |
454 |
# Move several functions to be local variables, since this is a long
|
455 |
# running loop.
|
|
456 |
search = self._file_ids_altered_regex.search |
|
2163.2.5
by John Arbash Meinel
Inline the cache lookup, and explain why |
457 |
unescape = _unescape_xml |
2163.2.3
by John Arbash Meinel
Change to local variables to save another 300ms |
458 |
setdefault = result.setdefault |
2039.1.1
by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000) |
459 |
pb = ui.ui_factory.nested_progress_bar() |
460 |
try: |
|
461 |
for line in w.iter_lines_added_or_present_in_versions( |
|
2163.2.3
by John Arbash Meinel
Change to local variables to save another 300ms |
462 |
selected_revision_ids, pb=pb): |
463 |
match = search(line) |
|
2163.2.1
by John Arbash Meinel
Speed up the fileids_altered_by_revision_ids processing |
464 |
if match is None: |
465 |
continue
|
|
2163.2.5
by John Arbash Meinel
Inline the cache lookup, and explain why |
466 |
# One call to match.group() returning multiple items is quite a
|
467 |
# bit faster than 2 calls to match.group() each returning 1
|
|
2163.2.1
by John Arbash Meinel
Speed up the fileids_altered_by_revision_ids processing |
468 |
file_id, revision_id = match.group('file_id', 'revision_id') |
2163.2.5
by John Arbash Meinel
Inline the cache lookup, and explain why |
469 |
|
470 |
# Inlining the cache lookups helps a lot when you make 170,000
|
|
471 |
# lines and 350k ids, versus 8.4 unique ids.
|
|
472 |
# Using a cache helps in 2 ways:
|
|
473 |
# 1) Avoids unnecessary decoding calls
|
|
474 |
# 2) Re-uses cached strings, which helps in future set and
|
|
475 |
# equality checks.
|
|
476 |
# (2) is enough that removing encoding entirely along with
|
|
477 |
# the cache (so we are using plain strings) results in no
|
|
478 |
# performance improvement.
|
|
479 |
try: |
|
480 |
revision_id = unescape_revid_cache[revision_id] |
|
481 |
except KeyError: |
|
482 |
unescaped = unescape(revision_id) |
|
483 |
unescape_revid_cache[revision_id] = unescaped |
|
484 |
revision_id = unescaped |
|
485 |
||
2039.1.1
by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000) |
486 |
if revision_id in selected_revision_ids: |
2163.2.5
by John Arbash Meinel
Inline the cache lookup, and explain why |
487 |
try: |
488 |
file_id = unescape_fileid_cache[file_id] |
|
489 |
except KeyError: |
|
490 |
unescaped = unescape(file_id) |
|
491 |
unescape_fileid_cache[file_id] = unescaped |
|
492 |
file_id = unescaped |
|
2163.2.3
by John Arbash Meinel
Change to local variables to save another 300ms |
493 |
setdefault(file_id, set()).add(revision_id) |
2039.1.1
by Aaron Bentley
Clean up progress properly when interrupted during fetch (#54000) |
494 |
finally: |
495 |
pb.finished() |
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
496 |
return result |
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
497 |
|
1185.65.27
by Robert Collins
Tweak storage towards mergability. |
498 |
@needs_read_lock
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
499 |
def get_inventory_weave(self): |
500 |
return self.control_weaves.get_weave('inventory', |
|
501 |
self.get_transaction()) |
|
502 |
||
1185.65.27
by Robert Collins
Tweak storage towards mergability. |
503 |
@needs_read_lock
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
504 |
def get_inventory(self, revision_id): |
505 |
"""Get Inventory object by hash."""
|
|
1740.2.3
by Aaron Bentley
Only reserialize the working tree basis inventory when needed. |
506 |
return self.deserialise_inventory( |
507 |
revision_id, self.get_inventory_xml(revision_id)) |
|
508 |
||
509 |
def deserialise_inventory(self, revision_id, xml): |
|
510 |
"""Transform the xml into an inventory object.
|
|
511 |
||
512 |
:param revision_id: The expected revision id of the inventory.
|
|
513 |
:param xml: A serialised inventory.
|
|
514 |
"""
|
|
1910.2.48
by Aaron Bentley
Update from review comments |
515 |
result = self._serializer.read_inventory_from_string(xml) |
1910.2.1
by Aaron Bentley
Ensure root entry always has a revision |
516 |
result.root.revision = revision_id |
517 |
return result |
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
518 |
|
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
519 |
def serialise_inventory(self, inv): |
1910.2.48
by Aaron Bentley
Update from review comments |
520 |
return self._serializer.write_inventory_to_string(inv) |
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
521 |
|
1185.65.27
by Robert Collins
Tweak storage towards mergability. |
522 |
@needs_read_lock
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
523 |
def get_inventory_xml(self, revision_id): |
524 |
"""Get inventory XML as a file object."""
|
|
525 |
try: |
|
526 |
assert isinstance(revision_id, basestring), type(revision_id) |
|
527 |
iw = self.get_inventory_weave() |
|
1563.2.18
by Robert Collins
get knit repositories really using knits for text storage. |
528 |
return iw.get_text(revision_id) |
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
529 |
except IndexError: |
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
530 |
raise errors.HistoryMissing(self, 'inventory', revision_id) |
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
531 |
|
1185.65.27
by Robert Collins
Tweak storage towards mergability. |
532 |
@needs_read_lock
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
533 |
def get_inventory_sha1(self, revision_id): |
534 |
"""Return the sha1 hash of the inventory entry
|
|
535 |
"""
|
|
536 |
return self.get_revision(revision_id).inventory_sha1 |
|
537 |
||
1185.65.27
by Robert Collins
Tweak storage towards mergability. |
538 |
@needs_read_lock
|
1590.1.1
by Robert Collins
Improve common_ancestor performance. |
539 |
def get_revision_graph(self, revision_id=None): |
540 |
"""Return a dictionary containing the revision graph.
|
|
541 |
|
|
1836.3.1
by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION. |
542 |
:param revision_id: The revision_id to get a graph from. If None, then
|
543 |
the entire revision graph is returned. This is a deprecated mode of
|
|
544 |
operation and will be removed in the future.
|
|
1590.1.1
by Robert Collins
Improve common_ancestor performance. |
545 |
:return: a dictionary of revision_id->revision_parents_list.
|
546 |
"""
|
|
1836.3.1
by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION. |
547 |
# special case NULL_REVISION
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
548 |
if revision_id == _mod_revision.NULL_REVISION: |
1836.3.1
by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION. |
549 |
return {} |
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
550 |
a_weave = self.get_inventory_weave() |
551 |
all_revisions = self._eliminate_revisions_not_present( |
|
552 |
a_weave.versions()) |
|
553 |
entire_graph = dict([(node, a_weave.get_parents(node)) for |
|
1590.1.1
by Robert Collins
Improve common_ancestor performance. |
554 |
node in all_revisions]) |
555 |
if revision_id is None: |
|
556 |
return entire_graph |
|
557 |
elif revision_id not in entire_graph: |
|
558 |
raise errors.NoSuchRevision(self, revision_id) |
|
559 |
else: |
|
560 |
# add what can be reached from revision_id
|
|
561 |
result = {} |
|
562 |
pending = set([revision_id]) |
|
563 |
while len(pending) > 0: |
|
564 |
node = pending.pop() |
|
565 |
result[node] = entire_graph[node] |
|
566 |
for revision_id in result[node]: |
|
567 |
if revision_id not in result: |
|
568 |
pending.add(revision_id) |
|
569 |
return result |
|
570 |
||
571 |
@needs_read_lock
|
|
1594.2.3
by Robert Collins
bugfix revision.MultipleRevisionSources.get_revision_graph to integrate ghosts between sources. [slow on weaves, fast on knits. |
572 |
def get_revision_graph_with_ghosts(self, revision_ids=None): |
573 |
"""Return a graph of the revisions with ghosts marked as applicable.
|
|
574 |
||
575 |
:param revision_ids: an iterable of revisions to graph or None for all.
|
|
576 |
:return: a Graph object with the graph reachable from revision_ids.
|
|
577 |
"""
|
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
578 |
result = graph.Graph() |
1594.2.3
by Robert Collins
bugfix revision.MultipleRevisionSources.get_revision_graph to integrate ghosts between sources. [slow on weaves, fast on knits. |
579 |
if not revision_ids: |
1773.4.2
by Martin Pool
Cleanup of imports; undeprecate all_revision_ids() |
580 |
pending = set(self.all_revision_ids()) |
1594.2.3
by Robert Collins
bugfix revision.MultipleRevisionSources.get_revision_graph to integrate ghosts between sources. [slow on weaves, fast on knits. |
581 |
required = set([]) |
582 |
else: |
|
583 |
pending = set(revision_ids) |
|
1836.3.1
by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION. |
584 |
# special case NULL_REVISION
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
585 |
if _mod_revision.NULL_REVISION in pending: |
586 |
pending.remove(_mod_revision.NULL_REVISION) |
|
1836.3.1
by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION. |
587 |
required = set(pending) |
1594.2.3
by Robert Collins
bugfix revision.MultipleRevisionSources.get_revision_graph to integrate ghosts between sources. [slow on weaves, fast on knits. |
588 |
done = set([]) |
589 |
while len(pending): |
|
590 |
revision_id = pending.pop() |
|
591 |
try: |
|
592 |
rev = self.get_revision(revision_id) |
|
593 |
except errors.NoSuchRevision: |
|
594 |
if revision_id in required: |
|
595 |
raise
|
|
596 |
# a ghost
|
|
597 |
result.add_ghost(revision_id) |
|
598 |
continue
|
|
599 |
for parent_id in rev.parent_ids: |
|
600 |
# is this queued or done ?
|
|
601 |
if (parent_id not in pending and |
|
602 |
parent_id not in done): |
|
603 |
# no, queue it.
|
|
604 |
pending.add(parent_id) |
|
605 |
result.add_node(revision_id, rev.parent_ids) |
|
1594.2.15
by Robert Collins
Unfuck performance. |
606 |
done.add(revision_id) |
1594.2.3
by Robert Collins
bugfix revision.MultipleRevisionSources.get_revision_graph to integrate ghosts between sources. [slow on weaves, fast on knits. |
607 |
return result |
608 |
||
609 |
@needs_read_lock
|
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
610 |
def get_revision_inventory(self, revision_id): |
611 |
"""Return inventory of a past revision."""
|
|
612 |
# TODO: Unify this with get_inventory()
|
|
613 |
# bzr 0.0.6 and later imposes the constraint that the inventory_id
|
|
614 |
# must be the same as its revision, so this is trivial.
|
|
1534.4.28
by Robert Collins
first cut at merge from integration. |
615 |
if revision_id is None: |
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
616 |
# This does not make sense: if there is no revision,
|
617 |
# then it is the current tree inventory surely ?!
|
|
618 |
# and thus get_root_id() is something that looks at the last
|
|
619 |
# commit on the branch, and the get_root_id is an inventory check.
|
|
620 |
raise NotImplementedError |
|
621 |
# return Inventory(self.get_root_id())
|
|
622 |
else: |
|
623 |
return self.get_inventory(revision_id) |
|
624 |
||
1185.65.27
by Robert Collins
Tweak storage towards mergability. |
625 |
@needs_read_lock
|
1534.6.3
by Robert Collins
find_repository sufficiently robust. |
626 |
def is_shared(self): |
627 |
"""Return True if this repository is flagged as a shared repository."""
|
|
1596.2.12
by Robert Collins
Merge and make Knit Repository use the revision store for all possible queries. |
628 |
raise NotImplementedError(self.is_shared) |
1534.6.3
by Robert Collins
find_repository sufficiently robust. |
629 |
|
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
630 |
@needs_write_lock
|
1692.1.1
by Robert Collins
* Repository.reconcile now takes a thorough keyword parameter to allow |
631 |
def reconcile(self, other=None, thorough=False): |
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
632 |
"""Reconcile this repository."""
|
633 |
from bzrlib.reconcile import RepoReconciler |
|
1692.1.1
by Robert Collins
* Repository.reconcile now takes a thorough keyword parameter to allow |
634 |
reconciler = RepoReconciler(self, thorough=thorough) |
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
635 |
reconciler.reconcile() |
636 |
return reconciler |
|
637 |
||
1534.6.3
by Robert Collins
find_repository sufficiently robust. |
638 |
@needs_read_lock
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
639 |
def revision_tree(self, revision_id): |
640 |
"""Return Tree for a revision on this branch.
|
|
641 |
||
1852.5.1
by Robert Collins
Deprecate EmptyTree in favour of using Repository.revision_tree. |
642 |
`revision_id` may be None for the empty tree revision.
|
643 |
"""
|
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
644 |
# TODO: refactor this to use an existing revision object
|
645 |
# so we don't need to read it in twice.
|
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
646 |
if revision_id is None or revision_id == _mod_revision.NULL_REVISION: |
1731.1.61
by Aaron Bentley
Merge bzr.dev |
647 |
return RevisionTree(self, Inventory(root_id=None), |
648 |
_mod_revision.NULL_REVISION) |
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
649 |
else: |
650 |
inv = self.get_revision_inventory(revision_id) |
|
1185.65.17
by Robert Collins
Merge from integration, mode-changes are broken. |
651 |
return RevisionTree(self, inv, revision_id) |
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
652 |
|
1185.65.27
by Robert Collins
Tweak storage towards mergability. |
653 |
@needs_read_lock
|
1756.3.3
by Aaron Bentley
More refactoring, introduce revision_trees. |
654 |
def revision_trees(self, revision_ids): |
655 |
"""Return Tree for a revision on this branch.
|
|
656 |
||
1756.3.19
by Aaron Bentley
Documentation and cleanups |
657 |
`revision_id` may not be None or 'null:'"""
|
1756.3.3
by Aaron Bentley
More refactoring, introduce revision_trees. |
658 |
assert None not in revision_ids |
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
659 |
assert _mod_revision.NULL_REVISION not in revision_ids |
1756.3.5
by Aaron Bentley
Switch to get_texts, optimize get_texts |
660 |
texts = self.get_inventory_weave().get_texts(revision_ids) |
1756.3.3
by Aaron Bentley
More refactoring, introduce revision_trees. |
661 |
for text, revision_id in zip(texts, revision_ids): |
662 |
inv = self.deserialise_inventory(revision_id, text) |
|
663 |
yield RevisionTree(self, inv, revision_id) |
|
664 |
||
665 |
@needs_read_lock
|
|
1185.66.2
by Aaron Bentley
Moved get_ancestry to RevisionStorage |
666 |
def get_ancestry(self, revision_id): |
667 |
"""Return a list of revision-ids integrated by a revision.
|
|
1732.2.4
by Martin Pool
Split check into Branch.check and Repository.check |
668 |
|
669 |
The first element of the list is always None, indicating the origin
|
|
670 |
revision. This might change when we have history horizons, or
|
|
671 |
perhaps we should have a new API.
|
|
1185.66.2
by Aaron Bentley
Moved get_ancestry to RevisionStorage |
672 |
|
673 |
This is topologically sorted.
|
|
674 |
"""
|
|
675 |
if revision_id is None: |
|
676 |
return [None] |
|
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
677 |
if not self.has_revision(revision_id): |
678 |
raise errors.NoSuchRevision(self, revision_id) |
|
1185.66.2
by Aaron Bentley
Moved get_ancestry to RevisionStorage |
679 |
w = self.get_inventory_weave() |
1594.2.9
by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all. |
680 |
candidates = w.get_ancestry(revision_id) |
681 |
return [None] + candidates # self._eliminate_revisions_not_present(candidates) |
|
1185.66.2
by Aaron Bentley
Moved get_ancestry to RevisionStorage |
682 |
|
1185.65.4
by Aaron Bentley
Fixed cat command |
683 |
@needs_read_lock
|
684 |
def print_file(self, file, revision_id): |
|
1185.65.29
by Robert Collins
Implement final review suggestions. |
685 |
"""Print `file` to stdout.
|
686 |
|
|
687 |
FIXME RBC 20060125 as John Meinel points out this is a bad api
|
|
688 |
- it writes to stdout, it assumes that that is valid etc. Fix
|
|
689 |
by creating a new more flexible convenience function.
|
|
690 |
"""
|
|
1185.65.4
by Aaron Bentley
Fixed cat command |
691 |
tree = self.revision_tree(revision_id) |
692 |
# use inventory as it was in that revision
|
|
693 |
file_id = tree.inventory.path2id(file) |
|
694 |
if not file_id: |
|
1685.1.26
by John Arbash Meinel
Repository had a bug with what exception was raised when a file was missing |
695 |
# TODO: jam 20060427 Write a test for this code path
|
696 |
# it had a bug in it, and was raising the wrong
|
|
697 |
# exception.
|
|
698 |
raise errors.BzrError("%r is not present in revision %s" % (file, revision_id)) |
|
1185.65.4
by Aaron Bentley
Fixed cat command |
699 |
tree.print_file(file_id) |
700 |
||
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
701 |
def get_transaction(self): |
702 |
return self.control_files.get_transaction() |
|
703 |
||
1590.1.1
by Robert Collins
Improve common_ancestor performance. |
704 |
def revision_parents(self, revid): |
705 |
return self.get_inventory_weave().parent_names(revid) |
|
706 |
||
1185.65.27
by Robert Collins
Tweak storage towards mergability. |
707 |
@needs_write_lock
|
1534.6.5
by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes. |
708 |
def set_make_working_trees(self, new_value): |
709 |
"""Set the policy flag for making working trees when creating branches.
|
|
710 |
||
711 |
This only applies to branches that use this repository.
|
|
712 |
||
713 |
The default is 'True'.
|
|
714 |
:param new_value: True to restore the default, False to disable making
|
|
715 |
working trees.
|
|
716 |
"""
|
|
1596.2.12
by Robert Collins
Merge and make Knit Repository use the revision store for all possible queries. |
717 |
raise NotImplementedError(self.set_make_working_trees) |
1534.6.5
by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes. |
718 |
|
719 |
def make_working_trees(self): |
|
720 |
"""Returns the policy for making working trees on new branches."""
|
|
1596.2.12
by Robert Collins
Merge and make Knit Repository use the revision store for all possible queries. |
721 |
raise NotImplementedError(self.make_working_trees) |
1534.6.5
by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes. |
722 |
|
723 |
@needs_write_lock
|
|
1185.65.1
by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch |
724 |
def sign_revision(self, revision_id, gpg_strategy): |
725 |
plaintext = Testament.from_revision(self, revision_id).as_short_text() |
|
726 |
self.store_revision_signature(gpg_strategy, plaintext, revision_id) |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
727 |
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
728 |
@needs_read_lock
|
729 |
def has_signature_for_revision_id(self, revision_id): |
|
730 |
"""Query for a revision signature for revision_id in the repository."""
|
|
731 |
return self._revision_store.has_signature(revision_id, |
|
732 |
self.get_transaction()) |
|
733 |
||
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
734 |
@needs_read_lock
|
735 |
def get_signature_text(self, revision_id): |
|
736 |
"""Return the text for a signature."""
|
|
737 |
return self._revision_store.get_signature_text(revision_id, |
|
738 |
self.get_transaction()) |
|
739 |
||
1732.2.4
by Martin Pool
Split check into Branch.check and Repository.check |
740 |
@needs_read_lock
|
741 |
def check(self, revision_ids): |
|
742 |
"""Check consistency of all history of given revision_ids.
|
|
743 |
||
744 |
Different repository implementations should override _check().
|
|
745 |
||
746 |
:param revision_ids: A non-empty list of revision_ids whose ancestry
|
|
747 |
will be checked. Typically the last revision_id of a branch.
|
|
748 |
"""
|
|
749 |
if not revision_ids: |
|
750 |
raise ValueError("revision_ids must be non-empty in %s.check" |
|
751 |
% (self,)) |
|
752 |
return self._check(revision_ids) |
|
753 |
||
754 |
def _check(self, revision_ids): |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
755 |
result = check.Check(self) |
1732.2.4
by Martin Pool
Split check into Branch.check and Repository.check |
756 |
result.check() |
757 |
return result |
|
758 |
||
1904.2.3
by Martin Pool
Give a warning on access to old repository formats |
759 |
def _warn_if_deprecated(self): |
1904.2.5
by Martin Pool
Fix format warning inside test suite and add test |
760 |
global _deprecation_warning_done |
761 |
if _deprecation_warning_done: |
|
762 |
return
|
|
763 |
_deprecation_warning_done = True |
|
1904.2.3
by Martin Pool
Give a warning on access to old repository formats |
764 |
warning("Format %s for %s is deprecated - please use 'bzr upgrade' to get better performance" |
765 |
% (self._format, self.bzrdir.transport.base)) |
|
766 |
||
1910.2.63
by Aaron Bentley
Add supports_rich_root member to repository |
767 |
def supports_rich_root(self): |
768 |
return self._format.rich_root_data |
|
769 |
||
2150.2.2
by Robert Collins
Change the commit builder selected-revision-id test to use a unicode revision id where possible, leading to stricter testing of the hypothetical unicode revision id support in bzr. |
770 |
def _check_ascii_revisionid(self, revision_id, method): |
771 |
"""Private helper for ascii-only repositories."""
|
|
772 |
# weave repositories refuse to store revisionids that are non-ascii.
|
|
773 |
if revision_id is not None: |
|
774 |
# weaves require ascii revision ids.
|
|
775 |
if isinstance(revision_id, unicode): |
|
776 |
try: |
|
777 |
revision_id.encode('ascii') |
|
778 |
except UnicodeEncodeError: |
|
779 |
raise errors.NonAsciiRevisionId(method, self) |
|
780 |
||
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
781 |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
782 |
class AllInOneRepository(Repository): |
783 |
"""Legacy support - the repository behaviour for all-in-one branches."""
|
|
784 |
||
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
785 |
def __init__(self, _format, a_bzrdir, _revision_store, control_store, text_store): |
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
786 |
# we reuse one control files instance.
|
787 |
dir_mode = a_bzrdir._control_files._dir_mode |
|
788 |
file_mode = a_bzrdir._control_files._file_mode |
|
789 |
||
790 |
def get_store(name, compressed=True, prefixed=False): |
|
791 |
# FIXME: This approach of assuming stores are all entirely compressed
|
|
792 |
# or entirely uncompressed is tidy, but breaks upgrade from
|
|
793 |
# some existing branches where there's a mixture; we probably
|
|
794 |
# still want the option to look for both.
|
|
795 |
relpath = a_bzrdir._control_files._escape(name) |
|
796 |
store = TextStore(a_bzrdir._control_files._transport.clone(relpath), |
|
797 |
prefixed=prefixed, compressed=compressed, |
|
798 |
dir_mode=dir_mode, |
|
799 |
file_mode=file_mode) |
|
800 |
#if self._transport.should_cache():
|
|
801 |
# cache_path = os.path.join(self.cache_root, name)
|
|
802 |
# os.mkdir(cache_path)
|
|
803 |
# store = bzrlib.store.CachedStore(store, cache_path)
|
|
804 |
return store |
|
805 |
||
806 |
# not broken out yet because the controlweaves|inventory_store
|
|
807 |
# and text_store | weave_store bits are still different.
|
|
808 |
if isinstance(_format, RepositoryFormat4): |
|
1563.2.23
by Robert Collins
Add add_revision and get_revision methods to RevisionStore |
809 |
# cannot remove these - there is still no consistent api
|
810 |
# which allows access to this old info.
|
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
811 |
self.inventory_store = get_store('inventory-store') |
1563.2.18
by Robert Collins
get knit repositories really using knits for text storage. |
812 |
text_store = get_store('text-store') |
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
813 |
super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, _revision_store, control_store, text_store) |
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
814 |
|
2150.2.2
by Robert Collins
Change the commit builder selected-revision-id test to use a unicode revision id where possible, leading to stricter testing of the hypothetical unicode revision id support in bzr. |
815 |
def get_commit_builder(self, branch, parents, config, timestamp=None, |
816 |
timezone=None, committer=None, revprops=None, |
|
817 |
revision_id=None): |
|
818 |
self._check_ascii_revisionid(revision_id, self.get_commit_builder) |
|
819 |
return Repository.get_commit_builder(self, branch, parents, config, |
|
820 |
timestamp, timezone, committer, revprops, revision_id) |
|
821 |
||
1596.2.12
by Robert Collins
Merge and make Knit Repository use the revision store for all possible queries. |
822 |
@needs_read_lock
|
823 |
def is_shared(self): |
|
824 |
"""AllInOne repositories cannot be shared."""
|
|
825 |
return False |
|
826 |
||
827 |
@needs_write_lock
|
|
828 |
def set_make_working_trees(self, new_value): |
|
829 |
"""Set the policy flag for making working trees when creating branches.
|
|
830 |
||
831 |
This only applies to branches that use this repository.
|
|
832 |
||
833 |
The default is 'True'.
|
|
834 |
:param new_value: True to restore the default, False to disable making
|
|
835 |
working trees.
|
|
836 |
"""
|
|
837 |
raise NotImplementedError(self.set_make_working_trees) |
|
838 |
||
839 |
def make_working_trees(self): |
|
840 |
"""Returns the policy for making working trees on new branches."""
|
|
841 |
return True |
|
842 |
||
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
843 |
|
1185.82.84
by Aaron Bentley
Moved stuff around |
844 |
def install_revision(repository, rev, revision_tree): |
845 |
"""Install all revision data into a repository."""
|
|
846 |
present_parents = [] |
|
847 |
parent_trees = {} |
|
848 |
for p_id in rev.parent_ids: |
|
849 |
if repository.has_revision(p_id): |
|
850 |
present_parents.append(p_id) |
|
851 |
parent_trees[p_id] = repository.revision_tree(p_id) |
|
852 |
else: |
|
1852.5.1
by Robert Collins
Deprecate EmptyTree in favour of using Repository.revision_tree. |
853 |
parent_trees[p_id] = repository.revision_tree(None) |
1185.82.84
by Aaron Bentley
Moved stuff around |
854 |
|
855 |
inv = revision_tree.inventory |
|
1910.2.51
by Aaron Bentley
Bundles now corrupt repositories |
856 |
entries = inv.iter_entries() |
1852.6.3
by Robert Collins
Make iter(Tree) consistent for all tree types. |
857 |
# backwards compatability hack: skip the root id.
|
1910.2.63
by Aaron Bentley
Add supports_rich_root member to repository |
858 |
if not repository.supports_rich_root(): |
1910.2.60
by Aaron Bentley
Ensure that new-model revisions aren't installed into old-model repos |
859 |
path, root = entries.next() |
860 |
if root.revision != rev.revision_id: |
|
1910.2.63
by Aaron Bentley
Add supports_rich_root member to repository |
861 |
raise errors.IncompatibleRevision(repr(repository)) |
1185.82.84
by Aaron Bentley
Moved stuff around |
862 |
# Add the texts that are not already present
|
1852.6.3
by Robert Collins
Make iter(Tree) consistent for all tree types. |
863 |
for path, ie in entries: |
1185.82.84
by Aaron Bentley
Moved stuff around |
864 |
w = repository.weave_store.get_weave_or_empty(ie.file_id, |
865 |
repository.get_transaction()) |
|
866 |
if ie.revision not in w: |
|
867 |
text_parents = [] |
|
1740.2.2
by Aaron Bentley
Add test for the basis inventory automatically adding the revision id. |
868 |
# FIXME: TODO: The following loop *may* be overlapping/duplicate
|
1759.2.1
by Jelmer Vernooij
Fix some types (found using aspell). |
869 |
# with InventoryEntry.find_previous_heads(). if it is, then there
|
1740.2.2
by Aaron Bentley
Add test for the basis inventory automatically adding the revision id. |
870 |
# is a latent bug here where the parents may have ancestors of each
|
871 |
# other. RBC, AB
|
|
1185.82.84
by Aaron Bentley
Moved stuff around |
872 |
for revision, tree in parent_trees.iteritems(): |
873 |
if ie.file_id not in tree: |
|
874 |
continue
|
|
875 |
parent_id = tree.inventory[ie.file_id].revision |
|
876 |
if parent_id in text_parents: |
|
877 |
continue
|
|
878 |
text_parents.append(parent_id) |
|
879 |
||
880 |
vfile = repository.weave_store.get_weave_or_empty(ie.file_id, |
|
881 |
repository.get_transaction()) |
|
882 |
lines = revision_tree.get_file(ie.file_id).readlines() |
|
883 |
vfile.add_lines(rev.revision_id, text_parents, lines) |
|
884 |
try: |
|
885 |
# install the inventory
|
|
886 |
repository.add_inventory(rev.revision_id, inv, present_parents) |
|
887 |
except errors.RevisionAlreadyPresent: |
|
888 |
pass
|
|
889 |
repository.add_revision(rev.revision_id, rev, inv) |
|
890 |
||
891 |
||
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
892 |
class MetaDirRepository(Repository): |
893 |
"""Repositories in the new meta-dir layout."""
|
|
894 |
||
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
895 |
def __init__(self, _format, a_bzrdir, control_files, _revision_store, control_store, text_store): |
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
896 |
super(MetaDirRepository, self).__init__(_format, |
897 |
a_bzrdir, |
|
898 |
control_files, |
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
899 |
_revision_store, |
1563.2.23
by Robert Collins
Add add_revision and get_revision methods to RevisionStore |
900 |
control_store, |
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
901 |
text_store) |
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
902 |
dir_mode = self.control_files._dir_mode |
903 |
file_mode = self.control_files._file_mode |
|
904 |
||
1596.2.12
by Robert Collins
Merge and make Knit Repository use the revision store for all possible queries. |
905 |
@needs_read_lock
|
906 |
def is_shared(self): |
|
907 |
"""Return True if this repository is flagged as a shared repository."""
|
|
908 |
return self.control_files._transport.has('shared-storage') |
|
909 |
||
910 |
@needs_write_lock
|
|
911 |
def set_make_working_trees(self, new_value): |
|
912 |
"""Set the policy flag for making working trees when creating branches.
|
|
913 |
||
914 |
This only applies to branches that use this repository.
|
|
915 |
||
916 |
The default is 'True'.
|
|
917 |
:param new_value: True to restore the default, False to disable making
|
|
918 |
working trees.
|
|
919 |
"""
|
|
920 |
if new_value: |
|
921 |
try: |
|
922 |
self.control_files._transport.delete('no-working-trees') |
|
923 |
except errors.NoSuchFile: |
|
924 |
pass
|
|
925 |
else: |
|
926 |
self.control_files.put_utf8('no-working-trees', '') |
|
927 |
||
928 |
def make_working_trees(self): |
|
929 |
"""Returns the policy for making working trees on new branches."""
|
|
930 |
return not self.control_files._transport.has('no-working-trees') |
|
931 |
||
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
932 |
|
2150.2.2
by Robert Collins
Change the commit builder selected-revision-id test to use a unicode revision id where possible, leading to stricter testing of the hypothetical unicode revision id support in bzr. |
933 |
class WeaveMetaDirRepository(MetaDirRepository): |
934 |
"""A subclass of MetaDirRepository to set weave specific policy."""
|
|
935 |
||
936 |
def get_commit_builder(self, branch, parents, config, timestamp=None, |
|
937 |
timezone=None, committer=None, revprops=None, |
|
938 |
revision_id=None): |
|
939 |
self._check_ascii_revisionid(revision_id, self.get_commit_builder) |
|
940 |
return MetaDirRepository.get_commit_builder(self, branch, parents, |
|
941 |
config, timestamp, timezone, committer, revprops, revision_id) |
|
942 |
||
943 |
||
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
944 |
class KnitRepository(MetaDirRepository): |
945 |
"""Knit format repository."""
|
|
946 |
||
1904.2.3
by Martin Pool
Give a warning on access to old repository formats |
947 |
def _warn_if_deprecated(self): |
948 |
# This class isn't deprecated
|
|
949 |
pass
|
|
950 |
||
1740.3.6
by Jelmer Vernooij
Move inventory writing to the commit builder. |
951 |
def _inventory_add_lines(self, inv_vf, revid, parents, lines): |
952 |
inv_vf.add_lines_with_ghosts(revid, parents, lines) |
|
953 |
||
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
954 |
@needs_read_lock
|
1732.2.4
by Martin Pool
Split check into Branch.check and Repository.check |
955 |
def _all_revision_ids(self): |
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
956 |
"""See Repository.all_revision_ids()."""
|
1732.2.4
by Martin Pool
Split check into Branch.check and Repository.check |
957 |
# Knits get the revision graph from the index of the revision knit, so
|
958 |
# it's always possible even if they're on an unlistable transport.
|
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
959 |
return self._revision_store.all_revision_ids(self.get_transaction()) |
960 |
||
1732.2.6
by Martin Pool
Restore removed fileid_involved* methods |
961 |
def fileid_involved_between_revs(self, from_revid, to_revid): |
962 |
"""Find file_id(s) which are involved in the changes between revisions.
|
|
963 |
||
964 |
This determines the set of revisions which are involved, and then
|
|
965 |
finds all file ids affected by those revisions.
|
|
966 |
"""
|
|
967 |
vf = self._get_revision_vf() |
|
968 |
from_set = set(vf.get_ancestry(from_revid)) |
|
969 |
to_set = set(vf.get_ancestry(to_revid)) |
|
970 |
changed = to_set.difference(from_set) |
|
971 |
return self._fileid_involved_by_set(changed) |
|
972 |
||
973 |
def fileid_involved(self, last_revid=None): |
|
974 |
"""Find all file_ids modified in the ancestry of last_revid.
|
|
975 |
||
976 |
:param last_revid: If None, last_revision() will be used.
|
|
977 |
"""
|
|
978 |
if not last_revid: |
|
979 |
changed = set(self.all_revision_ids()) |
|
980 |
else: |
|
981 |
changed = set(self.get_ancestry(last_revid)) |
|
982 |
if None in changed: |
|
983 |
changed.remove(None) |
|
984 |
return self._fileid_involved_by_set(changed) |
|
985 |
||
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
986 |
@needs_read_lock
|
987 |
def get_ancestry(self, revision_id): |
|
988 |
"""Return a list of revision-ids integrated by a revision.
|
|
989 |
|
|
990 |
This is topologically sorted.
|
|
991 |
"""
|
|
992 |
if revision_id is None: |
|
993 |
return [None] |
|
1596.2.12
by Robert Collins
Merge and make Knit Repository use the revision store for all possible queries. |
994 |
vf = self._get_revision_vf() |
1594.2.9
by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all. |
995 |
try: |
996 |
return [None] + vf.get_ancestry(revision_id) |
|
997 |
except errors.RevisionNotPresent: |
|
998 |
raise errors.NoSuchRevision(self, revision_id) |
|
999 |
||
1000 |
@needs_read_lock
|
|
1594.2.10
by Robert Collins
Teach knit fetching and branching to only duplicate relevant data avoiding unnecessary reconciles. |
1001 |
def get_revision(self, revision_id): |
1002 |
"""Return the Revision object for a named revision"""
|
|
1003 |
return self.get_revision_reconcile(revision_id) |
|
1004 |
||
1005 |
@needs_read_lock
|
|
1596.2.12
by Robert Collins
Merge and make Knit Repository use the revision store for all possible queries. |
1006 |
def get_revision_graph(self, revision_id=None): |
1007 |
"""Return a dictionary containing the revision graph.
|
|
1836.3.1
by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION. |
1008 |
|
1009 |
:param revision_id: The revision_id to get a graph from. If None, then
|
|
1010 |
the entire revision graph is returned. This is a deprecated mode of
|
|
1011 |
operation and will be removed in the future.
|
|
1596.2.12
by Robert Collins
Merge and make Knit Repository use the revision store for all possible queries. |
1012 |
:return: a dictionary of revision_id->revision_parents_list.
|
1013 |
"""
|
|
1836.3.1
by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION. |
1014 |
# special case NULL_REVISION
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
1015 |
if revision_id == _mod_revision.NULL_REVISION: |
1836.3.1
by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION. |
1016 |
return {} |
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
1017 |
a_weave = self._get_revision_vf() |
1018 |
entire_graph = a_weave.get_graph() |
|
1596.2.12
by Robert Collins
Merge and make Knit Repository use the revision store for all possible queries. |
1019 |
if revision_id is None: |
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
1020 |
return a_weave.get_graph() |
1021 |
elif revision_id not in a_weave: |
|
1596.2.12
by Robert Collins
Merge and make Knit Repository use the revision store for all possible queries. |
1022 |
raise errors.NoSuchRevision(self, revision_id) |
1023 |
else: |
|
1024 |
# add what can be reached from revision_id
|
|
1025 |
result = {} |
|
1026 |
pending = set([revision_id]) |
|
1027 |
while len(pending) > 0: |
|
1028 |
node = pending.pop() |
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
1029 |
result[node] = a_weave.get_parents(node) |
1596.2.12
by Robert Collins
Merge and make Knit Repository use the revision store for all possible queries. |
1030 |
for revision_id in result[node]: |
1031 |
if revision_id not in result: |
|
1032 |
pending.add(revision_id) |
|
1033 |
return result |
|
1034 |
||
1035 |
@needs_read_lock
|
|
1594.2.9
by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all. |
1036 |
def get_revision_graph_with_ghosts(self, revision_ids=None): |
1037 |
"""Return a graph of the revisions with ghosts marked as applicable.
|
|
1038 |
||
1039 |
:param revision_ids: an iterable of revisions to graph or None for all.
|
|
1040 |
:return: a Graph object with the graph reachable from revision_ids.
|
|
1041 |
"""
|
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
1042 |
result = graph.Graph() |
1596.2.12
by Robert Collins
Merge and make Knit Repository use the revision store for all possible queries. |
1043 |
vf = self._get_revision_vf() |
1628.1.7
by Robert Collins
Tune get_revision_graph_with_ghosts for Knit repositories. |
1044 |
versions = set(vf.versions()) |
1594.2.9
by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all. |
1045 |
if not revision_ids: |
1773.4.2
by Martin Pool
Cleanup of imports; undeprecate all_revision_ids() |
1046 |
pending = set(self.all_revision_ids()) |
1594.2.9
by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all. |
1047 |
required = set([]) |
1048 |
else: |
|
1049 |
pending = set(revision_ids) |
|
1836.3.1
by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION. |
1050 |
# special case NULL_REVISION
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
1051 |
if _mod_revision.NULL_REVISION in pending: |
1052 |
pending.remove(_mod_revision.NULL_REVISION) |
|
1836.3.1
by Robert Collins
(robertc) Teach repository.get_revision_graph, and revision.common_ancestor, about NULL_REVISION. |
1053 |
required = set(pending) |
1594.2.9
by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all. |
1054 |
done = set([]) |
1055 |
while len(pending): |
|
1056 |
revision_id = pending.pop() |
|
1057 |
if not revision_id in versions: |
|
1058 |
if revision_id in required: |
|
1059 |
raise errors.NoSuchRevision(self, revision_id) |
|
1060 |
# a ghost
|
|
1061 |
result.add_ghost(revision_id) |
|
1759.2.2
by Jelmer Vernooij
Revert some of my spelling fixes and fix some typos after review by Aaron. |
1062 |
# mark it as done so we don't try for it again.
|
1628.1.7
by Robert Collins
Tune get_revision_graph_with_ghosts for Knit repositories. |
1063 |
done.add(revision_id) |
1594.2.9
by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all. |
1064 |
continue
|
1065 |
parent_ids = vf.get_parents_with_ghosts(revision_id) |
|
1066 |
for parent_id in parent_ids: |
|
1067 |
# is this queued or done ?
|
|
1068 |
if (parent_id not in pending and |
|
1069 |
parent_id not in done): |
|
1070 |
# no, queue it.
|
|
1071 |
pending.add(parent_id) |
|
1072 |
result.add_node(revision_id, parent_ids) |
|
1628.1.7
by Robert Collins
Tune get_revision_graph_with_ghosts for Knit repositories. |
1073 |
done.add(revision_id) |
1594.2.9
by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all. |
1074 |
return result |
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
1075 |
|
1596.2.12
by Robert Collins
Merge and make Knit Repository use the revision store for all possible queries. |
1076 |
def _get_revision_vf(self): |
1607.1.2
by Robert Collins
Merge in knit-using-revision-versioned-file-graph tuning work. |
1077 |
""":return: a versioned file containing the revisions."""
|
1596.2.12
by Robert Collins
Merge and make Knit Repository use the revision store for all possible queries. |
1078 |
vf = self._revision_store.get_revision_file(self.get_transaction()) |
1079 |
return vf |
|
1080 |
||
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
1081 |
@needs_write_lock
|
1692.1.1
by Robert Collins
* Repository.reconcile now takes a thorough keyword parameter to allow |
1082 |
def reconcile(self, other=None, thorough=False): |
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
1083 |
"""Reconcile this repository."""
|
1084 |
from bzrlib.reconcile import KnitReconciler |
|
1692.1.1
by Robert Collins
* Repository.reconcile now takes a thorough keyword parameter to allow |
1085 |
reconciler = KnitReconciler(self, thorough=thorough) |
1594.2.7
by Robert Collins
Add versionedfile.fix_parents api for correcting data post hoc. |
1086 |
reconciler.reconcile() |
1087 |
return reconciler |
|
1088 |
||
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
1089 |
def revision_parents(self, revision_id): |
1090 |
return self._get_revision_vf().get_parents(revision_id) |
|
1091 |
||
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
1092 |
|
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
1093 |
class KnitRepository2(KnitRepository): |
1094 |
""""""
|
|
1910.2.48
by Aaron Bentley
Update from review comments |
1095 |
def __init__(self, _format, a_bzrdir, control_files, _revision_store, |
1096 |
control_store, text_store): |
|
1097 |
KnitRepository.__init__(self, _format, a_bzrdir, control_files, |
|
1098 |
_revision_store, control_store, text_store) |
|
1099 |
self._serializer = xml6.serializer_v6 |
|
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
1100 |
|
1101 |
def deserialise_inventory(self, revision_id, xml): |
|
1102 |
"""Transform the xml into an inventory object.
|
|
1103 |
||
1104 |
:param revision_id: The expected revision id of the inventory.
|
|
1105 |
:param xml: A serialised inventory.
|
|
1106 |
"""
|
|
1910.2.48
by Aaron Bentley
Update from review comments |
1107 |
result = self._serializer.read_inventory_from_string(xml) |
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
1108 |
assert result.root.revision is not None |
1109 |
return result |
|
1110 |
||
1111 |
def serialise_inventory(self, inv): |
|
1112 |
"""Transform the inventory object into XML text.
|
|
1113 |
||
1114 |
:param revision_id: The expected revision id of the inventory.
|
|
1115 |
:param xml: A serialised inventory.
|
|
1116 |
"""
|
|
1910.2.23
by Aaron Bentley
Fix up test cases that manually construct inventories |
1117 |
assert inv.revision_id is not None |
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
1118 |
assert inv.root.revision is not None |
1910.2.48
by Aaron Bentley
Update from review comments |
1119 |
return KnitRepository.serialise_inventory(self, inv) |
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
1120 |
|
1121 |
def get_commit_builder(self, branch, parents, config, timestamp=None, |
|
1122 |
timezone=None, committer=None, revprops=None, |
|
1123 |
revision_id=None): |
|
1124 |
"""Obtain a CommitBuilder for this repository.
|
|
1125 |
|
|
1126 |
:param branch: Branch to commit to.
|
|
1127 |
:param parents: Revision ids of the parents of the new revision.
|
|
1128 |
:param config: Configuration to use.
|
|
1129 |
:param timestamp: Optional timestamp recorded for commit.
|
|
1130 |
:param timezone: Optional timezone for timestamp.
|
|
1131 |
:param committer: Optional committer to set for commit.
|
|
1132 |
:param revprops: Optional dictionary of revision properties.
|
|
1133 |
:param revision_id: Optional revision id.
|
|
1134 |
"""
|
|
1135 |
return RootCommitBuilder(self, parents, config, timestamp, timezone, |
|
1136 |
committer, revprops, revision_id) |
|
1137 |
||
1910.2.46
by Aaron Bentley
Whitespace fix |
1138 |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1139 |
class RepositoryFormat(object): |
1140 |
"""A repository format.
|
|
1141 |
||
1142 |
Formats provide three things:
|
|
1143 |
* An initialization routine to construct repository data on disk.
|
|
1144 |
* a format string which is used when the BzrDir supports versioned
|
|
1145 |
children.
|
|
1146 |
* an open routine which returns a Repository instance.
|
|
1147 |
||
1148 |
Formats are placed in an dict by their format string for reference
|
|
1149 |
during opening. These should be subclasses of RepositoryFormat
|
|
1150 |
for consistency.
|
|
1151 |
||
1152 |
Once a format is deprecated, just deprecate the initialize and open
|
|
1153 |
methods on the format class. Do not deprecate the object, as the
|
|
1154 |
object will be created every system load.
|
|
1155 |
||
1156 |
Common instance attributes:
|
|
1157 |
_matchingbzrdir - the bzrdir format that the repository format was
|
|
1158 |
originally written to work with. This can be used if manually
|
|
1159 |
constructing a bzrdir and repository, or more commonly for test suite
|
|
1160 |
parameterisation.
|
|
1161 |
"""
|
|
1162 |
||
2241.1.1
by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary |
1163 |
_registry = registry.Registry() |
1164 |
"""Registry of formats, indexed by their identifying format string."""
|
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1165 |
|
1904.2.3
by Martin Pool
Give a warning on access to old repository formats |
1166 |
def __str__(self): |
1167 |
return "<%s>" % self.__class__.__name__ |
|
1168 |
||
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1169 |
@classmethod
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
1170 |
def find_format(klass, a_bzrdir): |
2241.1.1
by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary |
1171 |
"""Return the format for the repository object in a_bzrdir.
|
1172 |
|
|
1173 |
This is used by bzr native formats that have a "format" file in
|
|
1174 |
the repository. Other methods may be used by different types of
|
|
1175 |
control directory.
|
|
1176 |
"""
|
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
1177 |
try: |
1178 |
transport = a_bzrdir.get_repository_transport(None) |
|
1179 |
format_string = transport.get("format").read() |
|
2241.1.1
by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary |
1180 |
return klass._registry.get(format_string) |
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
1181 |
except errors.NoSuchFile: |
1182 |
raise errors.NoRepositoryPresent(a_bzrdir) |
|
1183 |
except KeyError: |
|
1740.5.6
by Martin Pool
Clean up many exception classes. |
1184 |
raise errors.UnknownFormatError(format=format_string) |
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
1185 |
|
2241.1.1
by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary |
1186 |
@classmethod
|
1187 |
def register_format(klass, format): |
|
1188 |
klass._registry.register(format.get_format_string(), format) |
|
1189 |
||
1190 |
@classmethod
|
|
1191 |
@deprecated_method(symbol_versioning.zero_fourteen) |
|
1192 |
def set_default_format(klass, format): |
|
1193 |
klass._set_default_format(format) |
|
1194 |
||
1195 |
@classmethod
|
|
1196 |
def _set_default_format(klass, format): |
|
1197 |
"""Set the default format for new Repository creation.
|
|
1198 |
||
1199 |
The format must already be registered.
|
|
1200 |
"""
|
|
1201 |
klass._registry.default_key = format.get_format_string() |
|
1202 |
||
1203 |
@classmethod
|
|
1204 |
def unregister_format(klass, format): |
|
1205 |
klass._registry.remove(format.get_format_string()) |
|
1563.2.23
by Robert Collins
Add add_revision and get_revision methods to RevisionStore |
1206 |
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
1207 |
@classmethod
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1208 |
def get_default_format(klass): |
1209 |
"""Return the current default format."""
|
|
2241.1.1
by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary |
1210 |
return klass._registry.get(klass._registry.default_key) |
1211 |
||
1212 |
def _get_control_store(self, repo_transport, control_files): |
|
1213 |
"""Return the control store for this repository."""
|
|
1214 |
raise NotImplementedError(self._get_control_store) |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1215 |
|
1216 |
def get_format_string(self): |
|
1217 |
"""Return the ASCII format string that identifies this format.
|
|
1218 |
|
|
1219 |
Note that in pre format ?? repositories the format string is
|
|
1220 |
not permitted nor written to disk.
|
|
1221 |
"""
|
|
1222 |
raise NotImplementedError(self.get_format_string) |
|
1223 |
||
1624.3.19
by Olaf Conradi
New call get_format_description to give a user-friendly description of a |
1224 |
def get_format_description(self): |
1759.2.1
by Jelmer Vernooij
Fix some types (found using aspell). |
1225 |
"""Return the short description for this format."""
|
1624.3.19
by Olaf Conradi
New call get_format_description to give a user-friendly description of a |
1226 |
raise NotImplementedError(self.get_format_description) |
1227 |
||
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1228 |
def _get_revision_store(self, repo_transport, control_files): |
1229 |
"""Return the revision store object for this a_bzrdir."""
|
|
1556.1.5
by Robert Collins
Review feedback. |
1230 |
raise NotImplementedError(self._get_revision_store) |
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1231 |
|
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
1232 |
def _get_text_rev_store(self, |
1233 |
transport, |
|
1234 |
control_files, |
|
1235 |
name, |
|
1236 |
compressed=True, |
|
1563.2.28
by Robert Collins
Add total_size to the revision_store api. |
1237 |
prefixed=False, |
1238 |
serializer=None): |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1239 |
"""Common logic for getting a revision store for a repository.
|
1240 |
|
|
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
1241 |
see self._get_revision_store for the subclass-overridable method to
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1242 |
get the store for a repository.
|
1243 |
"""
|
|
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
1244 |
from bzrlib.store.revision.text import TextRevisionStore |
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1245 |
dir_mode = control_files._dir_mode |
1246 |
file_mode = control_files._file_mode |
|
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
1247 |
text_store =TextStore(transport.clone(name), |
1248 |
prefixed=prefixed, |
|
1249 |
compressed=compressed, |
|
1250 |
dir_mode=dir_mode, |
|
1251 |
file_mode=file_mode) |
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
1252 |
_revision_store = TextRevisionStore(text_store, serializer) |
1253 |
return _revision_store |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1254 |
|
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
1255 |
def _get_versioned_file_store(self, |
1256 |
name, |
|
1257 |
transport, |
|
1258 |
control_files, |
|
1259 |
prefixed=True, |
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
1260 |
versionedfile_class=weave.WeaveFile, |
1946.2.5
by John Arbash Meinel
Make knit stores delay creation, but not control stores |
1261 |
versionedfile_kwargs={}, |
1608.2.12
by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely |
1262 |
escaped=False): |
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
1263 |
weave_transport = control_files._transport.clone(name) |
1264 |
dir_mode = control_files._dir_mode |
|
1265 |
file_mode = control_files._file_mode |
|
1266 |
return VersionedFileStore(weave_transport, prefixed=prefixed, |
|
1608.2.12
by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely |
1267 |
dir_mode=dir_mode, |
1268 |
file_mode=file_mode, |
|
1269 |
versionedfile_class=versionedfile_class, |
|
1946.2.5
by John Arbash Meinel
Make knit stores delay creation, but not control stores |
1270 |
versionedfile_kwargs=versionedfile_kwargs, |
1608.2.12
by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely |
1271 |
escaped=escaped) |
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
1272 |
|
1534.6.1
by Robert Collins
allow API creation of shared repositories |
1273 |
def initialize(self, a_bzrdir, shared=False): |
1274 |
"""Initialize a repository of this format in a_bzrdir.
|
|
1275 |
||
1276 |
:param a_bzrdir: The bzrdir to put the new repository in it.
|
|
1277 |
:param shared: The repository should be initialized as a sharable one.
|
|
1278 |
||
1279 |
This may raise UninitializableFormat if shared repository are not
|
|
1280 |
compatible the a_bzrdir.
|
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1281 |
"""
|
1282 |
||
1283 |
def is_supported(self): |
|
1284 |
"""Is this format supported?
|
|
1285 |
||
1286 |
Supported formats must be initializable and openable.
|
|
1287 |
Unsupported formats may not support initialization or committing or
|
|
1288 |
some other features depending on the reason for not being supported.
|
|
1289 |
"""
|
|
1290 |
return True |
|
1291 |
||
1910.2.12
by Aaron Bentley
Implement knit repo format 2 |
1292 |
def check_conversion_target(self, target_format): |
1293 |
raise NotImplementedError(self.check_conversion_target) |
|
1294 |
||
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1295 |
def open(self, a_bzrdir, _found=False): |
1296 |
"""Return an instance of this format for the bzrdir a_bzrdir.
|
|
1297 |
|
|
1298 |
_found is a private parameter, do not use it.
|
|
1299 |
"""
|
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1300 |
raise NotImplementedError(self.open) |
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1301 |
|
1302 |
||
1534.6.1
by Robert Collins
allow API creation of shared repositories |
1303 |
class PreSplitOutRepositoryFormat(RepositoryFormat): |
1304 |
"""Base class for the pre split out repository formats."""
|
|
1305 |
||
1910.2.14
by Aaron Bentley
Fail when trying to use interrepository on Knit2 and Knit1 |
1306 |
rich_root_data = False |
1307 |
||
1534.6.1
by Robert Collins
allow API creation of shared repositories |
1308 |
def initialize(self, a_bzrdir, shared=False, _internal=False): |
1309 |
"""Create a weave repository.
|
|
1310 |
|
|
1311 |
TODO: when creating split out bzr branch formats, move this to a common
|
|
1312 |
base for Format5, Format6. or something like that.
|
|
1313 |
"""
|
|
1314 |
if shared: |
|
1315 |
raise errors.IncompatibleFormat(self, a_bzrdir._format) |
|
1316 |
||
1317 |
if not _internal: |
|
1318 |
# always initialized when the bzrdir is.
|
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1319 |
return self.open(a_bzrdir, _found=True) |
1534.6.1
by Robert Collins
allow API creation of shared repositories |
1320 |
|
1321 |
# Create an empty weave
|
|
1322 |
sio = StringIO() |
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
1323 |
weavefile.write_weave_v5(weave.Weave(), sio) |
1534.6.1
by Robert Collins
allow API creation of shared repositories |
1324 |
empty_weave = sio.getvalue() |
1325 |
||
1326 |
mutter('creating repository in %s.', a_bzrdir.transport.base) |
|
1327 |
dirs = ['revision-store', 'weaves'] |
|
1553.5.56
by Martin Pool
Format 7 repo now uses LockDir! |
1328 |
files = [('inventory.weave', StringIO(empty_weave)), |
1534.6.1
by Robert Collins
allow API creation of shared repositories |
1329 |
]
|
1330 |
||
1759.2.2
by Jelmer Vernooij
Revert some of my spelling fixes and fix some typos after review by Aaron. |
1331 |
# FIXME: RBC 20060125 don't peek under the covers
|
1534.6.1
by Robert Collins
allow API creation of shared repositories |
1332 |
# NB: no need to escape relative paths that are url safe.
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
1333 |
control_files = lockable_files.LockableFiles(a_bzrdir.transport, |
1334 |
'branch-lock', lockable_files.TransportLock) |
|
1553.5.63
by Martin Pool
Lock type is now mandatory for LockableFiles constructor |
1335 |
control_files.create_lock() |
1534.6.1
by Robert Collins
allow API creation of shared repositories |
1336 |
control_files.lock_write() |
1337 |
control_files._transport.mkdir_multi(dirs, |
|
1338 |
mode=control_files._dir_mode) |
|
1339 |
try: |
|
1340 |
for file, content in files: |
|
1341 |
control_files.put(file, content) |
|
1342 |
finally: |
|
1343 |
control_files.unlock() |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1344 |
return self.open(a_bzrdir, _found=True) |
1345 |
||
1563.2.23
by Robert Collins
Add add_revision and get_revision methods to RevisionStore |
1346 |
def _get_control_store(self, repo_transport, control_files): |
1347 |
"""Return the control store for this repository."""
|
|
1348 |
return self._get_versioned_file_store('', |
|
1349 |
repo_transport, |
|
1350 |
control_files, |
|
1351 |
prefixed=False) |
|
1352 |
||
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
1353 |
def _get_text_store(self, transport, control_files): |
1354 |
"""Get a store for file texts for this format."""
|
|
1355 |
raise NotImplementedError(self._get_text_store) |
|
1356 |
||
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1357 |
def open(self, a_bzrdir, _found=False): |
1358 |
"""See RepositoryFormat.open()."""
|
|
1359 |
if not _found: |
|
1360 |
# we are being called directly and must probe.
|
|
1361 |
raise NotImplementedError |
|
1362 |
||
1363 |
repo_transport = a_bzrdir.get_repository_transport(None) |
|
1364 |
control_files = a_bzrdir._control_files |
|
1563.2.23
by Robert Collins
Add add_revision and get_revision methods to RevisionStore |
1365 |
text_store = self._get_text_store(repo_transport, control_files) |
1366 |
control_store = self._get_control_store(repo_transport, control_files) |
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
1367 |
_revision_store = self._get_revision_store(repo_transport, control_files) |
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1368 |
return AllInOneRepository(_format=self, |
1369 |
a_bzrdir=a_bzrdir, |
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
1370 |
_revision_store=_revision_store, |
1563.2.23
by Robert Collins
Add add_revision and get_revision methods to RevisionStore |
1371 |
control_store=control_store, |
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
1372 |
text_store=text_store) |
1534.6.1
by Robert Collins
allow API creation of shared repositories |
1373 |
|
1910.2.12
by Aaron Bentley
Implement knit repo format 2 |
1374 |
def check_conversion_target(self, target_format): |
1375 |
pass
|
|
1376 |
||
1534.6.1
by Robert Collins
allow API creation of shared repositories |
1377 |
|
1378 |
class RepositoryFormat4(PreSplitOutRepositoryFormat): |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1379 |
"""Bzr repository format 4.
|
1380 |
||
1381 |
This repository format has:
|
|
1382 |
- flat stores
|
|
1383 |
- TextStores for texts, inventories,revisions.
|
|
1384 |
||
1385 |
This format is deprecated: it indexes texts using a text id which is
|
|
1759.2.1
by Jelmer Vernooij
Fix some types (found using aspell). |
1386 |
removed in format 5; initialization and write support for this format
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1387 |
has been removed.
|
1388 |
"""
|
|
1389 |
||
1390 |
def __init__(self): |
|
1391 |
super(RepositoryFormat4, self).__init__() |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
1392 |
self._matchingbzrdir = bzrdir.BzrDirFormat4() |
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1393 |
|
1624.3.19
by Olaf Conradi
New call get_format_description to give a user-friendly description of a |
1394 |
def get_format_description(self): |
1395 |
"""See RepositoryFormat.get_format_description()."""
|
|
1396 |
return "Repository format 4" |
|
1397 |
||
1534.6.1
by Robert Collins
allow API creation of shared repositories |
1398 |
def initialize(self, url, shared=False, _internal=False): |
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1399 |
"""Format 4 branches cannot be created."""
|
1400 |
raise errors.UninitializableFormat(self) |
|
1401 |
||
1402 |
def is_supported(self): |
|
1403 |
"""Format 4 is not supported.
|
|
1404 |
||
1405 |
It is not supported because the model changed from 4 to 5 and the
|
|
1406 |
conversion logic is expensive - so doing it on the fly was not
|
|
1407 |
feasible.
|
|
1408 |
"""
|
|
1409 |
return False |
|
1410 |
||
1563.2.23
by Robert Collins
Add add_revision and get_revision methods to RevisionStore |
1411 |
def _get_control_store(self, repo_transport, control_files): |
1412 |
"""Format 4 repositories have no formal control store at this point.
|
|
1413 |
|
|
1414 |
This will cause any control-file-needing apis to fail - this is desired.
|
|
1415 |
"""
|
|
1416 |
return None |
|
1417 |
||
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1418 |
def _get_revision_store(self, repo_transport, control_files): |
1419 |
"""See RepositoryFormat._get_revision_store()."""
|
|
1563.2.28
by Robert Collins
Add total_size to the revision_store api. |
1420 |
from bzrlib.xml4 import serializer_v4 |
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
1421 |
return self._get_text_rev_store(repo_transport, |
1422 |
control_files, |
|
1563.2.28
by Robert Collins
Add total_size to the revision_store api. |
1423 |
'revision-store', |
1424 |
serializer=serializer_v4) |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1425 |
|
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
1426 |
def _get_text_store(self, transport, control_files): |
1427 |
"""See RepositoryFormat._get_text_store()."""
|
|
1428 |
||
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1429 |
|
1534.6.1
by Robert Collins
allow API creation of shared repositories |
1430 |
class RepositoryFormat5(PreSplitOutRepositoryFormat): |
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1431 |
"""Bzr control format 5.
|
1432 |
||
1433 |
This repository format has:
|
|
1434 |
- weaves for file texts and inventory
|
|
1435 |
- flat stores
|
|
1436 |
- TextStores for revisions and signatures.
|
|
1437 |
"""
|
|
1438 |
||
1439 |
def __init__(self): |
|
1440 |
super(RepositoryFormat5, self).__init__() |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
1441 |
self._matchingbzrdir = bzrdir.BzrDirFormat5() |
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1442 |
|
1624.3.19
by Olaf Conradi
New call get_format_description to give a user-friendly description of a |
1443 |
def get_format_description(self): |
1444 |
"""See RepositoryFormat.get_format_description()."""
|
|
1445 |
return "Weave repository format 5" |
|
1446 |
||
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1447 |
def _get_revision_store(self, repo_transport, control_files): |
1448 |
"""See RepositoryFormat._get_revision_store()."""
|
|
1449 |
"""Return the revision store object for this a_bzrdir."""
|
|
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
1450 |
return self._get_text_rev_store(repo_transport, |
1451 |
control_files, |
|
1452 |
'revision-store', |
|
1453 |
compressed=False) |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1454 |
|
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
1455 |
def _get_text_store(self, transport, control_files): |
1456 |
"""See RepositoryFormat._get_text_store()."""
|
|
1457 |
return self._get_versioned_file_store('weaves', transport, control_files, prefixed=False) |
|
1458 |
||
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1459 |
|
1534.6.1
by Robert Collins
allow API creation of shared repositories |
1460 |
class RepositoryFormat6(PreSplitOutRepositoryFormat): |
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1461 |
"""Bzr control format 6.
|
1462 |
||
1463 |
This repository format has:
|
|
1464 |
- weaves for file texts and inventory
|
|
1465 |
- hash subdirectory based stores.
|
|
1466 |
- TextStores for revisions and signatures.
|
|
1467 |
"""
|
|
1468 |
||
1469 |
def __init__(self): |
|
1470 |
super(RepositoryFormat6, self).__init__() |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
1471 |
self._matchingbzrdir = bzrdir.BzrDirFormat6() |
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1472 |
|
1624.3.19
by Olaf Conradi
New call get_format_description to give a user-friendly description of a |
1473 |
def get_format_description(self): |
1474 |
"""See RepositoryFormat.get_format_description()."""
|
|
1475 |
return "Weave repository format 6" |
|
1476 |
||
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1477 |
def _get_revision_store(self, repo_transport, control_files): |
1478 |
"""See RepositoryFormat._get_revision_store()."""
|
|
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
1479 |
return self._get_text_rev_store(repo_transport, |
1480 |
control_files, |
|
1481 |
'revision-store', |
|
1482 |
compressed=False, |
|
1483 |
prefixed=True) |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1484 |
|
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
1485 |
def _get_text_store(self, transport, control_files): |
1486 |
"""See RepositoryFormat._get_text_store()."""
|
|
1487 |
return self._get_versioned_file_store('weaves', transport, control_files) |
|
1488 |
||
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1489 |
|
1490 |
class MetaDirRepositoryFormat(RepositoryFormat): |
|
1759.2.1
by Jelmer Vernooij
Fix some types (found using aspell). |
1491 |
"""Common base class for the new repositories using the metadir layout."""
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1492 |
|
1910.2.14
by Aaron Bentley
Fail when trying to use interrepository on Knit2 and Knit1 |
1493 |
rich_root_data = False |
1494 |
||
1556.1.4
by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same. |
1495 |
def __init__(self): |
1496 |
super(MetaDirRepositoryFormat, self).__init__() |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
1497 |
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1() |
1556.1.4
by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same. |
1498 |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1499 |
def _create_control_files(self, a_bzrdir): |
1500 |
"""Create the required files and the initial control_files object."""
|
|
1759.2.2
by Jelmer Vernooij
Revert some of my spelling fixes and fix some typos after review by Aaron. |
1501 |
# FIXME: RBC 20060125 don't peek under the covers
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
1502 |
# NB: no need to escape relative paths that are url safe.
|
1503 |
repository_transport = a_bzrdir.get_repository_transport(self) |
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
1504 |
control_files = lockable_files.LockableFiles(repository_transport, |
1505 |
'lock', lockdir.LockDir) |
|
1553.5.61
by Martin Pool
Locks protecting LockableFiles must now be explicitly created before use. |
1506 |
control_files.create_lock() |
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1507 |
return control_files |
1508 |
||
1509 |
def _upload_blank_content(self, a_bzrdir, dirs, files, utf8_files, shared): |
|
1510 |
"""Upload the initial blank content."""
|
|
1511 |
control_files = self._create_control_files(a_bzrdir) |
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
1512 |
control_files.lock_write() |
1513 |
try: |
|
1553.5.49
by Martin Pool
Use LockDirs for repo format 7 |
1514 |
control_files._transport.mkdir_multi(dirs, |
1515 |
mode=control_files._dir_mode) |
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
1516 |
for file, content in files: |
1517 |
control_files.put(file, content) |
|
1518 |
for file, content in utf8_files: |
|
1519 |
control_files.put_utf8(file, content) |
|
1534.6.1
by Robert Collins
allow API creation of shared repositories |
1520 |
if shared == True: |
1521 |
control_files.put_utf8('shared-storage', '') |
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
1522 |
finally: |
1523 |
control_files.unlock() |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1524 |
|
1525 |
||
1526 |
class RepositoryFormat7(MetaDirRepositoryFormat): |
|
1527 |
"""Bzr repository 7.
|
|
1528 |
||
1529 |
This repository format has:
|
|
1530 |
- weaves for file texts and inventory
|
|
1531 |
- hash subdirectory based stores.
|
|
1532 |
- TextStores for revisions and signatures.
|
|
1533 |
- a format marker of its own
|
|
1534 |
- an optional 'shared-storage' flag
|
|
1535 |
- an optional 'no-working-trees' flag
|
|
1536 |
"""
|
|
1537 |
||
1563.2.35
by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too. |
1538 |
def _get_control_store(self, repo_transport, control_files): |
1539 |
"""Return the control store for this repository."""
|
|
1540 |
return self._get_versioned_file_store('', |
|
1541 |
repo_transport, |
|
1542 |
control_files, |
|
1543 |
prefixed=False) |
|
1544 |
||
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1545 |
def get_format_string(self): |
1546 |
"""See RepositoryFormat.get_format_string()."""
|
|
1547 |
return "Bazaar-NG Repository format 7" |
|
1548 |
||
1624.3.19
by Olaf Conradi
New call get_format_description to give a user-friendly description of a |
1549 |
def get_format_description(self): |
1550 |
"""See RepositoryFormat.get_format_description()."""
|
|
1551 |
return "Weave repository format 7" |
|
1552 |
||
1910.2.12
by Aaron Bentley
Implement knit repo format 2 |
1553 |
def check_conversion_target(self, target_format): |
1554 |
pass
|
|
1555 |
||
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
1556 |
def _get_revision_store(self, repo_transport, control_files): |
1557 |
"""See RepositoryFormat._get_revision_store()."""
|
|
1558 |
return self._get_text_rev_store(repo_transport, |
|
1559 |
control_files, |
|
1560 |
'revision-store', |
|
1561 |
compressed=False, |
|
1562 |
prefixed=True, |
|
1563 |
)
|
|
1564 |
||
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
1565 |
def _get_text_store(self, transport, control_files): |
1566 |
"""See RepositoryFormat._get_text_store()."""
|
|
1567 |
return self._get_versioned_file_store('weaves', |
|
1568 |
transport, |
|
1569 |
control_files) |
|
1570 |
||
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1571 |
def initialize(self, a_bzrdir, shared=False): |
1572 |
"""Create a weave repository.
|
|
1573 |
||
1574 |
:param shared: If true the repository will be initialized as a shared
|
|
1575 |
repository.
|
|
1576 |
"""
|
|
1577 |
# Create an empty weave
|
|
1578 |
sio = StringIO() |
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
1579 |
weavefile.write_weave_v5(weave.Weave(), sio) |
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1580 |
empty_weave = sio.getvalue() |
1581 |
||
1582 |
mutter('creating repository in %s.', a_bzrdir.transport.base) |
|
1583 |
dirs = ['revision-store', 'weaves'] |
|
1584 |
files = [('inventory.weave', StringIO(empty_weave)), |
|
1585 |
]
|
|
1586 |
utf8_files = [('format', self.get_format_string())] |
|
1587 |
||
1588 |
self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared) |
|
1589 |
return self.open(a_bzrdir=a_bzrdir, _found=True) |
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
1590 |
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
1591 |
def open(self, a_bzrdir, _found=False, _override_transport=None): |
1592 |
"""See RepositoryFormat.open().
|
|
1593 |
|
|
1594 |
:param _override_transport: INTERNAL USE ONLY. Allows opening the
|
|
1595 |
repository at a slightly different url
|
|
1596 |
than normal. I.e. during 'upgrade'.
|
|
1597 |
"""
|
|
1598 |
if not _found: |
|
1599 |
format = RepositoryFormat.find_format(a_bzrdir) |
|
1600 |
assert format.__class__ == self.__class__ |
|
1601 |
if _override_transport is not None: |
|
1602 |
repo_transport = _override_transport |
|
1603 |
else: |
|
1604 |
repo_transport = a_bzrdir.get_repository_transport(None) |
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
1605 |
control_files = lockable_files.LockableFiles(repo_transport, |
1606 |
'lock', lockdir.LockDir) |
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
1607 |
text_store = self._get_text_store(repo_transport, control_files) |
1608 |
control_store = self._get_control_store(repo_transport, control_files) |
|
1609 |
_revision_store = self._get_revision_store(repo_transport, control_files) |
|
2150.2.2
by Robert Collins
Change the commit builder selected-revision-id test to use a unicode revision id where possible, leading to stricter testing of the hypothetical unicode revision id support in bzr. |
1610 |
return WeaveMetaDirRepository(_format=self, |
1611 |
a_bzrdir=a_bzrdir, |
|
1612 |
control_files=control_files, |
|
1613 |
_revision_store=_revision_store, |
|
1614 |
control_store=control_store, |
|
1615 |
text_store=text_store) |
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
1616 |
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
1617 |
|
1910.2.11
by Aaron Bentley
Start work on Knit format 2 |
1618 |
class RepositoryFormatKnit(MetaDirRepositoryFormat): |
1619 |
"""Bzr repository knit format (generalized).
|
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1620 |
|
1621 |
This repository format has:
|
|
1622 |
- knits for file texts and inventory
|
|
1623 |
- hash subdirectory based stores.
|
|
1624 |
- knits for revisions and signatures
|
|
1625 |
- TextStores for revisions and signatures.
|
|
1626 |
- a format marker of its own
|
|
1627 |
- an optional 'shared-storage' flag
|
|
1628 |
- an optional 'no-working-trees' flag
|
|
1553.5.62
by Martin Pool
Add tests that MetaDir repositories use LockDirs |
1629 |
- a LockDir lock
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1630 |
"""
|
1631 |
||
1563.2.35
by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too. |
1632 |
def _get_control_store(self, repo_transport, control_files): |
1633 |
"""Return the control store for this repository."""
|
|
1628.1.5
by Robert Collins
Make inventory knits not annotated, only delta compressed. |
1634 |
return VersionedFileStore( |
1635 |
repo_transport, |
|
1636 |
prefixed=False, |
|
1637 |
file_mode=control_files._file_mode, |
|
1996.3.5
by John Arbash Meinel
Cleanup, deprecated, and get the tests passing again. |
1638 |
versionedfile_class=knit.KnitVersionedFile, |
1639 |
versionedfile_kwargs={'factory':knit.KnitPlainFactory()}, |
|
1628.1.5
by Robert Collins
Make inventory knits not annotated, only delta compressed. |
1640 |
)
|
1563.2.35
by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too. |
1641 |
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
1642 |
def _get_revision_store(self, repo_transport, control_files): |
1643 |
"""See RepositoryFormat._get_revision_store()."""
|
|
1644 |
from bzrlib.store.revision.knit import KnitRevisionStore |
|
1645 |
versioned_file_store = VersionedFileStore( |
|
1563.2.35
by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too. |
1646 |
repo_transport, |
1651.1.1
by Martin Pool
[merge][wip] Storage escaping |
1647 |
file_mode=control_files._file_mode, |
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
1648 |
prefixed=False, |
1563.2.34
by Robert Collins
Remove the commit and rollback transaction methods as misleading, and implement a WriteTransaction |
1649 |
precious=True, |
1996.3.5
by John Arbash Meinel
Cleanup, deprecated, and get the tests passing again. |
1650 |
versionedfile_class=knit.KnitVersionedFile, |
1651 |
versionedfile_kwargs={'delta':False, |
|
1652 |
'factory':knit.KnitPlainFactory(), |
|
1653 |
},
|
|
1608.2.12
by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely |
1654 |
escaped=True, |
1651.1.1
by Martin Pool
[merge][wip] Storage escaping |
1655 |
)
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
1656 |
return KnitRevisionStore(versioned_file_store) |
1657 |
||
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
1658 |
def _get_text_store(self, transport, control_files): |
1659 |
"""See RepositoryFormat._get_text_store()."""
|
|
1660 |
return self._get_versioned_file_store('knits', |
|
1996.3.5
by John Arbash Meinel
Cleanup, deprecated, and get the tests passing again. |
1661 |
transport, |
1662 |
control_files, |
|
1663 |
versionedfile_class=knit.KnitVersionedFile, |
|
1664 |
versionedfile_kwargs={ |
|
1665 |
'create_parent_dir':True, |
|
1666 |
'delay_create':True, |
|
1667 |
'dir_mode':control_files._dir_mode, |
|
1668 |
},
|
|
1669 |
escaped=True) |
|
1563.2.17
by Robert Collins
Change knits repositories to use a knit versioned file store for file texts. |
1670 |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1671 |
def initialize(self, a_bzrdir, shared=False): |
1672 |
"""Create a knit format 1 repository.
|
|
1673 |
||
1658.1.7
by Martin Pool
(RepositoryFormatKnit1.initialize) remove dead code that constructs weaves |
1674 |
:param a_bzrdir: bzrdir to contain the new repository; must already
|
1675 |
be initialized.
|
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1676 |
:param shared: If true the repository will be initialized as a shared
|
1677 |
repository.
|
|
1678 |
"""
|
|
1679 |
mutter('creating repository in %s.', a_bzrdir.transport.base) |
|
1707.3.29
by John Arbash Meinel
reverting 1734 |
1680 |
dirs = ['revision-store', 'knits'] |
1658.1.7
by Martin Pool
(RepositoryFormatKnit1.initialize) remove dead code that constructs weaves |
1681 |
files = [] |
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1682 |
utf8_files = [('format', self.get_format_string())] |
1683 |
||
1684 |
self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared) |
|
1563.2.25
by Robert Collins
Merge in upstream. |
1685 |
repo_transport = a_bzrdir.get_repository_transport(None) |
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
1686 |
control_files = lockable_files.LockableFiles(repo_transport, |
1687 |
'lock', lockdir.LockDir) |
|
1563.2.25
by Robert Collins
Merge in upstream. |
1688 |
control_store = self._get_control_store(repo_transport, control_files) |
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
1689 |
transaction = transactions.WriteTransaction() |
1563.2.34
by Robert Collins
Remove the commit and rollback transaction methods as misleading, and implement a WriteTransaction |
1690 |
# trigger a write of the inventory store.
|
1563.2.35
by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too. |
1691 |
control_store.get_weave_or_empty('inventory', transaction) |
1692 |
_revision_store = self._get_revision_store(repo_transport, control_files) |
|
2150.2.2
by Robert Collins
Change the commit builder selected-revision-id test to use a unicode revision id where possible, leading to stricter testing of the hypothetical unicode revision id support in bzr. |
1693 |
# the revision id here is irrelevant: it will not be stored, and cannot
|
1694 |
# already exist.
|
|
1563.2.35
by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too. |
1695 |
_revision_store.has_revision_id('A', transaction) |
1696 |
_revision_store.get_signature_file(transaction) |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1697 |
return self.open(a_bzrdir=a_bzrdir, _found=True) |
1698 |
||
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
1699 |
def open(self, a_bzrdir, _found=False, _override_transport=None): |
1700 |
"""See RepositoryFormat.open().
|
|
1701 |
|
|
1702 |
:param _override_transport: INTERNAL USE ONLY. Allows opening the
|
|
1703 |
repository at a slightly different url
|
|
1704 |
than normal. I.e. during 'upgrade'.
|
|
1705 |
"""
|
|
1706 |
if not _found: |
|
1707 |
format = RepositoryFormat.find_format(a_bzrdir) |
|
1708 |
assert format.__class__ == self.__class__ |
|
1709 |
if _override_transport is not None: |
|
1710 |
repo_transport = _override_transport |
|
1711 |
else: |
|
1712 |
repo_transport = a_bzrdir.get_repository_transport(None) |
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
1713 |
control_files = lockable_files.LockableFiles(repo_transport, |
1714 |
'lock', lockdir.LockDir) |
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
1715 |
text_store = self._get_text_store(repo_transport, control_files) |
1716 |
control_store = self._get_control_store(repo_transport, control_files) |
|
1717 |
_revision_store = self._get_revision_store(repo_transport, control_files) |
|
1718 |
return KnitRepository(_format=self, |
|
1719 |
a_bzrdir=a_bzrdir, |
|
1720 |
control_files=control_files, |
|
1721 |
_revision_store=_revision_store, |
|
1722 |
control_store=control_store, |
|
1723 |
text_store=text_store) |
|
1724 |
||
1910.2.12
by Aaron Bentley
Implement knit repo format 2 |
1725 |
|
1910.2.11
by Aaron Bentley
Start work on Knit format 2 |
1726 |
class RepositoryFormatKnit1(RepositoryFormatKnit): |
1727 |
"""Bzr repository knit format 1.
|
|
1728 |
||
1729 |
This repository format has:
|
|
1730 |
- knits for file texts and inventory
|
|
1731 |
- hash subdirectory based stores.
|
|
1732 |
- knits for revisions and signatures
|
|
1733 |
- TextStores for revisions and signatures.
|
|
1734 |
- a format marker of its own
|
|
1735 |
- an optional 'shared-storage' flag
|
|
1736 |
- an optional 'no-working-trees' flag
|
|
1737 |
- a LockDir lock
|
|
1738 |
||
1739 |
This format was introduced in bzr 0.8.
|
|
1740 |
"""
|
|
1741 |
def get_format_string(self): |
|
1742 |
"""See RepositoryFormat.get_format_string()."""
|
|
1743 |
return "Bazaar-NG Knit Repository Format 1" |
|
1744 |
||
1745 |
def get_format_description(self): |
|
1746 |
"""See RepositoryFormat.get_format_description()."""
|
|
1747 |
return "Knit repository format 1" |
|
1556.1.3
by Robert Collins
Rearrangment of Repository logic to be less type code driven, and bugfix InterRepository.missing_revision_ids |
1748 |
|
1910.2.12
by Aaron Bentley
Implement knit repo format 2 |
1749 |
def check_conversion_target(self, target_format): |
1750 |
pass
|
|
1751 |
||
1752 |
||
1753 |
class RepositoryFormatKnit2(RepositoryFormatKnit): |
|
1754 |
"""Bzr repository knit format 2.
|
|
1755 |
||
1756 |
THIS FORMAT IS EXPERIMENTAL
|
|
1757 |
This repository format has:
|
|
1758 |
- knits for file texts and inventory
|
|
1759 |
- hash subdirectory based stores.
|
|
1760 |
- knits for revisions and signatures
|
|
1761 |
- TextStores for revisions and signatures.
|
|
1762 |
- a format marker of its own
|
|
1763 |
- an optional 'shared-storage' flag
|
|
1764 |
- an optional 'no-working-trees' flag
|
|
1765 |
- a LockDir lock
|
|
1766 |
- Support for recording full info about the tree root
|
|
1767 |
||
1768 |
"""
|
|
1910.2.14
by Aaron Bentley
Fail when trying to use interrepository on Knit2 and Knit1 |
1769 |
|
1770 |
rich_root_data = True |
|
1771 |
||
1910.2.12
by Aaron Bentley
Implement knit repo format 2 |
1772 |
def get_format_string(self): |
1773 |
"""See RepositoryFormat.get_format_string()."""
|
|
1910.2.48
by Aaron Bentley
Update from review comments |
1774 |
return "Bazaar Knit Repository Format 2\n" |
1910.2.12
by Aaron Bentley
Implement knit repo format 2 |
1775 |
|
1776 |
def get_format_description(self): |
|
1777 |
"""See RepositoryFormat.get_format_description()."""
|
|
1778 |
return "Knit repository format 2" |
|
1779 |
||
1780 |
def check_conversion_target(self, target_format): |
|
1910.2.14
by Aaron Bentley
Fail when trying to use interrepository on Knit2 and Knit1 |
1781 |
if not target_format.rich_root_data: |
1910.2.12
by Aaron Bentley
Implement knit repo format 2 |
1782 |
raise errors.BadConversionTarget( |
1783 |
'Does not support rich root data.', target_format) |
|
1784 |
||
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
1785 |
def open(self, a_bzrdir, _found=False, _override_transport=None): |
1786 |
"""See RepositoryFormat.open().
|
|
1787 |
|
|
1788 |
:param _override_transport: INTERNAL USE ONLY. Allows opening the
|
|
1789 |
repository at a slightly different url
|
|
1790 |
than normal. I.e. during 'upgrade'.
|
|
1791 |
"""
|
|
1792 |
if not _found: |
|
1793 |
format = RepositoryFormat.find_format(a_bzrdir) |
|
1794 |
assert format.__class__ == self.__class__ |
|
1795 |
if _override_transport is not None: |
|
1796 |
repo_transport = _override_transport |
|
1797 |
else: |
|
1798 |
repo_transport = a_bzrdir.get_repository_transport(None) |
|
1996.3.20
by John Arbash Meinel
[merge] bzr.dev 2063 |
1799 |
control_files = lockable_files.LockableFiles(repo_transport, 'lock', |
1800 |
lockdir.LockDir) |
|
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
1801 |
text_store = self._get_text_store(repo_transport, control_files) |
1802 |
control_store = self._get_control_store(repo_transport, control_files) |
|
1803 |
_revision_store = self._get_revision_store(repo_transport, control_files) |
|
1804 |
return KnitRepository2(_format=self, |
|
1805 |
a_bzrdir=a_bzrdir, |
|
1806 |
control_files=control_files, |
|
1807 |
_revision_store=_revision_store, |
|
1808 |
control_store=control_store, |
|
1809 |
text_store=text_store) |
|
1810 |
||
1811 |
||
1910.2.12
by Aaron Bentley
Implement knit repo format 2 |
1812 |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1813 |
# formats which have no format string are not discoverable
|
1814 |
# and not independently creatable, so are not registered.
|
|
1666.1.6
by Robert Collins
Make knit the default format. |
1815 |
RepositoryFormat.register_format(RepositoryFormat7()) |
2241.1.1
by Martin Pool
Change RepositoryFormat to use a Registry rather than ad-hoc dictionary |
1816 |
# KEEP in sync with bzrdir.format_registry default, which controls the overall
|
1817 |
# default control directory format
|
|
1910.2.42
by Aaron Bentley
Restore RepositoryFormatKnit1 as the default |
1818 |
_default_format = RepositoryFormatKnit1() |
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
1819 |
RepositoryFormat.register_format(_default_format) |
1910.2.42
by Aaron Bentley
Restore RepositoryFormatKnit1 as the default |
1820 |
RepositoryFormat.register_format(RepositoryFormatKnit2()) |
2204.4.11
by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests |
1821 |
RepositoryFormat._set_default_format(_default_format) |
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
1822 |
_legacy_formats = [RepositoryFormat4(), |
1823 |
RepositoryFormat5(), |
|
1824 |
RepositoryFormat6()] |
|
1825 |
||
1826 |
||
1563.2.12
by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile. |
1827 |
class InterRepository(InterObject): |
1534.1.27
by Robert Collins
Start InterRepository with InterRepository.get. |
1828 |
"""This class represents operations taking place between two repositories.
|
1829 |
||
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
1830 |
Its instances have methods like copy_content and fetch, and contain
|
1534.1.27
by Robert Collins
Start InterRepository with InterRepository.get. |
1831 |
references to the source and target repositories these operations can be
|
1832 |
carried out on.
|
|
1833 |
||
1834 |
Often we will provide convenience methods on 'repository' which carry out
|
|
1835 |
operations with another repository - they will always forward to
|
|
1836 |
InterRepository.get(other).method_name(parameters).
|
|
1837 |
"""
|
|
1838 |
||
1910.2.15
by Aaron Bentley
Back out inter.get changes, make optimizers an ordered list |
1839 |
_optimisers = [] |
1534.1.28
by Robert Collins
Allow for optimised InterRepository selection. |
1840 |
"""The available optimised InterRepository types."""
|
1841 |
||
1910.2.15
by Aaron Bentley
Back out inter.get changes, make optimizers an ordered list |
1842 |
def copy_content(self, revision_id=None, basis=None): |
1843 |
raise NotImplementedError(self.copy_content) |
|
1844 |
||
1845 |
def fetch(self, revision_id=None, pb=None): |
|
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
1846 |
"""Fetch the content required to construct revision_id.
|
1847 |
||
1910.7.17
by Andrew Bennetts
Various cosmetic changes. |
1848 |
The content is copied from self.source to self.target.
|
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
1849 |
|
1850 |
:param revision_id: if None all content is copied, if NULL_REVISION no
|
|
1851 |
content is copied.
|
|
1852 |
:param pb: optional progress bar to use for progress reports. If not
|
|
1853 |
provided a default one will be created.
|
|
1854 |
||
1855 |
Returns the copied revision count and the failed revisions in a tuple:
|
|
1856 |
(copied, failures).
|
|
1857 |
"""
|
|
1910.2.15
by Aaron Bentley
Back out inter.get changes, make optimizers an ordered list |
1858 |
raise NotImplementedError(self.fetch) |
1859 |
||
1860 |
@needs_read_lock
|
|
1861 |
def missing_revision_ids(self, revision_id=None): |
|
1862 |
"""Return the revision ids that source has that target does not.
|
|
1863 |
|
|
1864 |
These are returned in topological order.
|
|
1865 |
||
1866 |
:param revision_id: only return revision ids included by this
|
|
1867 |
revision_id.
|
|
1868 |
"""
|
|
1869 |
# generic, possibly worst case, slow code path.
|
|
1870 |
target_ids = set(self.target.all_revision_ids()) |
|
1871 |
if revision_id is not None: |
|
1872 |
source_ids = self.source.get_ancestry(revision_id) |
|
1963.2.6
by Robey Pointer
pychecker is on crack; go back to using 'is None'. |
1873 |
assert source_ids[0] is None |
1910.2.15
by Aaron Bentley
Back out inter.get changes, make optimizers an ordered list |
1874 |
source_ids.pop(0) |
1875 |
else: |
|
1876 |
source_ids = self.source.all_revision_ids() |
|
1877 |
result_set = set(source_ids).difference(target_ids) |
|
1878 |
# this may look like a no-op: its not. It preserves the ordering
|
|
1879 |
# other_ids had while only returning the members from other_ids
|
|
1880 |
# that we've decided we need.
|
|
1881 |
return [rev_id for rev_id in source_ids if rev_id in result_set] |
|
1882 |
||
1883 |
||
1884 |
class InterSameDataRepository(InterRepository): |
|
1885 |
"""Code for converting between repositories that represent the same data.
|
|
1886 |
|
|
1887 |
Data format and model must match for this to work.
|
|
1888 |
"""
|
|
1889 |
||
1890 |
_matching_repo_format = RepositoryFormat4() |
|
1891 |
"""Repository format for testing with."""
|
|
1892 |
||
1910.2.14
by Aaron Bentley
Fail when trying to use interrepository on Knit2 and Knit1 |
1893 |
@staticmethod
|
1894 |
def is_compatible(source, target): |
|
1910.2.15
by Aaron Bentley
Back out inter.get changes, make optimizers an ordered list |
1895 |
if not isinstance(source, Repository): |
1896 |
return False |
|
1897 |
if not isinstance(target, Repository): |
|
1898 |
return False |
|
1910.2.14
by Aaron Bentley
Fail when trying to use interrepository on Knit2 and Knit1 |
1899 |
if source._format.rich_root_data == target._format.rich_root_data: |
1900 |
return True |
|
1901 |
else: |
|
1902 |
return False |
|
1903 |
||
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
1904 |
@needs_write_lock
|
1905 |
def copy_content(self, revision_id=None, basis=None): |
|
1906 |
"""Make a complete copy of the content in self into destination.
|
|
1907 |
|
|
1908 |
This is a destructive operation! Do not use it on existing
|
|
1909 |
repositories.
|
|
1910 |
||
1911 |
:param revision_id: Only copy the content needed to construct
|
|
1912 |
revision_id and its parents.
|
|
1913 |
:param basis: Copy the needed data preferentially from basis.
|
|
1914 |
"""
|
|
1915 |
try: |
|
1916 |
self.target.set_make_working_trees(self.source.make_working_trees()) |
|
1917 |
except NotImplementedError: |
|
1918 |
pass
|
|
1919 |
# grab the basis available data
|
|
1920 |
if basis is not None: |
|
1921 |
self.target.fetch(basis, revision_id=revision_id) |
|
1759.2.2
by Jelmer Vernooij
Revert some of my spelling fixes and fix some typos after review by Aaron. |
1922 |
# but don't bother fetching if we have the needed data now.
|
1996.3.20
by John Arbash Meinel
[merge] bzr.dev 2063 |
1923 |
if (revision_id not in (None, _mod_revision.NULL_REVISION) and |
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
1924 |
self.target.has_revision(revision_id)): |
1925 |
return
|
|
1926 |
self.target.fetch(self.source, revision_id=revision_id) |
|
1927 |
||
1928 |
@needs_write_lock
|
|
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
1929 |
def fetch(self, revision_id=None, pb=None): |
1910.7.20
by Andrew Bennetts
Merge from bzr.dev |
1930 |
"""See InterRepository.fetch()."""
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
1931 |
from bzrlib.fetch import GenericRepoFetcher |
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
1932 |
mutter("Using fetch logic to copy between %s(%s) and %s(%s)", |
1910.2.15
by Aaron Bentley
Back out inter.get changes, make optimizers an ordered list |
1933 |
self.source, self.source._format, self.target, |
1934 |
self.target._format) |
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
1935 |
f = GenericRepoFetcher(to_repository=self.target, |
1936 |
from_repository=self.source, |
|
1937 |
last_revision=revision_id, |
|
1938 |
pb=pb) |
|
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
1939 |
return f.count_copied, f.failed_revisions |
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
1940 |
|
1910.2.15
by Aaron Bentley
Back out inter.get changes, make optimizers an ordered list |
1941 |
|
1942 |
class InterWeaveRepo(InterSameDataRepository): |
|
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
1943 |
"""Optimised code paths between Weave based repositories."""
|
1944 |
||
1666.1.6
by Robert Collins
Make knit the default format. |
1945 |
_matching_repo_format = RepositoryFormat7() |
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
1946 |
"""Repository format for testing with."""
|
1947 |
||
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
1948 |
@staticmethod
|
1949 |
def is_compatible(source, target): |
|
1950 |
"""Be compatible with known Weave formats.
|
|
1951 |
|
|
1759.2.2
by Jelmer Vernooij
Revert some of my spelling fixes and fix some typos after review by Aaron. |
1952 |
We don't test for the stores being of specific types because that
|
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
1953 |
could lead to confusing results, and there is no need to be
|
1954 |
overly general.
|
|
1955 |
"""
|
|
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
1956 |
try: |
1957 |
return (isinstance(source._format, (RepositoryFormat5, |
|
1958 |
RepositoryFormat6, |
|
1959 |
RepositoryFormat7)) and |
|
1960 |
isinstance(target._format, (RepositoryFormat5, |
|
1961 |
RepositoryFormat6, |
|
1962 |
RepositoryFormat7))) |
|
1963 |
except AttributeError: |
|
1964 |
return False |
|
1965 |
||
1966 |
@needs_write_lock
|
|
1967 |
def copy_content(self, revision_id=None, basis=None): |
|
1968 |
"""See InterRepository.copy_content()."""
|
|
1969 |
# weave specific optimised path:
|
|
1970 |
if basis is not None: |
|
1971 |
# copy the basis in, then fetch remaining data.
|
|
1972 |
basis.copy_content_into(self.target, revision_id) |
|
1759.2.2
by Jelmer Vernooij
Revert some of my spelling fixes and fix some typos after review by Aaron. |
1973 |
# the basis copy_content_into could miss-set this.
|
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
1974 |
try: |
1975 |
self.target.set_make_working_trees(self.source.make_working_trees()) |
|
1976 |
except NotImplementedError: |
|
1977 |
pass
|
|
1978 |
self.target.fetch(self.source, revision_id=revision_id) |
|
1979 |
else: |
|
1980 |
try: |
|
1981 |
self.target.set_make_working_trees(self.source.make_working_trees()) |
|
1982 |
except NotImplementedError: |
|
1983 |
pass
|
|
1984 |
# FIXME do not peek!
|
|
1985 |
if self.source.control_files._transport.listable(): |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
1986 |
pb = ui.ui_factory.nested_progress_bar() |
1594.1.3
by Robert Collins
Fixup pb usage to use nested_progress_bar. |
1987 |
try: |
1563.2.37
by Robert Collins
Merge in nested progress bars |
1988 |
self.target.weave_store.copy_all_ids( |
1989 |
self.source.weave_store, |
|
1990 |
pb=pb, |
|
1991 |
from_transaction=self.source.get_transaction(), |
|
1992 |
to_transaction=self.target.get_transaction()) |
|
1594.1.3
by Robert Collins
Fixup pb usage to use nested_progress_bar. |
1993 |
pb.update('copying inventory', 0, 1) |
1994 |
self.target.control_weaves.copy_multi( |
|
1563.2.37
by Robert Collins
Merge in nested progress bars |
1995 |
self.source.control_weaves, ['inventory'], |
1996 |
from_transaction=self.source.get_transaction(), |
|
1997 |
to_transaction=self.target.get_transaction()) |
|
1998 |
self.target._revision_store.text_store.copy_all_ids( |
|
1999 |
self.source._revision_store.text_store, |
|
2000 |
pb=pb) |
|
1594.1.3
by Robert Collins
Fixup pb usage to use nested_progress_bar. |
2001 |
finally: |
2002 |
pb.finished() |
|
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
2003 |
else: |
2004 |
self.target.fetch(self.source, revision_id=revision_id) |
|
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
2005 |
|
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
2006 |
@needs_write_lock
|
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
2007 |
def fetch(self, revision_id=None, pb=None): |
2008 |
"""See InterRepository.fetch()."""
|
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
2009 |
from bzrlib.fetch import GenericRepoFetcher |
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
2010 |
mutter("Using fetch logic to copy between %s(%s) and %s(%s)", |
2011 |
self.source, self.source._format, self.target, self.target._format) |
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
2012 |
f = GenericRepoFetcher(to_repository=self.target, |
2013 |
from_repository=self.source, |
|
2014 |
last_revision=revision_id, |
|
2015 |
pb=pb) |
|
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
2016 |
return f.count_copied, f.failed_revisions |
2017 |
||
1534.1.34
by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method. |
2018 |
@needs_read_lock
|
2019 |
def missing_revision_ids(self, revision_id=None): |
|
2020 |
"""See InterRepository.missing_revision_ids()."""
|
|
2021 |
# we want all revisions to satisfy revision_id in source.
|
|
1759.2.2
by Jelmer Vernooij
Revert some of my spelling fixes and fix some typos after review by Aaron. |
2022 |
# but we don't want to stat every file here and there.
|
1534.1.34
by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method. |
2023 |
# we want then, all revisions other needs to satisfy revision_id
|
2024 |
# checked, but not those that we have locally.
|
|
2025 |
# so the first thing is to get a subset of the revisions to
|
|
2026 |
# satisfy revision_id in source, and then eliminate those that
|
|
2027 |
# we do already have.
|
|
2028 |
# this is slow on high latency connection to self, but as as this
|
|
2029 |
# disk format scales terribly for push anyway due to rewriting
|
|
2030 |
# inventory.weave, this is considered acceptable.
|
|
2031 |
# - RBC 20060209
|
|
2032 |
if revision_id is not None: |
|
2033 |
source_ids = self.source.get_ancestry(revision_id) |
|
1963.2.6
by Robey Pointer
pychecker is on crack; go back to using 'is None'. |
2034 |
assert source_ids[0] is None |
1668.1.14
by Martin Pool
merge olaf - InvalidRevisionId fixes |
2035 |
source_ids.pop(0) |
1534.1.34
by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method. |
2036 |
else: |
2037 |
source_ids = self.source._all_possible_ids() |
|
2038 |
source_ids_set = set(source_ids) |
|
2039 |
# source_ids is the worst possible case we may need to pull.
|
|
2040 |
# now we want to filter source_ids against what we actually
|
|
1759.2.2
by Jelmer Vernooij
Revert some of my spelling fixes and fix some typos after review by Aaron. |
2041 |
# have in target, but don't try to check for existence where we know
|
1534.1.34
by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method. |
2042 |
# we do not have a revision as that would be pointless.
|
2043 |
target_ids = set(self.target._all_possible_ids()) |
|
2044 |
possibly_present_revisions = target_ids.intersection(source_ids_set) |
|
2045 |
actually_present_revisions = set(self.target._eliminate_revisions_not_present(possibly_present_revisions)) |
|
2046 |
required_revisions = source_ids_set.difference(actually_present_revisions) |
|
2047 |
required_topo_revisions = [rev_id for rev_id in source_ids if rev_id in required_revisions] |
|
2048 |
if revision_id is not None: |
|
2049 |
# we used get_ancestry to determine source_ids then we are assured all
|
|
2050 |
# revisions referenced are present as they are installed in topological order.
|
|
2051 |
# and the tip revision was validated by get_ancestry.
|
|
2052 |
return required_topo_revisions |
|
2053 |
else: |
|
2054 |
# if we just grabbed the possibly available ids, then
|
|
2055 |
# we only have an estimate of whats available and need to validate
|
|
2056 |
# that against the revision records.
|
|
2057 |
return self.source._eliminate_revisions_not_present(required_topo_revisions) |
|
2058 |
||
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
2059 |
|
1910.2.15
by Aaron Bentley
Back out inter.get changes, make optimizers an ordered list |
2060 |
class InterKnitRepo(InterSameDataRepository): |
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
2061 |
"""Optimised code paths between Knit based repositories."""
|
2062 |
||
2063 |
_matching_repo_format = RepositoryFormatKnit1() |
|
2064 |
"""Repository format for testing with."""
|
|
2065 |
||
2066 |
@staticmethod
|
|
2067 |
def is_compatible(source, target): |
|
2068 |
"""Be compatible with known Knit formats.
|
|
2069 |
|
|
1759.2.2
by Jelmer Vernooij
Revert some of my spelling fixes and fix some typos after review by Aaron. |
2070 |
We don't test for the stores being of specific types because that
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
2071 |
could lead to confusing results, and there is no need to be
|
2072 |
overly general.
|
|
2073 |
"""
|
|
2074 |
try: |
|
2075 |
return (isinstance(source._format, (RepositoryFormatKnit1)) and |
|
2076 |
isinstance(target._format, (RepositoryFormatKnit1))) |
|
2077 |
except AttributeError: |
|
2078 |
return False |
|
2079 |
||
2080 |
@needs_write_lock
|
|
2081 |
def fetch(self, revision_id=None, pb=None): |
|
2082 |
"""See InterRepository.fetch()."""
|
|
2083 |
from bzrlib.fetch import KnitRepoFetcher |
|
2084 |
mutter("Using fetch logic to copy between %s(%s) and %s(%s)", |
|
2085 |
self.source, self.source._format, self.target, self.target._format) |
|
2086 |
f = KnitRepoFetcher(to_repository=self.target, |
|
2087 |
from_repository=self.source, |
|
2088 |
last_revision=revision_id, |
|
2089 |
pb=pb) |
|
2090 |
return f.count_copied, f.failed_revisions |
|
2091 |
||
2092 |
@needs_read_lock
|
|
2093 |
def missing_revision_ids(self, revision_id=None): |
|
2094 |
"""See InterRepository.missing_revision_ids()."""
|
|
2095 |
if revision_id is not None: |
|
2096 |
source_ids = self.source.get_ancestry(revision_id) |
|
1963.2.6
by Robey Pointer
pychecker is on crack; go back to using 'is None'. |
2097 |
assert source_ids[0] is None |
1668.1.14
by Martin Pool
merge olaf - InvalidRevisionId fixes |
2098 |
source_ids.pop(0) |
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
2099 |
else: |
2100 |
source_ids = self.source._all_possible_ids() |
|
2101 |
source_ids_set = set(source_ids) |
|
2102 |
# source_ids is the worst possible case we may need to pull.
|
|
2103 |
# now we want to filter source_ids against what we actually
|
|
1759.2.2
by Jelmer Vernooij
Revert some of my spelling fixes and fix some typos after review by Aaron. |
2104 |
# have in target, but don't try to check for existence where we know
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
2105 |
# we do not have a revision as that would be pointless.
|
2106 |
target_ids = set(self.target._all_possible_ids()) |
|
2107 |
possibly_present_revisions = target_ids.intersection(source_ids_set) |
|
2108 |
actually_present_revisions = set(self.target._eliminate_revisions_not_present(possibly_present_revisions)) |
|
2109 |
required_revisions = source_ids_set.difference(actually_present_revisions) |
|
2110 |
required_topo_revisions = [rev_id for rev_id in source_ids if rev_id in required_revisions] |
|
2111 |
if revision_id is not None: |
|
2112 |
# we used get_ancestry to determine source_ids then we are assured all
|
|
2113 |
# revisions referenced are present as they are installed in topological order.
|
|
2114 |
# and the tip revision was validated by get_ancestry.
|
|
2115 |
return required_topo_revisions |
|
2116 |
else: |
|
2117 |
# if we just grabbed the possibly available ids, then
|
|
2118 |
# we only have an estimate of whats available and need to validate
|
|
2119 |
# that against the revision records.
|
|
2120 |
return self.source._eliminate_revisions_not_present(required_topo_revisions) |
|
2121 |
||
1910.2.17
by Aaron Bentley
Get fetching from 1 to 2 under test |
2122 |
|
1910.2.24
by Aaron Bentley
Got intra-repository fetch working between model1 and 2 for all types |
2123 |
class InterModel1and2(InterRepository): |
2124 |
||
2125 |
_matching_repo_format = None |
|
2126 |
||
2127 |
@staticmethod
|
|
2128 |
def is_compatible(source, target): |
|
2129 |
if not isinstance(source, Repository): |
|
2130 |
return False |
|
2131 |
if not isinstance(target, Repository): |
|
2132 |
return False |
|
2133 |
if not source._format.rich_root_data and target._format.rich_root_data: |
|
2134 |
return True |
|
2135 |
else: |
|
2136 |
return False |
|
2137 |
||
2138 |
@needs_write_lock
|
|
2139 |
def fetch(self, revision_id=None, pb=None): |
|
2140 |
"""See InterRepository.fetch()."""
|
|
2141 |
from bzrlib.fetch import Model1toKnit2Fetcher |
|
2142 |
f = Model1toKnit2Fetcher(to_repository=self.target, |
|
2143 |
from_repository=self.source, |
|
2144 |
last_revision=revision_id, |
|
2145 |
pb=pb) |
|
2146 |
return f.count_copied, f.failed_revisions |
|
2147 |
||
1910.2.26
by Aaron Bentley
Fix up some test cases |
2148 |
@needs_write_lock
|
2149 |
def copy_content(self, revision_id=None, basis=None): |
|
2150 |
"""Make a complete copy of the content in self into destination.
|
|
2151 |
|
|
2152 |
This is a destructive operation! Do not use it on existing
|
|
2153 |
repositories.
|
|
2154 |
||
2155 |
:param revision_id: Only copy the content needed to construct
|
|
2156 |
revision_id and its parents.
|
|
2157 |
:param basis: Copy the needed data preferentially from basis.
|
|
2158 |
"""
|
|
2159 |
try: |
|
2160 |
self.target.set_make_working_trees(self.source.make_working_trees()) |
|
2161 |
except NotImplementedError: |
|
2162 |
pass
|
|
2163 |
# grab the basis available data
|
|
2164 |
if basis is not None: |
|
2165 |
self.target.fetch(basis, revision_id=revision_id) |
|
2166 |
# but don't bother fetching if we have the needed data now.
|
|
1996.3.20
by John Arbash Meinel
[merge] bzr.dev 2063 |
2167 |
if (revision_id not in (None, _mod_revision.NULL_REVISION) and |
1910.2.26
by Aaron Bentley
Fix up some test cases |
2168 |
self.target.has_revision(revision_id)): |
2169 |
return
|
|
2170 |
self.target.fetch(self.source, revision_id=revision_id) |
|
2171 |
||
1910.2.24
by Aaron Bentley
Got intra-repository fetch working between model1 and 2 for all types |
2172 |
|
1910.2.17
by Aaron Bentley
Get fetching from 1 to 2 under test |
2173 |
class InterKnit1and2(InterKnitRepo): |
2174 |
||
1910.2.24
by Aaron Bentley
Got intra-repository fetch working between model1 and 2 for all types |
2175 |
_matching_repo_format = None |
2176 |
||
1910.2.17
by Aaron Bentley
Get fetching from 1 to 2 under test |
2177 |
@staticmethod
|
2178 |
def is_compatible(source, target): |
|
2179 |
"""Be compatible with Knit1 source and Knit2 target"""
|
|
2180 |
try: |
|
2181 |
return (isinstance(source._format, (RepositoryFormatKnit1)) and |
|
2182 |
isinstance(target._format, (RepositoryFormatKnit2))) |
|
2183 |
except AttributeError: |
|
2184 |
return False |
|
2185 |
||
2186 |
@needs_write_lock
|
|
2187 |
def fetch(self, revision_id=None, pb=None): |
|
2188 |
"""See InterRepository.fetch()."""
|
|
2189 |
from bzrlib.fetch import Knit1to2Fetcher |
|
2190 |
mutter("Using fetch logic to copy between %s(%s) and %s(%s)", |
|
2191 |
self.source, self.source._format, self.target, |
|
2192 |
self.target._format) |
|
2193 |
f = Knit1to2Fetcher(to_repository=self.target, |
|
2194 |
from_repository=self.source, |
|
2195 |
last_revision=revision_id, |
|
2196 |
pb=pb) |
|
2197 |
return f.count_copied, f.failed_revisions |
|
2198 |
||
2199 |
||
1910.2.15
by Aaron Bentley
Back out inter.get changes, make optimizers an ordered list |
2200 |
InterRepository.register_optimiser(InterSameDataRepository) |
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
2201 |
InterRepository.register_optimiser(InterWeaveRepo) |
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
2202 |
InterRepository.register_optimiser(InterKnitRepo) |
1910.2.24
by Aaron Bentley
Got intra-repository fetch working between model1 and 2 for all types |
2203 |
InterRepository.register_optimiser(InterModel1and2) |
1910.2.17
by Aaron Bentley
Get fetching from 1 to 2 under test |
2204 |
InterRepository.register_optimiser(InterKnit1and2) |
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
2205 |
|
2206 |
||
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
2207 |
class RepositoryTestProviderAdapter(object): |
2208 |
"""A tool to generate a suite testing multiple repository formats at once.
|
|
2209 |
||
2210 |
This is done by copying the test once for each transport and injecting
|
|
2211 |
the transport_server, transport_readonly_server, and bzrdir_format and
|
|
2212 |
repository_format classes into each copy. Each copy is also given a new id()
|
|
2213 |
to make it easy to identify.
|
|
2214 |
"""
|
|
2215 |
||
2216 |
def __init__(self, transport_server, transport_readonly_server, formats): |
|
2217 |
self._transport_server = transport_server |
|
2218 |
self._transport_readonly_server = transport_readonly_server |
|
2219 |
self._formats = formats |
|
2220 |
||
2221 |
def adapt(self, test): |
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
2222 |
result = unittest.TestSuite() |
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
2223 |
for repository_format, bzrdir_format in self._formats: |
2224 |
new_test = deepcopy(test) |
|
2225 |
new_test.transport_server = self._transport_server |
|
2226 |
new_test.transport_readonly_server = self._transport_readonly_server |
|
2227 |
new_test.bzrdir_format = bzrdir_format |
|
2228 |
new_test.repository_format = repository_format |
|
2229 |
def make_new_test_id(): |
|
2230 |
new_id = "%s(%s)" % (new_test.id(), repository_format.__class__.__name__) |
|
2231 |
return lambda: new_id |
|
2232 |
new_test.id = make_new_test_id() |
|
2233 |
result.addTest(new_test) |
|
2234 |
return result |
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
2235 |
|
2236 |
||
2237 |
class InterRepositoryTestProviderAdapter(object): |
|
2238 |
"""A tool to generate a suite testing multiple inter repository formats.
|
|
2239 |
||
2240 |
This is done by copying the test once for each interrepo provider and injecting
|
|
2241 |
the transport_server, transport_readonly_server, repository_format and
|
|
2242 |
repository_to_format classes into each copy.
|
|
2243 |
Each copy is also given a new id() to make it easy to identify.
|
|
2244 |
"""
|
|
2245 |
||
2246 |
def __init__(self, transport_server, transport_readonly_server, formats): |
|
2247 |
self._transport_server = transport_server |
|
2248 |
self._transport_readonly_server = transport_readonly_server |
|
2249 |
self._formats = formats |
|
2250 |
||
2251 |
def adapt(self, test): |
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
2252 |
result = unittest.TestSuite() |
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
2253 |
for interrepo_class, repository_format, repository_format_to in self._formats: |
2254 |
new_test = deepcopy(test) |
|
2255 |
new_test.transport_server = self._transport_server |
|
2256 |
new_test.transport_readonly_server = self._transport_readonly_server |
|
2257 |
new_test.interrepo_class = interrepo_class |
|
2258 |
new_test.repository_format = repository_format |
|
2259 |
new_test.repository_format_to = repository_format_to |
|
2260 |
def make_new_test_id(): |
|
2261 |
new_id = "%s(%s)" % (new_test.id(), interrepo_class.__name__) |
|
2262 |
return lambda: new_id |
|
2263 |
new_test.id = make_new_test_id() |
|
2264 |
result.addTest(new_test) |
|
2265 |
return result |
|
2266 |
||
2267 |
@staticmethod
|
|
2268 |
def default_test_list(): |
|
2269 |
"""Generate the default list of interrepo permutations to test."""
|
|
2270 |
result = [] |
|
2271 |
# test the default InterRepository between format 6 and the current
|
|
2272 |
# default format.
|
|
1534.1.33
by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations. |
2273 |
# XXX: robertc 20060220 reinstate this when there are two supported
|
2274 |
# formats which do not have an optimal code path between them.
|
|
1910.2.24
by Aaron Bentley
Got intra-repository fetch working between model1 and 2 for all types |
2275 |
#result.append((InterRepository,
|
2276 |
# RepositoryFormat6(),
|
|
2277 |
# RepositoryFormatKnit1()))
|
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
2278 |
for optimiser in InterRepository._optimisers: |
1910.2.24
by Aaron Bentley
Got intra-repository fetch working between model1 and 2 for all types |
2279 |
if optimiser._matching_repo_format is not None: |
2280 |
result.append((optimiser, |
|
2281 |
optimiser._matching_repo_format, |
|
2282 |
optimiser._matching_repo_format |
|
2283 |
))
|
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
2284 |
# if there are specific combinations we want to use, we can add them
|
2285 |
# here.
|
|
1910.2.24
by Aaron Bentley
Got intra-repository fetch working between model1 and 2 for all types |
2286 |
result.append((InterModel1and2, RepositoryFormat5(), |
2287 |
RepositoryFormatKnit2())) |
|
2288 |
result.append((InterKnit1and2, RepositoryFormatKnit1(), |
|
2289 |
RepositoryFormatKnit2())) |
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
2290 |
return result |
1556.1.4
by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same. |
2291 |
|
2292 |
||
2293 |
class CopyConverter(object): |
|
2294 |
"""A repository conversion tool which just performs a copy of the content.
|
|
2295 |
|
|
2296 |
This is slow but quite reliable.
|
|
2297 |
"""
|
|
2298 |
||
2299 |
def __init__(self, target_format): |
|
2300 |
"""Create a CopyConverter.
|
|
2301 |
||
2302 |
:param target_format: The format the resulting repository should be.
|
|
2303 |
"""
|
|
2304 |
self.target_format = target_format |
|
2305 |
||
2306 |
def convert(self, repo, pb): |
|
2307 |
"""Perform the conversion of to_convert, giving feedback via pb.
|
|
2308 |
||
2309 |
:param to_convert: The disk object to convert.
|
|
2310 |
:param pb: a progress bar to use for progress information.
|
|
2311 |
"""
|
|
2312 |
self.pb = pb |
|
2313 |
self.count = 0 |
|
1596.2.22
by Robert Collins
Fetch changes to use new pb. |
2314 |
self.total = 4 |
1556.1.4
by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same. |
2315 |
# this is only useful with metadir layouts - separated repo content.
|
2316 |
# trigger an assertion if not such
|
|
2317 |
repo._format.get_format_string() |
|
2318 |
self.repo_dir = repo.bzrdir |
|
2319 |
self.step('Moving repository to repository.backup') |
|
2320 |
self.repo_dir.transport.move('repository', 'repository.backup') |
|
2321 |
backup_transport = self.repo_dir.transport.clone('repository.backup') |
|
1910.2.12
by Aaron Bentley
Implement knit repo format 2 |
2322 |
repo._format.check_conversion_target(self.target_format) |
1556.1.4
by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same. |
2323 |
self.source_repo = repo._format.open(self.repo_dir, |
2324 |
_found=True, |
|
2325 |
_override_transport=backup_transport) |
|
2326 |
self.step('Creating new repository') |
|
2327 |
converted = self.target_format.initialize(self.repo_dir, |
|
2328 |
self.source_repo.is_shared()) |
|
2329 |
converted.lock_write() |
|
2330 |
try: |
|
2331 |
self.step('Copying content into repository.') |
|
2332 |
self.source_repo.copy_content_into(converted) |
|
2333 |
finally: |
|
2334 |
converted.unlock() |
|
2335 |
self.step('Deleting old repository content.') |
|
2336 |
self.repo_dir.transport.delete_tree('repository.backup') |
|
2337 |
self.pb.note('repository converted') |
|
2338 |
||
2339 |
def step(self, message): |
|
2340 |
"""Update the pb by a step."""
|
|
2341 |
self.count +=1 |
|
2342 |
self.pb.update(message, self.count, self.total) |
|
1596.1.1
by Martin Pool
Use simple xml unescaping rather than importing xml.sax |
2343 |
|
2344 |
||
1740.3.1
by Jelmer Vernooij
Introduce and use CommitBuilder objects. |
2345 |
class CommitBuilder(object): |
2346 |
"""Provides an interface to build up a commit.
|
|
2347 |
||
2348 |
This allows describing a tree to be committed without needing to
|
|
2349 |
know the internals of the format of the repository.
|
|
2350 |
"""
|
|
1910.2.4
by Aaron Bentley
Support old CommitBuilders |
2351 |
|
2352 |
record_root_entry = False |
|
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
2353 |
def __init__(self, repository, parents, config, timestamp=None, |
2354 |
timezone=None, committer=None, revprops=None, |
|
2355 |
revision_id=None): |
|
2356 |
"""Initiate a CommitBuilder.
|
|
2357 |
||
2358 |
:param repository: Repository to commit to.
|
|
2359 |
:param parents: Revision ids of the parents of the new revision.
|
|
2360 |
:param config: Configuration to use.
|
|
2361 |
:param timestamp: Optional timestamp recorded for commit.
|
|
2362 |
:param timezone: Optional timezone for timestamp.
|
|
2363 |
:param committer: Optional committer to set for commit.
|
|
2364 |
:param revprops: Optional dictionary of revision properties.
|
|
2365 |
:param revision_id: Optional revision id.
|
|
2366 |
"""
|
|
2367 |
self._config = config |
|
2368 |
||
2369 |
if committer is None: |
|
2370 |
self._committer = self._config.username() |
|
2371 |
else: |
|
2372 |
assert isinstance(committer, basestring), type(committer) |
|
2373 |
self._committer = committer |
|
2374 |
||
1731.1.33
by Aaron Bentley
Revert no-special-root changes |
2375 |
self.new_inventory = Inventory(None) |
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
2376 |
self._new_revision_id = revision_id |
1740.3.6
by Jelmer Vernooij
Move inventory writing to the commit builder. |
2377 |
self.parents = parents |
1740.3.1
by Jelmer Vernooij
Introduce and use CommitBuilder objects. |
2378 |
self.repository = repository |
1740.3.6
by Jelmer Vernooij
Move inventory writing to the commit builder. |
2379 |
|
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
2380 |
self._revprops = {} |
2381 |
if revprops is not None: |
|
2382 |
self._revprops.update(revprops) |
|
2383 |
||
2384 |
if timestamp is None: |
|
1864.2.1
by John Arbash Meinel
Commit timestamp restricted to 1ms precision. |
2385 |
timestamp = time.time() |
2386 |
# Restrict resolution to 1ms
|
|
2387 |
self._timestamp = round(timestamp, 3) |
|
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
2388 |
|
2389 |
if timezone is None: |
|
2390 |
self._timezone = local_time_offset() |
|
2391 |
else: |
|
2392 |
self._timezone = int(timezone) |
|
2393 |
||
2394 |
self._generate_revision_if_needed() |
|
2395 |
||
1740.3.9
by Jelmer Vernooij
Make the commit message the first argument of CommitBuilder.commit(). |
2396 |
def commit(self, message): |
1740.3.8
by Jelmer Vernooij
Move make_revision() to commit builder. |
2397 |
"""Make the actual commit.
|
2398 |
||
2399 |
:return: The revision id of the recorded revision.
|
|
2400 |
"""
|
|
1996.3.4
by John Arbash Meinel
lazy_import bzrlib/repository.py |
2401 |
rev = _mod_revision.Revision( |
2402 |
timestamp=self._timestamp, |
|
1740.3.8
by Jelmer Vernooij
Move make_revision() to commit builder. |
2403 |
timezone=self._timezone, |
2404 |
committer=self._committer, |
|
1740.3.9
by Jelmer Vernooij
Make the commit message the first argument of CommitBuilder.commit(). |
2405 |
message=message, |
1740.3.8
by Jelmer Vernooij
Move make_revision() to commit builder. |
2406 |
inventory_sha1=self.inv_sha1, |
2407 |
revision_id=self._new_revision_id, |
|
2408 |
properties=self._revprops) |
|
2409 |
rev.parent_ids = self.parents |
|
2410 |
self.repository.add_revision(self._new_revision_id, rev, |
|
2411 |
self.new_inventory, self._config) |
|
2412 |
return self._new_revision_id |
|
2413 |
||
2041.1.5
by John Arbash Meinel
CommitBuilder.get_tree => CommitBuilder.revision_tree |
2414 |
def revision_tree(self): |
2041.1.1
by John Arbash Meinel
Add a 'get_tree()' call that returns a RevisionTree for the newly committed tree |
2415 |
"""Return the tree that was just committed.
|
2416 |
||
2417 |
After calling commit() this can be called to get a RevisionTree
|
|
2418 |
representing the newly committed tree. This is preferred to
|
|
2419 |
calling Repository.revision_tree() because that may require
|
|
2420 |
deserializing the inventory, while we already have a copy in
|
|
2421 |
memory.
|
|
2422 |
"""
|
|
2423 |
return RevisionTree(self.repository, self.new_inventory, |
|
2424 |
self._new_revision_id) |
|
2425 |
||
1740.3.6
by Jelmer Vernooij
Move inventory writing to the commit builder. |
2426 |
def finish_inventory(self): |
1740.3.9
by Jelmer Vernooij
Make the commit message the first argument of CommitBuilder.commit(). |
2427 |
"""Tell the builder that the inventory is finished."""
|
1910.2.3
by Aaron Bentley
All tests pass |
2428 |
if self.new_inventory.root is None: |
1910.2.9
by Aaron Bentley
Inroduce assertDeprecated, and use it to test old commitbuilder API |
2429 |
symbol_versioning.warn('Root entry should be supplied to' |
2430 |
' record_entry_contents, as of bzr 0.10.', |
|
1910.2.3
by Aaron Bentley
All tests pass |
2431 |
DeprecationWarning, stacklevel=2) |
2432 |
self.new_inventory.add(InventoryDirectory(ROOT_ID, '', None)) |
|
1757.1.2
by Robert Collins
Bugfix CommitBuilders recording of the inventory revision id. |
2433 |
self.new_inventory.revision_id = self._new_revision_id |
1740.3.8
by Jelmer Vernooij
Move make_revision() to commit builder. |
2434 |
self.inv_sha1 = self.repository.add_inventory( |
1740.3.6
by Jelmer Vernooij
Move inventory writing to the commit builder. |
2435 |
self._new_revision_id, |
2436 |
self.new_inventory, |
|
2437 |
self.parents |
|
2438 |
)
|
|
1740.3.1
by Jelmer Vernooij
Introduce and use CommitBuilder objects. |
2439 |
|
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
2440 |
def _gen_revision_id(self): |
2441 |
"""Return new revision-id."""
|
|
2116.4.1
by John Arbash Meinel
Update file and revision id generators. |
2442 |
return generate_ids.gen_revision_id(self._config.username(), |
2443 |
self._timestamp) |
|
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
2444 |
|
2445 |
def _generate_revision_if_needed(self): |
|
2446 |
"""Create a revision id if None was supplied.
|
|
2447 |
|
|
2448 |
If the repository can not support user-specified revision ids
|
|
2150.2.2
by Robert Collins
Change the commit builder selected-revision-id test to use a unicode revision id where possible, leading to stricter testing of the hypothetical unicode revision id support in bzr. |
2449 |
they should override this function and raise CannotSetRevisionId
|
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
2450 |
if _new_revision_id is not None.
|
2451 |
||
2150.2.2
by Robert Collins
Change the commit builder selected-revision-id test to use a unicode revision id where possible, leading to stricter testing of the hypothetical unicode revision id support in bzr. |
2452 |
:raises: CannotSetRevisionId
|
1740.3.3
by Jelmer Vernooij
Move storing directories and links to commit builder. |
2453 |
"""
|
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
2454 |
if self._new_revision_id is None: |
2455 |
self._new_revision_id = self._gen_revision_id() |
|
1740.3.3
by Jelmer Vernooij
Move storing directories and links to commit builder. |
2456 |
|
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
2457 |
def record_entry_contents(self, ie, parent_invs, path, tree): |
1740.3.1
by Jelmer Vernooij
Introduce and use CommitBuilder objects. |
2458 |
"""Record the content of ie from tree into the commit if needed.
|
2459 |
||
1910.2.3
by Aaron Bentley
All tests pass |
2460 |
Side effect: sets ie.revision when unchanged
|
2461 |
||
1740.3.1
by Jelmer Vernooij
Introduce and use CommitBuilder objects. |
2462 |
:param ie: An inventory entry present in the commit.
|
2463 |
:param parent_invs: The inventories of the parent revisions of the
|
|
2464 |
commit.
|
|
2465 |
:param path: The path the entry is at in the tree.
|
|
2466 |
:param tree: The tree which contains this entry and should be used to
|
|
2467 |
obtain content.
|
|
2468 |
"""
|
|
1910.2.8
by Aaron Bentley
Fix commit_builder when root not passed to record_entry_contents |
2469 |
if self.new_inventory.root is None and ie.parent_id is not None: |
1910.2.9
by Aaron Bentley
Inroduce assertDeprecated, and use it to test old commitbuilder API |
2470 |
symbol_versioning.warn('Root entry should be supplied to' |
2471 |
' record_entry_contents, as of bzr 0.10.', |
|
1910.2.8
by Aaron Bentley
Fix commit_builder when root not passed to record_entry_contents |
2472 |
DeprecationWarning, stacklevel=2) |
2473 |
self.record_entry_contents(tree.inventory.root.copy(), parent_invs, |
|
2474 |
'', tree) |
|
1907.1.1
by Aaron Bentley
Unshelved all changes except those related to removing RootEntry |
2475 |
self.new_inventory.add(ie) |
1740.3.6
by Jelmer Vernooij
Move inventory writing to the commit builder. |
2476 |
|
1740.3.4
by Jelmer Vernooij
Move inventory to commit builder. |
2477 |
# ie.revision is always None if the InventoryEntry is considered
|
2478 |
# for committing. ie.snapshot will record the correct revision
|
|
2479 |
# which may be the sole parent if it is untouched.
|
|
1740.3.6
by Jelmer Vernooij
Move inventory writing to the commit builder. |
2480 |
if ie.revision is not None: |
2481 |
return
|
|
1910.2.3
by Aaron Bentley
All tests pass |
2482 |
|
2483 |
# In this revision format, root entries have no knit or weave
|
|
2484 |
if ie is self.new_inventory.root: |
|
2044.1.1
by Robert Collins
(Robert Collins) Forward merge from 0.11rc2 NEWS and performance-regression fix. |
2485 |
# When serializing out to disk and back in
|
2486 |
# root.revision is always _new_revision_id
|
|
2487 |
ie.revision = self._new_revision_id |
|
1910.2.3
by Aaron Bentley
All tests pass |
2488 |
return
|
1740.3.1
by Jelmer Vernooij
Introduce and use CommitBuilder objects. |
2489 |
previous_entries = ie.find_previous_heads( |
2490 |
parent_invs, |
|
2491 |
self.repository.weave_store, |
|
2492 |
self.repository.get_transaction()) |
|
1740.3.6
by Jelmer Vernooij
Move inventory writing to the commit builder. |
2493 |
# we are creating a new revision for ie in the history store
|
2494 |
# and inventory.
|
|
1740.3.7
by Jelmer Vernooij
Move committer, log, revprops, timestamp and timezone to CommitBuilder. |
2495 |
ie.snapshot(self._new_revision_id, path, previous_entries, tree, self) |
1740.3.3
by Jelmer Vernooij
Move storing directories and links to commit builder. |
2496 |
|
2497 |
def modified_directory(self, file_id, file_parents): |
|
2498 |
"""Record the presence of a symbolic link.
|
|
2499 |
||
2500 |
:param file_id: The file_id of the link to record.
|
|
2501 |
:param file_parents: The per-file parent revision ids.
|
|
2502 |
"""
|
|
2503 |
self._add_text_to_weave(file_id, [], file_parents.keys()) |
|
1740.3.2
by Jelmer Vernooij
Move storing file texts to commit builder. |
2504 |
|
1740.3.3
by Jelmer Vernooij
Move storing directories and links to commit builder. |
2505 |
def modified_file_text(self, file_id, file_parents, |
2506 |
get_content_byte_lines, text_sha1=None, |
|
2507 |
text_size=None): |
|
1740.3.2
by Jelmer Vernooij
Move storing file texts to commit builder. |
2508 |
"""Record the text of file file_id
|
2509 |
||
2510 |
:param file_id: The file_id of the file to record the text of.
|
|
2511 |
:param file_parents: The per-file parent revision ids.
|
|
2512 |
:param get_content_byte_lines: A callable which will return the byte
|
|
2513 |
lines for the file.
|
|
2514 |
:param text_sha1: Optional SHA1 of the file contents.
|
|
2515 |
:param text_size: Optional size of the file contents.
|
|
2516 |
"""
|
|
1711.2.101
by John Arbash Meinel
Clean up some unnecessary mutter() calls |
2517 |
# mutter('storing text of file {%s} in revision {%s} into %r',
|
2518 |
# file_id, self._new_revision_id, self.repository.weave_store)
|
|
1740.3.2
by Jelmer Vernooij
Move storing file texts to commit builder. |
2519 |
# special case to avoid diffing on renames or
|
2520 |
# reparenting
|
|
2521 |
if (len(file_parents) == 1 |
|
2522 |
and text_sha1 == file_parents.values()[0].text_sha1 |
|
2523 |
and text_size == file_parents.values()[0].text_size): |
|
2524 |
previous_ie = file_parents.values()[0] |
|
2525 |
versionedfile = self.repository.weave_store.get_weave(file_id, |
|
2526 |
self.repository.get_transaction()) |
|
1740.3.3
by Jelmer Vernooij
Move storing directories and links to commit builder. |
2527 |
versionedfile.clone_text(self._new_revision_id, |
1740.3.2
by Jelmer Vernooij
Move storing file texts to commit builder. |
2528 |
previous_ie.revision, file_parents.keys()) |
2529 |
return text_sha1, text_size |
|
2530 |
else: |
|
2531 |
new_lines = get_content_byte_lines() |
|
2532 |
# TODO: Rather than invoking sha_strings here, _add_text_to_weave
|
|
2533 |
# should return the SHA1 and size
|
|
2534 |
self._add_text_to_weave(file_id, new_lines, file_parents.keys()) |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
2535 |
return osutils.sha_strings(new_lines), \ |
1740.3.2
by Jelmer Vernooij
Move storing file texts to commit builder. |
2536 |
sum(map(len, new_lines)) |
2537 |
||
1740.3.3
by Jelmer Vernooij
Move storing directories and links to commit builder. |
2538 |
def modified_link(self, file_id, file_parents, link_target): |
2539 |
"""Record the presence of a symbolic link.
|
|
2540 |
||
2541 |
:param file_id: The file_id of the link to record.
|
|
2542 |
:param file_parents: The per-file parent revision ids.
|
|
2543 |
:param link_target: Target location of this link.
|
|
2544 |
"""
|
|
2545 |
self._add_text_to_weave(file_id, [], file_parents.keys()) |
|
2546 |
||
1740.3.2
by Jelmer Vernooij
Move storing file texts to commit builder. |
2547 |
def _add_text_to_weave(self, file_id, new_lines, parents): |
2548 |
versionedfile = self.repository.weave_store.get_weave_or_empty( |
|
2549 |
file_id, self.repository.get_transaction()) |
|
1740.3.3
by Jelmer Vernooij
Move storing directories and links to commit builder. |
2550 |
versionedfile.add_lines(self._new_revision_id, parents, new_lines) |
1740.3.2
by Jelmer Vernooij
Move storing file texts to commit builder. |
2551 |
versionedfile.clear_cache() |
1740.3.1
by Jelmer Vernooij
Introduce and use CommitBuilder objects. |
2552 |
|
2553 |
||
1910.2.6
by Aaron Bentley
Update for merge review, handle deprecations |
2554 |
class _CommitBuilder(CommitBuilder): |
1910.2.4
by Aaron Bentley
Support old CommitBuilders |
2555 |
"""Temporary class so old CommitBuilders are detected properly
|
2556 |
|
|
2557 |
Note: CommitBuilder works whether or not root entry is recorded.
|
|
2558 |
"""
|
|
2559 |
||
2560 |
record_root_entry = True |
|
2561 |
||
2562 |
||
1910.2.22
by Aaron Bentley
Make commits preserve root entry data |
2563 |
class RootCommitBuilder(CommitBuilder): |
2564 |
"""This commitbuilder actually records the root id"""
|
|
2565 |
||
2566 |
record_root_entry = True |
|
2567 |
||
2568 |
def record_entry_contents(self, ie, parent_invs, path, tree): |
|
2569 |
"""Record the content of ie from tree into the commit if needed.
|
|
2570 |
||
2571 |
Side effect: sets ie.revision when unchanged
|
|
2572 |
||
2573 |
:param ie: An inventory entry present in the commit.
|
|
2574 |
:param parent_invs: The inventories of the parent revisions of the
|
|
2575 |
commit.
|
|
2576 |
:param path: The path the entry is at in the tree.
|
|
2577 |
:param tree: The tree which contains this entry and should be used to
|
|
2578 |
obtain content.
|
|
2579 |
"""
|
|
2580 |
assert self.new_inventory.root is not None or ie.parent_id is None |
|
2581 |
self.new_inventory.add(ie) |
|
2582 |
||
2583 |
# ie.revision is always None if the InventoryEntry is considered
|
|
2584 |
# for committing. ie.snapshot will record the correct revision
|
|
2585 |
# which may be the sole parent if it is untouched.
|
|
2586 |
if ie.revision is not None: |
|
2587 |
return
|
|
2588 |
||
2589 |
previous_entries = ie.find_previous_heads( |
|
2590 |
parent_invs, |
|
2591 |
self.repository.weave_store, |
|
2592 |
self.repository.get_transaction()) |
|
2593 |
# we are creating a new revision for ie in the history store
|
|
2594 |
# and inventory.
|
|
2595 |
ie.snapshot(self._new_revision_id, path, previous_entries, tree, self) |
|
2596 |
||
2597 |
||
1843.2.4
by Aaron Bentley
Switch to John Meinel's _unescape_xml implementation |
2598 |
_unescape_map = { |
2599 |
'apos':"'", |
|
2600 |
'quot':'"', |
|
2601 |
'amp':'&', |
|
2602 |
'lt':'<', |
|
2603 |
'gt':'>' |
|
2604 |
}
|
|
2605 |
||
2606 |
||
2607 |
def _unescaper(match, _map=_unescape_map): |
|
2608 |
return _map[match.group(1)] |
|
2609 |
||
2610 |
||
2611 |
_unescape_re = None |
|
2612 |
||
2613 |
||
1596.1.1
by Martin Pool
Use simple xml unescaping rather than importing xml.sax |
2614 |
def _unescape_xml(data): |
1843.2.4
by Aaron Bentley
Switch to John Meinel's _unescape_xml implementation |
2615 |
"""Unescape predefined XML entities in a string of data."""
|
2616 |
global _unescape_re |
|
2617 |
if _unescape_re is None: |
|
2120.2.1
by John Arbash Meinel
Remove tabs from source files, and add a test to keep it that way. |
2618 |
_unescape_re = re.compile('\&([^;]*);') |
1843.2.4
by Aaron Bentley
Switch to John Meinel's _unescape_xml implementation |
2619 |
return _unescape_re.sub(_unescaper, data) |