141
130
format, UnknownFormatError or UnsupportedFormatError are raised.
142
131
If there is one, it is returned, along with the unused portion of url.
144
control, relpath = bzrdir.BzrDir.open_containing(url,
133
control, relpath = bzrdir.BzrDir.open_containing(url)
146
134
return control.open_branch(), relpath
148
def get_config(self):
149
return BranchConfig(self)
151
def _get_nick(self, local=False, possible_transports=None):
152
config = self.get_config()
153
# explicit overrides master, but don't look for master if local is True
154
if not local and not config.has_explicit_nickname():
156
master = self.get_master_branch(possible_transports)
157
if master is not None:
158
# return the master branch value
160
except errors.BzrError, e:
161
# Silently fall back to local implicit nick if the master is
163
mutter("Could not connect to bound branch, "
164
"falling back to local nick.\n " + str(e))
165
return config.get_nickname()
137
@deprecated_function(zero_eight)
138
def initialize(base):
139
"""Create a new working tree and branch, rooted at 'base' (url)
141
NOTE: This will soon be deprecated in favour of creation
144
return bzrdir.BzrDir.create_standalone_workingtree(base).branch
146
def setup_caching(self, cache_root):
147
"""Subclasses that care about caching should override this, and set
148
up cached stores located under cache_root.
150
# seems to be unused, 2006-01-13 mbp
151
warn('%s is deprecated' % self.setup_caching)
152
self.cache_root = cache_root
155
cfg = self.tree_config()
156
return cfg.get_option(u"nickname", default=self.base.split('/')[-2])
167
158
def _set_nick(self, nick):
168
self.get_config().set_user_option('nickname', nick, warn_masked=True)
159
cfg = self.tree_config()
160
cfg.set_option(nick, "nickname")
161
assert cfg.get_option("nickname") == nick
170
163
nick = property(_get_nick, _set_nick)
173
raise NotImplementedError(self.is_locked)
175
165
def lock_write(self):
176
raise NotImplementedError(self.lock_write)
166
raise NotImplementedError('lock_write is abstract')
178
168
def lock_read(self):
179
raise NotImplementedError(self.lock_read)
169
raise NotImplementedError('lock_read is abstract')
181
171
def unlock(self):
182
raise NotImplementedError(self.unlock)
172
raise NotImplementedError('unlock is abstract')
184
174
def peek_lock_mode(self):
185
175
"""Return lock mode for the Branch: 'r', 'w' or None"""
186
176
raise NotImplementedError(self.peek_lock_mode)
188
def get_physical_lock_status(self):
189
raise NotImplementedError(self.get_physical_lock_status)
192
def get_revision_id_to_revno_map(self):
193
"""Return the revision_id => dotted revno map.
195
This will be regenerated on demand, but will be cached.
197
:return: A dictionary mapping revision_id => dotted revno.
198
This dictionary should not be modified by the caller.
200
if self._revision_id_to_revno_cache is not None:
201
mapping = self._revision_id_to_revno_cache
203
mapping = self._gen_revno_map()
204
self._cache_revision_id_to_revno(mapping)
205
# TODO: jam 20070417 Since this is being cached, should we be returning
207
# I would rather not, and instead just declare that users should not
208
# modify the return value.
211
def _gen_revno_map(self):
212
"""Create a new mapping from revision ids to dotted revnos.
214
Dotted revnos are generated based on the current tip in the revision
216
This is the worker function for get_revision_id_to_revno_map, which
217
just caches the return value.
219
:return: A dictionary mapping revision_id => dotted revno.
221
last_revision = self.last_revision()
222
revision_graph = repository._old_get_graph(self.repository,
224
merge_sorted_revisions = tsort.merge_sort(
229
revision_id_to_revno = dict((rev_id, revno)
230
for seq_num, rev_id, depth, revno, end_of_merge
231
in merge_sorted_revisions)
232
return revision_id_to_revno
234
def leave_lock_in_place(self):
235
"""Tell this branch object not to release the physical lock when this
178
def abspath(self, name):
179
"""Return absolute filename for something in the branch
238
If lock_write doesn't return a token, then this method is not supported.
240
self.control_files.leave_in_place()
242
def dont_leave_lock_in_place(self):
243
"""Tell this branch object to release the physical lock when this
244
object is unlocked, even if it didn't originally acquire it.
246
If lock_write doesn't return a token, then this method is not supported.
248
self.control_files.dont_leave_in_place()
250
def bind(self, other):
251
"""Bind the local branch the other branch.
253
:param other: The branch to bind to
256
raise errors.UpgradeRequired(self.base)
181
XXX: Robert Collins 20051017 what is this used for? why is it a branch
182
method and not a tree method.
184
raise NotImplementedError('abspath is abstract')
258
186
@needs_write_lock
259
187
def fetch(self, from_branch, last_revision=None, pb=None):
268
196
(copied, failures).
270
198
if self.base == from_branch.base:
199
raise Exception("can't fetch from a branch to itself %s, %s" %
200
(self.base, to_branch.base))
273
nested_pb = ui.ui_factory.nested_progress_bar()
202
pb = bzrlib.ui.ui_factory.progress_bar()
278
204
from_branch.lock_read()
280
206
if last_revision is None:
281
207
pb.update('get source history')
282
last_revision = from_branch.last_revision()
283
last_revision = _mod_revision.ensure_null(last_revision)
208
from_history = from_branch.revision_history()
210
last_revision = from_history[-1]
212
# no history in the source branch
213
last_revision = NULL_REVISION
284
214
return self.repository.fetch(from_branch.repository,
285
215
revision_id=last_revision,
288
if nested_pb is not None:
290
218
from_branch.unlock()
292
def get_bound_location(self):
293
"""Return the URL of the branch we are bound to.
295
Older format branches cannot bind, please be sure to use a metadir
300
def get_old_bound_location(self):
301
"""Return the URL of the branch we used to be bound to
303
raise errors.UpgradeRequired(self.base)
305
def get_commit_builder(self, parents, config=None, timestamp=None,
306
timezone=None, committer=None, revprops=None,
308
"""Obtain a CommitBuilder for this branch.
310
:param parents: Revision ids of the parents of the new revision.
311
:param config: Optional configuration to use.
312
:param timestamp: Optional timestamp recorded for commit.
313
:param timezone: Optional timezone for timestamp.
314
:param committer: Optional committer to set for commit.
315
:param revprops: Optional dictionary of revision properties.
316
:param revision_id: Optional revision id.
320
config = self.get_config()
322
return self.repository.get_commit_builder(self, parents, config,
323
timestamp, timezone, committer, revprops, revision_id)
325
def get_master_branch(self, possible_transports=None):
326
"""Return the branch we are bound to.
328
:return: Either a Branch, or None
332
def get_revision_delta(self, revno):
333
"""Return the delta for one revision.
335
The delta is relative to its mainline predecessor, or the
336
empty tree for revision 1.
338
rh = self.revision_history()
339
if not (1 <= revno <= len(rh)):
340
raise errors.InvalidRevisionNumber(revno)
341
return self.repository.get_revision_delta(rh[revno-1])
343
def get_stacked_on_url(self):
344
"""Get the URL this branch is stacked against.
346
:raises NotStacked: If the branch is not stacked.
347
:raises UnstackableBranchFormat: If the branch does not support
350
raise NotImplementedError(self.get_stacked_on_url)
220
def get_root_id(self):
221
"""Return the id of this branches root"""
222
raise NotImplementedError('get_root_id is abstract')
352
224
def print_file(self, file, revision_id):
353
225
"""Print `file` to stdout."""
354
raise NotImplementedError(self.print_file)
226
raise NotImplementedError('print_file is abstract')
228
def append_revision(self, *revision_ids):
229
raise NotImplementedError('append_revision is abstract')
356
231
def set_revision_history(self, rev_history):
357
raise NotImplementedError(self.set_revision_history)
359
def set_stacked_on_url(self, url):
360
"""Set the URL this branch is stacked against.
362
:raises UnstackableBranchFormat: If the branch does not support
364
:raises UnstackableRepositoryFormat: If the repository does not support
367
raise NotImplementedError(self.set_stacked_on_url)
369
def _cache_revision_history(self, rev_history):
370
"""Set the cached revision history to rev_history.
372
The revision_history method will use this cache to avoid regenerating
373
the revision history.
375
This API is semi-public; it only for use by subclasses, all other code
376
should consider it to be private.
378
self._revision_history_cache = rev_history
380
def _cache_revision_id_to_revno(self, revision_id_to_revno):
381
"""Set the cached revision_id => revno map to revision_id_to_revno.
383
This API is semi-public; it only for use by subclasses, all other code
384
should consider it to be private.
386
self._revision_id_to_revno_cache = revision_id_to_revno
388
def _clear_cached_state(self):
389
"""Clear any cached data on this branch, e.g. cached revision history.
391
This means the next call to revision_history will need to call
392
_gen_revision_history.
394
This API is semi-public; it only for use by subclasses, all other code
395
should consider it to be private.
397
self._revision_history_cache = None
398
self._revision_id_to_revno_cache = None
399
self._last_revision_info_cache = None
401
def _gen_revision_history(self):
402
"""Return sequence of revision hashes on to this branch.
404
Unlike revision_history, this method always regenerates or rereads the
405
revision history, i.e. it does not cache the result, so repeated calls
408
Concrete subclasses should override this instead of revision_history so
409
that subclasses do not need to deal with caching logic.
411
This API is semi-public; it only for use by subclasses, all other code
412
should consider it to be private.
414
raise NotImplementedError(self._gen_revision_history)
232
raise NotImplementedError('set_revision_history is abstract')
417
234
def revision_history(self):
418
"""Return sequence of revision ids on this branch.
420
This method will cache the revision history for as long as it is safe to
423
if 'evil' in debug.debug_flags:
424
mutter_callsite(3, "revision_history scales with history.")
425
if self._revision_history_cache is not None:
426
history = self._revision_history_cache
428
history = self._gen_revision_history()
429
self._cache_revision_history(history)
235
"""Return sequence of revision hashes on to this branch."""
236
raise NotImplementedError('revision_history is abstract')
433
239
"""Return current revision number for this branch.
481
290
common_index = min(self_len, other_len) -1
482
291
if common_index >= 0 and \
483
292
self_history[common_index] != other_history[common_index]:
484
raise errors.DivergedBranches(self, other)
293
raise DivergedBranches(self, other)
486
295
if stop_revision is None:
487
296
stop_revision = other_len
298
assert isinstance(stop_revision, int)
489
299
if stop_revision > other_len:
490
raise errors.NoSuchRevision(self, stop_revision)
300
raise bzrlib.errors.NoSuchRevision(self, stop_revision)
491
301
return other_history[self_len:stop_revision]
494
def update_revisions(self, other, stop_revision=None, overwrite=False,
496
"""Pull in new perfect-fit revisions.
498
:param other: Another Branch to pull from
499
:param stop_revision: Updated until the given revision
500
:param overwrite: Always set the branch pointer, rather than checking
501
to see if it is a proper descendant.
502
:param graph: A Graph object that can be used to query history
503
information. This can be None.
508
other_revno, other_last_revision = other.last_revision_info()
509
stop_revno = None # unknown
510
if stop_revision is None:
511
stop_revision = other_last_revision
512
if _mod_revision.is_null(stop_revision):
513
# if there are no commits, we're done.
515
stop_revno = other_revno
517
# what's the current last revision, before we fetch [and change it
519
last_rev = _mod_revision.ensure_null(self.last_revision())
520
# we fetch here so that we don't process data twice in the common
521
# case of having something to pull, and so that the check for
522
# already merged can operate on the just fetched graph, which will
523
# be cached in memory.
524
self.fetch(other, stop_revision)
525
# Check to see if one is an ancestor of the other
528
graph = self.repository.get_graph()
529
if self._check_if_descendant_or_diverged(
530
stop_revision, last_rev, graph, other):
531
# stop_revision is a descendant of last_rev, but we aren't
532
# overwriting, so we're done.
534
if stop_revno is None:
536
graph = self.repository.get_graph()
537
this_revno, this_last_revision = self.last_revision_info()
538
stop_revno = graph.find_distance_to_null(stop_revision,
539
[(other_last_revision, other_revno),
540
(this_last_revision, this_revno)])
541
self.set_last_revision_info(stop_revno, stop_revision)
303
def update_revisions(self, other, stop_revision=None):
304
"""Pull in new perfect-fit revisions."""
305
raise NotImplementedError('update_revisions is abstract')
307
def pullable_revisions(self, other, stop_revision):
308
raise NotImplementedError('pullable_revisions is abstract')
545
310
def revision_id_to_revno(self, revision_id):
546
311
"""Given a revision id, return its revno"""
547
if _mod_revision.is_null(revision_id):
312
if revision_id is None:
549
314
history = self.revision_history()
551
316
return history.index(revision_id) + 1
552
317
except ValueError:
553
raise errors.NoSuchRevision(self, revision_id)
318
raise bzrlib.errors.NoSuchRevision(self, revision_id)
555
320
def get_rev_id(self, revno, history=None):
556
321
"""Find the revision id of the specified revno."""
558
return _mod_revision.NULL_REVISION
559
324
if history is None:
560
325
history = self.revision_history()
561
if revno <= 0 or revno > len(history):
562
raise errors.NoSuchRevision(self, revno)
326
elif revno <= 0 or revno > len(history):
327
raise bzrlib.errors.NoSuchRevision(self, revno)
563
328
return history[revno - 1]
565
def pull(self, source, overwrite=False, stop_revision=None,
566
possible_transports=None, _override_hook_target=None):
567
"""Mirror source into this branch.
569
This branch is considered to be 'local', having low latency.
571
:returns: PullResult instance
573
raise NotImplementedError(self.pull)
575
def push(self, target, overwrite=False, stop_revision=None):
576
"""Mirror this branch into target.
578
This branch is considered to be 'local', having low latency.
580
raise NotImplementedError(self.push)
330
def pull(self, source, overwrite=False, stop_revision=None):
331
raise NotImplementedError('pull is abstract')
582
333
def basis_tree(self):
583
"""Return `Tree` object for last revision."""
334
"""Return `Tree` object for last revision.
336
If there are no revisions yet, return an `EmptyTree`.
584
338
return self.repository.revision_tree(self.last_revision())
340
def rename_one(self, from_rel, to_rel):
343
This can change the directory or the filename or both.
345
raise NotImplementedError('rename_one is abstract')
347
def move(self, from_paths, to_name):
350
to_name must exist as a versioned directory.
352
If to_name exists and is a directory, the files are moved into
353
it, keeping their old names. If it is a directory,
355
Note that to_name is only the last component of the new name;
356
this doesn't change the directory.
358
This returns a list of (from_path, to_path) pairs for each
361
raise NotImplementedError('move is abstract')
586
363
def get_parent(self):
587
364
"""Return the parent location of the branch.
742
471
revision_id: if not None, the revision history in the new branch will
743
472
be truncated to end with revision_id.
745
self._synchronize_history(destination, revision_id)
747
parent = self.get_parent()
748
except errors.InaccessibleParent, e:
749
mutter('parent was not accessible to copy: %s', e)
752
destination.set_parent(parent)
753
self.tags.merge_to(destination.tags)
757
"""Check consistency of the branch.
759
In particular this checks that revisions given in the revision-history
760
do actually match up in the revision graph, and that they're all
761
present in the repository.
763
Callers will typically also want to check the repository.
765
:return: A BranchCheckResult.
767
mainline_parent_id = None
768
last_revno, last_revision_id = self.last_revision_info()
769
real_rev_history = list(self.repository.iter_reverse_revision_history(
771
real_rev_history.reverse()
772
if len(real_rev_history) != last_revno:
773
raise errors.BzrCheckError('revno does not match len(mainline)'
774
' %s != %s' % (last_revno, len(real_rev_history)))
775
# TODO: We should probably also check that real_rev_history actually
776
# matches self.revision_history()
777
for revision_id in real_rev_history:
474
new_history = self.revision_history()
475
if revision_id is not None:
779
revision = self.repository.get_revision(revision_id)
780
except errors.NoSuchRevision, e:
781
raise errors.BzrCheckError("mainline revision {%s} not in repository"
783
# In general the first entry on the revision history has no parents.
784
# But it's not illegal for it to have parents listed; this can happen
785
# in imports from Arch when the parents weren't reachable.
786
if mainline_parent_id is not None:
787
if mainline_parent_id not in revision.parent_ids:
788
raise errors.BzrCheckError("previous revision {%s} not listed among "
790
% (mainline_parent_id, revision_id))
791
mainline_parent_id = revision_id
792
return BranchCheckResult(self)
794
def _get_checkout_format(self):
795
"""Return the most suitable metadir for a checkout of this branch.
796
Weaves are used if this branch's repository uses weaves.
798
if isinstance(self.bzrdir, bzrdir.BzrDirPreSplitOut):
799
from bzrlib.repofmt import weaverepo
800
format = bzrdir.BzrDirMetaFormat1()
801
format.repository_format = weaverepo.RepositoryFormat7()
803
format = self.repository.bzrdir.checkout_metadir()
804
format.set_branch_format(self._format)
807
def create_checkout(self, to_location, revision_id=None,
808
lightweight=False, accelerator_tree=None,
810
"""Create a checkout of a branch.
812
:param to_location: The url to produce the checkout at
813
:param revision_id: The revision to check out
814
:param lightweight: If True, produce a lightweight checkout, otherwise,
815
produce a bound branch (heavyweight checkout)
816
:param accelerator_tree: A tree which can be used for retrieving file
817
contents more quickly than the revision tree, i.e. a workingtree.
818
The revision tree will be used for cases where accelerator_tree's
819
content is different.
820
:param hardlink: If true, hard-link files from accelerator_tree,
822
:return: The tree of the created checkout
824
t = transport.get_transport(to_location)
827
format = self._get_checkout_format()
828
checkout = format.initialize_on_transport(t)
829
from_branch = BranchReferenceFormat().initialize(checkout, self)
831
format = self._get_checkout_format()
832
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
833
to_location, force_new_tree=False, format=format)
834
checkout = checkout_branch.bzrdir
835
checkout_branch.bind(self)
836
# pull up to the specified revision_id to set the initial
837
# branch tip correctly, and seed it with history.
838
checkout_branch.pull(self, stop_revision=revision_id)
840
tree = checkout.create_workingtree(revision_id,
841
from_branch=from_branch,
842
accelerator_tree=accelerator_tree,
844
basis_tree = tree.basis_tree()
845
basis_tree.lock_read()
847
for path, file_id in basis_tree.iter_references():
848
reference_parent = self.reference_parent(file_id, path)
849
reference_parent.create_checkout(tree.abspath(path),
850
basis_tree.get_reference_revision(file_id, path),
857
def reconcile(self, thorough=True):
858
"""Make sure the data stored in this branch is consistent."""
859
from bzrlib.reconcile import BranchReconciler
860
reconciler = BranchReconciler(self, thorough=thorough)
861
reconciler.reconcile()
864
def reference_parent(self, file_id, path):
865
"""Return the parent branch for a tree-reference file_id
866
:param file_id: The file_id of the tree reference
867
:param path: The path of the file_id in the tree
868
:return: A branch associated with the file_id
870
# FIXME should provide multiple branches, based on config
871
return Branch.open(self.bzrdir.root_transport.clone(path).base)
873
def supports_tags(self):
874
return self._format.supports_tags()
876
def _check_if_descendant_or_diverged(self, revision_a, revision_b, graph,
878
"""Ensure that revision_b is a descendant of revision_a.
880
This is a helper function for update_revisions.
882
:raises: DivergedBranches if revision_b has diverged from revision_a.
883
:returns: True if revision_b is a descendant of revision_a.
885
relation = self._revision_relations(revision_a, revision_b, graph)
886
if relation == 'b_descends_from_a':
888
elif relation == 'diverged':
889
raise errors.DivergedBranches(self, other_branch)
890
elif relation == 'a_descends_from_b':
893
raise AssertionError("invalid relation: %r" % (relation,))
895
def _revision_relations(self, revision_a, revision_b, graph):
896
"""Determine the relationship between two revisions.
898
:returns: One of: 'a_descends_from_b', 'b_descends_from_a', 'diverged'
900
heads = graph.heads([revision_a, revision_b])
901
if heads == set([revision_b]):
902
return 'b_descends_from_a'
903
elif heads == set([revision_a, revision_b]):
904
# These branches have diverged
906
elif heads == set([revision_a]):
907
return 'a_descends_from_b'
909
raise AssertionError("invalid heads: %r" % (heads,))
477
new_history = new_history[:new_history.index(revision_id) + 1]
479
rev = self.repository.get_revision(revision_id)
480
new_history = rev.get_history(self.repository)[1:]
481
destination.set_revision_history(new_history)
482
parent = self.get_parent()
484
destination.set_parent(parent)
912
487
class BranchFormat(object):
1052
558
def set_default_format(klass, format):
1053
559
klass._default_format = format
1055
def supports_stacking(self):
1056
"""True if this format records a stacked-on branch."""
1060
562
def unregister_format(klass, format):
563
assert klass._formats[format.get_format_string()] is format
1061
564
del klass._formats[format.get_format_string()]
1064
return self.get_format_string().rstrip()
1066
def supports_tags(self):
1067
"""True if this format supports tags stored in the branch"""
1068
return False # by default
1071
class BranchHooks(Hooks):
1072
"""A dictionary mapping hook name to a list of callables for branch hooks.
1074
e.g. ['set_rh'] Is the list of items to be called when the
1075
set_revision_history function is invoked.
1079
"""Create the default hooks.
1081
These are all empty initially, because by default nothing should get
1084
Hooks.__init__(self)
1085
# Introduced in 0.15:
1086
# invoked whenever the revision history has been set
1087
# with set_revision_history. The api signature is
1088
# (branch, revision_history), and the branch will
1091
# Invoked after a branch is opened. The api signature is (branch).
1093
# invoked after a push operation completes.
1094
# the api signature is
1096
# containing the members
1097
# (source, local, master, old_revno, old_revid, new_revno, new_revid)
1098
# where local is the local target branch or None, master is the target
1099
# master branch, and the rest should be self explanatory. The source
1100
# is read locked and the target branches write locked. Source will
1101
# be the local low-latency branch.
1102
self['post_push'] = []
1103
# invoked after a pull operation completes.
1104
# the api signature is
1106
# containing the members
1107
# (source, local, master, old_revno, old_revid, new_revno, new_revid)
1108
# where local is the local branch or None, master is the target
1109
# master branch, and the rest should be self explanatory. The source
1110
# is read locked and the target branches write locked. The local
1111
# branch is the low-latency branch.
1112
self['post_pull'] = []
1113
# invoked before a commit operation takes place.
1114
# the api signature is
1115
# (local, master, old_revno, old_revid, future_revno, future_revid,
1116
# tree_delta, future_tree).
1117
# old_revid is NULL_REVISION for the first commit to a branch
1118
# tree_delta is a TreeDelta object describing changes from the basis
1119
# revision, hooks MUST NOT modify this delta
1120
# future_tree is an in-memory tree obtained from
1121
# CommitBuilder.revision_tree() and hooks MUST NOT modify this tree
1122
self['pre_commit'] = []
1123
# invoked after a commit operation completes.
1124
# the api signature is
1125
# (local, master, old_revno, old_revid, new_revno, new_revid)
1126
# old_revid is NULL_REVISION for the first commit to a branch.
1127
self['post_commit'] = []
1128
# invoked after a uncommit operation completes.
1129
# the api signature is
1130
# (local, master, old_revno, old_revid, new_revno, new_revid) where
1131
# local is the local branch or None, master is the target branch,
1132
# and an empty branch recieves new_revno of 0, new_revid of None.
1133
self['post_uncommit'] = []
1135
# Invoked before the tip of a branch changes.
1136
# the api signature is
1137
# (params) where params is a ChangeBranchTipParams with the members
1138
# (branch, old_revno, new_revno, old_revid, new_revid)
1139
self['pre_change_branch_tip'] = []
1141
# Invoked after the tip of a branch changes.
1142
# the api signature is
1143
# (params) where params is a ChangeBranchTipParams with the members
1144
# (branch, old_revno, new_revno, old_revid, new_revid)
1145
self['post_change_branch_tip'] = []
1147
# Invoked when a stacked branch activates its fallback locations and
1148
# allows the transformation of the url of said location.
1149
# the api signature is
1150
# (branch, url) where branch is the branch having its fallback
1151
# location activated and url is the url for the fallback location.
1152
# The hook should return a url.
1153
self['transform_fallback_location'] = []
1156
# install the default hooks into the Branch class.
1157
Branch.hooks = BranchHooks()
1160
class ChangeBranchTipParams(object):
1161
"""Object holding parameters passed to *_change_branch_tip hooks.
1163
There are 5 fields that hooks may wish to access:
1165
:ivar branch: the branch being changed
1166
:ivar old_revno: revision number before the change
1167
:ivar new_revno: revision number after the change
1168
:ivar old_revid: revision id before the change
1169
:ivar new_revid: revision id after the change
1171
The revid fields are strings. The revno fields are integers.
1174
def __init__(self, branch, old_revno, new_revno, old_revid, new_revid):
1175
"""Create a group of ChangeBranchTip parameters.
1177
:param branch: The branch being changed.
1178
:param old_revno: Revision number before the change.
1179
:param new_revno: Revision number after the change.
1180
:param old_revid: Tip revision id before the change.
1181
:param new_revid: Tip revision id after the change.
1183
self.branch = branch
1184
self.old_revno = old_revno
1185
self.new_revno = new_revno
1186
self.old_revid = old_revid
1187
self.new_revid = new_revid
1189
def __eq__(self, other):
1190
return self.__dict__ == other.__dict__
1193
return "<%s of %s from (%s, %s) to (%s, %s)>" % (
1194
self.__class__.__name__, self.branch,
1195
self.old_revno, self.old_revid, self.new_revno, self.new_revid)
1198
567
class BzrBranchFormat4(BranchFormat):
1199
568
"""Bzr branch format 4.
1233
606
a_bzrdir=a_bzrdir,
1234
607
_repository=a_bzrdir.open_repository())
1237
return "Bazaar-NG branch format 4"
1240
class BranchFormatMetadir(BranchFormat):
1241
"""Common logic for meta-dir based branch formats."""
1243
def _branch_class(self):
1244
"""What class to instantiate on open calls."""
1245
raise NotImplementedError(self._branch_class)
1247
def open(self, a_bzrdir, _found=False):
1248
"""Return the branch object for a_bzrdir.
1250
_found is a private parameter, do not use it. It is used to indicate
1251
if format probing has already be done.
1254
format = BranchFormat.find_format(a_bzrdir)
1255
if format.__class__ != self.__class__:
1256
raise AssertionError("wrong format %r found for %r" %
1259
transport = a_bzrdir.get_branch_transport(None)
1260
control_files = lockable_files.LockableFiles(transport, 'lock',
1262
return self._branch_class()(_format=self,
1263
_control_files=control_files,
1265
_repository=a_bzrdir.find_repository())
1266
except errors.NoSuchFile:
1267
raise errors.NotBranchError(path=transport.base)
1270
super(BranchFormatMetadir, self).__init__()
1271
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
1273
def supports_tags(self):
1277
class BzrBranchFormat5(BranchFormatMetadir):
610
class BzrBranchFormat5(BranchFormat):
1278
611
"""Bzr branch format 5.
1280
613
This format has:
1281
614
- a revision-history file.
1282
615
- a format string
1283
- a lock dir guarding the branch itself
1284
- all of this stored in a branch/ subdirectory
1285
617
- works with shared repositories.
1287
This format is new in bzr 0.8.
1290
def _branch_class(self):
1293
620
def get_format_string(self):
1294
621
"""See BranchFormat.get_format_string()."""
1295
622
return "Bazaar-NG branch format 5\n"
1297
def get_format_description(self):
1298
"""See BranchFormat.get_format_description()."""
1299
return "Branch format 5"
1301
624
def initialize(self, a_bzrdir):
1302
625
"""Create a branch of this format in a_bzrdir."""
626
mutter('creating branch in %s', a_bzrdir.transport.base)
627
branch_transport = a_bzrdir.get_branch_transport(self)
1303
629
utf8_files = [('revision-history', ''),
1304
630
('branch-name', ''),
1306
return self._initialize_helper(a_bzrdir, utf8_files)
1308
def supports_tags(self):
1312
class BzrBranchFormat6(BranchFormatMetadir):
1313
"""Branch format with last-revision and tags.
1315
Unlike previous formats, this has no explicit revision history. Instead,
1316
this just stores the last-revision, and the left-hand history leading
1317
up to there is the history.
1319
This format was introduced in bzr 0.15
1320
and became the default in 0.91.
1323
def _branch_class(self):
1326
def get_format_string(self):
1327
"""See BranchFormat.get_format_string()."""
1328
return "Bazaar Branch Format 6 (bzr 0.15)\n"
1330
def get_format_description(self):
1331
"""See BranchFormat.get_format_description()."""
1332
return "Branch format 6"
1334
def initialize(self, a_bzrdir):
1335
"""Create a branch of this format in a_bzrdir."""
1336
utf8_files = [('last-revision', '0 null:\n'),
1337
('branch.conf', ''),
1340
return self._initialize_helper(a_bzrdir, utf8_files)
1343
class BzrBranchFormat7(BranchFormatMetadir):
1344
"""Branch format with last-revision, tags, and a stacked location pointer.
1346
The stacked location pointer is passed down to the repository and requires
1347
a repository format with supports_external_lookups = True.
1349
This format was introduced in bzr 1.6.
1352
def _branch_class(self):
1355
def get_format_string(self):
1356
"""See BranchFormat.get_format_string()."""
1357
return "Bazaar Branch Format 7 (needs bzr 1.6)\n"
1359
def get_format_description(self):
1360
"""See BranchFormat.get_format_description()."""
1361
return "Branch format 7"
1363
def initialize(self, a_bzrdir):
1364
"""Create a branch of this format in a_bzrdir."""
1365
utf8_files = [('last-revision', '0 null:\n'),
1366
('branch.conf', ''),
1369
return self._initialize_helper(a_bzrdir, utf8_files)
633
branch_transport.put(lock_file, StringIO()) # TODO get the file mode from the bzrdir lock files., mode=file_mode)
634
control_files = LockableFiles(branch_transport, 'lock')
635
control_files.lock_write()
636
control_files.put_utf8('format', self.get_format_string())
638
for file, content in utf8_files:
639
control_files.put_utf8(file, content)
641
control_files.unlock()
642
return self.open(a_bzrdir, _found=True, )
1371
644
def __init__(self):
1372
super(BzrBranchFormat7, self).__init__()
1373
self._matchingbzrdir.repository_format = \
1374
RepositoryFormatKnitPack5RichRoot()
1376
def supports_stacking(self):
645
super(BzrBranchFormat5, self).__init__()
646
self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
648
def open(self, a_bzrdir, _found=False):
649
"""Return the branch object for a_bzrdir
651
_found is a private parameter, do not use it. It is used to indicate
652
if format probing has already be done.
655
format = BranchFormat.find_format(a_bzrdir)
656
assert format.__class__ == self.__class__
657
transport = a_bzrdir.get_branch_transport(None)
658
control_files = LockableFiles(transport, 'lock')
659
return BzrBranch(_format=self,
660
_control_files=control_files,
662
_repository=a_bzrdir.find_repository())
1380
665
class BranchReferenceFormat(BranchFormat):
1483
743
Note that it's "local" in the context of the filesystem; it doesn't
1484
744
really matter if it's on an nfs/smb/afs/coda/... share, as long as
1485
745
it's writable, and can be accessed via the normal filesystem API.
1487
:ivar _transport: Transport for file operations on this branch's
1488
control files, typically pointing to the .bzr/branch directory.
1489
:ivar repository: Repository for this branch.
1490
:ivar base: The url of the base directory for this branch; the one
1491
containing the .bzr directory.
747
# We actually expect this class to be somewhat short-lived; part of its
748
# purpose is to try to isolate what bits of the branch logic are tied to
749
# filesystem access, so that in a later step, we can extricate them to
750
# a separarte ("storage") class.
751
_inventory_weave = None
1494
def __init__(self, _format=None,
753
# Map some sort of prefix into a namespace
754
# stuff like "revno:10", "revid:", etc.
755
# This should match a prefix with a function which accepts
756
REVISION_NAMESPACES = {}
758
def __init__(self, transport=DEPRECATED_PARAMETER, init=DEPRECATED_PARAMETER,
759
relax_version_check=DEPRECATED_PARAMETER, _format=None,
1495
760
_control_files=None, a_bzrdir=None, _repository=None):
1496
"""Create new branch object at a particular location."""
761
"""Create new branch object at a particular location.
763
transport -- A Transport object, defining how to access files.
765
init -- If True, create new control files in a previously
766
unversioned directory. If False, the branch must already
769
relax_version_check -- If true, the usual check for the branch
770
version is not applied. This is intended only for
771
upgrade/recovery type use; it's not guaranteed that
772
all operations will work on old format branches.
1497
774
if a_bzrdir is None:
1498
raise ValueError('a_bzrdir must be supplied')
775
self.bzrdir = bzrdir.BzrDir.open(transport.base)
1500
777
self.bzrdir = a_bzrdir
1501
self._base = self.bzrdir.transport.clone('..').base
1502
# XXX: We should be able to just do
1503
# self.base = self.bzrdir.root_transport.base
1504
# but this does not quite work yet -- mbp 20080522
778
self._transport = self.bzrdir.transport.clone('..')
779
self._base = self._transport.base
1505
780
self._format = _format
1506
781
if _control_files is None:
1507
raise ValueError('BzrBranch _control_files is None')
782
raise BzrBadParameterMissing('_control_files')
1508
783
self.control_files = _control_files
1509
self._transport = _control_files._transport
784
if deprecated_passed(init):
785
warn("BzrBranch.__init__(..., init=XXX): The init parameter is "
786
"deprecated as of bzr 0.8. Please use Branch.create().",
790
# this is slower than before deprecation, oh well never mind.
792
self._initialize(transport.base)
793
self._check_format(_format)
794
if deprecated_passed(relax_version_check):
795
warn("BzrBranch.__init__(..., relax_version_check=XXX_: The "
796
"relax_version_check parameter is deprecated as of bzr 0.8. "
797
"Please use BzrDir.open_downlevel, or a BzrBranchFormat's "
801
if (not relax_version_check
802
and not self._format.is_supported()):
803
raise errors.UnsupportedFormatError(
804
'sorry, branch format %r not supported' % fmt,
805
['use a different bzr version',
806
'or remove the .bzr directory'
807
' and "bzr init" again'])
808
if deprecated_passed(transport):
809
warn("BzrBranch.__init__(transport=XXX...): The transport "
810
"parameter is deprecated as of bzr 0.8. "
811
"Please use Branch.open, or bzrdir.open_branch().",
1510
814
self.repository = _repository
1511
Branch.__init__(self)
1513
816
def __str__(self):
1514
817
return '%s(%r)' % (self.__class__.__name__, self.base)
1516
819
__repr__ = __str__
822
# TODO: It might be best to do this somewhere else,
823
# but it is nice for a Branch object to automatically
824
# cache it's information.
825
# Alternatively, we could have the Transport objects cache requests
826
# See the earlier discussion about how major objects (like Branch)
827
# should never expect their __del__ function to run.
828
# XXX: cache_root seems to be unused, 2006-01-13 mbp
829
if hasattr(self, 'cache_root') and self.cache_root is not None:
831
shutil.rmtree(self.cache_root)
834
self.cache_root = None
1518
836
def _get_base(self):
1519
"""Returns the directory containing the control directory."""
1520
837
return self._base
1522
839
base = property(_get_base, doc="The URL for the root of this branch.")
1524
def is_locked(self):
1525
return self.control_files.is_locked()
1527
def lock_write(self, token=None):
1528
repo_token = self.repository.lock_write()
1530
token = self.control_files.lock_write(token=token)
1532
self.repository.unlock()
841
def _finish_transaction(self):
842
"""Exit the current transaction."""
843
return self.control_files._finish_transaction()
845
def get_transaction(self):
846
"""Return the current active transaction.
848
If no transaction is active, this returns a passthrough object
849
for which all data is immediately flushed and no caching happens.
851
# this is an explicit function so that we can do tricky stuff
852
# when the storage in rev_storage is elsewhere.
853
# we probably need to hook the two 'lock a location' and
854
# 'have a transaction' together more delicately, so that
855
# we can have two locks (branch and storage) and one transaction
856
# ... and finishing the transaction unlocks both, but unlocking
857
# does not. - RBC 20051121
858
return self.control_files.get_transaction()
860
def _set_transaction(self, transaction):
861
"""Set a new active transaction."""
862
return self.control_files._set_transaction(transaction)
864
def abspath(self, name):
865
"""See Branch.abspath."""
866
return self.control_files._transport.abspath(name)
868
def _check_format(self, format):
869
"""Identify the branch format if needed.
871
The format is stored as a reference to the format object in
872
self._format for code that needs to check it later.
874
The format parameter is either None or the branch format class
875
used to open this branch.
877
FIXME: DELETE THIS METHOD when pre 0.8 support is removed.
880
format = BzrBranchFormat.find_format(self.bzrdir)
881
self._format = format
882
mutter("got branch format %s", self._format)
885
def get_root_id(self):
886
"""See Branch.get_root_id."""
887
tree = self.repository.revision_tree(self.last_revision())
888
return tree.inventory.root.file_id
890
def lock_write(self):
891
# TODO: test for failed two phase locks. This is known broken.
892
self.control_files.lock_write()
893
self.repository.lock_write()
1536
895
def lock_read(self):
896
# TODO: test for failed two phase locks. This is known broken.
897
self.control_files.lock_read()
1537
898
self.repository.lock_read()
1539
self.control_files.lock_read()
1541
self.repository.unlock()
1544
900
def unlock(self):
1545
901
# TODO: test for failed two phase locks. This is known broken.
1547
self.control_files.unlock()
1549
self.repository.unlock()
1550
if not self.control_files.is_locked():
1551
# we just released the lock
1552
self._clear_cached_state()
902
self.repository.unlock()
903
self.control_files.unlock()
1554
905
def peek_lock_mode(self):
1555
906
if self.control_files._lock_count == 0:
1558
909
return self.control_files._lock_mode
1560
def get_physical_lock_status(self):
1561
return self.control_files.get_physical_lock_status()
1563
911
@needs_read_lock
1564
912
def print_file(self, file, revision_id):
1565
913
"""See Branch.print_file."""
1566
914
return self.repository.print_file(file, revision_id)
1568
def _write_revision_history(self, history):
1569
"""Factored out of set_revision_history.
1571
This performs the actual writing to disk.
1572
It is intended to be called by BzrBranch5.set_revision_history."""
1573
self._transport.put_bytes(
1574
'revision-history', '\n'.join(history),
1575
mode=self.bzrdir._get_file_mode())
917
def append_revision(self, *revision_ids):
918
"""See Branch.append_revision."""
919
for revision_id in revision_ids:
920
mutter("add {%s} to revision-history" % revision_id)
921
rev_history = self.revision_history()
922
rev_history.extend(revision_ids)
923
self.set_revision_history(rev_history)
1577
925
@needs_write_lock
1578
926
def set_revision_history(self, rev_history):
1579
927
"""See Branch.set_revision_history."""
1580
if 'evil' in debug.debug_flags:
1581
mutter_callsite(3, "set_revision_history scales with history.")
1582
check_not_reserved_id = _mod_revision.check_not_reserved_id
1583
for rev_id in rev_history:
1584
check_not_reserved_id(rev_id)
1585
if Branch.hooks['post_change_branch_tip']:
1586
# Don't calculate the last_revision_info() if there are no hooks
1588
old_revno, old_revid = self.last_revision_info()
1589
if len(rev_history) == 0:
1590
revid = _mod_revision.NULL_REVISION
1592
revid = rev_history[-1]
1593
self._run_pre_change_branch_tip_hooks(len(rev_history), revid)
1594
self._write_revision_history(rev_history)
1595
self._clear_cached_state()
1596
self._cache_revision_history(rev_history)
1597
for hook in Branch.hooks['set_rh']:
1598
hook(self, rev_history)
1599
if Branch.hooks['post_change_branch_tip']:
1600
self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1602
def _synchronize_history(self, destination, revision_id):
1603
"""Synchronize last revision and revision history between branches.
1605
This version is most efficient when the destination is also a
1606
BzrBranch5, but works for BzrBranch6 as long as the revision
1607
history is the true lefthand parent history, and all of the revisions
1608
are in the destination's repository. If not, set_revision_history
1611
:param destination: The branch to copy the history into
1612
:param revision_id: The revision-id to truncate history at. May
1613
be None to copy complete history.
1615
if revision_id == _mod_revision.NULL_REVISION:
1618
new_history = self.revision_history()
1619
if revision_id is not None and new_history != []:
1621
new_history = new_history[:new_history.index(revision_id) + 1]
1623
rev = self.repository.get_revision(revision_id)
1624
new_history = rev.get_history(self.repository)[1:]
1625
destination.set_revision_history(new_history)
1627
def _run_pre_change_branch_tip_hooks(self, new_revno, new_revid):
1628
"""Run the pre_change_branch_tip hooks."""
1629
hooks = Branch.hooks['pre_change_branch_tip']
1632
old_revno, old_revid = self.last_revision_info()
1633
params = ChangeBranchTipParams(
1634
self, old_revno, new_revno, old_revid, new_revid)
1638
except errors.TipChangeRejected:
1641
exc_info = sys.exc_info()
1642
hook_name = Branch.hooks.get_hook_name(hook)
1643
raise errors.HookFailed(
1644
'pre_change_branch_tip', hook_name, exc_info)
1646
def _run_post_change_branch_tip_hooks(self, old_revno, old_revid):
1647
"""Run the post_change_branch_tip hooks."""
1648
hooks = Branch.hooks['post_change_branch_tip']
1651
new_revno, new_revid = self.last_revision_info()
1652
params = ChangeBranchTipParams(
1653
self, old_revno, new_revno, old_revid, new_revid)
1658
def set_last_revision_info(self, revno, revision_id):
1659
"""Set the last revision of this branch.
1661
The caller is responsible for checking that the revno is correct
1662
for this revision id.
1664
It may be possible to set the branch last revision to an id not
1665
present in the repository. However, branches can also be
1666
configured to check constraints on history, in which case this may not
1669
revision_id = _mod_revision.ensure_null(revision_id)
1670
# this old format stores the full history, but this api doesn't
1671
# provide it, so we must generate, and might as well check it's
1673
history = self._lefthand_history(revision_id)
1674
if len(history) != revno:
1675
raise AssertionError('%d != %d' % (len(history), revno))
1676
self.set_revision_history(history)
1678
def _gen_revision_history(self):
1679
history = self._transport.get_bytes('revision-history').split('\n')
1680
if history[-1:] == ['']:
1681
# There shouldn't be a trailing newline, but just in case.
1685
def _lefthand_history(self, revision_id, last_rev=None,
1687
if 'evil' in debug.debug_flags:
1688
mutter_callsite(4, "_lefthand_history scales with history.")
1689
# stop_revision must be a descendant of last_revision
1690
graph = self.repository.get_graph()
1691
if last_rev is not None:
1692
if not graph.is_ancestor(last_rev, revision_id):
1693
# our previous tip is not merged into stop_revision
1694
raise errors.DivergedBranches(self, other_branch)
1695
# make a new revision history from the graph
1696
parents_map = graph.get_parent_map([revision_id])
1697
if revision_id not in parents_map:
1698
raise errors.NoSuchRevision(self, revision_id)
1699
current_rev_id = revision_id
1701
check_not_reserved_id = _mod_revision.check_not_reserved_id
1702
# Do not include ghosts or graph origin in revision_history
1703
while (current_rev_id in parents_map and
1704
len(parents_map[current_rev_id]) > 0):
1705
check_not_reserved_id(current_rev_id)
1706
new_history.append(current_rev_id)
1707
current_rev_id = parents_map[current_rev_id][0]
1708
parents_map = graph.get_parent_map([current_rev_id])
1709
new_history.reverse()
1713
def generate_revision_history(self, revision_id, last_rev=None,
1715
"""Create a new revision history that will finish with revision_id.
1717
:param revision_id: the new tip to use.
1718
:param last_rev: The previous last_revision. If not None, then this
1719
must be a ancestory of revision_id, or DivergedBranches is raised.
1720
:param other_branch: The other branch that DivergedBranches should
1721
raise with respect to.
1723
self.set_revision_history(self._lefthand_history(revision_id,
1724
last_rev, other_branch))
928
self.control_files.put_utf8(
929
'revision-history', '\n'.join(rev_history))
931
def get_revision_delta(self, revno):
932
"""Return the delta for one revision.
934
The delta is relative to its mainline predecessor, or the
935
empty tree for revision 1.
937
assert isinstance(revno, int)
938
rh = self.revision_history()
939
if not (1 <= revno <= len(rh)):
940
raise InvalidRevisionNumber(revno)
942
# revno is 1-based; list is 0-based
944
new_tree = self.repository.revision_tree(rh[revno-1])
946
old_tree = EmptyTree()
948
old_tree = self.repository.revision_tree(rh[revno-2])
949
return compare_trees(old_tree, new_tree)
952
def revision_history(self):
953
"""See Branch.revision_history."""
954
# FIXME are transactions bound to control files ? RBC 20051121
955
transaction = self.get_transaction()
956
history = transaction.map.find_revision_history()
957
if history is not None:
958
mutter("cache hit for revision-history in %s", self)
960
history = [l.rstrip('\r\n') for l in
961
self.control_files.get_utf8('revision-history').readlines()]
962
transaction.map.add_revision_history(history)
963
# this call is disabled because revision_history is
964
# not really an object yet, and the transaction is for objects.
965
# transaction.register_clean(history, precious=True)
968
def update_revisions(self, other, stop_revision=None):
969
"""See Branch.update_revisions."""
970
if stop_revision is None:
971
stop_revision = other.last_revision()
972
### Should this be checking is_ancestor instead of revision_history?
973
if (stop_revision is not None and
974
stop_revision in self.revision_history()):
976
self.fetch(other, stop_revision)
977
pullable_revs = self.pullable_revisions(other, stop_revision)
978
if len(pullable_revs) > 0:
979
self.append_revision(*pullable_revs)
981
def pullable_revisions(self, other, stop_revision):
982
"""See Branch.pullable_revisions."""
983
other_revno = other.revision_id_to_revno(stop_revision)
985
return self.missing_revisions(other, other_revno)
986
except DivergedBranches, e:
988
pullable_revs = get_intervening_revisions(self.last_revision(),
991
assert self.last_revision() not in pullable_revs
993
except bzrlib.errors.NotAncestor:
994
if is_ancestor(self.last_revision(), stop_revision, self):
1726
999
def basis_tree(self):
1727
1000
"""See Branch.basis_tree."""
1728
1001
return self.repository.revision_tree(self.last_revision())
1003
@deprecated_method(zero_eight)
1004
def working_tree(self):
1005
"""Create a Working tree object for this branch."""
1006
from bzrlib.workingtree import WorkingTree
1007
from bzrlib.transport.local import LocalTransport
1008
if (self.base.find('://') != -1 or
1009
not isinstance(self._transport, LocalTransport)):
1010
raise NoWorkingTree(self.base)
1011
return self.bzrdir.open_workingtree()
1730
1013
@needs_write_lock
1731
def pull(self, source, overwrite=False, stop_revision=None,
1732
_hook_master=None, run_hooks=True, possible_transports=None,
1733
_override_hook_target=None):
1736
:param _hook_master: Private parameter - set the branch to
1737
be supplied as the master to pull hooks.
1738
:param run_hooks: Private parameter - if false, this branch
1739
is being called because it's the master of the primary branch,
1740
so it should not run its hooks.
1741
:param _override_hook_target: Private parameter - set the branch to be
1742
supplied as the target_branch to pull hooks.
1744
result = PullResult()
1745
result.source_branch = source
1746
if _override_hook_target is None:
1747
result.target_branch = self
1749
result.target_branch = _override_hook_target
1014
def pull(self, source, overwrite=False, stop_revision=None):
1015
"""See Branch.pull."""
1750
1016
source.lock_read()
1752
# We assume that during 'pull' the local repository is closer than
1754
graph = self.repository.get_graph(source.repository)
1755
result.old_revno, result.old_revid = self.last_revision_info()
1756
self.update_revisions(source, stop_revision, overwrite=overwrite,
1758
result.tag_conflicts = source.tags.merge_to(self.tags, overwrite)
1759
result.new_revno, result.new_revid = self.last_revision_info()
1761
result.master_branch = _hook_master
1762
result.local_branch = result.target_branch
1764
result.master_branch = result.target_branch
1765
result.local_branch = None
1767
for hook in Branch.hooks['post_pull']:
1018
old_count = len(self.revision_history())
1020
self.update_revisions(source,stop_revision)
1021
except DivergedBranches:
1025
self.set_revision_history(source.revision_history())
1026
new_count = len(self.revision_history())
1027
return new_count - old_count
1770
1029
source.unlock()
1773
def _get_parent_location(self):
1031
def get_parent(self):
1032
"""See Branch.get_parent."""
1774
1034
_locs = ['parent', 'pull', 'x-pull']
1775
1035
for l in _locs:
1777
return self._transport.get_bytes(l).strip('\n')
1778
except errors.NoSuchFile:
1037
return self.control_files.get_utf8(l).read().strip('\n')
1783
def push(self, target, overwrite=False, stop_revision=None,
1784
_override_hook_source_branch=None):
1787
This is the basic concrete implementation of push()
1789
:param _override_hook_source_branch: If specified, run
1790
the hooks passing this Branch as the source, rather than self.
1791
This is for use of RemoteBranch, where push is delegated to the
1792
underlying vfs-based Branch.
1794
# TODO: Public option to disable running hooks - should be trivial but
1796
return _run_with_write_locked_target(
1797
target, self._push_with_bound_branches, target, overwrite,
1799
_override_hook_source_branch=_override_hook_source_branch)
1801
def _push_with_bound_branches(self, target, overwrite,
1803
_override_hook_source_branch=None):
1804
"""Push from self into target, and into target's master if any.
1806
This is on the base BzrBranch class even though it doesn't support
1807
bound branches because the *target* might be bound.
1810
if _override_hook_source_branch:
1811
result.source_branch = _override_hook_source_branch
1812
for hook in Branch.hooks['post_push']:
1815
bound_location = target.get_bound_location()
1816
if bound_location and target.base != bound_location:
1817
# there is a master branch.
1819
# XXX: Why the second check? Is it even supported for a branch to
1820
# be bound to itself? -- mbp 20070507
1821
master_branch = target.get_master_branch()
1822
master_branch.lock_write()
1824
# push into the master from this branch.
1825
self._basic_push(master_branch, overwrite, stop_revision)
1826
# and push into the target branch from this. Note that we push from
1827
# this branch again, because its considered the highest bandwidth
1829
result = self._basic_push(target, overwrite, stop_revision)
1830
result.master_branch = master_branch
1831
result.local_branch = target
1835
master_branch.unlock()
1838
result = self._basic_push(target, overwrite, stop_revision)
1839
# TODO: Why set master_branch and local_branch if there's no
1840
# binding? Maybe cleaner to just leave them unset? -- mbp
1842
result.master_branch = target
1843
result.local_branch = None
1847
def _basic_push(self, target, overwrite, stop_revision):
1848
"""Basic implementation of push without bound branches or hooks.
1850
Must be called with self read locked and target write locked.
1852
result = PushResult()
1853
result.source_branch = self
1854
result.target_branch = target
1855
result.old_revno, result.old_revid = target.last_revision_info()
1856
if result.old_revid != self.last_revision():
1857
# We assume that during 'push' this repository is closer than
1859
graph = self.repository.get_graph(target.repository)
1860
target.update_revisions(self, stop_revision, overwrite=overwrite,
1862
if self._push_should_merge_tags():
1863
result.tag_conflicts = self.tags.merge_to(target.tags, overwrite)
1864
result.new_revno, result.new_revid = target.last_revision_info()
1867
def _push_should_merge_tags(self):
1868
"""Should _basic_push merge this branch's tags into the target?
1870
The default implementation returns False if this branch has no tags,
1871
and True the rest of the time. Subclasses may override this.
1873
return self.tags.supports_tags() and self.tags.get_tag_dict()
1875
def get_parent(self):
1876
"""See Branch.get_parent."""
1877
parent = self._get_parent_location()
1880
# This is an old-format absolute path to a local branch
1881
# turn it into a url
1882
if parent.startswith('/'):
1883
parent = urlutils.local_path_to_url(parent.decode('utf8'))
1885
return urlutils.join(self.base[:-1], parent)
1886
except errors.InvalidURLJoin, e:
1887
raise errors.InaccessibleParent(parent, self.base)
1889
def get_stacked_on_url(self):
1890
raise errors.UnstackableBranchFormat(self._format, self.base)
1042
def get_push_location(self):
1043
"""See Branch.get_push_location."""
1044
config = bzrlib.config.BranchConfig(self)
1045
push_loc = config.get_user_option('push_location')
1892
1048
def set_push_location(self, location):
1893
1049
"""See Branch.set_push_location."""
1894
self.get_config().set_user_option(
1895
'push_location', location,
1896
store=_mod_config.STORE_LOCATION_NORECURSE)
1050
config = bzrlib.config.LocationConfig(self.base)
1051
config.set_user_option('push_location', location)
1898
1053
@needs_write_lock
1899
1054
def set_parent(self, url):
1901
1056
# TODO: Maybe delete old location files?
1902
1057
# URLs should never be unicode, even on the local fs,
1903
1058
# FIXUP this and get_parent in a future branch format bump:
1904
# read and rewrite the file. RBC 20060125
1906
if isinstance(url, unicode):
1908
url = url.encode('ascii')
1909
except UnicodeEncodeError:
1910
raise errors.InvalidURL(url,
1911
"Urls must be 7-bit ascii, "
1912
"use bzrlib.urlutils.escape")
1913
url = urlutils.relative_url(self.base, url)
1914
self._set_parent_location(url)
1916
def _set_parent_location(self, url):
1918
self._transport.delete('parent')
1920
self._transport.put_bytes('parent', url + '\n',
1921
mode=self.bzrdir._get_file_mode())
1923
def set_stacked_on_url(self, url):
1924
raise errors.UnstackableBranchFormat(self._format, self.base)
1927
class BzrBranch5(BzrBranch):
1928
"""A format 5 branch. This supports new features over plain branches.
1930
It has support for a master_branch which is the data for bound branches.
1934
def pull(self, source, overwrite=False, stop_revision=None,
1935
run_hooks=True, possible_transports=None,
1936
_override_hook_target=None):
1937
"""Pull from source into self, updating my master if any.
1939
:param run_hooks: Private parameter - if false, this branch
1940
is being called because it's the master of the primary branch,
1941
so it should not run its hooks.
1943
bound_location = self.get_bound_location()
1944
master_branch = None
1945
if bound_location and source.base != bound_location:
1946
# not pulling from master, so we need to update master.
1947
master_branch = self.get_master_branch(possible_transports)
1948
master_branch.lock_write()
1951
# pull from source into master.
1952
master_branch.pull(source, overwrite, stop_revision,
1954
return super(BzrBranch5, self).pull(source, overwrite,
1955
stop_revision, _hook_master=master_branch,
1956
run_hooks=run_hooks,
1957
_override_hook_target=_override_hook_target)
1960
master_branch.unlock()
1962
def get_bound_location(self):
1964
return self._transport.get_bytes('bound')[:-1]
1965
except errors.NoSuchFile:
1969
def get_master_branch(self, possible_transports=None):
1970
"""Return the branch we are bound to.
1972
:return: Either a Branch, or None
1974
This could memoise the branch, but if thats done
1975
it must be revalidated on each new lock.
1976
So for now we just don't memoise it.
1977
# RBC 20060304 review this decision.
1979
bound_loc = self.get_bound_location()
1983
return Branch.open(bound_loc,
1984
possible_transports=possible_transports)
1985
except (errors.NotBranchError, errors.ConnectionError), e:
1986
raise errors.BoundBranchConnectionFailure(
1990
def set_bound_location(self, location):
1991
"""Set the target where this branch is bound to.
1993
:param location: URL to the target branch
1996
self._transport.put_bytes('bound', location+'\n',
1997
mode=self.bzrdir._get_file_mode())
2000
self._transport.delete('bound')
2001
except errors.NoSuchFile:
2006
def bind(self, other):
2007
"""Bind this branch to the branch other.
2009
This does not push or pull data between the branches, though it does
2010
check for divergence to raise an error when the branches are not
2011
either the same, or one a prefix of the other. That behaviour may not
2012
be useful, so that check may be removed in future.
2014
:param other: The branch to bind to
2017
# TODO: jam 20051230 Consider checking if the target is bound
2018
# It is debatable whether you should be able to bind to
2019
# a branch which is itself bound.
2020
# Committing is obviously forbidden,
2021
# but binding itself may not be.
2022
# Since we *have* to check at commit time, we don't
2023
# *need* to check here
2025
# we want to raise diverged if:
2026
# last_rev is not in the other_last_rev history, AND
2027
# other_last_rev is not in our history, and do it without pulling
2029
self.set_bound_location(other.base)
2033
"""If bound, unbind"""
2034
return self.set_bound_location(None)
2037
def update(self, possible_transports=None):
2038
"""Synchronise this branch with the master branch if any.
2040
:return: None or the last_revision that was pivoted out during the
2043
master = self.get_master_branch(possible_transports)
2044
if master is not None:
2045
old_tip = _mod_revision.ensure_null(self.last_revision())
2046
self.pull(master, overwrite=True)
2047
if self.repository.get_graph().is_ancestor(old_tip,
2048
_mod_revision.ensure_null(self.last_revision())):
2054
class BzrBranch7(BzrBranch5):
2055
"""A branch with support for a fallback repository."""
2057
def _get_fallback_repository(self, url):
2058
"""Get the repository we fallback to at url."""
2059
url = urlutils.join(self.base, url)
2060
return bzrdir.BzrDir.open(url).open_branch().repository
2062
def _activate_fallback_location(self, url):
2063
"""Activate the branch/repository from url as a fallback repository."""
2064
self.repository.add_fallback_repository(
2065
self._get_fallback_repository(url))
2067
def _open_hook(self):
2069
url = self.get_stacked_on_url()
2070
except (errors.UnstackableRepositoryFormat, errors.NotStacked,
2071
errors.UnstackableBranchFormat):
2074
for hook in Branch.hooks['transform_fallback_location']:
2075
url = hook(self, url)
2077
hook_name = Branch.hooks.get_hook_name(hook)
2078
raise AssertionError(
2079
"'transform_fallback_location' hook %s returned "
2080
"None, not a URL." % hook_name)
2081
self._activate_fallback_location(url)
2083
def _check_stackable_repo(self):
2084
if not self.repository._format.supports_external_lookups:
2085
raise errors.UnstackableRepositoryFormat(self.repository._format,
2086
self.repository.base)
2088
def __init__(self, *args, **kwargs):
2089
super(BzrBranch7, self).__init__(*args, **kwargs)
2090
self._last_revision_info_cache = None
2091
self._partial_revision_history_cache = []
2093
def _clear_cached_state(self):
2094
super(BzrBranch7, self)._clear_cached_state()
2095
self._last_revision_info_cache = None
2096
self._partial_revision_history_cache = []
2098
def _last_revision_info(self):
2099
revision_string = self._transport.get_bytes('last-revision')
2100
revno, revision_id = revision_string.rstrip('\n').split(' ', 1)
2101
revision_id = cache_utf8.get_cached_utf8(revision_id)
2103
return revno, revision_id
2105
def _write_last_revision_info(self, revno, revision_id):
2106
"""Simply write out the revision id, with no checks.
2108
Use set_last_revision_info to perform this safely.
2110
Does not update the revision_history cache.
2111
Intended to be called by set_last_revision_info and
2112
_write_revision_history.
2114
revision_id = _mod_revision.ensure_null(revision_id)
2115
out_string = '%d %s\n' % (revno, revision_id)
2116
self._transport.put_bytes('last-revision', out_string,
2117
mode=self.bzrdir._get_file_mode())
2120
def set_last_revision_info(self, revno, revision_id):
2121
revision_id = _mod_revision.ensure_null(revision_id)
2122
old_revno, old_revid = self.last_revision_info()
2123
if self._get_append_revisions_only():
2124
self._check_history_violation(revision_id)
2125
self._run_pre_change_branch_tip_hooks(revno, revision_id)
2126
self._write_last_revision_info(revno, revision_id)
2127
self._clear_cached_state()
2128
self._last_revision_info_cache = revno, revision_id
2129
self._run_post_change_branch_tip_hooks(old_revno, old_revid)
2131
def _synchronize_history(self, destination, revision_id):
2132
"""Synchronize last revision and revision history between branches.
2134
:see: Branch._synchronize_history
2136
# XXX: The base Branch has a fast implementation of this method based
2137
# on set_last_revision_info, but BzrBranch/BzrBranch5 have a slower one
2138
# that uses set_revision_history. This class inherits from BzrBranch5,
2139
# but wants the fast implementation, so it calls
2140
# Branch._synchronize_history directly.
2141
Branch._synchronize_history(self, destination, revision_id)
2143
def _check_history_violation(self, revision_id):
2144
last_revision = _mod_revision.ensure_null(self.last_revision())
2145
if _mod_revision.is_null(last_revision):
2147
if last_revision not in self._lefthand_history(revision_id):
2148
raise errors.AppendRevisionsOnlyViolation(self.base)
2150
def _gen_revision_history(self):
2151
"""Generate the revision history from last revision
2153
last_revno, last_revision = self.last_revision_info()
2154
self._extend_partial_history(stop_index=last_revno-1)
2155
return list(reversed(self._partial_revision_history_cache))
2157
def _extend_partial_history(self, stop_index=None, stop_revision=None):
2158
"""Extend the partial history to include a given index
2160
If a stop_index is supplied, stop when that index has been reached.
2161
If a stop_revision is supplied, stop when that revision is
2162
encountered. Otherwise, stop when the beginning of history is
2165
:param stop_index: The index which should be present. When it is
2166
present, history extension will stop.
2167
:param revision_id: The revision id which should be present. When
2168
it is encountered, history extension will stop.
2170
repo = self.repository
2171
if len(self._partial_revision_history_cache) == 0:
2172
iterator = repo.iter_reverse_revision_history(self.last_revision())
2174
start_revision = self._partial_revision_history_cache[-1]
2175
iterator = repo.iter_reverse_revision_history(start_revision)
2176
#skip the last revision in the list
2177
next_revision = iterator.next()
2178
for revision_id in iterator:
2179
self._partial_revision_history_cache.append(revision_id)
2180
if (stop_index is not None and
2181
len(self._partial_revision_history_cache) > stop_index):
2183
if revision_id == stop_revision:
2186
def _write_revision_history(self, history):
2187
"""Factored out of set_revision_history.
2189
This performs the actual writing to disk, with format-specific checks.
2190
It is intended to be called by BzrBranch5.set_revision_history.
2192
if len(history) == 0:
2193
last_revision = 'null:'
2195
if history != self._lefthand_history(history[-1]):
2196
raise errors.NotLefthandHistory(history)
2197
last_revision = history[-1]
2198
if self._get_append_revisions_only():
2199
self._check_history_violation(last_revision)
2200
self._write_last_revision_info(len(history), last_revision)
2203
def _set_parent_location(self, url):
2204
"""Set the parent branch"""
2205
self._set_config_location('parent_location', url, make_relative=True)
2208
def _get_parent_location(self):
2209
"""Set the parent branch"""
2210
return self._get_config_location('parent_location')
2212
def set_push_location(self, location):
2213
"""See Branch.set_push_location."""
2214
self._set_config_location('push_location', location)
2216
def set_bound_location(self, location):
2217
"""See Branch.set_push_location."""
2219
config = self.get_config()
2220
if location is None:
2221
if config.get_user_option('bound') != 'True':
2224
config.set_user_option('bound', 'False', warn_masked=True)
2227
self._set_config_location('bound_location', location,
2229
config.set_user_option('bound', 'True', warn_masked=True)
2232
def _get_bound_location(self, bound):
2233
"""Return the bound location in the config file.
2235
Return None if the bound parameter does not match"""
2236
config = self.get_config()
2237
config_bound = (config.get_user_option('bound') == 'True')
2238
if config_bound != bound:
2240
return self._get_config_location('bound_location', config=config)
2242
def get_bound_location(self):
2243
"""See Branch.set_push_location."""
2244
return self._get_bound_location(True)
2246
def get_old_bound_location(self):
2247
"""See Branch.get_old_bound_location"""
2248
return self._get_bound_location(False)
2250
def get_stacked_on_url(self):
2251
# you can always ask for the URL; but you might not be able to use it
2252
# if the repo can't support stacking.
2253
## self._check_stackable_repo()
2254
stacked_url = self._get_config_location('stacked_on_location')
2255
if stacked_url is None:
2256
raise errors.NotStacked(self)
2259
def set_append_revisions_only(self, enabled):
2264
self.get_config().set_user_option('append_revisions_only', value,
2267
def set_stacked_on_url(self, url):
2268
self._check_stackable_repo()
2271
old_url = self.get_stacked_on_url()
2272
except (errors.NotStacked, errors.UnstackableBranchFormat,
2273
errors.UnstackableRepositoryFormat):
2276
# repositories don't offer an interface to remove fallback
2277
# repositories today; take the conceptually simpler option and just
2279
self.repository = self.bzrdir.find_repository()
2280
# for every revision reference the branch has, ensure it is pulled
2282
source_repository = self._get_fallback_repository(old_url)
2283
for revision_id in chain([self.last_revision()],
2284
self.tags.get_reverse_tag_dict()):
2285
self.repository.fetch(source_repository, revision_id,
2288
self._activate_fallback_location(url)
2289
# write this out after the repository is stacked to avoid setting a
2290
# stacked config that doesn't work.
2291
self._set_config_location('stacked_on_location', url)
2293
def _get_append_revisions_only(self):
2294
value = self.get_config().get_user_option('append_revisions_only')
2295
return value == 'True'
2297
def _make_tags(self):
2298
return BasicTags(self)
2301
def generate_revision_history(self, revision_id, last_rev=None,
2303
"""See BzrBranch5.generate_revision_history"""
2304
history = self._lefthand_history(revision_id, last_rev, other_branch)
2305
revno = len(history)
2306
self.set_last_revision_info(revno, revision_id)
2309
def get_rev_id(self, revno, history=None):
2310
"""Find the revision id of the specified revno."""
2312
return _mod_revision.NULL_REVISION
2314
last_revno, last_revision_id = self.last_revision_info()
2315
if revno <= 0 or revno > last_revno:
2316
raise errors.NoSuchRevision(self, revno)
2318
if history is not None:
2319
return history[revno - 1]
2321
index = last_revno - revno
2322
if len(self._partial_revision_history_cache) <= index:
2323
self._extend_partial_history(stop_index=index)
2324
if len(self._partial_revision_history_cache) > index:
2325
return self._partial_revision_history_cache[index]
2327
raise errors.NoSuchRevision(self, revno)
2330
def revision_id_to_revno(self, revision_id):
2331
"""Given a revision id, return its revno"""
2332
if _mod_revision.is_null(revision_id):
2335
index = self._partial_revision_history_cache.index(revision_id)
1059
# read and rewrite the file, and have the new format code read
1060
# using .get not .get_utf8. RBC 20060125
1061
self.control_files.put_utf8('parent', url + '\n')
1063
def tree_config(self):
1064
return TreeConfig(self)
1066
def _get_truncated_history(self, revision_id):
1067
history = self.revision_history()
1068
if revision_id is None:
1071
idx = history.index(revision_id)
2336
1072
except ValueError:
2337
self._extend_partial_history(stop_revision=revision_id)
2338
index = len(self._partial_revision_history_cache) - 1
2339
if self._partial_revision_history_cache[index] != revision_id:
2340
raise errors.NoSuchRevision(self, revision_id)
2341
return self.revno() - index
2344
class BzrBranch6(BzrBranch7):
2345
"""See BzrBranchFormat6 for the capabilities of this branch.
2347
This subclass of BzrBranch7 disables the new features BzrBranch7 added,
2351
def get_stacked_on_url(self):
2352
raise errors.UnstackableBranchFormat(self._format, self.base)
2354
def set_stacked_on_url(self, url):
2355
raise errors.UnstackableBranchFormat(self._format, self.base)
2358
######################################################################
2359
# results of operations
2362
class _Result(object):
2364
def _show_tag_conficts(self, to_file):
2365
if not getattr(self, 'tag_conflicts', None):
2367
to_file.write('Conflicting tags:\n')
2368
for name, value1, value2 in self.tag_conflicts:
2369
to_file.write(' %s\n' % (name, ))
2372
class PullResult(_Result):
2373
"""Result of a Branch.pull operation.
2375
:ivar old_revno: Revision number before pull.
2376
:ivar new_revno: Revision number after pull.
2377
:ivar old_revid: Tip revision id before pull.
2378
:ivar new_revid: Tip revision id after pull.
2379
:ivar source_branch: Source (local) branch object.
2380
:ivar master_branch: Master branch of the target, or the target if no
2382
:ivar local_branch: target branch if there is a Master, else None
2383
:ivar target_branch: Target/destination branch object.
2384
:ivar tag_conflicts: A list of tag conflicts, see BasicTags.merge_to
2388
# DEPRECATED: pull used to return the change in revno
2389
return self.new_revno - self.old_revno
2391
def report(self, to_file):
2393
if self.old_revid == self.new_revid:
2394
to_file.write('No revisions to pull.\n')
2396
to_file.write('Now on revision %d.\n' % self.new_revno)
2397
self._show_tag_conficts(to_file)
2400
class PushResult(_Result):
2401
"""Result of a Branch.push operation.
2403
:ivar old_revno: Revision number before push.
2404
:ivar new_revno: Revision number after push.
2405
:ivar old_revid: Tip revision id before push.
2406
:ivar new_revid: Tip revision id after push.
2407
:ivar source_branch: Source branch object.
2408
:ivar master_branch: Master branch of the target, or None.
2409
:ivar target_branch: Target/destination branch object.
2413
# DEPRECATED: push used to return the change in revno
2414
return self.new_revno - self.old_revno
2416
def report(self, to_file):
2417
"""Write a human-readable description of the result."""
2418
if self.old_revid == self.new_revid:
2419
to_file.write('No new revisions to push.\n')
2421
to_file.write('Pushed up to revision %d.\n' % self.new_revno)
2422
self._show_tag_conficts(to_file)
2425
class BranchCheckResult(object):
2426
"""Results of checking branch consistency.
2431
def __init__(self, branch):
2432
self.branch = branch
2434
def report_results(self, verbose):
2435
"""Report the check results via trace.note.
2437
:param verbose: Requests more detailed display of what was checked,
2440
note('checked branch %s format %s',
2442
self.branch._format)
2445
class Converter5to6(object):
2446
"""Perform an in-place upgrade of format 5 to format 6"""
2448
def convert(self, branch):
2449
# Data for 5 and 6 can peacefully coexist.
2450
format = BzrBranchFormat6()
2451
new_branch = format.open(branch.bzrdir, _found=True)
2453
# Copy source data into target
2454
new_branch._write_last_revision_info(*branch.last_revision_info())
2455
new_branch.set_parent(branch.get_parent())
2456
new_branch.set_bound_location(branch.get_bound_location())
2457
new_branch.set_push_location(branch.get_push_location())
2459
# New branch has no tags by default
2460
new_branch.tags._set_tag_dict({})
2462
# Copying done; now update target format
2463
new_branch._transport.put_bytes('format',
2464
format.get_format_string(),
2465
mode=new_branch.bzrdir._get_file_mode())
2467
# Clean up old files
2468
new_branch._transport.delete('revision-history')
2470
branch.set_parent(None)
2471
except errors.NoSuchFile:
2473
branch.set_bound_location(None)
2476
class Converter6to7(object):
2477
"""Perform an in-place upgrade of format 6 to format 7"""
2479
def convert(self, branch):
2480
format = BzrBranchFormat7()
2481
branch._set_config_location('stacked_on_location', '')
2482
# update target format
2483
branch._transport.put_bytes('format', format.get_format_string())
2487
def _run_with_write_locked_target(target, callable, *args, **kwargs):
2488
"""Run ``callable(*args, **kwargs)``, write-locking target for the
2491
_run_with_write_locked_target will attempt to release the lock it acquires.
2493
If an exception is raised by callable, then that exception *will* be
2494
propagated, even if the unlock attempt raises its own error. Thus
2495
_run_with_write_locked_target should be preferred to simply doing::
2499
return callable(*args, **kwargs)
1073
raise InvalidRevisionId(revision_id=revision, branch=self)
1074
return history[:idx+1]
1077
def _clone_weave(self, to_location, revision=None, basis_branch=None):
1079
from bzrlib.workingtree import WorkingTree
1080
assert isinstance(to_location, basestring)
1081
if basis_branch is not None:
1082
note("basis_branch is not supported for fast weave copy yet.")
1084
history = self._get_truncated_history(revision)
1085
if not bzrlib.osutils.lexists(to_location):
1086
os.mkdir(to_location)
1087
bzrdir_to = self.bzrdir._format.initialize(to_location)
1088
self.repository.clone(bzrdir_to)
1089
branch_to = bzrdir_to.create_branch()
1090
mutter("copy branch from %s to %s", self, branch_to)
1092
# FIXME duplicate code with base .clone().
1093
# .. would template method be useful here? RBC 20051207
1094
branch_to.set_parent(self.base)
1095
branch_to.append_revision(*history)
1096
WorkingTree.create(branch_to, branch_to.base)
1101
class BranchTestProviderAdapter(object):
1102
"""A tool to generate a suite testing multiple branch formats at once.
1104
This is done by copying the test once for each transport and injecting
1105
the transport_server, transport_readonly_server, and branch_format
1106
classes into each copy. Each copy is also given a new id() to make it
1110
def __init__(self, transport_server, transport_readonly_server, formats):
1111
self._transport_server = transport_server
1112
self._transport_readonly_server = transport_readonly_server
1113
self._formats = formats
2504
# This is very similar to bzrlib.decorators.needs_write_lock. Perhaps they
2505
# should share code?
2508
result = callable(*args, **kwargs)
2510
exc_info = sys.exc_info()
2514
raise exc_info[0], exc_info[1], exc_info[2]
1115
def adapt(self, test):
1116
result = TestSuite()
1117
for branch_format, bzrdir_format in self._formats:
1118
new_test = deepcopy(test)
1119
new_test.transport_server = self._transport_server
1120
new_test.transport_readonly_server = self._transport_readonly_server
1121
new_test.bzrdir_format = bzrdir_format
1122
new_test.branch_format = branch_format
1123
def make_new_test_id():
1124
new_id = "%s(%s)" % (new_test.id(), branch_format.__class__.__name__)
1125
return lambda: new_id
1126
new_test.id = make_new_test_id()
1127
result.addTest(new_test)
1131
######################################################################
1135
@deprecated_function(zero_eight)
1136
def ScratchBranch(*args, **kwargs):
1137
"""See bzrlib.bzrdir.ScratchDir."""
1138
d = ScratchDir(*args, **kwargs)
1139
return d.open_branch()
1142
@deprecated_function(zero_eight)
1143
def is_control_file(*args, **kwargs):
1144
"""See bzrlib.workingtree.is_control_file."""
1145
return bzrlib.workingtree.is_control_file(*args, **kwargs)