bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
70
by mbp at sourcefrog
Prepare for smart recursive add. |
1 |
# Copyright (C) 2005 Canonical Ltd
|
2 |
||
|
1
by mbp at sourcefrog
import from baz patch-364 |
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.
|
|
7 |
||
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.
|
|
12 |
||
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
|
|
16 |
||
17 |
||
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
18 |
from copy import deepcopy |
|
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
19 |
from cStringIO import StringIO |
20 |
import errno |
|
21 |
import os |
|
|
1497
by Robert Collins
Move Branch.read_working_inventory to WorkingTree. |
22 |
import shutil |
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
23 |
import sys |
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
24 |
from unittest import TestSuite |
|
1372
by Martin Pool
- avoid converting inventories to/from StringIO |
25 |
from warnings import warn |
26 |
||
|
1
by mbp at sourcefrog
import from baz patch-364 |
27 |
|
28 |
import bzrlib |
|
|
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
29 |
from bzrlib.config import TreeConfig |
30 |
from bzrlib.delta import compare_trees |
|
31 |
import bzrlib.errors as errors |
|
32 |
from bzrlib.errors import (BzrError, InvalidRevisionNumber, InvalidRevisionId, |
|
33 |
NoSuchRevision, HistoryMissing, NotBranchError, |
|
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
34 |
DivergedBranches, LockError, |
35 |
UninitializableFormat, |
|
36 |
UnlistableStore, |
|
|
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
37 |
UnlistableBranch, NoSuchFile, NotVersionedError, |
38 |
NoWorkingTree) |
|
|
1399.1.8
by Robert Collins
factor out inventory directory logic into 'InventoryDirectory' class |
39 |
import bzrlib.inventory as inventory |
|
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
40 |
from bzrlib.inventory import Inventory |
|
1508.1.5
by Robert Collins
Move add from Branch to WorkingTree. |
41 |
from bzrlib.osutils import (isdir, quotefn, |
|
1185.31.32
by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \ |
42 |
rename, splitpath, sha_file, |
|
1534.4.1
by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib. |
43 |
file_kind, abspath, normpath, pathjoin, |
44 |
safe_unicode, |
|
45 |
)
|
|
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
46 |
from bzrlib.textui import show_status |
|
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
47 |
from bzrlib.trace import mutter, note |
48 |
from bzrlib.tree import EmptyTree, RevisionTree |
|
|
1185.12.98
by Aaron Bentley
Support for forcing merges of unrelated trees |
49 |
from bzrlib.revision import (Revision, is_ancestor, get_intervening_revisions, |
50 |
NULL_REVISION) |
|
|
1393.2.1
by John Arbash Meinel
Merged in split-storage-2 branch. Need to cleanup a little bit more still. |
51 |
from bzrlib.store import copy_all |
|
1393.2.2
by John Arbash Meinel
Updated stores to use Transport |
52 |
from bzrlib.store.text import TextStore |
|
1393.2.3
by John Arbash Meinel
Fixing typos, updating stores, getting tests to pass. |
53 |
from bzrlib.store.weave import WeaveStore |
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
54 |
from bzrlib.symbol_versioning import deprecated_nonce, deprecated_passed |
|
1442.1.60
by Robert Collins
gpg sign commits if the policy says we need to |
55 |
from bzrlib.testament import Testament |
|
1417.1.6
by Robert Collins
introduce transactions for grouping actions done to and with branches |
56 |
import bzrlib.transactions as transactions |
|
1393.2.4
by John Arbash Meinel
All tests pass. |
57 |
from bzrlib.transport import Transport, get_transport |
|
1189
by Martin Pool
- BROKEN: partial support for commit into weave |
58 |
import bzrlib.xml5 |
|
1104
by Martin Pool
- Add a simple UIFactory |
59 |
import bzrlib.ui |
60 |
||
|
1094
by Martin Pool
- merge aaron's merge improvements 999..1008 |
61 |
|
|
1186
by Martin Pool
- start implementing v5 format; Branch refuses to operate on old branches |
62 |
BZR_BRANCH_FORMAT_4 = "Bazaar-NG branch, format 0.0.4\n" |
63 |
BZR_BRANCH_FORMAT_5 = "Bazaar-NG branch, format 5\n" |
|
|
1429
by Robert Collins
merge in niemeyers prefixed-store patch |
64 |
BZR_BRANCH_FORMAT_6 = "Bazaar-NG branch, format 6\n" |
|
1
by mbp at sourcefrog
import from baz patch-364 |
65 |
## TODO: Maybe include checks for common corruption of newlines, etc?
|
66 |
||
67 |
||
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
68 |
# TODO: Some operations like log might retrieve the same revisions
|
69 |
# repeatedly to calculate deltas. We could perhaps have a weakref
|
|
|
1223
by Martin Pool
- store inventories in weave |
70 |
# cache in memory to make this faster. In general anything can be
|
71 |
# cached in memory between lock and unlock operations.
|
|
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
72 |
|
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
73 |
def find_branch(*ignored, **ignored_too): |
74 |
# XXX: leave this here for about one release, then remove it
|
|
75 |
raise NotImplementedError('find_branch() is not supported anymore, ' |
|
76 |
'please use one of the new branch constructors') |
|
|
416
by Martin Pool
- bzr log and bzr root now accept an http URL |
77 |
|
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
78 |
|
79 |
def needs_read_lock(unbound): |
|
80 |
"""Decorate unbound to take out and release a read lock.""" |
|
81 |
def decorated(self, *args, **kwargs): |
|
82 |
self.lock_read() |
|
83 |
try: |
|
84 |
return unbound(self, *args, **kwargs) |
|
85 |
finally: |
|
86 |
self.unlock() |
|
87 |
return decorated |
|
88 |
||
89 |
||
90 |
def needs_write_lock(unbound): |
|
91 |
"""Decorate unbound to take out and release a write lock.""" |
|
92 |
def decorated(self, *args, **kwargs): |
|
93 |
self.lock_write() |
|
94 |
try: |
|
95 |
return unbound(self, *args, **kwargs) |
|
96 |
finally: |
|
97 |
self.unlock() |
|
98 |
return decorated |
|
99 |
||
|
1
by mbp at sourcefrog
import from baz patch-364 |
100 |
######################################################################
|
101 |
# branch objects
|
|
102 |
||
|
558
by Martin Pool
- All top-level classes inherit from object |
103 |
class Branch(object): |
|
1
by mbp at sourcefrog
import from baz patch-364 |
104 |
"""Branch holding a history of revisions. |
105 |
||
|
343
by Martin Pool
doc |
106 |
base
|
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
107 |
Base directory/url of the branch.
|
108 |
"""
|
|
|
1534.4.1
by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib. |
109 |
# this is really an instance variable - FIXME move it there
|
110 |
# - RBC 20060112
|
|
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
111 |
base = None |
112 |
||
|
1534.4.1
by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib. |
113 |
_default_initializer = None |
114 |
"""The default initializer for making new branches.""" |
|
115 |
||
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
116 |
def __init__(self, *ignored, **ignored_too): |
117 |
raise NotImplementedError('The Branch class is abstract') |
|
118 |
||
119 |
@staticmethod
|
|
|
1393.1.2
by Martin Pool
- better representation in Branch factories of opening old formats |
120 |
def open_downlevel(base): |
121 |
"""Open a branch which may be of an old format. |
|
122 |
|
|
123 |
Only local branches are supported."""
|
|
|
1495.1.5
by Jelmer Vernooij
Rename NativeBranch -> BzrBranch |
124 |
return BzrBranch(get_transport(base), relax_version_check=True) |
|
1393.1.2
by Martin Pool
- better representation in Branch factories of opening old formats |
125 |
|
126 |
@staticmethod
|
|
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
127 |
def open(base): |
128 |
"""Open an existing branch, rooted at 'base' (url)""" |
|
|
1393.2.4
by John Arbash Meinel
All tests pass. |
129 |
t = get_transport(base) |
|
1393.1.63
by Martin Pool
- add some trace statements |
130 |
mutter("trying to open %r with transport %r", base, t) |
|
1495.1.5
by Jelmer Vernooij
Rename NativeBranch -> BzrBranch |
131 |
return BzrBranch(t) |
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
132 |
|
133 |
@staticmethod
|
|
|
1185.2.8
by Lalo Martins
creating the new branch constructors |
134 |
def open_containing(url): |
|
1185.1.41
by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid |
135 |
"""Open an existing branch which contains url. |
136 |
|
|
137 |
This probes for a branch at url, and searches upwards from there.
|
|
|
1185.17.2
by Martin Pool
[pick] avoid problems in fetching when .bzr is not listable |
138 |
|
139 |
Basically we keep looking up until we find the control directory or
|
|
140 |
run into the root. If there isn't one, raises NotBranchError.
|
|
|
1442.1.64
by Robert Collins
Branch.open_containing now returns a tuple (Branch, relative-path). |
141 |
If there is one, it is returned, along with the unused portion of url.
|
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
142 |
"""
|
|
1393.2.4
by John Arbash Meinel
All tests pass. |
143 |
t = get_transport(url) |
|
1185.17.2
by Martin Pool
[pick] avoid problems in fetching when .bzr is not listable |
144 |
while True: |
145 |
try: |
|
|
1495.1.5
by Jelmer Vernooij
Rename NativeBranch -> BzrBranch |
146 |
return BzrBranch(t), t.relpath(url) |
|
1185.31.38
by John Arbash Meinel
Changing os.path.normpath to osutils.normpath |
147 |
except NotBranchError, e: |
148 |
mutter('not a branch in: %r %s', t.base, e) |
|
|
1185.17.2
by Martin Pool
[pick] avoid problems in fetching when .bzr is not listable |
149 |
new_t = t.clone('..') |
150 |
if new_t.base == t.base: |
|
151 |
# reached the root, whatever that may be
|
|
|
1185.16.61
by mbp at sourcefrog
- start introducing hct error classes |
152 |
raise NotBranchError(path=url) |
|
1185.17.2
by Martin Pool
[pick] avoid problems in fetching when .bzr is not listable |
153 |
t = new_t |
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
154 |
|
155 |
@staticmethod
|
|
156 |
def initialize(base): |
|
|
1534.4.1
by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib. |
157 |
"""Create a new branch, rooted at 'base' (url) |
158 |
|
|
159 |
This will call the current default initializer with base
|
|
160 |
as the only parameter.
|
|
161 |
"""
|
|
162 |
return Branch._default_initializer(safe_unicode(base)) |
|
163 |
||
164 |
@staticmethod
|
|
165 |
def get_default_initializer(): |
|
166 |
"""Return the initializer being used for new branches.""" |
|
167 |
return Branch._default_initializer |
|
168 |
||
169 |
@staticmethod
|
|
170 |
def set_default_initializer(initializer): |
|
171 |
"""Set the initializer to be used for new branches.""" |
|
172 |
Branch._default_initializer = staticmethod(initializer) |
|
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
173 |
|
174 |
def setup_caching(self, cache_root): |
|
175 |
"""Subclasses that care about caching should override this, and set |
|
176 |
up cached stores located under cache_root.
|
|
177 |
"""
|
|
|
1400.1.1
by Robert Collins
implement a basic test for the ui branch command from http servers |
178 |
self.cache_root = cache_root |
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
179 |
|
|
1185.35.11
by Aaron Bentley
Added support for branch nicks |
180 |
def _get_nick(self): |
181 |
cfg = self.tree_config() |
|
|
1530.1.3
by Robert Collins
transport implementations now tested consistently. |
182 |
return cfg.get_option(u"nickname", default=self.base.split('/')[-2]) |
|
1185.35.11
by Aaron Bentley
Added support for branch nicks |
183 |
|
184 |
def _set_nick(self, nick): |
|
185 |
cfg = self.tree_config() |
|
186 |
cfg.set_option(nick, "nickname") |
|
187 |
assert cfg.get_option("nickname") == nick |
|
188 |
||
189 |
nick = property(_get_nick, _set_nick) |
|
190 |
||
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
191 |
def push_stores(self, branch_to): |
192 |
"""Copy the content of this branches store to branch_to.""" |
|
193 |
raise NotImplementedError('push_stores is abstract') |
|
194 |
||
195 |
def get_transaction(self): |
|
196 |
"""Return the current active transaction. |
|
197 |
||
198 |
If no transaction is active, this returns a passthrough object
|
|
199 |
for which all data is immediately flushed and no caching happens.
|
|
200 |
"""
|
|
201 |
raise NotImplementedError('get_transaction is abstract') |
|
202 |
||
203 |
def lock_write(self): |
|
204 |
raise NotImplementedError('lock_write is abstract') |
|
205 |
||
206 |
def lock_read(self): |
|
207 |
raise NotImplementedError('lock_read is abstract') |
|
208 |
||
209 |
def unlock(self): |
|
210 |
raise NotImplementedError('unlock is abstract') |
|
211 |
||
212 |
def abspath(self, name): |
|
213 |
"""Return absolute filename for something in the branch |
|
214 |
|
|
215 |
XXX: Robert Collins 20051017 what is this used for? why is it a branch
|
|
216 |
method and not a tree method.
|
|
217 |
"""
|
|
218 |
raise NotImplementedError('abspath is abstract') |
|
219 |
||
220 |
def controlfilename(self, file_or_path): |
|
221 |
"""Return location relative to branch.""" |
|
222 |
raise NotImplementedError('controlfilename is abstract') |
|
223 |
||
224 |
def controlfile(self, file_or_path, mode='r'): |
|
225 |
"""Open a control file for this branch. |
|
226 |
||
227 |
There are two classes of file in the control directory: text
|
|
228 |
and binary. binary files are untranslated byte streams. Text
|
|
229 |
control files are stored with Unix newlines and in UTF-8, even
|
|
230 |
if the platform or locale defaults are different.
|
|
231 |
||
232 |
Controlfiles should almost never be opened in write mode but
|
|
233 |
rather should be atomically copied and replaced using atomicfile.
|
|
234 |
"""
|
|
235 |
raise NotImplementedError('controlfile is abstract') |
|
236 |
||
237 |
def put_controlfile(self, path, f, encode=True): |
|
238 |
"""Write an entry as a controlfile. |
|
239 |
||
240 |
:param path: The path to put the file, relative to the .bzr control
|
|
241 |
directory
|
|
242 |
:param f: A file-like or string object whose contents should be copied.
|
|
243 |
:param encode: If true, encode the contents as utf-8
|
|
244 |
"""
|
|
245 |
raise NotImplementedError('put_controlfile is abstract') |
|
246 |
||
247 |
def put_controlfiles(self, files, encode=True): |
|
248 |
"""Write several entries as controlfiles. |
|
249 |
||
250 |
:param files: A list of [(path, file)] pairs, where the path is the directory
|
|
251 |
underneath the bzr control directory
|
|
252 |
:param encode: If true, encode the contents as utf-8
|
|
253 |
"""
|
|
254 |
raise NotImplementedError('put_controlfiles is abstract') |
|
255 |
||
256 |
def get_root_id(self): |
|
257 |
"""Return the id of this branches root""" |
|
258 |
raise NotImplementedError('get_root_id is abstract') |
|
259 |
||
260 |
def set_root_id(self, file_id): |
|
261 |
raise NotImplementedError('set_root_id is abstract') |
|
262 |
||
|
1185.50.9
by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision |
263 |
def print_file(self, file, revision_id): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
264 |
"""Print `file` to stdout.""" |
265 |
raise NotImplementedError('print_file is abstract') |
|
266 |
||
267 |
def append_revision(self, *revision_ids): |
|
268 |
raise NotImplementedError('append_revision is abstract') |
|
269 |
||
270 |
def set_revision_history(self, rev_history): |
|
271 |
raise NotImplementedError('set_revision_history is abstract') |
|
272 |
||
273 |
def has_revision(self, revision_id): |
|
274 |
"""True if this branch has a copy of the revision. |
|
275 |
||
276 |
This does not necessarily imply the revision is merge
|
|
277 |
or on the mainline."""
|
|
278 |
raise NotImplementedError('has_revision is abstract') |
|
279 |
||
280 |
def get_revision_xml(self, revision_id): |
|
281 |
raise NotImplementedError('get_revision_xml is abstract') |
|
282 |
||
283 |
def get_revision(self, revision_id): |
|
284 |
"""Return the Revision object for a named revision""" |
|
285 |
raise NotImplementedError('get_revision is abstract') |
|
286 |
||
287 |
def get_revision_delta(self, revno): |
|
288 |
"""Return the delta for one revision. |
|
289 |
||
290 |
The delta is relative to its mainline predecessor, or the
|
|
291 |
empty tree for revision 1.
|
|
292 |
"""
|
|
|
1495.1.3
by Jelmer Vernooij
Move some more generic methods from NativeBranch to Branch. |
293 |
assert isinstance(revno, int) |
294 |
rh = self.revision_history() |
|
295 |
if not (1 <= revno <= len(rh)): |
|
296 |
raise InvalidRevisionNumber(revno) |
|
297 |
||
298 |
# revno is 1-based; list is 0-based
|
|
299 |
||
300 |
new_tree = self.revision_tree(rh[revno-1]) |
|
301 |
if revno == 1: |
|
302 |
old_tree = EmptyTree() |
|
303 |
else: |
|
304 |
old_tree = self.revision_tree(rh[revno-2]) |
|
305 |
||
306 |
return compare_trees(old_tree, new_tree) |
|
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
307 |
|
308 |
def get_revision_sha1(self, revision_id): |
|
309 |
"""Hash the stored value of a revision, and return it.""" |
|
310 |
raise NotImplementedError('get_revision_sha1 is abstract') |
|
311 |
||
312 |
def get_ancestry(self, revision_id): |
|
313 |
"""Return a list of revision-ids integrated by a revision. |
|
314 |
|
|
315 |
This currently returns a list, but the ordering is not guaranteed:
|
|
316 |
treat it as a set.
|
|
317 |
"""
|
|
318 |
raise NotImplementedError('get_ancestry is abstract') |
|
319 |
||
320 |
def get_inventory(self, revision_id): |
|
321 |
"""Get Inventory object by hash.""" |
|
322 |
raise NotImplementedError('get_inventory is abstract') |
|
323 |
||
324 |
def get_inventory_xml(self, revision_id): |
|
325 |
"""Get inventory XML as a file object.""" |
|
326 |
raise NotImplementedError('get_inventory_xml is abstract') |
|
327 |
||
328 |
def get_inventory_sha1(self, revision_id): |
|
329 |
"""Return the sha1 hash of the inventory entry.""" |
|
330 |
raise NotImplementedError('get_inventory_sha1 is abstract') |
|
331 |
||
332 |
def get_revision_inventory(self, revision_id): |
|
333 |
"""Return inventory of a past revision.""" |
|
334 |
raise NotImplementedError('get_revision_inventory is abstract') |
|
335 |
||
336 |
def revision_history(self): |
|
337 |
"""Return sequence of revision hashes on to this branch.""" |
|
338 |
raise NotImplementedError('revision_history is abstract') |
|
339 |
||
340 |
def revno(self): |
|
341 |
"""Return current revision number for this branch. |
|
342 |
||
343 |
That is equivalent to the number of revisions committed to
|
|
344 |
this branch.
|
|
345 |
"""
|
|
346 |
return len(self.revision_history()) |
|
347 |
||
348 |
def last_revision(self): |
|
349 |
"""Return last patch hash, or None if no history.""" |
|
350 |
ph = self.revision_history() |
|
351 |
if ph: |
|
352 |
return ph[-1] |
|
353 |
else: |
|
354 |
return None |
|
355 |
||
356 |
def missing_revisions(self, other, stop_revision=None, diverged_ok=False): |
|
357 |
"""Return a list of new revisions that would perfectly fit. |
|
358 |
|
|
359 |
If self and other have not diverged, return a list of the revisions
|
|
360 |
present in other, but missing from self.
|
|
361 |
||
362 |
>>> from bzrlib.commit import commit
|
|
363 |
>>> bzrlib.trace.silent = True
|
|
364 |
>>> br1 = ScratchBranch()
|
|
365 |
>>> br2 = ScratchBranch()
|
|
366 |
>>> br1.missing_revisions(br2)
|
|
367 |
[]
|
|
368 |
>>> commit(br2, "lala!", rev_id="REVISION-ID-1")
|
|
369 |
>>> br1.missing_revisions(br2)
|
|
370 |
[u'REVISION-ID-1']
|
|
371 |
>>> br2.missing_revisions(br1)
|
|
372 |
[]
|
|
373 |
>>> commit(br1, "lala!", rev_id="REVISION-ID-1")
|
|
374 |
>>> br1.missing_revisions(br2)
|
|
375 |
[]
|
|
376 |
>>> commit(br2, "lala!", rev_id="REVISION-ID-2A")
|
|
377 |
>>> br1.missing_revisions(br2)
|
|
378 |
[u'REVISION-ID-2A']
|
|
379 |
>>> commit(br1, "lala!", rev_id="REVISION-ID-2B")
|
|
380 |
>>> br1.missing_revisions(br2)
|
|
381 |
Traceback (most recent call last):
|
|
|
1185.56.1
by Michael Ellerman
Simplify handling of DivergedBranches in cmd_pull() |
382 |
DivergedBranches: These branches have diverged. Try merge.
|
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
383 |
"""
|
384 |
self_history = self.revision_history() |
|
385 |
self_len = len(self_history) |
|
386 |
other_history = other.revision_history() |
|
387 |
other_len = len(other_history) |
|
388 |
common_index = min(self_len, other_len) -1 |
|
389 |
if common_index >= 0 and \ |
|
390 |
self_history[common_index] != other_history[common_index]: |
|
391 |
raise DivergedBranches(self, other) |
|
392 |
||
393 |
if stop_revision is None: |
|
394 |
stop_revision = other_len |
|
395 |
else: |
|
396 |
assert isinstance(stop_revision, int) |
|
397 |
if stop_revision > other_len: |
|
398 |
raise bzrlib.errors.NoSuchRevision(self, stop_revision) |
|
399 |
return other_history[self_len:stop_revision] |
|
400 |
||
401 |
def update_revisions(self, other, stop_revision=None): |
|
402 |
"""Pull in new perfect-fit revisions.""" |
|
403 |
raise NotImplementedError('update_revisions is abstract') |
|
404 |
||
405 |
def pullable_revisions(self, other, stop_revision): |
|
406 |
raise NotImplementedError('pullable_revisions is abstract') |
|
407 |
||
408 |
def revision_id_to_revno(self, revision_id): |
|
409 |
"""Given a revision id, return its revno""" |
|
410 |
if revision_id is None: |
|
411 |
return 0 |
|
412 |
history = self.revision_history() |
|
413 |
try: |
|
414 |
return history.index(revision_id) + 1 |
|
415 |
except ValueError: |
|
416 |
raise bzrlib.errors.NoSuchRevision(self, revision_id) |
|
417 |
||
418 |
def get_rev_id(self, revno, history=None): |
|
419 |
"""Find the revision id of the specified revno.""" |
|
420 |
if revno == 0: |
|
421 |
return None |
|
422 |
if history is None: |
|
423 |
history = self.revision_history() |
|
424 |
elif revno <= 0 or revno > len(history): |
|
425 |
raise bzrlib.errors.NoSuchRevision(self, revno) |
|
426 |
return history[revno - 1] |
|
427 |
||
428 |
def revision_tree(self, revision_id): |
|
429 |
"""Return Tree for a revision on this branch. |
|
430 |
||
431 |
`revision_id` may be None for the null revision, in which case
|
|
432 |
an `EmptyTree` is returned."""
|
|
433 |
raise NotImplementedError('revision_tree is abstract') |
|
434 |
||
435 |
def working_tree(self): |
|
|
1508.1.15
by Robert Collins
Merge from mpool. |
436 |
"""Return a `Tree` for the working copy if this is a local branch.""" |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
437 |
raise NotImplementedError('working_tree is abstract') |
438 |
||
439 |
def pull(self, source, overwrite=False): |
|
440 |
raise NotImplementedError('pull is abstract') |
|
441 |
||
442 |
def basis_tree(self): |
|
443 |
"""Return `Tree` object for last revision. |
|
444 |
||
445 |
If there are no revisions yet, return an `EmptyTree`.
|
|
446 |
"""
|
|
447 |
return self.revision_tree(self.last_revision()) |
|
448 |
||
449 |
def rename_one(self, from_rel, to_rel): |
|
450 |
"""Rename one file. |
|
451 |
||
452 |
This can change the directory or the filename or both.
|
|
453 |
"""
|
|
454 |
raise NotImplementedError('rename_one is abstract') |
|
455 |
||
456 |
def move(self, from_paths, to_name): |
|
457 |
"""Rename files. |
|
458 |
||
459 |
to_name must exist as a versioned directory.
|
|
460 |
||
461 |
If to_name exists and is a directory, the files are moved into
|
|
462 |
it, keeping their old names. If it is a directory,
|
|
463 |
||
464 |
Note that to_name is only the last component of the new name;
|
|
465 |
this doesn't change the directory.
|
|
466 |
||
467 |
This returns a list of (from_path, to_path) pairs for each
|
|
468 |
entry that is moved.
|
|
469 |
"""
|
|
470 |
raise NotImplementedError('move is abstract') |
|
471 |
||
472 |
def get_parent(self): |
|
473 |
"""Return the parent location of the branch. |
|
474 |
||
475 |
This is the default location for push/pull/missing. The usual
|
|
476 |
pattern is that the user can override it by specifying a
|
|
477 |
location.
|
|
478 |
"""
|
|
479 |
raise NotImplementedError('get_parent is abstract') |
|
480 |
||
481 |
def get_push_location(self): |
|
482 |
"""Return the None or the location to push this branch to.""" |
|
483 |
raise NotImplementedError('get_push_location is abstract') |
|
484 |
||
485 |
def set_push_location(self, location): |
|
486 |
"""Set a new push location for this branch.""" |
|
487 |
raise NotImplementedError('set_push_location is abstract') |
|
488 |
||
489 |
def set_parent(self, url): |
|
490 |
raise NotImplementedError('set_parent is abstract') |
|
491 |
||
492 |
def check_revno(self, revno): |
|
493 |
"""\ |
|
494 |
Check whether a revno corresponds to any revision.
|
|
495 |
Zero (the NULL revision) is considered valid.
|
|
496 |
"""
|
|
497 |
if revno != 0: |
|
498 |
self.check_real_revno(revno) |
|
499 |
||
500 |
def check_real_revno(self, revno): |
|
501 |
"""\ |
|
502 |
Check whether a revno corresponds to a real revision.
|
|
503 |
Zero (the NULL revision) is considered invalid
|
|
504 |
"""
|
|
505 |
if revno < 1 or revno > self.revno(): |
|
506 |
raise InvalidRevisionNumber(revno) |
|
507 |
||
508 |
def sign_revision(self, revision_id, gpg_strategy): |
|
509 |
raise NotImplementedError('sign_revision is abstract') |
|
510 |
||
511 |
def store_revision_signature(self, gpg_strategy, plaintext, revision_id): |
|
512 |
raise NotImplementedError('store_revision_signature is abstract') |
|
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
513 |
|
|
1534.4.1
by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib. |
514 |
|
|
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
515 |
class BzrBranchFormat(object): |
516 |
"""An encapsulation of the initialization and open routines for a format. |
|
517 |
||
518 |
Formats provide three things:
|
|
519 |
* An initialization routine,
|
|
520 |
* a format string,
|
|
521 |
* an open routine.
|
|
522 |
||
523 |
Formats are placed in an dict by their format string for reference
|
|
524 |
during branch opening. Its not required that these be instances, they
|
|
525 |
can be classes themselves with class methods - it simply depends on
|
|
526 |
whether state is needed for a given format or not.
|
|
527 |
||
528 |
Once a format is deprecated, just deprecate the initialize and open
|
|
529 |
methods on the format class. Do not deprecate the object, as the
|
|
530 |
object will be created every time regardless.
|
|
531 |
"""
|
|
532 |
||
533 |
_formats = {} |
|
534 |
"""The known formats.""" |
|
535 |
||
536 |
@classmethod
|
|
|
1534.4.4
by Robert Collins
Make BzrBranchFormat.find_format take a transport not a url for efficiency. |
537 |
def find_format(klass, transport): |
|
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
538 |
"""Return the format registered for URL.""" |
|
1534.4.4
by Robert Collins
Make BzrBranchFormat.find_format take a transport not a url for efficiency. |
539 |
return klass._formats[transport.get(".bzr/branch-format").read()] |
|
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
540 |
|
541 |
def get_format_string(self): |
|
542 |
"""Return the ASCII format string that identifies this format.""" |
|
543 |
raise NotImplementedError(self.get_format_string) |
|
544 |
||
545 |
def _find_modes(self, t): |
|
546 |
"""Determine the appropriate modes for files and directories. |
|
547 |
|
|
548 |
FIXME: When this merges into, or from storage,
|
|
549 |
this code becomes delgatable to a LockableFiles instance.
|
|
550 |
||
551 |
For now its cribbed and returns (dir_mode, file_mode)
|
|
552 |
"""
|
|
553 |
try: |
|
554 |
st = t.stat('.') |
|
555 |
except errors.TransportNotPossible: |
|
556 |
dir_mode = 0755 |
|
557 |
file_mode = 0644 |
|
558 |
else: |
|
559 |
dir_mode = st.st_mode & 07777 |
|
560 |
# Remove the sticky and execute bits for files
|
|
561 |
file_mode = dir_mode & ~07111 |
|
562 |
if not BzrBranch._set_dir_mode: |
|
563 |
dir_mode = None |
|
564 |
if not BzrBranch._set_file_mode: |
|
565 |
file_mode = None |
|
566 |
return dir_mode, file_mode |
|
567 |
||
568 |
def initialize(self, url): |
|
569 |
"""Create a branch of this format at url and return an open branch.""" |
|
570 |
t = get_transport(url) |
|
571 |
from bzrlib.inventory import Inventory |
|
572 |
from bzrlib.weavefile import write_weave_v5 |
|
573 |
from bzrlib.weave import Weave |
|
574 |
||
575 |
# Create an empty inventory
|
|
576 |
sio = StringIO() |
|
577 |
# if we want per-tree root ids then this is the place to set
|
|
578 |
# them; they're not needed for now and so ommitted for
|
|
579 |
# simplicity.
|
|
580 |
bzrlib.xml5.serializer_v5.write_inventory(Inventory(), sio) |
|
581 |
empty_inv = sio.getvalue() |
|
582 |
sio = StringIO() |
|
583 |
bzrlib.weavefile.write_weave_v5(Weave(), sio) |
|
584 |
empty_weave = sio.getvalue() |
|
585 |
||
586 |
# Since we don't have a .bzr directory, inherit the
|
|
587 |
# mode from the root directory
|
|
588 |
dir_mode, file_mode = self._find_modes(t) |
|
589 |
||
590 |
t.mkdir('.bzr', mode=dir_mode) |
|
591 |
control = t.clone('.bzr') |
|
592 |
dirs = ['revision-store', 'weaves'] |
|
593 |
files = [('README', |
|
594 |
StringIO("This is a Bazaar-NG control directory.\n" |
|
595 |
"Do not change any files in this directory.\n")), |
|
596 |
('branch-format', StringIO(self.get_format_string())), |
|
597 |
('revision-history', StringIO('')), |
|
598 |
('branch-name', StringIO('')), |
|
599 |
('branch-lock', StringIO('')), |
|
600 |
('pending-merges', StringIO('')), |
|
601 |
('inventory', StringIO(empty_inv)), |
|
602 |
('inventory.weave', StringIO(empty_weave)), |
|
603 |
('ancestry.weave', StringIO(empty_weave)) |
|
604 |
]
|
|
605 |
control.mkdir_multi(dirs, mode=dir_mode) |
|
606 |
control.put_multi(files, mode=file_mode) |
|
607 |
mutter('created control directory in ' + t.base) |
|
608 |
return BzrBranch(t) |
|
609 |
||
610 |
def open(self, url, branch): |
|
611 |
"""Fill out the data in branch for the branch at url.""" |
|
612 |
raise NotImplementedError(self.open) |
|
613 |
||
614 |
@classmethod
|
|
615 |
def register_format(klass, format): |
|
616 |
klass._formats[format.get_format_string()] = format |
|
617 |
||
618 |
||
619 |
class BzrBranchFormat4(BzrBranchFormat): |
|
620 |
"""Bzr branch format 4. |
|
621 |
||
622 |
This format has:
|
|
623 |
- flat stores
|
|
624 |
- TextStores for texts, inventories,revisions.
|
|
625 |
||
626 |
This format is deprecated: it indexes texts using a text it which is
|
|
627 |
removed in format 5; write support for this format has been removed.
|
|
628 |
"""
|
|
629 |
||
630 |
def get_format_string(self): |
|
631 |
"""See BzrBranchFormat.get_format_string().""" |
|
632 |
return BZR_BRANCH_FORMAT_4 |
|
633 |
||
634 |
def initialize(self, url): |
|
635 |
"""Format 4 branches cannot be created.""" |
|
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
636 |
raise UninitializableFormat(self) |
|
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
637 |
|
638 |
||
639 |
class BzrBranchFormat5(BzrBranchFormat): |
|
640 |
"""Bzr branch format 5. |
|
641 |
||
642 |
This format has:
|
|
643 |
- weaves for file texts and inventory
|
|
644 |
- flat stores
|
|
645 |
- TextStores for revisions and signatures.
|
|
646 |
"""
|
|
647 |
||
648 |
def get_format_string(self): |
|
649 |
"""See BzrBranchFormat.get_format_string().""" |
|
650 |
return BZR_BRANCH_FORMAT_5 |
|
651 |
||
652 |
||
653 |
class BzrBranchFormat6(BzrBranchFormat): |
|
654 |
"""Bzr branch format 6. |
|
655 |
||
656 |
This format has:
|
|
657 |
- weaves for file texts and inventory
|
|
658 |
- hash subdirectory based stores.
|
|
659 |
- TextStores for revisions and signatures.
|
|
660 |
"""
|
|
661 |
||
662 |
def get_format_string(self): |
|
663 |
"""See BzrBranchFormat.get_format_string().""" |
|
664 |
return BZR_BRANCH_FORMAT_6 |
|
665 |
||
666 |
||
667 |
BzrBranchFormat.register_format(BzrBranchFormat4()) |
|
668 |
BzrBranchFormat.register_format(BzrBranchFormat5()) |
|
669 |
BzrBranchFormat.register_format(BzrBranchFormat6()) |
|
670 |
||
|
1495.1.5
by Jelmer Vernooij
Rename NativeBranch -> BzrBranch |
671 |
class BzrBranch(Branch): |
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
672 |
"""A branch stored in the actual filesystem. |
673 |
||
674 |
Note that it's "local" in the context of the filesystem; it doesn't
|
|
675 |
really matter if it's on an nfs/smb/afs/coda/... share, as long as
|
|
676 |
it's writable, and can be accessed via the normal filesystem API.
|
|
|
578
by Martin Pool
- start to move toward Branch.lock and unlock methods, |
677 |
|
678 |
_lock_mode
|
|
|
580
by Martin Pool
- Use explicit lock methods on a branch, rather than doing it |
679 |
None, or 'r' or 'w'
|
680 |
||
681 |
_lock_count
|
|
682 |
If _lock_mode is true, a positive count of the number of times the
|
|
683 |
lock has been taken.
|
|
|
578
by Martin Pool
- start to move toward Branch.lock and unlock methods, |
684 |
|
|
614
by Martin Pool
- unify two defintions of LockError |
685 |
_lock
|
686 |
Lock object from bzrlib.lock.
|
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
687 |
"""
|
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
688 |
# We actually expect this class to be somewhat short-lived; part of its
|
689 |
# purpose is to try to isolate what bits of the branch logic are tied to
|
|
690 |
# filesystem access, so that in a later step, we can extricate them to
|
|
691 |
# a separarte ("storage") class.
|
|
|
578
by Martin Pool
- start to move toward Branch.lock and unlock methods, |
692 |
_lock_mode = None |
|
580
by Martin Pool
- Use explicit lock methods on a branch, rather than doing it |
693 |
_lock_count = None |
|
615
by Martin Pool
Major rework of locking code: |
694 |
_lock = None |
|
1223
by Martin Pool
- store inventories in weave |
695 |
_inventory_weave = None |
|
1185.58.7
by John Arbash Meinel
Added the ability to disable setting permissions |
696 |
# If set to False (by a plugin, etc) BzrBranch will not set the
|
697 |
# mode on created files or directories
|
|
698 |
_set_file_mode = True |
|
699 |
_set_dir_mode = True |
|
|
353
by Martin Pool
- Per-branch locks in read and write modes. |
700 |
|
|
897
by Martin Pool
- merge john's revision-naming code |
701 |
# Map some sort of prefix into a namespace
|
702 |
# stuff like "revno:10", "revid:", etc.
|
|
703 |
# This should match a prefix with a function which accepts
|
|
704 |
REVISION_NAMESPACES = {} |
|
705 |
||
|
1391
by Robert Collins
merge from integration |
706 |
def push_stores(self, branch_to): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
707 |
"""See Branch.push_stores.""" |
|
1391
by Robert Collins
merge from integration |
708 |
if (self._branch_format != branch_to._branch_format |
709 |
or self._branch_format != 4): |
|
710 |
from bzrlib.fetch import greedy_fetch |
|
|
1393
by Robert Collins
reenable remotebranch tests |
711 |
mutter("falling back to fetch logic to push between %s(%s) and %s(%s)", |
712 |
self, self._branch_format, branch_to, branch_to._branch_format) |
|
|
1391
by Robert Collins
merge from integration |
713 |
greedy_fetch(to_branch=branch_to, from_branch=self, |
714 |
revision=self.last_revision()) |
|
715 |
return
|
|
716 |
||
717 |
store_pairs = ((self.text_store, branch_to.text_store), |
|
718 |
(self.inventory_store, branch_to.inventory_store), |
|
719 |
(self.revision_store, branch_to.revision_store)) |
|
720 |
try: |
|
721 |
for from_store, to_store in store_pairs: |
|
722 |
copy_all(from_store, to_store) |
|
723 |
except UnlistableStore: |
|
724 |
raise UnlistableBranch(from_store) |
|
725 |
||
|
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
726 |
def __init__(self, transport, init=deprecated_nonce, |
|
1293
by Martin Pool
- add Branch constructor option to relax version check |
727 |
relax_version_check=False): |
|
1
by mbp at sourcefrog
import from baz patch-364 |
728 |
"""Create new branch object at a particular location. |
729 |
||
|
907.1.2
by John Arbash Meinel
Working on making Branch() do all of it's work over a Transport. |
730 |
transport -- A Transport object, defining how to access files.
|
|
62
by mbp at sourcefrog
- new find_branch_root function; based on suggestion from aaron |
731 |
|
|
254
by Martin Pool
- Doc cleanups from Magnus Therning |
732 |
init -- If True, create new control files in a previously
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
733 |
unversioned directory. If False, the branch must already
|
734 |
be versioned.
|
|
735 |
||
|
1293
by Martin Pool
- add Branch constructor option to relax version check |
736 |
relax_version_check -- If true, the usual check for the branch
|
737 |
version is not applied. This is intended only for
|
|
738 |
upgrade/recovery type use; it's not guaranteed that
|
|
739 |
all operations will work on old format branches.
|
|
740 |
||
|
1
by mbp at sourcefrog
import from baz patch-364 |
741 |
In the test suite, creation of new trees is tested using the
|
742 |
`ScratchBranch` class.
|
|
743 |
"""
|
|
|
1393.1.15
by Martin Pool
- better assertion message |
744 |
assert isinstance(transport, Transport), \ |
745 |
"%r is not a Transport" % transport |
|
|
907.1.8
by John Arbash Meinel
Changed the format for abspath. Updated branch to use a hidden _transport |
746 |
self._transport = transport |
|
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
747 |
if deprecated_passed(init): |
748 |
warn("BzrBranch.__init__(..., init=XXX): The init parameter is " |
|
749 |
"deprecated as of bzr 0.8. Please use Branch.initialize().", |
|
750 |
DeprecationWarning) |
|
751 |
if init: |
|
752 |
# this is slower than before deprecation, oh well never mind.
|
|
753 |
# -> its deprecated.
|
|
754 |
self._initialize(transport.base) |
|
|
1293
by Martin Pool
- add Branch constructor option to relax version check |
755 |
self._check_format(relax_version_check) |
|
1185.58.4
by John Arbash Meinel
Added permission checking to Branch, and propogated that change into the stores. |
756 |
self._find_modes() |
|
1393.2.2
by John Arbash Meinel
Updated stores to use Transport |
757 |
|
|
1429
by Robert Collins
merge in niemeyers prefixed-store patch |
758 |
def get_store(name, compressed=True, prefixed=False): |
|
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
759 |
relpath = self._rel_controlfilename(safe_unicode(name)) |
|
1185.16.159
by John Arbash Meinel
Updated the stores, all tests pass, and a store doesn't have to be 100% compressed |
760 |
store = TextStore(self._transport.clone(relpath), |
|
1185.58.4
by John Arbash Meinel
Added permission checking to Branch, and propogated that change into the stores. |
761 |
dir_mode=self._dir_mode, |
762 |
file_mode=self._file_mode, |
|
|
1185.16.159
by John Arbash Meinel
Updated the stores, all tests pass, and a store doesn't have to be 100% compressed |
763 |
prefixed=prefixed, |
764 |
compressed=compressed) |
|
|
1393.2.2
by John Arbash Meinel
Updated stores to use Transport |
765 |
return store |
|
1185.33.87
by Martin Pool
[patch] refactor code that make sure stores are opened with unicode filenames (robertc) |
766 |
|
|
1429
by Robert Collins
merge in niemeyers prefixed-store patch |
767 |
def get_weave(name, prefixed=False): |
|
1185.33.87
by Martin Pool
[patch] refactor code that make sure stores are opened with unicode filenames (robertc) |
768 |
relpath = self._rel_controlfilename(unicode(name)) |
|
1185.58.4
by John Arbash Meinel
Added permission checking to Branch, and propogated that change into the stores. |
769 |
ws = WeaveStore(self._transport.clone(relpath), |
770 |
prefixed=prefixed, |
|
771 |
dir_mode=self._dir_mode, |
|
772 |
file_mode=self._file_mode) |
|
|
1393.2.2
by John Arbash Meinel
Updated stores to use Transport |
773 |
if self._transport.should_cache(): |
774 |
ws.enable_cache = True |
|
775 |
return ws |
|
776 |
||
|
1296
by Martin Pool
- v4 branch should allow access to inventory and text stores |
777 |
if self._branch_format == 4: |
|
1185.33.87
by Martin Pool
[patch] refactor code that make sure stores are opened with unicode filenames (robertc) |
778 |
self.inventory_store = get_store('inventory-store') |
779 |
self.text_store = get_store('text-store') |
|
780 |
self.revision_store = get_store('revision-store') |
|
|
1390
by Robert Collins
pair programming worx... merge integration and weave |
781 |
elif self._branch_format == 5: |
|
1185.33.66
by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko) |
782 |
self.control_weaves = get_weave(u'') |
783 |
self.weave_store = get_weave(u'weaves') |
|
784 |
self.revision_store = get_store(u'revision-store', compressed=False) |
|
|
1429
by Robert Collins
merge in niemeyers prefixed-store patch |
785 |
elif self._branch_format == 6: |
|
1185.33.66
by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko) |
786 |
self.control_weaves = get_weave(u'') |
787 |
self.weave_store = get_weave(u'weaves', prefixed=True) |
|
788 |
self.revision_store = get_store(u'revision-store', compressed=False, |
|
|
1429
by Robert Collins
merge in niemeyers prefixed-store patch |
789 |
prefixed=True) |
|
1442.1.59
by Robert Collins
Add re-sign command to generate a digital signature on a single revision. |
790 |
self.revision_store.register_suffix('sig') |
|
1417.1.6
by Robert Collins
introduce transactions for grouping actions done to and with branches |
791 |
self._transaction = None |
|
1
by mbp at sourcefrog
import from baz patch-364 |
792 |
|
|
1534.4.1
by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib. |
793 |
@staticmethod
|
794 |
def _initialize(base): |
|
795 |
"""Create a bzr branch in the latest format.""" |
|
|
1534.4.2
by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches. |
796 |
return BzrBranchFormat6().initialize(base) |
|
1534.4.1
by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib. |
797 |
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
798 |
def __str__(self): |
|
907.1.5
by John Arbash Meinel
Some more work, including ScratchBranch changes. |
799 |
return '%s(%r)' % (self.__class__.__name__, self._transport.base) |
|
1
by mbp at sourcefrog
import from baz patch-364 |
800 |
|
801 |
__repr__ = __str__ |
|
802 |
||
|
578
by Martin Pool
- start to move toward Branch.lock and unlock methods, |
803 |
def __del__(self): |
|
615
by Martin Pool
Major rework of locking code: |
804 |
if self._lock_mode or self._lock: |
|
1390
by Robert Collins
pair programming worx... merge integration and weave |
805 |
# XXX: This should show something every time, and be suitable for
|
806 |
# headless operation and embedding
|
|
|
578
by Martin Pool
- start to move toward Branch.lock and unlock methods, |
807 |
warn("branch %r was not explicitly unlocked" % self) |
|
615
by Martin Pool
Major rework of locking code: |
808 |
self._lock.unlock() |
|
578
by Martin Pool
- start to move toward Branch.lock and unlock methods, |
809 |
|
|
907.1.23
by John Arbash Meinel
Branch objects now automatically create Cached stores if the protocol is_remote. |
810 |
# TODO: It might be best to do this somewhere else,
|
811 |
# but it is nice for a Branch object to automatically
|
|
812 |
# cache it's information.
|
|
813 |
# Alternatively, we could have the Transport objects cache requests
|
|
814 |
# See the earlier discussion about how major objects (like Branch)
|
|
815 |
# should never expect their __del__ function to run.
|
|
|
1185.11.9
by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv |
816 |
if hasattr(self, 'cache_root') and self.cache_root is not None: |
|
907.1.23
by John Arbash Meinel
Branch objects now automatically create Cached stores if the protocol is_remote. |
817 |
try: |
818 |
shutil.rmtree(self.cache_root) |
|
819 |
except: |
|
820 |
pass
|
|
821 |
self.cache_root = None |
|
822 |
||
|
907.1.17
by John Arbash Meinel
Adding a Branch.base property, removing pull_loc() |
823 |
def _get_base(self): |
|
907.1.19
by John Arbash Meinel
Updated ScratchBranch and Branch.base, All Tests PASS !!! |
824 |
if self._transport: |
825 |
return self._transport.base |
|
826 |
return None |
|
|
907.1.17
by John Arbash Meinel
Adding a Branch.base property, removing pull_loc() |
827 |
|
|
1442.1.5
by Robert Collins
Give branch.base a docstring. |
828 |
base = property(_get_base, doc="The URL for the root of this branch.") |
|
578
by Martin Pool
- start to move toward Branch.lock and unlock methods, |
829 |
|
|
1417.1.6
by Robert Collins
introduce transactions for grouping actions done to and with branches |
830 |
def _finish_transaction(self): |
831 |
"""Exit the current transaction.""" |
|
832 |
if self._transaction is None: |
|
833 |
raise errors.LockError('Branch %s is not in a transaction' % |
|
834 |
self) |
|
835 |
transaction = self._transaction |
|
836 |
self._transaction = None |
|
837 |
transaction.finish() |
|
838 |
||
839 |
def get_transaction(self): |
|
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
840 |
"""See Branch.get_transaction.""" |
|
1417.1.6
by Robert Collins
introduce transactions for grouping actions done to and with branches |
841 |
if self._transaction is None: |
842 |
return transactions.PassThroughTransaction() |
|
843 |
else: |
|
844 |
return self._transaction |
|
845 |
||
846 |
def _set_transaction(self, new_transaction): |
|
847 |
"""Set a new active transaction.""" |
|
848 |
if self._transaction is not None: |
|
849 |
raise errors.LockError('Branch %s is in a transaction already.' % |
|
850 |
self) |
|
851 |
self._transaction = new_transaction |
|
|
610
by Martin Pool
- replace Branch.lock(mode) with separate lock_read and lock_write |
852 |
|
853 |
def lock_write(self): |
|
|
1185.50.6
by John Arbash Meinel
Fixed a broken test from my 'push updates local working tree' fix |
854 |
#mutter("lock write: %s (%s)", self, self._lock_count)
|
|
907.1.2
by John Arbash Meinel
Working on making Branch() do all of it's work over a Transport. |
855 |
# TODO: Upgrade locking to support using a Transport,
|
856 |
# and potentially a remote locking protocol
|
|
|
610
by Martin Pool
- replace Branch.lock(mode) with separate lock_read and lock_write |
857 |
if self._lock_mode: |
858 |
if self._lock_mode != 'w': |
|
859 |
raise LockError("can't upgrade to a write lock from %r" % |
|
860 |
self._lock_mode) |
|
861 |
self._lock_count += 1 |
|
862 |
else: |
|
|
907.1.24
by John Arbash Meinel
Remote functionality work. |
863 |
self._lock = self._transport.lock_write( |
864 |
self._rel_controlfilename('branch-lock')) |
|
|
610
by Martin Pool
- replace Branch.lock(mode) with separate lock_read and lock_write |
865 |
self._lock_mode = 'w' |
866 |
self._lock_count = 1 |
|
|
1417.1.6
by Robert Collins
introduce transactions for grouping actions done to and with branches |
867 |
self._set_transaction(transactions.PassThroughTransaction()) |
|
610
by Martin Pool
- replace Branch.lock(mode) with separate lock_read and lock_write |
868 |
|
869 |
def lock_read(self): |
|
|
1185.50.6
by John Arbash Meinel
Fixed a broken test from my 'push updates local working tree' fix |
870 |
#mutter("lock read: %s (%s)", self, self._lock_count)
|
|
610
by Martin Pool
- replace Branch.lock(mode) with separate lock_read and lock_write |
871 |
if self._lock_mode: |
872 |
assert self._lock_mode in ('r', 'w'), \ |
|
873 |
"invalid lock mode %r" % self._lock_mode |
|
874 |
self._lock_count += 1 |
|
875 |
else: |
|
|
907.1.24
by John Arbash Meinel
Remote functionality work. |
876 |
self._lock = self._transport.lock_read( |
877 |
self._rel_controlfilename('branch-lock')) |
|
|
610
by Martin Pool
- replace Branch.lock(mode) with separate lock_read and lock_write |
878 |
self._lock_mode = 'r' |
879 |
self._lock_count = 1 |
|
|
1417.1.6
by Robert Collins
introduce transactions for grouping actions done to and with branches |
880 |
self._set_transaction(transactions.ReadOnlyTransaction()) |
|
1417.1.10
by Robert Collins
add a cache bound to Transactions, and a precious facility, so that we keep inventory.weave in memory, but can discard weaves for other such files. |
881 |
# 5K may be excessive, but hey, its a knob.
|
882 |
self.get_transaction().set_cache_size(5000) |
|
|
610
by Martin Pool
- replace Branch.lock(mode) with separate lock_read and lock_write |
883 |
|
|
578
by Martin Pool
- start to move toward Branch.lock and unlock methods, |
884 |
def unlock(self): |
|
1185.50.6
by John Arbash Meinel
Fixed a broken test from my 'push updates local working tree' fix |
885 |
#mutter("unlock: %s (%s)", self, self._lock_count)
|
|
578
by Martin Pool
- start to move toward Branch.lock and unlock methods, |
886 |
if not self._lock_mode: |
|
610
by Martin Pool
- replace Branch.lock(mode) with separate lock_read and lock_write |
887 |
raise LockError('branch %r is not locked' % (self)) |
|
580
by Martin Pool
- Use explicit lock methods on a branch, rather than doing it |
888 |
|
889 |
if self._lock_count > 1: |
|
890 |
self._lock_count -= 1 |
|
891 |
else: |
|
|
1417.1.6
by Robert Collins
introduce transactions for grouping actions done to and with branches |
892 |
self._finish_transaction() |
|
615
by Martin Pool
Major rework of locking code: |
893 |
self._lock.unlock() |
894 |
self._lock = None |
|
|
580
by Martin Pool
- Use explicit lock methods on a branch, rather than doing it |
895 |
self._lock_mode = self._lock_count = None |
|
353
by Martin Pool
- Per-branch locks in read and write modes. |
896 |
|
|
67
by mbp at sourcefrog
use abspath() for the function that makes an absolute |
897 |
def abspath(self, name): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
898 |
"""See Branch.abspath.""" |
|
907.1.5
by John Arbash Meinel
Some more work, including ScratchBranch changes. |
899 |
return self._transport.abspath(name) |
|
67
by mbp at sourcefrog
use abspath() for the function that makes an absolute |
900 |
|
|
907.1.2
by John Arbash Meinel
Working on making Branch() do all of it's work over a Transport. |
901 |
def _rel_controlfilename(self, file_or_path): |
|
1469
by Robert Collins
Change Transport.* to work with URL's. |
902 |
if not isinstance(file_or_path, basestring): |
|
1185.33.66
by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko) |
903 |
file_or_path = u'/'.join(file_or_path) |
|
1469
by Robert Collins
Change Transport.* to work with URL's. |
904 |
if file_or_path == '': |
905 |
return bzrlib.BZRDIR |
|
|
1185.33.66
by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko) |
906 |
return bzrlib.transport.urlescape(bzrlib.BZRDIR + u'/' + file_or_path) |
|
907.1.2
by John Arbash Meinel
Working on making Branch() do all of it's work over a Transport. |
907 |
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
908 |
def controlfilename(self, file_or_path): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
909 |
"""See Branch.controlfilename.""" |
|
907.1.8
by John Arbash Meinel
Changed the format for abspath. Updated branch to use a hidden _transport |
910 |
return self._transport.abspath(self._rel_controlfilename(file_or_path)) |
|
1
by mbp at sourcefrog
import from baz patch-364 |
911 |
|
912 |
def controlfile(self, file_or_path, mode='r'): |
|
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
913 |
"""See Branch.controlfile.""" |
|
907.1.2
by John Arbash Meinel
Working on making Branch() do all of it's work over a Transport. |
914 |
import codecs |
915 |
||
916 |
relpath = self._rel_controlfilename(file_or_path) |
|
917 |
#TODO: codecs.open() buffers linewise, so it was overloaded with
|
|
918 |
# a much larger buffer, do we need to do the same for getreader/getwriter?
|
|
919 |
if mode == 'rb': |
|
|
907.1.8
by John Arbash Meinel
Changed the format for abspath. Updated branch to use a hidden _transport |
920 |
return self._transport.get(relpath) |
|
907.1.2
by John Arbash Meinel
Working on making Branch() do all of it's work over a Transport. |
921 |
elif mode == 'wb': |
|
907.1.50
by John Arbash Meinel
Removed encode/decode from Transport.put/get, added more exceptions that can be thrown. |
922 |
raise BzrError("Branch.controlfile(mode='wb') is not supported, use put_controlfiles") |
|
907.1.2
by John Arbash Meinel
Working on making Branch() do all of it's work over a Transport. |
923 |
elif mode == 'r': |
|
1185.16.149
by Martin Pool
doc |
924 |
# XXX: Do we really want errors='replace'? Perhaps it should be
|
925 |
# an error, or at least reported, if there's incorrectly-encoded
|
|
926 |
# data inside a file.
|
|
927 |
# <https://launchpad.net/products/bzr/+bug/3823>
|
|
|
907.1.50
by John Arbash Meinel
Removed encode/decode from Transport.put/get, added more exceptions that can be thrown. |
928 |
return codecs.getreader('utf-8')(self._transport.get(relpath), errors='replace') |
|
907.1.2
by John Arbash Meinel
Working on making Branch() do all of it's work over a Transport. |
929 |
elif mode == 'w': |
|
907.1.50
by John Arbash Meinel
Removed encode/decode from Transport.put/get, added more exceptions that can be thrown. |
930 |
raise BzrError("Branch.controlfile(mode='w') is not supported, use put_controlfiles") |
|
245
by mbp at sourcefrog
- control files always in utf-8-unix format |
931 |
else: |
932 |
raise BzrError("invalid controlfile mode %r" % mode) |
|
933 |
||
|
907.1.50
by John Arbash Meinel
Removed encode/decode from Transport.put/get, added more exceptions that can be thrown. |
934 |
def put_controlfile(self, path, f, encode=True): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
935 |
"""See Branch.put_controlfile.""" |
|
907.1.50
by John Arbash Meinel
Removed encode/decode from Transport.put/get, added more exceptions that can be thrown. |
936 |
self.put_controlfiles([(path, f)], encode=encode) |
937 |
||
938 |
def put_controlfiles(self, files, encode=True): |
|
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
939 |
"""See Branch.put_controlfiles.""" |
|
907.1.50
by John Arbash Meinel
Removed encode/decode from Transport.put/get, added more exceptions that can be thrown. |
940 |
import codecs |
941 |
ctrl_files = [] |
|
942 |
for path, f in files: |
|
943 |
if encode: |
|
944 |
if isinstance(f, basestring): |
|
945 |
f = f.encode('utf-8', 'replace') |
|
946 |
else: |
|
947 |
f = codecs.getwriter('utf-8')(f, errors='replace') |
|
948 |
path = self._rel_controlfilename(path) |
|
949 |
ctrl_files.append((path, f)) |
|
|
1185.58.4
by John Arbash Meinel
Added permission checking to Branch, and propogated that change into the stores. |
950 |
self._transport.put_multi(ctrl_files, mode=self._file_mode) |
951 |
||
952 |
def _find_modes(self, path=None): |
|
953 |
"""Determine the appropriate modes for files and directories.""" |
|
954 |
try: |
|
955 |
if path is None: |
|
956 |
path = self._rel_controlfilename('') |
|
957 |
st = self._transport.stat(path) |
|
958 |
except errors.TransportNotPossible: |
|
959 |
self._dir_mode = 0755 |
|
960 |
self._file_mode = 0644 |
|
961 |
else: |
|
962 |
self._dir_mode = st.st_mode & 07777 |
|
963 |
# Remove the sticky and execute bits for files
|
|
964 |
self._file_mode = self._dir_mode & ~07111 |
|
|
1185.58.7
by John Arbash Meinel
Added the ability to disable setting permissions |
965 |
if not self._set_dir_mode: |
966 |
self._dir_mode = None |
|
967 |
if not self._set_file_mode: |
|
968 |
self._file_mode = None |
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
969 |
|
|
1293
by Martin Pool
- add Branch constructor option to relax version check |
970 |
def _check_format(self, relax_version_check): |
|
1
by mbp at sourcefrog
import from baz patch-364 |
971 |
"""Check this branch format is supported. |
972 |
||
|
1187
by Martin Pool
- improved check for branch version |
973 |
The format level is stored, as an integer, in
|
974 |
self._branch_format for code that needs to check it later.
|
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
975 |
|
976 |
In the future, we might need different in-memory Branch
|
|
977 |
classes to support downlevel branches. But not yet.
|
|
|
163
by mbp at sourcefrog
merge win32 portability fixes |
978 |
"""
|
|
1185.11.9
by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv |
979 |
try: |
980 |
fmt = self.controlfile('branch-format', 'r').read() |
|
981 |
except NoSuchFile: |
|
|
1185.16.61
by mbp at sourcefrog
- start introducing hct error classes |
982 |
raise NotBranchError(path=self.base) |
|
1393.1.63
by Martin Pool
- add some trace statements |
983 |
mutter("got branch format %r", fmt) |
|
1429
by Robert Collins
merge in niemeyers prefixed-store patch |
984 |
if fmt == BZR_BRANCH_FORMAT_6: |
985 |
self._branch_format = 6 |
|
986 |
elif fmt == BZR_BRANCH_FORMAT_5: |
|
|
1187
by Martin Pool
- improved check for branch version |
987 |
self._branch_format = 5 |
|
1294
by Martin Pool
- refactor branch version detection |
988 |
elif fmt == BZR_BRANCH_FORMAT_4: |
989 |
self._branch_format = 4 |
|
990 |
||
991 |
if (not relax_version_check |
|
|
1429
by Robert Collins
merge in niemeyers prefixed-store patch |
992 |
and self._branch_format not in (5, 6)): |
|
1185.1.53
by Robert Collins
raise a specific error on unsupported branches so that they can be distinguished from generic errors |
993 |
raise errors.UnsupportedFormatError( |
994 |
'sorry, branch format %r not supported' % fmt, |
|
|
576
by Martin Pool
- raise exceptions rather than using bailout() |
995 |
['use a different bzr version', |
|
1393.2.1
by John Arbash Meinel
Merged in split-storage-2 branch. Need to cleanup a little bit more still. |
996 |
'or remove the .bzr directory'
|
997 |
' and "bzr init" again']) |
|
|
907.1.2
by John Arbash Meinel
Working on making Branch() do all of it's work over a Transport. |
998 |
|
|
1508.1.15
by Robert Collins
Merge from mpool. |
999 |
@needs_read_lock
|
|
909
by Martin Pool
- merge John's code to give the tree root an explicit file id |
1000 |
def get_root_id(self): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1001 |
"""See Branch.get_root_id.""" |
|
1497
by Robert Collins
Move Branch.read_working_inventory to WorkingTree. |
1002 |
inv = self.get_inventory(self.last_revision()) |
|
909
by Martin Pool
- merge John's code to give the tree root an explicit file id |
1003 |
return inv.root.file_id |
|
1
by mbp at sourcefrog
import from baz patch-364 |
1004 |
|
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1005 |
@needs_read_lock
|
|
1185.50.9
by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision |
1006 |
def print_file(self, file, revision_id): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1007 |
"""See Branch.print_file.""" |
|
1185.50.9
by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision |
1008 |
tree = self.revision_tree(revision_id) |
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1009 |
# use inventory as it was in that revision
|
1010 |
file_id = tree.inventory.path2id(file) |
|
1011 |
if not file_id: |
|
|
1185.50.9
by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision |
1012 |
try: |
1013 |
revno = self.revision_id_to_revno(revision_id) |
|
1014 |
except errors.NoSuchRevision: |
|
1015 |
# TODO: This should not be BzrError,
|
|
1016 |
# but NoSuchFile doesn't fit either
|
|
1017 |
raise BzrError('%r is not present in revision %s' |
|
1018 |
% (file, revision_id)) |
|
1019 |
else: |
|
1020 |
raise BzrError('%r is not present in revision %s' |
|
1021 |
% (file, revno)) |
|
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1022 |
tree.print_file(file_id) |
1023 |
||
1024 |
@needs_write_lock
|
|
|
905
by Martin Pool
- merge aaron's append_multiple.patch |
1025 |
def append_revision(self, *revision_ids): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1026 |
"""See Branch.append_revision.""" |
|
905
by Martin Pool
- merge aaron's append_multiple.patch |
1027 |
for revision_id in revision_ids: |
1028 |
mutter("add {%s} to revision-history" % revision_id) |
|
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1029 |
rev_history = self.revision_history() |
1030 |
rev_history.extend(revision_ids) |
|
|
1442.1.68
by Robert Collins
'bzr pull' now accepts '--clobber'. |
1031 |
self.set_revision_history(rev_history) |
1032 |
||
1033 |
@needs_write_lock
|
|
1034 |
def set_revision_history(self, rev_history): |
|
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1035 |
"""See Branch.set_revision_history.""" |
|
1185.33.59
by Martin Pool
[patch] keep a cached basis inventory (Johan Rydberg) |
1036 |
old_revision = self.last_revision() |
1037 |
new_revision = rev_history[-1] |
|
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1038 |
self.put_controlfile('revision-history', '\n'.join(rev_history)) |
|
1185.49.26
by John Arbash Meinel
Adding tests for remote sftp branches without working trees, plus a bugfix to allow push to still work with a warning. |
1039 |
try: |
1040 |
self.working_tree().set_last_revision(new_revision, old_revision) |
|
1041 |
except NoWorkingTree: |
|
1042 |
mutter('Unable to set_last_revision without a working tree.') |
|
|
233
by mbp at sourcefrog
- more output from test.sh |
1043 |
|
|
1261
by Martin Pool
- new method Branch.has_revision |
1044 |
def has_revision(self, revision_id): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1045 |
"""See Branch.has_revision.""" |
|
1390
by Robert Collins
pair programming worx... merge integration and weave |
1046 |
return (revision_id is None |
|
1442.1.45
by Robert Collins
replace __contains__ calls in stores with has_id |
1047 |
or self.revision_store.has_id(revision_id)) |
|
1261
by Martin Pool
- new method Branch.has_revision |
1048 |
|
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1049 |
@needs_read_lock
|
|
1185.42.5
by Jelmer Vernooij
Make get_revision_xml_file() private |
1050 |
def _get_revision_xml_file(self, revision_id): |
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
1051 |
if not revision_id or not isinstance(revision_id, basestring): |
|
1185.16.103
by mbp at sourcefrog
Fix up all calls to InvalidRevisionId() to specify parameters. |
1052 |
raise InvalidRevisionId(revision_id=revision_id, branch=self) |
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
1053 |
try: |
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1054 |
return self.revision_store.get(revision_id) |
1055 |
except (IndexError, KeyError): |
|
1056 |
raise bzrlib.errors.NoSuchRevision(self, revision_id) |
|
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
1057 |
|
|
1231
by Martin Pool
- more progress on fetch on top of weaves |
1058 |
def get_revision_xml(self, revision_id): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1059 |
"""See Branch.get_revision_xml.""" |
|
1185.42.5
by Jelmer Vernooij
Make get_revision_xml_file() private |
1060 |
return self._get_revision_xml_file(revision_id).read() |
|
1231
by Martin Pool
- more progress on fetch on top of weaves |
1061 |
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
1062 |
def get_revision(self, revision_id): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1063 |
"""See Branch.get_revision.""" |
|
1185.42.5
by Jelmer Vernooij
Make get_revision_xml_file() private |
1064 |
xml_file = self._get_revision_xml_file(revision_id) |
|
1027
by Martin Pool
- better error message when failing to get revision from store |
1065 |
|
1066 |
try: |
|
|
1189
by Martin Pool
- BROKEN: partial support for commit into weave |
1067 |
r = bzrlib.xml5.serializer_v5.read_revision(xml_file) |
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
1068 |
except SyntaxError, e: |
1069 |
raise bzrlib.errors.BzrError('failed to unpack revision_xml', |
|
1070 |
[revision_id, |
|
1071 |
str(e)]) |
|
|
802
by Martin Pool
- Remove XMLMixin class in favour of simple pack_xml, unpack_xml functions |
1072 |
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
1073 |
assert r.revision_id == revision_id |
1074 |
return r |
|
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
1075 |
|
|
672
by Martin Pool
- revision records include the hash of their inventory and |
1076 |
def get_revision_sha1(self, revision_id): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1077 |
"""See Branch.get_revision_sha1.""" |
|
672
by Martin Pool
- revision records include the hash of their inventory and |
1078 |
# In the future, revision entries will be signed. At that
|
1079 |
# point, it is probably best *not* to include the signature
|
|
1080 |
# in the revision hash. Because that lets you re-sign
|
|
1081 |
# the revision, (add signatures/remove signatures) and still
|
|
1082 |
# have all hash pointers stay consistent.
|
|
1083 |
# But for now, just hash the contents.
|
|
|
1230
by Martin Pool
- remove Branch.get_revision_xml; use get_revision_xml_file instead |
1084 |
return bzrlib.osutils.sha_file(self.get_revision_xml_file(revision_id)) |
|
672
by Martin Pool
- revision records include the hash of their inventory and |
1085 |
|
|
1225
by Martin Pool
- branch now tracks ancestry - all merged revisions |
1086 |
def get_ancestry(self, revision_id): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1087 |
"""See Branch.get_ancestry.""" |
|
1390
by Robert Collins
pair programming worx... merge integration and weave |
1088 |
if revision_id is None: |
1089 |
return [None] |
|
|
1495.1.3
by Jelmer Vernooij
Move some more generic methods from NativeBranch to Branch. |
1090 |
w = self._get_inventory_weave() |
|
1415
by Robert Collins
remove the ancestry weave file |
1091 |
return [None] + map(w.idx_to_name, |
1092 |
w.inclusions([w.lookup(revision_id)])) |
|
|
1225
by Martin Pool
- branch now tracks ancestry - all merged revisions |
1093 |
|
|
1495.1.3
by Jelmer Vernooij
Move some more generic methods from NativeBranch to Branch. |
1094 |
def _get_inventory_weave(self): |
|
1417.1.8
by Robert Collins
use transactions in the weave store interface, which enables caching for log |
1095 |
return self.control_weaves.get_weave('inventory', |
1096 |
self.get_transaction()) |
|
|
1223
by Martin Pool
- store inventories in weave |
1097 |
|
|
1192
by Martin Pool
- clean up code for retrieving stored inventories |
1098 |
def get_inventory(self, revision_id): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1099 |
"""See Branch.get_inventory.""" |
|
1372
by Martin Pool
- avoid converting inventories to/from StringIO |
1100 |
xml = self.get_inventory_xml(revision_id) |
1101 |
return bzrlib.xml5.serializer_v5.read_inventory_from_string(xml) |
|
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
1102 |
|
|
1192
by Martin Pool
- clean up code for retrieving stored inventories |
1103 |
def get_inventory_xml(self, revision_id): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1104 |
"""See Branch.get_inventory_xml.""" |
|
1192
by Martin Pool
- clean up code for retrieving stored inventories |
1105 |
try: |
1106 |
assert isinstance(revision_id, basestring), type(revision_id) |
|
|
1495.1.3
by Jelmer Vernooij
Move some more generic methods from NativeBranch to Branch. |
1107 |
iw = self._get_inventory_weave() |
|
1223
by Martin Pool
- store inventories in weave |
1108 |
return iw.get_text(iw.lookup(revision_id)) |
|
1192
by Martin Pool
- clean up code for retrieving stored inventories |
1109 |
except IndexError: |
1110 |
raise bzrlib.errors.HistoryMissing(self, 'inventory', revision_id) |
|
|
1180
by Martin Pool
- start splitting code for xml (de)serialization away from objects |
1111 |
|
|
1192
by Martin Pool
- clean up code for retrieving stored inventories |
1112 |
def get_inventory_sha1(self, revision_id): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1113 |
"""See Branch.get_inventory_sha1.""" |
|
1223
by Martin Pool
- store inventories in weave |
1114 |
return self.get_revision(revision_id).inventory_sha1 |
|
672
by Martin Pool
- revision records include the hash of their inventory and |
1115 |
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
1116 |
def get_revision_inventory(self, revision_id): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1117 |
"""See Branch.get_revision_inventory.""" |
|
1372
by Martin Pool
- avoid converting inventories to/from StringIO |
1118 |
# TODO: Unify this with get_inventory()
|
|
1218
by Martin Pool
- fix up import |
1119 |
# bzr 0.0.6 and later imposes the constraint that the inventory_id
|
|
820
by Martin Pool
- faster Branch.get_revision_inventory now we know the ids are the same |
1120 |
# must be the same as its revision, so this is trivial.
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
1121 |
if revision_id == None: |
|
1497
by Robert Collins
Move Branch.read_working_inventory to WorkingTree. |
1122 |
# This does not make sense: if there is no revision,
|
1123 |
# then it is the current tree inventory surely ?!
|
|
1124 |
# and thus get_root_id() is something that looks at the last
|
|
1125 |
# commit on the branch, and the get_root_id is an inventory check.
|
|
1126 |
raise NotImplementedError |
|
1127 |
# return Inventory(self.get_root_id())
|
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
1128 |
else: |
|
820
by Martin Pool
- faster Branch.get_revision_inventory now we know the ids are the same |
1129 |
return self.get_inventory(revision_id) |
|
1
by mbp at sourcefrog
import from baz patch-364 |
1130 |
|
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1131 |
@needs_read_lock
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
1132 |
def revision_history(self): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1133 |
"""See Branch.revision_history.""" |
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1134 |
transaction = self.get_transaction() |
1135 |
history = transaction.map.find_revision_history() |
|
1136 |
if history is not None: |
|
1137 |
mutter("cache hit for revision-history in %s", self) |
|
|
1417.1.12
by Robert Collins
cache revision history during read transactions |
1138 |
return list(history) |
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1139 |
history = [l.rstrip('\r\n') for l in |
1140 |
self.controlfile('revision-history', 'r').readlines()] |
|
1141 |
transaction.map.add_revision_history(history) |
|
1142 |
# this call is disabled because revision_history is
|
|
1143 |
# not really an object yet, and the transaction is for objects.
|
|
1144 |
# transaction.register_clean(history, precious=True)
|
|
1145 |
return list(history) |
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
1146 |
|
|
974.1.28
by aaron.bentley at utoronto
factored install_revisions out of update_revisions, updated test cases for greedy_fetch |
1147 |
def update_revisions(self, other, stop_revision=None): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1148 |
"""See Branch.update_revisions.""" |
|
974.1.33
by aaron.bentley at utoronto
Added greedy_fetch to update_revisions |
1149 |
from bzrlib.fetch import greedy_fetch |
|
974.1.75
by Aaron Bentley
Sped up pull by copying locally first |
1150 |
if stop_revision is None: |
|
1390
by Robert Collins
pair programming worx... merge integration and weave |
1151 |
stop_revision = other.last_revision() |
|
1185.12.44
by abentley
Restored branch convergence to bzr pull |
1152 |
### Should this be checking is_ancestor instead of revision_history?
|
|
1441
by Robert Collins
tests passing is a good idea - move the branch open in cmd_branch to ensure this, and remove noise from the test suite |
1153 |
if (stop_revision is not None and |
1154 |
stop_revision in self.revision_history()): |
|
|
1440
by Robert Collins
further tuning of pull, do not do a local merge or fetch at all, if the remote branch is no newer than we are |
1155 |
return
|
|
1260
by Martin Pool
- some updates for fetch/update function |
1156 |
greedy_fetch(to_branch=self, from_branch=other, |
|
1261
by Martin Pool
- new method Branch.has_revision |
1157 |
revision=stop_revision) |
|
1185.12.44
by abentley
Restored branch convergence to bzr pull |
1158 |
pullable_revs = self.pullable_revisions(other, stop_revision) |
|
1185.12.45
by abentley
Cleanups for pull |
1159 |
if len(pullable_revs) > 0: |
|
1261
by Martin Pool
- new method Branch.has_revision |
1160 |
self.append_revision(*pullable_revs) |
|
1185.12.44
by abentley
Restored branch convergence to bzr pull |
1161 |
|
1162 |
def pullable_revisions(self, other, stop_revision): |
|
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1163 |
"""See Branch.pullable_revisions.""" |
|
1185.12.44
by abentley
Restored branch convergence to bzr pull |
1164 |
other_revno = other.revision_id_to_revno(stop_revision) |
1165 |
try: |
|
1166 |
return self.missing_revisions(other, other_revno) |
|
1167 |
except DivergedBranches, e: |
|
1168 |
try: |
|
1169 |
pullable_revs = get_intervening_revisions(self.last_revision(), |
|
1170 |
stop_revision, self) |
|
1171 |
assert self.last_revision() not in pullable_revs |
|
1172 |
return pullable_revs |
|
1173 |
except bzrlib.errors.NotAncestor: |
|
1174 |
if is_ancestor(self.last_revision(), stop_revision, self): |
|
1175 |
return [] |
|
1176 |
else: |
|
1177 |
raise e |
|
1178 |
||
|
1
by mbp at sourcefrog
import from baz patch-364 |
1179 |
def revision_tree(self, revision_id): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1180 |
"""See Branch.revision_tree.""" |
|
529
by Martin Pool
todo |
1181 |
# TODO: refactor this to use an existing revision object
|
1182 |
# so we don't need to read it in twice.
|
|
|
1185.12.98
by Aaron Bentley
Support for forcing merges of unrelated trees |
1183 |
if revision_id == None or revision_id == NULL_REVISION: |
|
974.1.26
by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472 |
1184 |
return EmptyTree() |
|
1
by mbp at sourcefrog
import from baz patch-364 |
1185 |
else: |
1186 |
inv = self.get_revision_inventory(revision_id) |
|
|
1185.50.28
by John Arbash Meinel
Lots of updates for 'bzr check' |
1187 |
return RevisionTree(self, inv, revision_id) |
|
1
by mbp at sourcefrog
import from baz patch-364 |
1188 |
|
|
1185.33.59
by Martin Pool
[patch] keep a cached basis inventory (Johan Rydberg) |
1189 |
def basis_tree(self): |
1190 |
"""See Branch.basis_tree.""" |
|
1191 |
try: |
|
1192 |
revision_id = self.revision_history()[-1] |
|
1193 |
xml = self.working_tree().read_basis_inventory(revision_id) |
|
1194 |
inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(xml) |
|
|
1185.50.28
by John Arbash Meinel
Lots of updates for 'bzr check' |
1195 |
return RevisionTree(self, inv, revision_id) |
|
1185.49.26
by John Arbash Meinel
Adding tests for remote sftp branches without working trees, plus a bugfix to allow push to still work with a warning. |
1196 |
except (IndexError, NoSuchFile, NoWorkingTree), e: |
|
1185.33.59
by Martin Pool
[patch] keep a cached basis inventory (Johan Rydberg) |
1197 |
return self.revision_tree(self.last_revision()) |
1198 |
||
|
1
by mbp at sourcefrog
import from baz patch-364 |
1199 |
def working_tree(self): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1200 |
"""See Branch.working_tree.""" |
|
1185.2.2
by Lalo Martins
cleaning up and refactoring the branch module. |
1201 |
from bzrlib.workingtree import WorkingTree |
|
1497
by Robert Collins
Move Branch.read_working_inventory to WorkingTree. |
1202 |
if self._transport.base.find('://') != -1: |
1203 |
raise NoWorkingTree(self.base) |
|
|
1457.1.1
by Robert Collins
rather than getting the branch inventory, WorkingTree can use the whole Branch, or make its own. |
1204 |
return WorkingTree(self.base, branch=self) |
|
1
by mbp at sourcefrog
import from baz patch-364 |
1205 |
|
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
1206 |
@needs_write_lock
|
1207 |
def pull(self, source, overwrite=False): |
|
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1208 |
"""See Branch.pull.""" |
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
1209 |
source.lock_read() |
1210 |
try: |
|
|
1185.33.44
by Martin Pool
[patch] show number of revisions pushed/pulled/merged (Robey Pointer) |
1211 |
old_count = len(self.revision_history()) |
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
1212 |
try: |
1213 |
self.update_revisions(source) |
|
1214 |
except DivergedBranches: |
|
1215 |
if not overwrite: |
|
1216 |
raise
|
|
|
1185.50.5
by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer) |
1217 |
if overwrite: |
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
1218 |
self.set_revision_history(source.revision_history()) |
|
1185.33.44
by Martin Pool
[patch] show number of revisions pushed/pulled/merged (Robey Pointer) |
1219 |
new_count = len(self.revision_history()) |
1220 |
return new_count - old_count |
|
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
1221 |
finally: |
1222 |
source.unlock() |
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
1223 |
|
|
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
1224 |
def get_parent(self): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1225 |
"""See Branch.get_parent.""" |
|
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
1226 |
import errno |
1227 |
_locs = ['parent', 'pull', 'x-pull'] |
|
1228 |
for l in _locs: |
|
1229 |
try: |
|
1230 |
return self.controlfile(l, 'r').read().strip('\n') |
|
|
1185.31.45
by John Arbash Meinel
Refactoring Exceptions found some places where the wrong exception was caught. |
1231 |
except NoSuchFile: |
1232 |
pass
|
|
|
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
1233 |
return None |
1234 |
||
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
1235 |
def get_push_location(self): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1236 |
"""See Branch.get_push_location.""" |
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
1237 |
config = bzrlib.config.BranchConfig(self) |
1238 |
push_loc = config.get_user_option('push_location') |
|
1239 |
return push_loc |
|
1240 |
||
1241 |
def set_push_location(self, location): |
|
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1242 |
"""See Branch.set_push_location.""" |
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
1243 |
config = bzrlib.config.LocationConfig(self.base) |
1244 |
config.set_user_option('push_location', location) |
|
1245 |
||
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1246 |
@needs_write_lock
|
|
1150
by Martin Pool
- add new Branch.set_parent and tests |
1247 |
def set_parent(self, url): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1248 |
"""See Branch.set_parent.""" |
|
1150
by Martin Pool
- add new Branch.set_parent and tests |
1249 |
# TODO: Maybe delete old location files?
|
1250 |
from bzrlib.atomicfile import AtomicFile |
|
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1251 |
f = AtomicFile(self.controlfilename('parent')) |
|
1150
by Martin Pool
- add new Branch.set_parent and tests |
1252 |
try: |
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1253 |
f.write(url + '\n') |
1254 |
f.commit() |
|
|
1150
by Martin Pool
- add new Branch.set_parent and tests |
1255 |
finally: |
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1256 |
f.close() |
|
1150
by Martin Pool
- add new Branch.set_parent and tests |
1257 |
|
|
1185.35.11
by Aaron Bentley
Added support for branch nicks |
1258 |
def tree_config(self): |
1259 |
return TreeConfig(self) |
|
1260 |
||
|
1442.1.60
by Robert Collins
gpg sign commits if the policy says we need to |
1261 |
def sign_revision(self, revision_id, gpg_strategy): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1262 |
"""See Branch.sign_revision.""" |
|
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
1263 |
plaintext = Testament.from_revision(self, revision_id).as_short_text() |
1264 |
self.store_revision_signature(gpg_strategy, plaintext, revision_id) |
|
1265 |
||
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1266 |
@needs_write_lock
|
|
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
1267 |
def store_revision_signature(self, gpg_strategy, plaintext, revision_id): |
|
1495.1.2
by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch. |
1268 |
"""See Branch.store_revision_signature.""" |
|
1442.1.63
by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py. |
1269 |
self.revision_store.add(StringIO(gpg_strategy.sign(plaintext)), |
1270 |
revision_id, "sig") |
|
|
1185.11.5
by John Arbash Meinel
Merged up-to-date against mainline, still broken. |
1271 |
|
1272 |
||
|
1534.4.1
by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib. |
1273 |
Branch.set_default_initializer(BzrBranch._initialize) |
1274 |
||
1275 |
||
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
1276 |
class BranchTestProviderAdapter(object): |
1277 |
"""A tool to generate a suite testing multiple branch formats at once. |
|
1278 |
||
1279 |
This is done by copying the test once for each transport and injecting
|
|
1280 |
the transport_server, transport_readonly_server, and branch_format
|
|
1281 |
classes into each copy. Each copy is also given a new id() to make it
|
|
1282 |
easy to identify.
|
|
1283 |
"""
|
|
1284 |
||
1285 |
def __init__(self, transport_server, transport_readonly_server, formats): |
|
1286 |
self._transport_server = transport_server |
|
1287 |
self._transport_readonly_server = transport_readonly_server |
|
1288 |
self._formats = formats |
|
1289 |
||
1290 |
def adapt(self, test): |
|
1291 |
result = TestSuite() |
|
1292 |
for format in self._formats: |
|
1293 |
new_test = deepcopy(test) |
|
1294 |
new_test.transport_server = self._transport_server |
|
1295 |
new_test.transport_readonly_server = self._transport_readonly_server |
|
1296 |
new_test.branch_format = format |
|
1297 |
def make_new_test_id(): |
|
1298 |
new_id = "%s(%s)" % (new_test.id(), format.__class__.__name__) |
|
1299 |
return lambda: new_id |
|
1300 |
new_test.id = make_new_test_id() |
|
1301 |
result.addTest(new_test) |
|
1302 |
return result |
|
1303 |
||
1304 |
||
|
1495.1.5
by Jelmer Vernooij
Rename NativeBranch -> BzrBranch |
1305 |
class ScratchBranch(BzrBranch): |
|
1
by mbp at sourcefrog
import from baz patch-364 |
1306 |
"""Special test class: a branch that cleans up after itself. |
1307 |
||
1308 |
>>> b = ScratchBranch()
|
|
1309 |
>>> isdir(b.base)
|
|
1310 |
True
|
|
1311 |
>>> bd = b.base
|
|
|
1442.1.42
by Robert Collins
rebuild ScratchBranch on top of ScratchTransport |
1312 |
>>> b._transport.__del__()
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
1313 |
>>> isdir(bd)
|
1314 |
False
|
|
1315 |
"""
|
|
|
1442.1.42
by Robert Collins
rebuild ScratchBranch on top of ScratchTransport |
1316 |
|
1317 |
def __init__(self, files=[], dirs=[], transport=None): |
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
1318 |
"""Make a test branch. |
1319 |
||
1320 |
This creates a temporary directory and runs init-tree in it.
|
|
1321 |
||
1322 |
If any files are listed, they are created in the working copy.
|
|
1323 |
"""
|
|
|
1442.1.42
by Robert Collins
rebuild ScratchBranch on top of ScratchTransport |
1324 |
if transport is None: |
1325 |
transport = bzrlib.transport.local.ScratchTransport() |
|
1326 |
super(ScratchBranch, self).__init__(transport, init=True) |
|
1327 |
else: |
|
1328 |
super(ScratchBranch, self).__init__(transport) |
|
1329 |
||
|
100
by mbp at sourcefrog
- add test case for ignore files |
1330 |
for d in dirs: |
|
907.1.8
by John Arbash Meinel
Changed the format for abspath. Updated branch to use a hidden _transport |
1331 |
self._transport.mkdir(d) |
|
100
by mbp at sourcefrog
- add test case for ignore files |
1332 |
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
1333 |
for f in files: |
|
907.1.8
by John Arbash Meinel
Changed the format for abspath. Updated branch to use a hidden _transport |
1334 |
self._transport.put(f, 'content of %s' % f) |
|
1
by mbp at sourcefrog
import from baz patch-364 |
1335 |
|
1336 |
||
|
622
by Martin Pool
Updated merge patch from Aaron |
1337 |
def clone(self): |
1338 |
""" |
|
1339 |
>>> orig = ScratchBranch(files=["file1", "file2"])
|
|
1340 |
>>> clone = orig.clone()
|
|
|
1185.1.40
by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch. |
1341 |
>>> if os.name != 'nt':
|
1342 |
... os.path.samefile(orig.base, clone.base)
|
|
1343 |
... else:
|
|
1344 |
... orig.base == clone.base
|
|
1345 |
...
|
|
|
622
by Martin Pool
Updated merge patch from Aaron |
1346 |
False
|
|
1185.31.32
by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \ |
1347 |
>>> os.path.isfile(pathjoin(clone.base, "file1"))
|
|
622
by Martin Pool
Updated merge patch from Aaron |
1348 |
True
|
1349 |
"""
|
|
|
800
by Martin Pool
Merge John's import-speedup branch: |
1350 |
from shutil import copytree |
|
1185.31.40
by John Arbash Meinel
Added osutils.mkdtemp() |
1351 |
from bzrlib.osutils import mkdtemp |
|
800
by Martin Pool
Merge John's import-speedup branch: |
1352 |
base = mkdtemp() |
|
622
by Martin Pool
Updated merge patch from Aaron |
1353 |
os.rmdir(base) |
|
800
by Martin Pool
Merge John's import-speedup branch: |
1354 |
copytree(self.base, base, symlinks=True) |
|
1442.1.42
by Robert Collins
rebuild ScratchBranch on top of ScratchTransport |
1355 |
return ScratchBranch( |
1356 |
transport=bzrlib.transport.local.ScratchTransport(base)) |
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
1357 |
|
1358 |
||
1359 |
######################################################################
|
|
1360 |
# predicates
|
|
1361 |
||
1362 |
||
1363 |
def is_control_file(filename): |
|
1364 |
## FIXME: better check
|
|
|
1185.31.38
by John Arbash Meinel
Changing os.path.normpath to osutils.normpath |
1365 |
filename = normpath(filename) |
|
1
by mbp at sourcefrog
import from baz patch-364 |
1366 |
while filename != '': |
1367 |
head, tail = os.path.split(filename) |
|
1368 |
## mutter('check %r for control file' % ((head, tail), ))
|
|
1369 |
if tail == bzrlib.BZRDIR: |
|
1370 |
return True |
|
|
70
by mbp at sourcefrog
Prepare for smart recursive add. |
1371 |
if filename == head: |
1372 |
break
|
|
|
1
by mbp at sourcefrog
import from baz patch-364 |
1373 |
filename = head |
1374 |
return False |