/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1
# Copyright (C) 2005, 2006 Canonical Ltd
70 by mbp at sourcefrog
Prepare for smart recursive add.
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
1185.62.20 by John Arbash Meinel
Giving nicer warning when there is a leftover xml.pyc file.
26
try:
27
    import xml.sax.saxutils
28
except ImportError:
29
    raise ImportError("We were unable to import 'xml.sax.saxutils',"
30
                      " most likely you have an xml.pyc or xml.pyo file"
31
                      " lying around in your bzrlib directory."
32
                      " Please remove it.")
1372 by Martin Pool
- avoid converting inventories to/from StringIO
33
1 by mbp at sourcefrog
import from baz patch-364
34
35
import bzrlib
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
36
import bzrlib.bzrdir as bzrdir
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
37
from bzrlib.config import TreeConfig
1534.4.28 by Robert Collins
first cut at merge from integration.
38
from bzrlib.decorators import needs_read_lock, needs_write_lock
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
39
from bzrlib.delta import compare_trees
40
import bzrlib.errors as errors
41
from bzrlib.errors import (BzrError, InvalidRevisionNumber, InvalidRevisionId,
42
                           NoSuchRevision, HistoryMissing, NotBranchError,
1551.1.1 by Martin Pool
[merge] branch-formats branch, and reconcile changes
43
                           DivergedBranches, LockError,
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
44
                           UninitializableFormat,
45
                           UnlistableStore,
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
46
                           UnlistableBranch, NoSuchFile, NotVersionedError,
47
                           NoWorkingTree)
1185.65.15 by Robert Collins
Merge from integration.
48
import bzrlib.inventory as inventory
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
49
from bzrlib.inventory import Inventory
1185.65.14 by Robert Collins
Merge from aaron. Whee, we are synced. Yay. Begone the foul demons of merge conflicts.
50
from bzrlib.lockable_files import LockableFiles
1508.1.5 by Robert Collins
Move add from Branch to WorkingTree.
51
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 \
52
                            rename, splitpath, sha_file,
1534.4.1 by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib.
53
                            file_kind, abspath, normpath, pathjoin,
54
                            safe_unicode,
55
                            )
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
56
from bzrlib.textui import show_status
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
57
from bzrlib.trace import mutter, note
58
from bzrlib.tree import EmptyTree, RevisionTree
1534.4.28 by Robert Collins
first cut at merge from integration.
59
from bzrlib.repository import Repository
1534.1.31 by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo.
60
from bzrlib.revision import (
61
                             get_intervening_revisions,
62
                             is_ancestor,
63
                             NULL_REVISION,
64
                             Revision,
65
                             )
1393.2.1 by John Arbash Meinel
Merged in split-storage-2 branch. Need to cleanup a little bit more still.
66
from bzrlib.store import copy_all
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
67
from bzrlib.symbol_versioning import *
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
68
import bzrlib.transactions as transactions
1393.2.4 by John Arbash Meinel
All tests pass.
69
from bzrlib.transport import Transport, get_transport
1185.65.15 by Robert Collins
Merge from integration.
70
from bzrlib.tree import EmptyTree, RevisionTree
1185.65.11 by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition.
71
import bzrlib.ui
1189 by Martin Pool
- BROKEN: partial support for commit into weave
72
import bzrlib.xml5
1104 by Martin Pool
- Add a simple UIFactory
73
1094 by Martin Pool
- merge aaron's merge improvements 999..1008
74
1186 by Martin Pool
- start implementing v5 format; Branch refuses to operate on old branches
75
BZR_BRANCH_FORMAT_4 = "Bazaar-NG branch, format 0.0.4\n"
76
BZR_BRANCH_FORMAT_5 = "Bazaar-NG branch, format 5\n"
1429 by Robert Collins
merge in niemeyers prefixed-store patch
77
BZR_BRANCH_FORMAT_6 = "Bazaar-NG branch, format 6\n"
1185.70.3 by Martin Pool
Various updates to make storage branch mergeable:
78
79
80
# TODO: Maybe include checks for common corruption of newlines, etc?
1 by mbp at sourcefrog
import from baz patch-364
81
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
82
# TODO: Some operations like log might retrieve the same revisions
83
# repeatedly to calculate deltas.  We could perhaps have a weakref
1223 by Martin Pool
- store inventories in weave
84
# cache in memory to make this faster.  In general anything can be
1185.65.29 by Robert Collins
Implement final review suggestions.
85
# cached in memory between lock and unlock operations. .. nb thats
86
# what the transaction identity map provides
416 by Martin Pool
- bzr log and bzr root now accept an http URL
87
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
88
1 by mbp at sourcefrog
import from baz patch-364
89
######################################################################
90
# branch objects
91
558 by Martin Pool
- All top-level classes inherit from object
92
class Branch(object):
1 by mbp at sourcefrog
import from baz patch-364
93
    """Branch holding a history of revisions.
94
343 by Martin Pool
doc
95
    base
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
96
        Base directory/url of the branch.
97
    """
1534.4.1 by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib.
98
    # this is really an instance variable - FIXME move it there
99
    # - RBC 20060112
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
100
    base = None
101
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
102
    @staticmethod
103
    def create(base):
104
        """Construct the current default format branch in a_bzrdir.
105
106
        This creates the current default BzrDir format, and if that 
107
        supports multiple Branch formats, then the default Branch format
108
        will take effect.
109
        """
110
        print "not usable until we have repositories"
111
        raise NotImplementedError("not usable right now")
112
        return bzrdir.BzrDir.create(base)
1534.4.1 by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib.
113
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
114
    def __init__(self, *ignored, **ignored_too):
115
        raise NotImplementedError('The Branch class is abstract')
116
117
    @staticmethod
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
118
    @deprecated_method(zero_eight)
1393.1.2 by Martin Pool
- better representation in Branch factories of opening old formats
119
    def open_downlevel(base):
1534.4.7 by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.
120
        """Open a branch which may be of an old format."""
121
        return Branch.open(base, _unsupported=True)
1393.1.2 by Martin Pool
- better representation in Branch factories of opening old formats
122
        
123
    @staticmethod
1534.4.7 by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.
124
    def open(base, _unsupported=False):
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
125
        """Open the repository rooted at base.
126
127
        For instance, if the repository is at URL/.bzr/repository,
128
        Repository.open(URL) -> a Repository instance.
1534.4.7 by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.
129
        """
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
130
        control = bzrdir.BzrDir.open(base, _unsupported)
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
131
        return control.open_branch(_unsupported)
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.
1534.4.22 by Robert Collins
update TODOs and move abstract methods that were misplaced on BzrBranchFormat5 to Branch.
141
        If there is one and it is either an unrecognised format or an unsupported 
142
        format, UnknownFormatError or UnsupportedFormatError are raised.
1442.1.64 by Robert Collins
Branch.open_containing now returns a tuple (Branch, relative-path).
143
        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.
144
        """
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
145
        control, relpath = bzrdir.BzrDir.open_containing(url)
146
        return control.open_branch(), relpath
1534.4.1 by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib.
147
148
    @staticmethod
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
149
    @deprecated_function(zero_eight)
150
    def initialize(base):
151
        """Create a new working tree and branch, rooted at 'base' (url)
1551.1.2 by Martin Pool
Deprecation warnings for popular APIs that will change in BzrDir
152
153
        NOTE: This will soon be deprecated in favour of creation
154
        through a BzrDir.
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
155
        """
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
156
        return bzrdir.BzrDir.create_standalone_workingtree(base).branch
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
157
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
158
    def setup_caching(self, cache_root):
159
        """Subclasses that care about caching should override this, and set
160
        up cached stores located under cache_root.
161
        """
1185.70.6 by Martin Pool
review fixups from John
162
        # seems to be unused, 2006-01-13 mbp
163
        warn('%s is deprecated' % self.setup_caching)
1400.1.1 by Robert Collins
implement a basic test for the ui branch command from http servers
164
        self.cache_root = cache_root
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
165
1185.35.11 by Aaron Bentley
Added support for branch nicks
166
    def _get_nick(self):
167
        cfg = self.tree_config()
1530.1.3 by Robert Collins
transport implementations now tested consistently.
168
        return cfg.get_option(u"nickname", default=self.base.split('/')[-2])
1185.35.11 by Aaron Bentley
Added support for branch nicks
169
170
    def _set_nick(self, nick):
171
        cfg = self.tree_config()
172
        cfg.set_option(nick, "nickname")
173
        assert cfg.get_option("nickname") == nick
174
175
    nick = property(_get_nick, _set_nick)
176
        
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
177
    def lock_write(self):
178
        raise NotImplementedError('lock_write is abstract')
179
        
180
    def lock_read(self):
181
        raise NotImplementedError('lock_read is abstract')
182
183
    def unlock(self):
184
        raise NotImplementedError('unlock is abstract')
185
1185.70.3 by Martin Pool
Various updates to make storage branch mergeable:
186
    def peek_lock_mode(self):
187
        """Return lock mode for the Branch: 'r', 'w' or None"""
1185.70.6 by Martin Pool
review fixups from John
188
        raise NotImplementedError(self.peek_lock_mode)
1185.70.3 by Martin Pool
Various updates to make storage branch mergeable:
189
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
190
    def abspath(self, name):
191
        """Return absolute filename for something in the branch
192
        
193
        XXX: Robert Collins 20051017 what is this used for? why is it a branch
194
        method and not a tree method.
195
        """
196
        raise NotImplementedError('abspath is abstract')
197
1534.1.31 by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo.
198
    @needs_write_lock
199
    def fetch(self, from_branch, last_revision=None, pb=None):
200
        """Copy revisions from from_branch into this branch.
201
202
        :param from_branch: Where to copy from.
203
        :param last_revision: What revision to stop at (None for at the end
204
                              of the branch.
205
        :param pb: An optional progress bar to use.
206
207
        Returns the copied revision count and the failed revisions in a tuple:
208
        (copied, failures).
209
        """
210
        if self.base == from_branch.base:
211
            raise Exception("can't fetch from a branch to itself %s, %s" % 
212
                            (self.base, to_branch.base))
213
        if pb is None:
214
            pb = bzrlib.ui.ui_factory.progress_bar()
215
216
        from_branch.lock_read()
217
        try:
218
            if last_revision is None:
219
                pb.update('get source history')
220
                from_history = from_branch.revision_history()
221
                if from_history:
222
                    last_revision = from_history[-1]
223
                else:
224
                    # no history in the source branch
225
                    last_revision = NULL_REVISION
226
            return self.repository.fetch(from_branch.repository,
227
                                         revision_id=last_revision,
228
                                         pb=pb)
229
        finally:
230
            from_branch.unlock()
231
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
232
    def get_root_id(self):
233
        """Return the id of this branches root"""
234
        raise NotImplementedError('get_root_id is abstract')
235
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
236
    def print_file(self, file, revision_id):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
237
        """Print `file` to stdout."""
238
        raise NotImplementedError('print_file is abstract')
239
240
    def append_revision(self, *revision_ids):
241
        raise NotImplementedError('append_revision is abstract')
242
243
    def set_revision_history(self, rev_history):
244
        raise NotImplementedError('set_revision_history is abstract')
245
246
    def revision_history(self):
247
        """Return sequence of revision hashes on to this branch."""
248
        raise NotImplementedError('revision_history is abstract')
249
250
    def revno(self):
251
        """Return current revision number for this branch.
252
253
        That is equivalent to the number of revisions committed to
254
        this branch.
255
        """
256
        return len(self.revision_history())
257
258
    def last_revision(self):
259
        """Return last patch hash, or None if no history."""
260
        ph = self.revision_history()
261
        if ph:
262
            return ph[-1]
263
        else:
264
            return None
265
266
    def missing_revisions(self, other, stop_revision=None, diverged_ok=False):
267
        """Return a list of new revisions that would perfectly fit.
268
        
269
        If self and other have not diverged, return a list of the revisions
270
        present in other, but missing from self.
271
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
272
        >>> from bzrlib.workingtree import WorkingTree
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
273
        >>> bzrlib.trace.silent = True
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
274
        >>> d1 = bzrdir.ScratchDir()
275
        >>> br1 = d1.open_branch()
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
276
        >>> wt1 = d1.open_workingtree()
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
277
        >>> d2 = bzrdir.ScratchDir()
278
        >>> br2 = d2.open_branch()
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
279
        >>> wt2 = d2.open_workingtree()
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
280
        >>> br1.missing_revisions(br2)
281
        []
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
282
        >>> wt2.commit("lala!", rev_id="REVISION-ID-1")
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
283
        >>> br1.missing_revisions(br2)
284
        [u'REVISION-ID-1']
285
        >>> br2.missing_revisions(br1)
286
        []
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
287
        >>> wt1.commit("lala!", rev_id="REVISION-ID-1")
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
288
        >>> br1.missing_revisions(br2)
289
        []
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
290
        >>> wt2.commit("lala!", rev_id="REVISION-ID-2A")
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
291
        >>> br1.missing_revisions(br2)
292
        [u'REVISION-ID-2A']
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
293
        >>> wt1.commit("lala!", rev_id="REVISION-ID-2B")
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
294
        >>> br1.missing_revisions(br2)
295
        Traceback (most recent call last):
1185.56.1 by Michael Ellerman
Simplify handling of DivergedBranches in cmd_pull()
296
        DivergedBranches: These branches have diverged.  Try merge.
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
297
        """
298
        self_history = self.revision_history()
299
        self_len = len(self_history)
300
        other_history = other.revision_history()
301
        other_len = len(other_history)
302
        common_index = min(self_len, other_len) -1
303
        if common_index >= 0 and \
304
            self_history[common_index] != other_history[common_index]:
305
            raise DivergedBranches(self, other)
306
307
        if stop_revision is None:
308
            stop_revision = other_len
309
        else:
310
            assert isinstance(stop_revision, int)
311
            if stop_revision > other_len:
312
                raise bzrlib.errors.NoSuchRevision(self, stop_revision)
313
        return other_history[self_len:stop_revision]
1185.66.1 by Aaron Bentley
Merged from mainline
314
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
315
    def update_revisions(self, other, stop_revision=None):
316
        """Pull in new perfect-fit revisions."""
317
        raise NotImplementedError('update_revisions is abstract')
318
319
    def pullable_revisions(self, other, stop_revision):
320
        raise NotImplementedError('pullable_revisions is abstract')
321
        
322
    def revision_id_to_revno(self, revision_id):
323
        """Given a revision id, return its revno"""
324
        if revision_id is None:
325
            return 0
326
        history = self.revision_history()
327
        try:
328
            return history.index(revision_id) + 1
329
        except ValueError:
330
            raise bzrlib.errors.NoSuchRevision(self, revision_id)
331
332
    def get_rev_id(self, revno, history=None):
333
        """Find the revision id of the specified revno."""
334
        if revno == 0:
335
            return None
336
        if history is None:
337
            history = self.revision_history()
338
        elif revno <= 0 or revno > len(history):
339
            raise bzrlib.errors.NoSuchRevision(self, revno)
340
        return history[revno - 1]
341
1185.76.1 by Erik Bågfors
Support for --revision in pull
342
    def pull(self, source, overwrite=False, stop_revision=None):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
343
        raise NotImplementedError('pull is abstract')
344
345
    def basis_tree(self):
346
        """Return `Tree` object for last revision.
347
348
        If there are no revisions yet, return an `EmptyTree`.
349
        """
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
350
        return self.repository.revision_tree(self.last_revision())
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
351
352
    def rename_one(self, from_rel, to_rel):
353
        """Rename one file.
354
355
        This can change the directory or the filename or both.
356
        """
357
        raise NotImplementedError('rename_one is abstract')
358
359
    def move(self, from_paths, to_name):
360
        """Rename files.
361
362
        to_name must exist as a versioned directory.
363
364
        If to_name exists and is a directory, the files are moved into
365
        it, keeping their old names.  If it is a directory, 
366
367
        Note that to_name is only the last component of the new name;
368
        this doesn't change the directory.
369
370
        This returns a list of (from_path, to_path) pairs for each
371
        entry that is moved.
372
        """
373
        raise NotImplementedError('move is abstract')
374
375
    def get_parent(self):
376
        """Return the parent location of the branch.
377
378
        This is the default location for push/pull/missing.  The usual
379
        pattern is that the user can override it by specifying a
380
        location.
381
        """
382
        raise NotImplementedError('get_parent is abstract')
383
384
    def get_push_location(self):
385
        """Return the None or the location to push this branch to."""
386
        raise NotImplementedError('get_push_location is abstract')
387
388
    def set_push_location(self, location):
389
        """Set a new push location for this branch."""
390
        raise NotImplementedError('set_push_location is abstract')
391
392
    def set_parent(self, url):
393
        raise NotImplementedError('set_parent is abstract')
394
395
    def check_revno(self, revno):
396
        """\
397
        Check whether a revno corresponds to any revision.
398
        Zero (the NULL revision) is considered valid.
399
        """
400
        if revno != 0:
401
            self.check_real_revno(revno)
402
            
403
    def check_real_revno(self, revno):
404
        """\
405
        Check whether a revno corresponds to a real revision.
406
        Zero (the NULL revision) is considered invalid
407
        """
408
        if revno < 1 or revno > self.revno():
409
            raise InvalidRevisionNumber(revno)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
410
411
    @needs_read_lock
412
    def clone(self, *args, **kwargs):
413
        """Clone this branch into to_bzrdir preserving all semantic values.
414
        
415
        revision_id: if not None, the revision history in the new branch will
416
                     be truncated to end with revision_id.
417
        """
418
        # for API compatability, until 0.8 releases we provide the old api:
419
        # def clone(self, to_location, revision=None, basis_branch=None, to_branch_format=None):
420
        # after 0.8 releases, the *args and **kwargs should be changed:
421
        # def clone(self, to_bzrdir, revision_id=None):
422
        if (kwargs.get('to_location', None) or
423
            kwargs.get('revision', None) or
424
            kwargs.get('basis_branch', None) or
425
            (len(args) and isinstance(args[0], basestring))):
426
            # backwards compatability api:
427
            warn("Branch.clone() has been deprecated for BzrDir.clone() from"
428
                 " bzrlib 0.8.", DeprecationWarning, stacklevel=3)
429
            # get basis_branch
430
            if len(args) > 2:
431
                basis_branch = args[2]
432
            else:
433
                basis_branch = kwargs.get('basis_branch', None)
434
            if basis_branch:
435
                basis = basis_branch.bzrdir
436
            else:
437
                basis = None
438
            # get revision
439
            if len(args) > 1:
440
                revision_id = args[1]
441
            else:
442
                revision_id = kwargs.get('revision', None)
443
            # get location
444
            if len(args):
445
                url = args[0]
446
            else:
447
                # no default to raise if not provided.
448
                url = kwargs.get('to_location')
449
            return self.bzrdir.clone(url,
450
                                     revision_id=revision_id,
451
                                     basis=basis).open_branch()
452
        # new cleaner api.
453
        # generate args by hand 
454
        if len(args) > 1:
455
            revision_id = args[1]
456
        else:
457
            revision_id = kwargs.get('revision_id', None)
458
        if len(args):
459
            to_bzrdir = args[0]
460
        else:
461
            # no default to raise if not provided.
462
            to_bzrdir = kwargs.get('to_bzrdir')
463
        result = self._format.initialize(to_bzrdir)
464
        self.copy_content_into(result, revision_id=revision_id)
465
        return  result
466
467
    @needs_read_lock
468
    def sprout(self, to_bzrdir, revision_id=None):
469
        """Create a new line of development from the branch, into to_bzrdir.
470
        
471
        revision_id: if not None, the revision history in the new branch will
472
                     be truncated to end with revision_id.
473
        """
474
        result = self._format.initialize(to_bzrdir)
475
        self.copy_content_into(result, revision_id=revision_id)
476
        result.set_parent(self.bzrdir.root_transport.base)
477
        return result
478
479
    @needs_read_lock
480
    def copy_content_into(self, destination, revision_id=None):
481
        """Copy the content of self into destination.
482
483
        revision_id: if not None, the revision history in the new branch will
484
                     be truncated to end with revision_id.
485
        """
486
        new_history = self.revision_history()
487
        if revision_id is not None:
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
488
            try:
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
489
                new_history = new_history[:new_history.index(revision_id) + 1]
490
            except ValueError:
491
                rev = self.repository.get_revision(revision_id)
492
                new_history = rev.get_history(self.repository)[1:]
493
        destination.set_revision_history(new_history)
494
        parent = self.get_parent()
495
        if parent:
496
            destination.set_parent(parent)
1185.66.1 by Aaron Bentley
Merged from mainline
497
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
498
499
class BranchFormat(object):
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
500
    """An encapsulation of the initialization and open routines for a format.
501
502
    Formats provide three things:
503
     * An initialization routine,
504
     * a format string,
505
     * an open routine.
506
507
    Formats are placed in an dict by their format string for reference 
508
    during branch opening. Its not required that these be instances, they
509
    can be classes themselves with class methods - it simply depends on 
510
    whether state is needed for a given format or not.
511
512
    Once a format is deprecated, just deprecate the initialize and open
513
    methods on the format class. Do not deprecate the object, as the 
514
    object will be created every time regardless.
515
    """
516
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
517
    _default_format = None
518
    """The default format used for new branches."""
519
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
520
    _formats = {}
521
    """The known formats."""
522
523
    @classmethod
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
524
    def find_format(klass, a_bzrdir):
525
        """Return the format for the branch object in a_bzrdir."""
526
        try:
527
            transport = a_bzrdir.get_branch_transport(None)
528
            format_string = transport.get("format").read()
529
            return klass._formats[format_string]
530
        except NoSuchFile:
531
            raise NotBranchError(path=transport.base)
532
        except KeyError:
533
            raise errors.UnknownFormatError(format_string)
534
535
    @classmethod
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
536
    def get_default_format(klass):
537
        """Return the current default format."""
538
        return klass._default_format
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
539
540
    def get_format_string(self):
541
        """Return the ASCII format string that identifies this format."""
542
        raise NotImplementedError(self.get_format_string)
543
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
544
    def initialize(self, a_bzrdir):
545
        """Create a branch of this format in a_bzrdir."""
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
546
        raise NotImplementedError(self.initialized)
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
547
1534.4.7 by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.
548
    def is_supported(self):
549
        """Is this format supported?
550
551
        Supported formats can be initialized and opened.
552
        Unsupported formats may not support initialization or committing or 
553
        some other features depending on the reason for not being supported.
554
        """
555
        return True
556
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
557
    def open(self, a_bzrdir, _found=False):
558
        """Return the branch object for a_bzrdir
559
560
        _found is a private parameter, do not use it. It is used to indicate
561
               if format probing has already be done.
562
        """
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
563
        raise NotImplementedError(self.open)
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
564
565
    @classmethod
566
    def register_format(klass, format):
567
        klass._formats[format.get_format_string()] = format
568
1534.4.7 by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.
569
    @classmethod
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
570
    def set_default_format(klass, format):
571
        klass._default_format = format
572
573
    @classmethod
1534.4.7 by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.
574
    def unregister_format(klass, format):
575
        assert klass._formats[format.get_format_string()] is format
576
        del klass._formats[format.get_format_string()]
577
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
578
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
579
class BzrBranchFormat4(BranchFormat):
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
580
    """Bzr branch format 4.
581
582
    This format has:
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
583
     - a revision-history file.
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
584
     - a branch-lock lock file [ to be shared with the bzrdir ]
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
585
    """
586
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
587
    def initialize(self, a_bzrdir):
588
        """Create a branch of this format in a_bzrdir."""
589
        mutter('creating branch in %s', a_bzrdir.transport.base)
590
        branch_transport = a_bzrdir.get_branch_transport(self)
591
        utf8_files = [('revision-history', ''),
592
                      ('branch-name', ''),
593
                      ]
594
        control_files = LockableFiles(branch_transport, 'branch-lock')
595
        control_files.lock_write()
596
        try:
597
            for file, content in utf8_files:
598
                control_files.put_utf8(file, content)
599
        finally:
600
            control_files.unlock()
601
        return self.open(a_bzrdir, _found=True)
602
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
603
    def __init__(self):
604
        super(BzrBranchFormat4, self).__init__()
605
        self._matchingbzrdir = bzrdir.BzrDirFormat6()
606
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
607
    def open(self, a_bzrdir, _found=False):
608
        """Return the branch object for a_bzrdir
609
610
        _found is a private parameter, do not use it. It is used to indicate
611
               if format probing has already be done.
612
        """
613
        if not _found:
614
            # we are being called directly and must probe.
615
            raise NotImplementedError
616
        return BzrBranch(_format=self,
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
617
                         _control_files=a_bzrdir._control_files,
1534.6.4 by Robert Collins
Creating or opening a branch will use the repository if the format supports that.
618
                         a_bzrdir=a_bzrdir,
619
                         _repository=a_bzrdir.open_repository())
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
620
621
622
class BzrBranchFormat5(BranchFormat):
623
    """Bzr branch format 5.
624
625
    This format has:
626
     - a revision-history file.
627
     - a format string
1534.6.4 by Robert Collins
Creating or opening a branch will use the repository if the format supports that.
628
     - a lock file.
629
     - works with shared repositories.
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
630
    """
631
632
    def get_format_string(self):
633
        """See BranchFormat.get_format_string()."""
634
        return "Bazaar-NG branch format 5\n"
635
        
636
    def initialize(self, a_bzrdir):
637
        """Create a branch of this format in a_bzrdir."""
638
        mutter('creating branch in %s', a_bzrdir.transport.base)
639
        branch_transport = a_bzrdir.get_branch_transport(self)
640
641
        utf8_files = [('revision-history', ''),
642
                      ('branch-name', ''),
643
                      ]
644
        lock_file = 'lock'
645
        branch_transport.put(lock_file, StringIO()) # TODO get the file mode from the bzrdir lock files., mode=file_mode)
646
        control_files = LockableFiles(branch_transport, 'lock')
647
        control_files.lock_write()
648
        control_files.put_utf8('format', self.get_format_string())
649
        try:
650
            for file, content in utf8_files:
651
                control_files.put_utf8(file, content)
652
        finally:
653
            control_files.unlock()
654
        return self.open(a_bzrdir, _found=True, )
655
656
    def __init__(self):
657
        super(BzrBranchFormat5, self).__init__()
658
        self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
659
660
    def open(self, a_bzrdir, _found=False):
661
        """Return the branch object for a_bzrdir
662
663
        _found is a private parameter, do not use it. It is used to indicate
664
               if format probing has already be done.
665
        """
666
        if not _found:
667
            format = BranchFormat.find_format(a_bzrdir)
668
            assert format.__class__ == self.__class__
669
        transport = a_bzrdir.get_branch_transport(None)
670
        control_files = LockableFiles(transport, 'lock')
671
        return BzrBranch(_format=self,
672
                         _control_files=control_files,
1534.6.4 by Robert Collins
Creating or opening a branch will use the repository if the format supports that.
673
                         a_bzrdir=a_bzrdir,
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
674
                         _repository=a_bzrdir.find_repository())
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
675
676
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
677
class BranchReferenceFormat(BranchFormat):
678
    """Bzr branch reference format.
679
680
    Branch references are used in implementing checkouts, they
681
    act as an alias to the real branch which is at some other url.
682
683
    This format has:
684
     - A location file
685
     - a format string
686
    """
687
688
    def get_format_string(self):
689
        """See BranchFormat.get_format_string()."""
690
        return "Bazaar-NG Branch Reference Format 1\n"
691
        
692
    def initialize(self, a_bzrdir, target_branch=None):
693
        """Create a branch of this format in a_bzrdir."""
694
        if target_branch is None:
695
            # this format does not implement branch itself, thus the implicit
696
            # creation contract must see it as uninitializable
697
            raise errors.UninitializableFormat(self)
698
        mutter('creating branch reference in %s', a_bzrdir.transport.base)
699
        branch_transport = a_bzrdir.get_branch_transport(self)
700
        # FIXME rbc 20060209 one j-a-ms encoding branch lands this str() cast is not needed.
701
        branch_transport.put('location', StringIO(str(target_branch.bzrdir.root_transport.base)))
702
        branch_transport.put('format', StringIO(self.get_format_string()))
703
        return self.open(a_bzrdir, _found=True)
704
705
    def __init__(self):
706
        super(BranchReferenceFormat, self).__init__()
707
        self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
708
709
    def _make_reference_clone_function(format, a_branch):
710
        """Create a clone() routine for a branch dynamically."""
711
        def clone(to_bzrdir, revision_id=None):
712
            """See Branch.clone()."""
713
            return format.initialize(to_bzrdir, a_branch)
714
            # cannot obey revision_id limits when cloning a reference ...
715
            # FIXME RBC 20060210 either nuke revision_id for clone, or
716
            # emit some sort of warning/error to the caller ?!
717
        return clone
718
719
    def open(self, a_bzrdir, _found=False):
720
        """Return the branch that the branch reference in a_bzrdir points at.
721
722
        _found is a private parameter, do not use it. It is used to indicate
723
               if format probing has already be done.
724
        """
725
        if not _found:
726
            format = BranchFormat.find_format(a_bzrdir)
727
            assert format.__class__ == self.__class__
728
        transport = a_bzrdir.get_branch_transport(None)
729
        real_bzrdir = bzrdir.BzrDir.open(transport.get('location').read())
730
        result = real_bzrdir.open_branch()
731
        # this changes the behaviour of result.clone to create a new reference
732
        # rather than a copy of the content of the branch.
733
        # I did not use a proxy object because that needs much more extensive
734
        # testing, and we are only changing one behaviour at the moment.
735
        # If we decide to alter more behaviours - i.e. the implicit nickname
736
        # then this should be refactored to introduce a tested proxy branch
737
        # and a subclass of that for use in overriding clone() and ....
738
        # - RBC 20060210
739
        result.clone = self._make_reference_clone_function(result)
740
        return result
741
742
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
743
# formats which have no format string are not discoverable
744
# and not independently creatable, so are not registered.
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
745
__default_format = BzrBranchFormat5()
746
BranchFormat.register_format(__default_format)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
747
BranchFormat.register_format(BranchReferenceFormat())
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
748
BranchFormat.set_default_format(__default_format)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
749
_legacy_formats = [BzrBranchFormat4(),
750
                   ]
1534.4.5 by Robert Collins
Turn branch format.open into a factory.
751
1495.1.5 by Jelmer Vernooij
Rename NativeBranch -> BzrBranch
752
class BzrBranch(Branch):
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
753
    """A branch stored in the actual filesystem.
754
755
    Note that it's "local" in the context of the filesystem; it doesn't
756
    really matter if it's on an nfs/smb/afs/coda/... share, as long as
757
    it's writable, and can be accessed via the normal filesystem API.
1 by mbp at sourcefrog
import from baz patch-364
758
    """
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
759
    # We actually expect this class to be somewhat short-lived; part of its
760
    # purpose is to try to isolate what bits of the branch logic are tied to
761
    # filesystem access, so that in a later step, we can extricate them to
762
    # a separarte ("storage") class.
1223 by Martin Pool
- store inventories in weave
763
    _inventory_weave = None
353 by Martin Pool
- Per-branch locks in read and write modes.
764
    
897 by Martin Pool
- merge john's revision-naming code
765
    # Map some sort of prefix into a namespace
766
    # stuff like "revno:10", "revid:", etc.
767
    # This should match a prefix with a function which accepts
768
    REVISION_NAMESPACES = {}
769
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
770
    def __init__(self, transport=DEPRECATED_PARAMETER, init=DEPRECATED_PARAMETER,
1534.4.32 by Robert Collins
Rename deprecated_nonce to DEPRECATED_PARAMETER
771
                 relax_version_check=DEPRECATED_PARAMETER, _format=None,
1534.6.4 by Robert Collins
Creating or opening a branch will use the repository if the format supports that.
772
                 _control_files=None, a_bzrdir=None, _repository=None):
1 by mbp at sourcefrog
import from baz patch-364
773
        """Create new branch object at a particular location.
774
907.1.2 by John Arbash Meinel
Working on making Branch() do all of it's work over a Transport.
775
        transport -- A Transport object, defining how to access files.
62 by mbp at sourcefrog
- new find_branch_root function; based on suggestion from aaron
776
        
254 by Martin Pool
- Doc cleanups from Magnus Therning
777
        init -- If True, create new control files in a previously
1 by mbp at sourcefrog
import from baz patch-364
778
             unversioned directory.  If False, the branch must already
779
             be versioned.
780
1293 by Martin Pool
- add Branch constructor option to relax version check
781
        relax_version_check -- If true, the usual check for the branch
782
            version is not applied.  This is intended only for
783
            upgrade/recovery type use; it's not guaranteed that
784
            all operations will work on old format branches.
1 by mbp at sourcefrog
import from baz patch-364
785
        """
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
786
        if a_bzrdir is None:
787
            self.bzrdir = bzrdir.BzrDir.open(transport.base)
788
        else:
789
            self.bzrdir = a_bzrdir
790
        self._transport = self.bzrdir.transport.clone('..')
1534.4.28 by Robert Collins
first cut at merge from integration.
791
        self._base = self._transport.base
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
792
        self._format = _format
1534.4.28 by Robert Collins
first cut at merge from integration.
793
        if _control_files is None:
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
794
            raise BzrBadParameterMissing('_control_files')
1534.4.28 by Robert Collins
first cut at merge from integration.
795
        self.control_files = _control_files
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
796
        if deprecated_passed(init):
797
            warn("BzrBranch.__init__(..., init=XXX): The init parameter is "
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
798
                 "deprecated as of bzr 0.8. Please use Branch.create().",
799
                 DeprecationWarning,
800
                 stacklevel=2)
1534.4.2 by Robert Collins
Introduce BranchFormats - factoring out intialisation of Branches.
801
            if init:
802
                # this is slower than before deprecation, oh well never mind.
803
                # -> its deprecated.
804
                self._initialize(transport.base)
1534.4.28 by Robert Collins
first cut at merge from integration.
805
        self._check_format(_format)
1534.4.7 by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.
806
        if deprecated_passed(relax_version_check):
807
            warn("BzrBranch.__init__(..., relax_version_check=XXX_: The "
808
                 "relax_version_check parameter is deprecated as of bzr 0.8. "
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
809
                 "Please use BzrDir.open_downlevel, or a BzrBranchFormat's "
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
810
                 "open() method.",
811
                 DeprecationWarning,
812
                 stacklevel=2)
1534.4.7 by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.
813
            if (not relax_version_check
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
814
                and not self._format.is_supported()):
1534.4.7 by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.
815
                raise errors.UnsupportedFormatError(
816
                        'sorry, branch format %r not supported' % fmt,
817
                        ['use a different bzr version',
818
                         'or remove the .bzr directory'
819
                         ' and "bzr init" again'])
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
820
        if deprecated_passed(transport):
821
            warn("BzrBranch.__init__(transport=XXX...): The transport "
822
                 "parameter is deprecated as of bzr 0.8. "
823
                 "Please use Branch.open, or bzrdir.open_branch().",
824
                 DeprecationWarning,
825
                 stacklevel=2)
1534.6.4 by Robert Collins
Creating or opening a branch will use the repository if the format supports that.
826
        self.repository = _repository
1534.4.1 by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib.
827
1 by mbp at sourcefrog
import from baz patch-364
828
    def __str__(self):
1185.65.11 by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition.
829
        return '%s(%r)' % (self.__class__.__name__, self.base)
1 by mbp at sourcefrog
import from baz patch-364
830
831
    __repr__ = __str__
832
578 by Martin Pool
- start to move toward Branch.lock and unlock methods,
833
    def __del__(self):
907.1.23 by John Arbash Meinel
Branch objects now automatically create Cached stores if the protocol is_remote.
834
        # TODO: It might be best to do this somewhere else,
835
        # but it is nice for a Branch object to automatically
836
        # cache it's information.
837
        # Alternatively, we could have the Transport objects cache requests
838
        # See the earlier discussion about how major objects (like Branch)
839
        # should never expect their __del__ function to run.
1185.70.6 by Martin Pool
review fixups from John
840
        # XXX: cache_root seems to be unused, 2006-01-13 mbp
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
841
        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.
842
            try:
843
                shutil.rmtree(self.cache_root)
844
            except:
845
                pass
846
            self.cache_root = None
847
907.1.17 by John Arbash Meinel
Adding a Branch.base property, removing pull_loc()
848
    def _get_base(self):
1185.69.2 by John Arbash Meinel
Changed LockableFiles to take the root directory directly. Moved mode information into LockableFiles instead of Branch
849
        return self._base
907.1.17 by John Arbash Meinel
Adding a Branch.base property, removing pull_loc()
850
1442.1.5 by Robert Collins
Give branch.base a docstring.
851
    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,
852
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
853
    def _finish_transaction(self):
854
        """Exit the current transaction."""
1185.65.13 by Robert Collins
Merge from integration
855
        return self.control_files._finish_transaction()
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
856
857
    def get_transaction(self):
1185.65.13 by Robert Collins
Merge from integration
858
        """Return the current active transaction.
859
860
        If no transaction is active, this returns a passthrough object
861
        for which all data is immediately flushed and no caching happens.
862
        """
863
        # this is an explicit function so that we can do tricky stuff
864
        # when the storage in rev_storage is elsewhere.
865
        # we probably need to hook the two 'lock a location' and 
866
        # 'have a transaction' together more delicately, so that
867
        # we can have two locks (branch and storage) and one transaction
868
        # ... and finishing the transaction unlocks both, but unlocking
869
        # does not. - RBC 20051121
870
        return self.control_files.get_transaction()
871
872
    def _set_transaction(self, transaction):
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
873
        """Set a new active transaction."""
1185.65.13 by Robert Collins
Merge from integration
874
        return self.control_files._set_transaction(transaction)
353 by Martin Pool
- Per-branch locks in read and write modes.
875
67 by mbp at sourcefrog
use abspath() for the function that makes an absolute
876
    def abspath(self, name):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
877
        """See Branch.abspath."""
1185.65.11 by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition.
878
        return self.control_files._transport.abspath(name)
1185.58.4 by John Arbash Meinel
Added permission checking to Branch, and propogated that change into the stores.
879
1534.4.7 by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.
880
    def _check_format(self, format):
1534.4.8 by Robert Collins
Unfuck upgrade.
881
        """Identify the branch format if needed.
1 by mbp at sourcefrog
import from baz patch-364
882
1534.4.8 by Robert Collins
Unfuck upgrade.
883
        The format is stored as a reference to the format object in
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
884
        self._format for code that needs to check it later.
1 by mbp at sourcefrog
import from baz patch-364
885
1534.4.5 by Robert Collins
Turn branch format.open into a factory.
886
        The format parameter is either None or the branch format class
887
        used to open this branch.
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
888
889
        FIXME: DELETE THIS METHOD when pre 0.8 support is removed.
163 by mbp at sourcefrog
merge win32 portability fixes
890
        """
1534.4.5 by Robert Collins
Turn branch format.open into a factory.
891
        if format is None:
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
892
            format = BzrBranchFormat.find_format(self.bzrdir)
893
        self._format = format
894
        mutter("got branch format %s", self._format)
907.1.2 by John Arbash Meinel
Working on making Branch() do all of it's work over a Transport.
895
1508.1.15 by Robert Collins
Merge from mpool.
896
    @needs_read_lock
909 by Martin Pool
- merge John's code to give the tree root an explicit file id
897
    def get_root_id(self):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
898
        """See Branch.get_root_id."""
1534.4.28 by Robert Collins
first cut at merge from integration.
899
        tree = self.repository.revision_tree(self.last_revision())
900
        return tree.inventory.root.file_id
1 by mbp at sourcefrog
import from baz patch-364
901
1185.65.3 by Aaron Bentley
Fixed locking-- all tests pass
902
    def lock_write(self):
1185.65.11 by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition.
903
        # TODO: test for failed two phase locks. This is known broken.
904
        self.control_files.lock_write()
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
905
        self.repository.lock_write()
1185.65.1 by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch
906
1185.65.3 by Aaron Bentley
Fixed locking-- all tests pass
907
    def lock_read(self):
1185.65.11 by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition.
908
        # TODO: test for failed two phase locks. This is known broken.
909
        self.control_files.lock_read()
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
910
        self.repository.lock_read()
1185.65.1 by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch
911
912
    def unlock(self):
1185.65.11 by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition.
913
        # TODO: test for failed two phase locks. This is known broken.
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
914
        self.repository.unlock()
1185.65.11 by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition.
915
        self.control_files.unlock()
1185.65.1 by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch
916
1185.70.3 by Martin Pool
Various updates to make storage branch mergeable:
917
    def peek_lock_mode(self):
918
        if self.control_files._lock_count == 0:
919
            return None
920
        else:
921
            return self.control_files._lock_mode
922
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
923
    @needs_read_lock
1185.50.9 by John Arbash Meinel
[bug 3632] Matthieu Moy- bzr cat should default to last revision
924
    def print_file(self, file, revision_id):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
925
        """See Branch.print_file."""
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
926
        return self.repository.print_file(file, revision_id)
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
927
928
    @needs_write_lock
905 by Martin Pool
- merge aaron's append_multiple.patch
929
    def append_revision(self, *revision_ids):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
930
        """See Branch.append_revision."""
905 by Martin Pool
- merge aaron's append_multiple.patch
931
        for revision_id in revision_ids:
932
            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.
933
        rev_history = self.revision_history()
934
        rev_history.extend(revision_ids)
1442.1.68 by Robert Collins
'bzr pull' now accepts '--clobber'.
935
        self.set_revision_history(rev_history)
936
937
    @needs_write_lock
938
    def set_revision_history(self, rev_history):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
939
        """See Branch.set_revision_history."""
1185.65.12 by Robert Collins
Remove the only-used-once put_controlfiles, and change put_controlfile to put and put_utf8.
940
        self.control_files.put_utf8(
1185.65.11 by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition.
941
            'revision-history', '\n'.join(rev_history))
233 by mbp at sourcefrog
- more output from test.sh
942
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
943
    def get_revision_delta(self, revno):
944
        """Return the delta for one revision.
945
946
        The delta is relative to its mainline predecessor, or the
947
        empty tree for revision 1.
948
        """
949
        assert isinstance(revno, int)
950
        rh = self.revision_history()
951
        if not (1 <= revno <= len(rh)):
952
            raise InvalidRevisionNumber(revno)
953
954
        # revno is 1-based; list is 0-based
955
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
956
        new_tree = self.repository.revision_tree(rh[revno-1])
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
957
        if revno == 1:
958
            old_tree = EmptyTree()
959
        else:
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
960
            old_tree = self.repository.revision_tree(rh[revno-2])
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
961
        return compare_trees(old_tree, new_tree)
962
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
963
    @needs_read_lock
1 by mbp at sourcefrog
import from baz patch-364
964
    def revision_history(self):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
965
        """See Branch.revision_history."""
1185.65.11 by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition.
966
        # FIXME are transactions bound to control files ? RBC 20051121
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
967
        transaction = self.get_transaction()
968
        history = transaction.map.find_revision_history()
969
        if history is not None:
970
            mutter("cache hit for revision-history in %s", self)
1417.1.12 by Robert Collins
cache revision history during read transactions
971
            return list(history)
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
972
        history = [l.rstrip('\r\n') for l in
1185.65.29 by Robert Collins
Implement final review suggestions.
973
                self.control_files.get_utf8('revision-history').readlines()]
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
974
        transaction.map.add_revision_history(history)
975
        # this call is disabled because revision_history is 
976
        # not really an object yet, and the transaction is for objects.
977
        # transaction.register_clean(history, precious=True)
978
        return list(history)
1 by mbp at sourcefrog
import from baz patch-364
979
974.1.28 by aaron.bentley at utoronto
factored install_revisions out of update_revisions, updated test cases for greedy_fetch
980
    def update_revisions(self, other, stop_revision=None):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
981
        """See Branch.update_revisions."""
974.1.75 by Aaron Bentley
Sped up pull by copying locally first
982
        if stop_revision is None:
1390 by Robert Collins
pair programming worx... merge integration and weave
983
            stop_revision = other.last_revision()
1185.12.44 by abentley
Restored branch convergence to bzr pull
984
        ### 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
985
        if (stop_revision is not None and 
986
            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
987
            return
1534.1.31 by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo.
988
        self.fetch(other, stop_revision)
1185.12.44 by abentley
Restored branch convergence to bzr pull
989
        pullable_revs = self.pullable_revisions(other, stop_revision)
1185.12.45 by abentley
Cleanups for pull
990
        if len(pullable_revs) > 0:
1261 by Martin Pool
- new method Branch.has_revision
991
            self.append_revision(*pullable_revs)
1185.12.44 by abentley
Restored branch convergence to bzr pull
992
993
    def pullable_revisions(self, other, stop_revision):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
994
        """See Branch.pullable_revisions."""
1185.12.44 by abentley
Restored branch convergence to bzr pull
995
        other_revno = other.revision_id_to_revno(stop_revision)
996
        try:
997
            return self.missing_revisions(other, other_revno)
998
        except DivergedBranches, e:
999
            try:
1000
                pullable_revs = get_intervening_revisions(self.last_revision(),
1185.65.1 by Aaron Bentley
Refactored out ControlFiles and RevisionStore from _Branch
1001
                                                          stop_revision, 
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
1002
                                                          self.repository)
1185.12.44 by abentley
Restored branch convergence to bzr pull
1003
                assert self.last_revision() not in pullable_revs
1004
                return pullable_revs
1005
            except bzrlib.errors.NotAncestor:
1006
                if is_ancestor(self.last_revision(), stop_revision, self):
1007
                    return []
1008
                else:
1009
                    raise e
1010
        
1185.33.59 by Martin Pool
[patch] keep a cached basis inventory (Johan Rydberg)
1011
    def basis_tree(self):
1012
        """See Branch.basis_tree."""
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
1013
        return self.repository.revision_tree(self.last_revision())
1185.33.59 by Martin Pool
[patch] keep a cached basis inventory (Johan Rydberg)
1014
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
1015
    @deprecated_method(zero_eight)
1 by mbp at sourcefrog
import from baz patch-364
1016
    def working_tree(self):
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
1017
        """Create a Working tree object for this branch."""
1185.2.2 by Lalo Martins
cleaning up and refactoring the branch module.
1018
        from bzrlib.workingtree import WorkingTree
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
1019
        from bzrlib.transport.local import LocalTransport
1534.4.28 by Robert Collins
first cut at merge from integration.
1020
        if (self.base.find('://') != -1 or 
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
1021
            not isinstance(self._transport, LocalTransport)):
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
1022
            raise NoWorkingTree(self.base)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
1023
        return self.bzrdir.open_workingtree()
1 by mbp at sourcefrog
import from baz patch-364
1024
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
1025
    @needs_write_lock
1185.76.1 by Erik Bågfors
Support for --revision in pull
1026
    def pull(self, source, overwrite=False, stop_revision=None):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
1027
        """See Branch.pull."""
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
1028
        source.lock_read()
1029
        try:
1185.33.44 by Martin Pool
[patch] show number of revisions pushed/pulled/merged (Robey Pointer)
1030
            old_count = len(self.revision_history())
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
1031
            try:
1185.76.1 by Erik Bågfors
Support for --revision in pull
1032
                self.update_revisions(source,stop_revision)
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
1033
            except DivergedBranches:
1034
                if not overwrite:
1035
                    raise
1185.50.5 by John Arbash Meinel
pull --overwrite should always overwrite, not just if diverged. (Test case from Robey Pointer)
1036
            if overwrite:
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
1037
                self.set_revision_history(source.revision_history())
1185.33.44 by Martin Pool
[patch] show number of revisions pushed/pulled/merged (Robey Pointer)
1038
            new_count = len(self.revision_history())
1039
            return new_count - old_count
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
1040
        finally:
1041
            source.unlock()
1 by mbp at sourcefrog
import from baz patch-364
1042
1149 by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it
1043
    def get_parent(self):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
1044
        """See Branch.get_parent."""
1149 by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it
1045
        import errno
1046
        _locs = ['parent', 'pull', 'x-pull']
1047
        for l in _locs:
1048
            try:
1185.65.29 by Robert Collins
Implement final review suggestions.
1049
                return self.control_files.get_utf8(l).read().strip('\n')
1185.31.45 by John Arbash Meinel
Refactoring Exceptions found some places where the wrong exception was caught.
1050
            except NoSuchFile:
1051
                pass
1149 by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it
1052
        return None
1053
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
1054
    def get_push_location(self):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
1055
        """See Branch.get_push_location."""
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
1056
        config = bzrlib.config.BranchConfig(self)
1057
        push_loc = config.get_user_option('push_location')
1058
        return push_loc
1059
1060
    def set_push_location(self, location):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
1061
        """See Branch.set_push_location."""
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
1062
        config = bzrlib.config.LocationConfig(self.base)
1063
        config.set_user_option('push_location', location)
1064
1442.1.63 by Robert Collins
Remove self.lock_*...finally: self.unlock() dead chickens from branch.py.
1065
    @needs_write_lock
1150 by Martin Pool
- add new Branch.set_parent and tests
1066
    def set_parent(self, url):
1495.1.2 by Jelmer Vernooij
Move some generic methods of NativeBranch to Branch.
1067
        """See Branch.set_parent."""
1150 by Martin Pool
- add new Branch.set_parent and tests
1068
        # TODO: Maybe delete old location files?
1185.65.29 by Robert Collins
Implement final review suggestions.
1069
        # URLs should never be unicode, even on the local fs,
1070
        # FIXUP this and get_parent in a future branch format bump:
1071
        # read and rewrite the file, and have the new format code read
1072
        # using .get not .get_utf8. RBC 20060125
1073
        self.control_files.put_utf8('parent', url + '\n')
1150 by Martin Pool
- add new Branch.set_parent and tests
1074
1185.35.11 by Aaron Bentley
Added support for branch nicks
1075
    def tree_config(self):
1076
        return TreeConfig(self)
1077
1185.66.8 by Aaron Bentley
Applied Jelmer's patch to make clone a branch operation
1078
    def _get_truncated_history(self, revision_id):
1079
        history = self.revision_history()
1080
        if revision_id is None:
1081
            return history
1082
        try:
1083
            idx = history.index(revision_id)
1084
        except ValueError:
1085
            raise InvalidRevisionId(revision_id=revision, branch=self)
1086
        return history[:idx+1]
1087
1088
    @needs_read_lock
1089
    def _clone_weave(self, to_location, revision=None, basis_branch=None):
1534.4.28 by Robert Collins
first cut at merge from integration.
1090
        # prevent leakage
1091
        from bzrlib.workingtree import WorkingTree
1185.66.8 by Aaron Bentley
Applied Jelmer's patch to make clone a branch operation
1092
        assert isinstance(to_location, basestring)
1093
        if basis_branch is not None:
1094
            note("basis_branch is not supported for fast weave copy yet.")
1095
1096
        history = self._get_truncated_history(revision)
1097
        if not bzrlib.osutils.lexists(to_location):
1098
            os.mkdir(to_location)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1099
        bzrdir_to = self.bzrdir._format.initialize(to_location)
1100
        self.repository.clone(bzrdir_to)
1101
        branch_to = bzrdir_to.create_branch()
1185.66.8 by Aaron Bentley
Applied Jelmer's patch to make clone a branch operation
1102
        mutter("copy branch from %s to %s", self, branch_to)
1103
1185.65.15 by Robert Collins
Merge from integration.
1104
        # FIXME duplicate code with base .clone().
1534.4.28 by Robert Collins
first cut at merge from integration.
1105
        # .. would template method be useful here?  RBC 20051207
1185.66.8 by Aaron Bentley
Applied Jelmer's patch to make clone a branch operation
1106
        branch_to.set_parent(self.base)
1185.65.15 by Robert Collins
Merge from integration.
1107
        branch_to.append_revision(*history)
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
1108
        WorkingTree.create(branch_to, branch_to.base)
1185.66.8 by Aaron Bentley
Applied Jelmer's patch to make clone a branch operation
1109
        mutter("copied")
1110
        return branch_to
1111
1534.4.1 by Robert Collins
Allow parameterisation of the branch initialisation for bzrlib.
1112
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
1113
class BranchTestProviderAdapter(object):
1114
    """A tool to generate a suite testing multiple branch formats at once.
1115
1116
    This is done by copying the test once for each transport and injecting
1117
    the transport_server, transport_readonly_server, and branch_format
1118
    classes into each copy. Each copy is also given a new id() to make it
1119
    easy to identify.
1120
    """
1121
1122
    def __init__(self, transport_server, transport_readonly_server, formats):
1123
        self._transport_server = transport_server
1124
        self._transport_readonly_server = transport_readonly_server
1125
        self._formats = formats
1126
    
1127
    def adapt(self, test):
1128
        result = TestSuite()
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1129
        for branch_format, bzrdir_format in self._formats:
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
1130
            new_test = deepcopy(test)
1131
            new_test.transport_server = self._transport_server
1132
            new_test.transport_readonly_server = self._transport_readonly_server
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1133
            new_test.bzrdir_format = bzrdir_format
1134
            new_test.branch_format = branch_format
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
1135
            def make_new_test_id():
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1136
                new_id = "%s(%s)" % (new_test.id(), branch_format.__class__.__name__)
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
1137
                return lambda: new_id
1138
            new_test.id = make_new_test_id()
1139
            result.addTest(new_test)
1140
        return result
1141
1142
1 by mbp at sourcefrog
import from baz patch-364
1143
######################################################################
1144
# predicates
1145
1146
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1147
@deprecated_function(zero_eight)
1148
def ScratchBranch(*args, **kwargs):
1149
    """See bzrlib.bzrdir.ScratchDir."""
1150
    d = ScratchDir(*args, **kwargs)
1151
    return d.open_branch()
1152
1153
1154
@deprecated_function(zero_eight)
1155
def is_control_file(*args, **kwargs):
1156
    """See bzrlib.workingtree.is_control_file."""
1157
    return bzrlib.workingtree.is_control_file(*args, **kwargs)