~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
596
596
            raise InvalidRevisionNumber(revno)
597
597
 
598
598
    @needs_read_lock
599
 
    def clone(self, *args, **kwargs):
 
599
    def clone(self, to_bzrdir, revision_id=None):
600
600
        """Clone this branch into to_bzrdir preserving all semantic values.
601
601
        
602
602
        revision_id: if not None, the revision history in the new branch will
603
603
                     be truncated to end with revision_id.
604
604
        """
605
 
        # for API compatibility, until 0.8 releases we provide the old api:
606
 
        # def clone(self, to_location, revision=None, basis_branch=None, to_branch_format=None):
607
 
        # after 0.8 releases, the *args and **kwargs should be changed:
608
 
        # def clone(self, to_bzrdir, revision_id=None):
609
 
        if (kwargs.get('to_location', None) or
610
 
            kwargs.get('revision', None) or
611
 
            kwargs.get('basis_branch', None) or
612
 
            (len(args) and isinstance(args[0], basestring))):
613
 
            # backwards compatibility api:
614
 
            warn("Branch.clone() has been deprecated for BzrDir.clone() from"
615
 
                 " bzrlib 0.8.", DeprecationWarning, stacklevel=3)
616
 
            # get basis_branch
617
 
            if len(args) > 2:
618
 
                basis_branch = args[2]
619
 
            else:
620
 
                basis_branch = kwargs.get('basis_branch', None)
621
 
            if basis_branch:
622
 
                basis = basis_branch.bzrdir
623
 
            else:
624
 
                basis = None
625
 
            # get revision
626
 
            if len(args) > 1:
627
 
                revision_id = args[1]
628
 
            else:
629
 
                revision_id = kwargs.get('revision', None)
630
 
            # get location
631
 
            if len(args):
632
 
                url = args[0]
633
 
            else:
634
 
                # no default to raise if not provided.
635
 
                url = kwargs.get('to_location')
636
 
            return self.bzrdir.clone(url,
637
 
                                     revision_id=revision_id,
638
 
                                     basis=basis).open_branch()
639
 
        # new cleaner api.
640
 
        # generate args by hand 
641
 
        if len(args) > 1:
642
 
            revision_id = args[1]
643
 
        else:
644
 
            revision_id = kwargs.get('revision_id', None)
645
 
        if len(args):
646
 
            to_bzrdir = args[0]
647
 
        else:
648
 
            # no default to raise if not provided.
649
 
            to_bzrdir = kwargs.get('to_bzrdir')
650
605
        result = self._format.initialize(to_bzrdir)
651
606
        self.copy_content_into(result, revision_id=revision_id)
652
607
        return  result
1236
1191
    it's writable, and can be accessed via the normal filesystem API.
1237
1192
    """
1238
1193
    
1239
 
    def __init__(self, transport=DEPRECATED_PARAMETER, init=DEPRECATED_PARAMETER,
1240
 
                 relax_version_check=DEPRECATED_PARAMETER, _format=None,
 
1194
    def __init__(self, _format=None,
1241
1195
                 _control_files=None, a_bzrdir=None, _repository=None):
1242
 
        """Create new branch object at a particular location.
1243
 
 
1244
 
        transport -- A Transport object, defining how to access files.
1245
 
        
1246
 
        init -- If True, create new control files in a previously
1247
 
             unversioned directory.  If False, the branch must already
1248
 
             be versioned.
1249
 
 
1250
 
        relax_version_check -- If true, the usual check for the branch
1251
 
            version is not applied.  This is intended only for
1252
 
            upgrade/recovery type use; it's not guaranteed that
1253
 
            all operations will work on old format branches.
1254
 
        """
 
1196
        """Create new branch object at a particular location."""
1255
1197
        Branch.__init__(self)
1256
1198
        if a_bzrdir is None:
1257
 
            self.bzrdir = bzrdir.BzrDir.open(transport.base)
 
1199
            raise ValueError('a_bzrdir must be supplied')
1258
1200
        else:
1259
1201
            self.bzrdir = a_bzrdir
1260
1202
        # self._transport used to point to the directory containing the
1266
1208
            raise ValueError('BzrBranch _control_files is None')
1267
1209
        self.control_files = _control_files
1268
1210
        self._transport = _control_files._transport
1269
 
        if deprecated_passed(init):
1270
 
            warn("BzrBranch.__init__(..., init=XXX): The init parameter is "
1271
 
                 "deprecated as of bzr 0.8. Please use Branch.create().",
1272
 
                 DeprecationWarning,
1273
 
                 stacklevel=2)
1274
 
            if init:
1275
 
                # this is slower than before deprecation, oh well never mind.
1276
 
                # -> its deprecated.
1277
 
                self._initialize(transport.base)
1278
 
        self._check_format(_format)
1279
 
        if deprecated_passed(relax_version_check):
1280
 
            warn("BzrBranch.__init__(..., relax_version_check=XXX_: The "
1281
 
                 "relax_version_check parameter is deprecated as of bzr 0.8. "
1282
 
                 "Please use BzrDir.open_downlevel, or a BzrBranchFormat's "
1283
 
                 "open() method.",
1284
 
                 DeprecationWarning,
1285
 
                 stacklevel=2)
1286
 
            if (not relax_version_check
1287
 
                and not self._format.is_supported()):
1288
 
                raise errors.UnsupportedFormatError(format=fmt)
1289
 
        if deprecated_passed(transport):
1290
 
            warn("BzrBranch.__init__(transport=XXX...): The transport "
1291
 
                 "parameter is deprecated as of bzr 0.8. "
1292
 
                 "Please use Branch.open, or bzrdir.open_branch().",
1293
 
                 DeprecationWarning,
1294
 
                 stacklevel=2)
1295
1211
        self.repository = _repository
1296
1212
 
1297
1213
    def __str__(self):
1309
1225
        """See Branch.abspath."""
1310
1226
        return self.control_files._transport.abspath(name)
1311
1227
 
1312
 
    def _check_format(self, format):
1313
 
        """Identify the branch format if needed.
1314
 
 
1315
 
        The format is stored as a reference to the format object in
1316
 
        self._format for code that needs to check it later.
1317
 
 
1318
 
        The format parameter is either None or the branch format class
1319
 
        used to open this branch.
1320
 
 
1321
 
        FIXME: DELETE THIS METHOD when pre 0.8 support is removed.
1322
 
        """
1323
 
        if format is None:
1324
 
            format = BranchFormat.find_format(self.bzrdir)
1325
 
        self._format = format
1326
 
        mutter("got branch format %s", self._format)
1327
1228
 
1328
1229
    @deprecated_method(zero_sixteen)
1329
1230
    @needs_read_lock