~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Andrew Bennetts
  • Date: 2008-07-25 06:42:08 UTC
  • mto: This revision was merged to the branch mainline in revision 3581.
  • Revision ID: andrew.bennetts@canonical.com-20080725064208-ui70gluukdypd4y9
Cherry-pick TipChangeRejected changes from pre-branch-tip-changed-hook loom.

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):
1579
1579
        check_not_reserved_id = _mod_revision.check_not_reserved_id
1580
1580
        for rev_id in rev_history:
1581
1581
            check_not_reserved_id(rev_id)
 
1582
        old_revno, old_revid = self.last_revision_info()
 
1583
        if len(rev_history) == 0:
 
1584
            revid = _mod_revision.NULL_REVISION
 
1585
        else:
 
1586
            revid = rev_history[-1]
 
1587
        self._run_pre_change_branch_tip_hooks(len(rev_history), revid)
1582
1588
        self._write_revision_history(rev_history)
1583
1589
        self._clear_cached_state()
1584
1590
        self._cache_revision_history(rev_history)
1585
1591
        for hook in Branch.hooks['set_rh']:
1586
1592
            hook(self, rev_history)
 
1593
        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1587
1594
 
1588
1595
    def _run_pre_change_branch_tip_hooks(self, new_revno, new_revid):
1589
1596
        """Run the pre_change_branch_tip hooks."""
1594
1601
        params = ChangeBranchTipParams(
1595
1602
            self, old_revno, new_revno, old_revid, new_revid)
1596
1603
        for hook in hooks:
1597
 
            hook(params)
 
1604
            try:
 
1605
                hook(params)
 
1606
            except errors.TipChangeRejected:
 
1607
                raise
 
1608
            except Exception:
 
1609
                exc_info = sys.exc_info()
 
1610
                hook_name = Branch.hooks.get_hook_name(hook)
 
1611
                raise errors.HookFailed(
 
1612
                    'pre_change_branch_tip', hook_name, exc_info)
1598
1613
 
1599
1614
    def _run_post_change_branch_tip_hooks(self, old_revno, old_revid):
1600
1615
        """Run the post_change_branch_tip hooks."""
1620
1635
        be permitted.
1621
1636
        """
1622
1637
        revision_id = _mod_revision.ensure_null(revision_id)
1623
 
        old_revno, old_revid = self.last_revision_info()
1624
1638
        # this old format stores the full history, but this api doesn't
1625
1639
        # provide it, so we must generate, and might as well check it's
1626
1640
        # correct
1627
1641
        history = self._lefthand_history(revision_id)
1628
1642
        if len(history) != revno:
1629
1643
            raise AssertionError('%d != %d' % (len(history), revno))
1630
 
        self._run_pre_change_branch_tip_hooks(revno, revision_id)
1631
1644
        self.set_revision_history(history)
1632
 
        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1633
1645
 
1634
1646
    def _gen_revision_history(self):
1635
1647
        history = self._transport.get_bytes('revision-history').split('\n')