~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Andrew Bennetts
  • Date: 2008-08-07 00:25:38 UTC
  • mfrom: (3612 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3613.
  • Revision ID: andrew.bennetts@canonical.com-20080807002538-mtl1fcgy2fdabha4
Merge from bzr.dev.

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
533
535
        finally:
534
536
            other.unlock()
535
537
 
536
 
 
537
 
 
538
538
    def revision_id_to_revno(self, revision_id):
539
539
        """Given a revision id, return its revno"""
540
540
        if _mod_revision.is_null(revision_id):
899
899
        elif relation == 'a_descends_from_b':
900
900
            return False
901
901
        else:
902
 
            raise AssertionError("invalid heads: %r" % heads)
 
902
            raise AssertionError("invalid relation: %r" % (relation,))
903
903
 
904
904
    def _revision_relations(self, revision_a, revision_b, graph):
905
905
        """Determine the relationship between two revisions.
915
915
        elif heads == set([revision_a]):
916
916
            return 'a_descends_from_b'
917
917
        else:
918
 
            raise AssertionError("invalid heads: %r" % heads)
 
918
            raise AssertionError("invalid heads: %r" % (heads,))
919
919
 
920
920
 
921
921
class BranchFormat(object):
1061
1061
    def set_default_format(klass, format):
1062
1062
        klass._default_format = format
1063
1063
 
 
1064
    def supports_stacking(self):
 
1065
        """True if this format records a stacked-on branch."""
 
1066
        return False
 
1067
 
1064
1068
    @classmethod
1065
1069
    def unregister_format(klass, format):
1066
1070
        del klass._formats[format.get_format_string()]
1368
1372
        self._matchingbzrdir.repository_format = \
1369
1373
            RepositoryFormatPackDevelopment1Subtree()
1370
1374
 
 
1375
    def supports_stacking(self):
 
1376
        return True
 
1377
 
1371
1378
 
1372
1379
class BranchReferenceFormat(BranchFormat):
1373
1380
    """Bzr branch reference format.
1579
1586
        check_not_reserved_id = _mod_revision.check_not_reserved_id
1580
1587
        for rev_id in rev_history:
1581
1588
            check_not_reserved_id(rev_id)
 
1589
        if Branch.hooks['post_change_branch_tip']:
 
1590
            # Don't calculate the last_revision_info() if there are no hooks
 
1591
            # that will use it.
 
1592
            old_revno, old_revid = self.last_revision_info()
 
1593
        if len(rev_history) == 0:
 
1594
            revid = _mod_revision.NULL_REVISION
 
1595
        else:
 
1596
            revid = rev_history[-1]
 
1597
        self._run_pre_change_branch_tip_hooks(len(rev_history), revid)
1582
1598
        self._write_revision_history(rev_history)
1583
1599
        self._clear_cached_state()
1584
1600
        self._cache_revision_history(rev_history)
1585
1601
        for hook in Branch.hooks['set_rh']:
1586
1602
            hook(self, rev_history)
 
1603
        if Branch.hooks['post_change_branch_tip']:
 
1604
            self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1587
1605
 
1588
1606
    def _run_pre_change_branch_tip_hooks(self, new_revno, new_revid):
1589
1607
        """Run the pre_change_branch_tip hooks."""
1594
1612
        params = ChangeBranchTipParams(
1595
1613
            self, old_revno, new_revno, old_revid, new_revid)
1596
1614
        for hook in hooks:
1597
 
            hook(params)
 
1615
            try:
 
1616
                hook(params)
 
1617
            except errors.TipChangeRejected:
 
1618
                raise
 
1619
            except Exception:
 
1620
                exc_info = sys.exc_info()
 
1621
                hook_name = Branch.hooks.get_hook_name(hook)
 
1622
                raise errors.HookFailed(
 
1623
                    'pre_change_branch_tip', hook_name, exc_info)
1598
1624
 
1599
1625
    def _run_post_change_branch_tip_hooks(self, old_revno, old_revid):
1600
1626
        """Run the post_change_branch_tip hooks."""
1620
1646
        be permitted.
1621
1647
        """
1622
1648
        revision_id = _mod_revision.ensure_null(revision_id)
1623
 
        old_revno, old_revid = self.last_revision_info()
1624
1649
        # this old format stores the full history, but this api doesn't
1625
1650
        # provide it, so we must generate, and might as well check it's
1626
1651
        # correct
1627
1652
        history = self._lefthand_history(revision_id)
1628
1653
        if len(history) != revno:
1629
1654
            raise AssertionError('%d != %d' % (len(history), revno))
1630
 
        self._run_pre_change_branch_tip_hooks(revno, revision_id)
1631
1655
        self.set_revision_history(history)
1632
 
        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1633
1656
 
1634
1657
    def _gen_revision_history(self):
1635
1658
        history = self._transport.get_bytes('revision-history').split('\n')