~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2005-08-29 10:57:01 UTC
  • mfrom: (1092.1.41)
  • Revision ID: mbp@sourcefrog.net-20050829105701-7aaa81ecf1bfee05
- merge in merge improvements and additional tests 
  from aaron and lifeless

robertc@robertcollins.net-20050825131100-85772edabc817481

Show diffs side-by-side

added added

removed removed

Lines of Context:
219
219
            self._lock.unlock()
220
220
 
221
221
 
222
 
 
223
222
    def lock_write(self):
224
223
        if self._lock_mode:
225
224
            if self._lock_mode != 'w':
235
234
            self._lock_count = 1
236
235
 
237
236
 
238
 
 
239
237
    def lock_read(self):
240
238
        if self._lock_mode:
241
239
            assert self._lock_mode in ('r', 'w'), \
248
246
            self._lock_mode = 'r'
249
247
            self._lock_count = 1
250
248
                        
251
 
 
252
 
            
253
249
    def unlock(self):
254
250
        if not self._lock_mode:
255
251
            from errors import LockError
262
258
            self._lock = None
263
259
            self._lock_mode = self._lock_count = None
264
260
 
265
 
 
266
261
    def abspath(self, name):
267
262
        """Return absolute filename for something in the branch"""
268
263
        return os.path.join(self.base, name)
269
264
 
270
 
 
271
265
    def relpath(self, path):
272
266
        """Return path relative to this branch of something inside it.
273
267
 
274
268
        Raises an error if path is not in this branch."""
275
269
        return _relpath(self.base, path)
276
270
 
277
 
 
278
271
    def controlfilename(self, file_or_path):
279
272
        """Return location relative to branch."""
280
273
        if isinstance(file_or_path, basestring):
307
300
        else:
308
301
            raise BzrError("invalid controlfile mode %r" % mode)
309
302
 
310
 
 
311
 
 
312
303
    def _make_control(self):
313
304
        from bzrlib.inventory import Inventory
314
305
        from bzrlib.xml import pack_xml
332
323
        # simplicity.
333
324
        pack_xml(Inventory(), self.controlfile('inventory','w'))
334
325
 
335
 
 
336
326
    def _check_format(self):
337
327
        """Check this branch format is supported.
338
328
 
829
819
        ## note("Added %d revisions." % count)
830
820
        pb.clear()
831
821
 
832
 
        
833
 
        
834
822
    def install_revisions(self, other, revision_ids, pb):
835
823
        if hasattr(other.revision_store, "prefetch"):
836
824
            other.revision_store.prefetch(revision_ids)
1414
1402
    """Return a new tree-root file id."""
1415
1403
    return gen_file_id('TREE_ROOT')
1416
1404
 
 
1405
 
 
1406
def pull_loc(branch):
 
1407
    # TODO: Should perhaps just make attribute be 'base' in
 
1408
    # RemoteBranch and Branch?
 
1409
    if hasattr(branch, "baseurl"):
 
1410
        return branch.baseurl
 
1411
    else:
 
1412
        return branch.base
 
1413
 
 
1414
 
 
1415
def copy_branch(branch_from, to_location, revision=None):
 
1416
    """Copy branch_from into the existing directory to_location.
 
1417
 
 
1418
    If revision is not None, the head of the new branch will be revision.
 
1419
    """
 
1420
    from bzrlib.merge import merge
 
1421
    from bzrlib.branch import Branch
 
1422
    br_to = Branch(to_location, init=True)
 
1423
    br_to.set_root_id(branch_from.get_root_id())
 
1424
    if revision is None:
 
1425
        revno = branch_from.revno()
 
1426
    else:
 
1427
        revno, rev_id = branch_from.get_revision_info(revision)
 
1428
    br_to.update_revisions(branch_from, stop_revision=revno)
 
1429
    merge((to_location, -1), (to_location, 0), this_dir=to_location,
 
1430
          check_clean=False, ignore_zero=True)
 
1431
    from_location = pull_loc(branch_from)
 
1432
    br_to.controlfile("x-pull", "wb").write(from_location + "\n")
 
1433