~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2005-09-01 12:59:42 UTC
  • Revision ID: mbp@sourcefrog.net-20050901125942-25443d6a887b9fab
- better explanation when merge fails with AmbiguousBase

Show diffs side-by-side

added added

removed removed

Lines of Context:
1280
1280
            self.unlock()
1281
1281
 
1282
1282
 
 
1283
    def get_parent(self):
 
1284
        """Return the parent location of the branch.
 
1285
 
 
1286
        This is the default location for push/pull/missing.  The usual
 
1287
        pattern is that the user can override it by specifying a
 
1288
        location.
 
1289
        """
 
1290
        import errno
 
1291
        _locs = ['parent', 'pull', 'x-pull']
 
1292
        for l in _locs:
 
1293
            try:
 
1294
                return self.controlfile(l, 'r').read().strip('\n')
 
1295
            except IOError, e:
 
1296
                if e.errno != errno.ENOENT:
 
1297
                    raise
 
1298
        return None
 
1299
 
 
1300
 
 
1301
    def set_parent(self, url):
 
1302
        # TODO: Maybe delete old location files?
 
1303
        from bzrlib.atomicfile import AtomicFile
 
1304
        self.lock_write()
 
1305
        try:
 
1306
            f = AtomicFile(self.controlfilename('parent'))
 
1307
            try:
 
1308
                f.write(url + '\n')
 
1309
                f.commit()
 
1310
            finally:
 
1311
                f.close()
 
1312
        finally:
 
1313
            self.unlock()
 
1314
 
 
1315
        
 
1316
 
1283
1317
 
1284
1318
class ScratchBranch(Branch):
1285
1319
    """Special test class: a branch that cleans up after itself.
1327
1361
        os.rmdir(base)
1328
1362
        copytree(self.base, base, symlinks=True)
1329
1363
        return ScratchBranch(base=base)
 
1364
 
 
1365
 
1330
1366
        
1331
1367
    def __del__(self):
1332
1368
        self.destroy()
1415
1451
def copy_branch(branch_from, to_location, revision=None):
1416
1452
    """Copy branch_from into the existing directory to_location.
1417
1453
 
1418
 
    If revision is not None, the head of the new branch will be revision.
 
1454
    revision
 
1455
        If not None, only revisions up to this point will be copied.
 
1456
        The head of the new branch will be that revision.
 
1457
 
 
1458
    to_location
 
1459
        The name of a local directory that exists but is empty.
1419
1460
    """
1420
1461
    from bzrlib.merge import merge
1421
1462
    from bzrlib.branch import Branch
 
1463
 
 
1464
    assert isinstance(branch_from, Branch)
 
1465
    assert isinstance(to_location, basestring)
 
1466
    
1422
1467
    br_to = Branch(to_location, init=True)
1423
1468
    br_to.set_root_id(branch_from.get_root_id())
1424
1469
    if revision is None:
1428
1473
    br_to.update_revisions(branch_from, stop_revision=revno)
1429
1474
    merge((to_location, -1), (to_location, 0), this_dir=to_location,
1430
1475
          check_clean=False, ignore_zero=True)
 
1476
    
1431
1477
    from_location = pull_loc(branch_from)
1432
 
    br_to.controlfile("x-pull", "wb").write(from_location + "\n")
 
1478
    br_to.set_parent(pull_loc(branch_from))
1433
1479