/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: John Arbash Meinel
  • Date: 2008-09-05 03:11:40 UTC
  • mfrom: (3691 +trunk)
  • mto: (3697.7.4 1.7)
  • mto: This revision was merged to the branch mainline in revision 3748.
  • Revision ID: john@arbash-meinel.com-20080905031140-hj0adlcf30l7i99v
Merge in bzr.dev 3691

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
 
18
import sys
 
19
 
18
20
from bzrlib.lazy_import import lazy_import
19
21
lazy_import(globals(), """
20
22
from itertools import chain
229
231
        """
230
232
        self.control_files.dont_leave_in_place()
231
233
 
232
 
    @deprecated_method(deprecated_in((0, 16, 0)))
233
 
    def abspath(self, name):
234
 
        """Return absolute filename for something in the branch
235
 
        
236
 
        XXX: Robert Collins 20051017 what is this used for? why is it a branch
237
 
        method and not a tree method.
238
 
        """
239
 
        raise NotImplementedError(self.abspath)
240
 
 
241
234
    def bind(self, other):
242
235
        """Bind the local branch the other branch.
243
236
 
533
526
        finally:
534
527
            other.unlock()
535
528
 
536
 
 
537
 
 
538
529
    def revision_id_to_revno(self, revision_id):
539
530
        """Given a revision id, return its revno"""
540
531
        if _mod_revision.is_null(revision_id):
576
567
        """Return `Tree` object for last revision."""
577
568
        return self.repository.revision_tree(self.last_revision())
578
569
 
579
 
    def rename_one(self, from_rel, to_rel):
580
 
        """Rename one file.
581
 
 
582
 
        This can change the directory or the filename or both.
583
 
        """
584
 
        raise NotImplementedError(self.rename_one)
585
 
 
586
 
    def move(self, from_paths, to_name):
587
 
        """Rename files.
588
 
 
589
 
        to_name must exist as a versioned directory.
590
 
 
591
 
        If to_name exists and is a directory, the files are moved into
592
 
        it, keeping their old names.  If it is a directory, 
593
 
 
594
 
        Note that to_name is only the last component of the new name;
595
 
        this doesn't change the directory.
596
 
 
597
 
        This returns a list of (from_path, to_path) pairs for each
598
 
        entry that is moved.
599
 
        """
600
 
        raise NotImplementedError(self.move)
601
 
 
602
570
    def get_parent(self):
603
571
        """Return the parent location of the branch.
604
572
 
704
672
        revision_id: if not None, the revision history in the new branch will
705
673
                     be truncated to end with revision_id.
706
674
        """
707
 
        result = self._format.initialize(to_bzrdir)
 
675
        result = to_bzrdir.create_branch()
708
676
        self.copy_content_into(result, revision_id=revision_id)
709
677
        return  result
710
678
 
711
679
    @needs_read_lock
712
680
    def sprout(self, to_bzrdir, revision_id=None):
713
681
        """Create a new line of development from the branch, into to_bzrdir.
714
 
        
 
682
 
 
683
        to_bzrdir controls the branch format.
 
684
 
715
685
        revision_id: if not None, the revision history in the new branch will
716
686
                     be truncated to end with revision_id.
717
687
        """
718
 
        result = self._format.initialize(to_bzrdir)
 
688
        result = to_bzrdir.create_branch()
719
689
        self.copy_content_into(result, revision_id=revision_id)
720
690
        result.set_parent(self.bzrdir.root_transport.base)
721
691
        return result
735
705
        """
736
706
        if revision_id == _mod_revision.NULL_REVISION:
737
707
            new_history = []
738
 
        new_history = self.revision_history()
 
708
        else:
 
709
            new_history = self.revision_history()
739
710
        if revision_id is not None and new_history != []:
740
711
            try:
741
712
                new_history = new_history[:new_history.index(revision_id) + 1]
899
870
        elif relation == 'a_descends_from_b':
900
871
            return False
901
872
        else:
902
 
            raise AssertionError("invalid heads: %r" % heads)
 
873
            raise AssertionError("invalid relation: %r" % (relation,))
903
874
 
904
875
    def _revision_relations(self, revision_a, revision_b, graph):
905
876
        """Determine the relationship between two revisions.
915
886
        elif heads == set([revision_a]):
916
887
            return 'a_descends_from_b'
917
888
        else:
918
 
            raise AssertionError("invalid heads: %r" % heads)
 
889
            raise AssertionError("invalid heads: %r" % (heads,))
919
890
 
920
891
 
921
892
class BranchFormat(object):
1061
1032
    def set_default_format(klass, format):
1062
1033
        klass._default_format = format
1063
1034
 
 
1035
    def supports_stacking(self):
 
1036
        """True if this format records a stacked-on branch."""
 
1037
        return False
 
1038
 
1064
1039
    @classmethod
1065
1040
    def unregister_format(klass, format):
1066
1041
        del klass._formats[format.get_format_string()]
1368
1343
        self._matchingbzrdir.repository_format = \
1369
1344
            RepositoryFormatPackDevelopment1Subtree()
1370
1345
 
 
1346
    def supports_stacking(self):
 
1347
        return True
 
1348
 
1371
1349
 
1372
1350
class BranchReferenceFormat(BranchFormat):
1373
1351
    """Bzr branch reference format.
1513
1491
 
1514
1492
    base = property(_get_base, doc="The URL for the root of this branch.")
1515
1493
 
1516
 
    @deprecated_method(deprecated_in((0, 16, 0)))
1517
 
    def abspath(self, name):
1518
 
        """See Branch.abspath."""
1519
 
        return self._transport.abspath(name)
1520
 
 
1521
1494
    def is_locked(self):
1522
1495
        return self.control_files.is_locked()
1523
1496
 
1579
1552
        check_not_reserved_id = _mod_revision.check_not_reserved_id
1580
1553
        for rev_id in rev_history:
1581
1554
            check_not_reserved_id(rev_id)
 
1555
        if Branch.hooks['post_change_branch_tip']:
 
1556
            # Don't calculate the last_revision_info() if there are no hooks
 
1557
            # that will use it.
 
1558
            old_revno, old_revid = self.last_revision_info()
 
1559
        if len(rev_history) == 0:
 
1560
            revid = _mod_revision.NULL_REVISION
 
1561
        else:
 
1562
            revid = rev_history[-1]
 
1563
        self._run_pre_change_branch_tip_hooks(len(rev_history), revid)
1582
1564
        self._write_revision_history(rev_history)
1583
1565
        self._clear_cached_state()
1584
1566
        self._cache_revision_history(rev_history)
1585
1567
        for hook in Branch.hooks['set_rh']:
1586
1568
            hook(self, rev_history)
 
1569
        if Branch.hooks['post_change_branch_tip']:
 
1570
            self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1587
1571
 
1588
1572
    def _run_pre_change_branch_tip_hooks(self, new_revno, new_revid):
1589
1573
        """Run the pre_change_branch_tip hooks."""
1594
1578
        params = ChangeBranchTipParams(
1595
1579
            self, old_revno, new_revno, old_revid, new_revid)
1596
1580
        for hook in hooks:
1597
 
            hook(params)
 
1581
            try:
 
1582
                hook(params)
 
1583
            except errors.TipChangeRejected:
 
1584
                raise
 
1585
            except Exception:
 
1586
                exc_info = sys.exc_info()
 
1587
                hook_name = Branch.hooks.get_hook_name(hook)
 
1588
                raise errors.HookFailed(
 
1589
                    'pre_change_branch_tip', hook_name, exc_info)
1598
1590
 
1599
1591
    def _run_post_change_branch_tip_hooks(self, old_revno, old_revid):
1600
1592
        """Run the post_change_branch_tip hooks."""
1620
1612
        be permitted.
1621
1613
        """
1622
1614
        revision_id = _mod_revision.ensure_null(revision_id)
1623
 
        old_revno, old_revid = self.last_revision_info()
1624
1615
        # this old format stores the full history, but this api doesn't
1625
1616
        # provide it, so we must generate, and might as well check it's
1626
1617
        # correct
1627
1618
        history = self._lefthand_history(revision_id)
1628
1619
        if len(history) != revno:
1629
1620
            raise AssertionError('%d != %d' % (len(history), revno))
1630
 
        self._run_pre_change_branch_tip_hooks(revno, revision_id)
1631
1621
        self.set_revision_history(history)
1632
 
        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1633
1622
 
1634
1623
    def _gen_revision_history(self):
1635
1624
        history = self._transport.get_bytes('revision-history').split('\n')