~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

(jelmer) Deprecate {lazy_,}register_filter_stack_map. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
766
766
        """Print `file` to stdout."""
767
767
        raise NotImplementedError(self.print_file)
768
768
 
769
 
    @deprecated_method(deprecated_in((2, 4, 0)))
770
 
    def set_revision_history(self, rev_history):
771
 
        """See Branch.set_revision_history."""
772
 
        self._set_revision_history(rev_history)
773
 
 
774
 
    @needs_write_lock
775
 
    def _set_revision_history(self, rev_history):
776
 
        if len(rev_history) == 0:
777
 
            revid = _mod_revision.NULL_REVISION
778
 
        else:
779
 
            revid = rev_history[-1]
780
 
        if rev_history != self._lefthand_history(revid):
781
 
            raise errors.NotLefthandHistory(rev_history)
782
 
        self.set_last_revision_info(len(rev_history), revid)
783
 
        self._cache_revision_history(rev_history)
784
 
        for hook in Branch.hooks['set_rh']:
785
 
            hook(self, rev_history)
786
 
 
787
769
    @needs_write_lock
788
770
    def set_last_revision_info(self, revno, revision_id):
789
771
        """Set the last revision of this branch.
986
968
        This means the next call to revision_history will need to call
987
969
        _gen_revision_history.
988
970
 
989
 
        This API is semi-public; it only for use by subclasses, all other code
990
 
        should consider it to be private.
 
971
        This API is semi-public; it is only for use by subclasses, all other
 
972
        code should consider it to be private.
991
973
        """
992
974
        self._revision_history_cache = None
993
975
        self._revision_id_to_revno_cache = None
1013
995
        """
1014
996
        raise NotImplementedError(self._gen_revision_history)
1015
997
 
1016
 
    @deprecated_method(deprecated_in((2, 5, 0)))
1017
 
    @needs_read_lock
1018
 
    def revision_history(self):
1019
 
        """Return sequence of revision ids on this branch.
1020
 
 
1021
 
        This method will cache the revision history for as long as it is safe to
1022
 
        do so.
1023
 
        """
1024
 
        return self._revision_history()
1025
 
 
1026
998
    def _revision_history(self):
1027
999
        if 'evil' in debug.debug_flags:
1028
1000
            mutter_callsite(3, "revision_history scales with history.")
1774
1746
class BranchHooks(Hooks):
1775
1747
    """A dictionary mapping hook name to a list of callables for branch hooks.
1776
1748
 
1777
 
    e.g. ['set_rh'] Is the list of items to be called when the
1778
 
    set_revision_history function is invoked.
 
1749
    e.g. ['post_push'] Is the list of items to be called when the
 
1750
    push function is invoked.
1779
1751
    """
1780
1752
 
1781
1753
    def __init__(self):
1785
1757
        notified.
1786
1758
        """
1787
1759
        Hooks.__init__(self, "bzrlib.branch", "Branch.hooks")
1788
 
        self.add_hook('set_rh',
1789
 
            "Invoked whenever the revision history has been set via "
1790
 
            "set_revision_history. The api signature is (branch, "
1791
 
            "revision_history), and the branch will be write-locked. "
1792
 
            "The set_rh hook can be expensive for bzr to trigger, a better "
1793
 
            "hook to use is Branch.post_change_branch_tip.", (0, 15))
1794
1760
        self.add_hook('open',
1795
1761
            "Called with the Branch object that has been opened after a "
1796
1762
            "branch is opened.", (1, 8))
2529
2495
 
2530
2496
    @only_raises(errors.LockNotHeld, errors.LockBroken)
2531
2497
    def unlock(self):
2532
 
        if self.conf_store is not None:
 
2498
        if self.control_files._lock_count == 1 and self.conf_store is not None:
2533
2499
            self.conf_store.save_changes()
2534
2500
        try:
2535
2501
            self.control_files.unlock()
2747
2713
        else:
2748
2714
            return (0, _mod_revision.NULL_REVISION)
2749
2715
 
2750
 
    @deprecated_method(deprecated_in((2, 4, 0)))
2751
 
    @needs_write_lock
2752
 
    def set_revision_history(self, rev_history):
2753
 
        """See Branch.set_revision_history."""
2754
 
        self._set_revision_history(rev_history)
2755
 
 
2756
2716
    def _set_revision_history(self, rev_history):
2757
2717
        if 'evil' in debug.debug_flags:
2758
2718
            mutter_callsite(3, "set_revision_history scales with history.")
2771
2731
        self._write_revision_history(rev_history)
2772
2732
        self._clear_cached_state()
2773
2733
        self._cache_revision_history(rev_history)
2774
 
        for hook in Branch.hooks['set_rh']:
2775
 
            hook(self, rev_history)
2776
2734
        if Branch.hooks['post_change_branch_tip']:
2777
2735
            self._run_post_change_branch_tip_hooks(old_revno, old_revid)
2778
2736