~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Jelmer Vernooij
  • Date: 2012-04-16 11:08:11 UTC
  • mfrom: (6521 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6522.
  • Revision ID: jelmer@samba.org-20120416110811-0y996ihqy9o2bb1t
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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.")
1617
1589
    def __ne__(self, other):
1618
1590
        return not (self == other)
1619
1591
 
1620
 
    @classmethod
1621
 
    @deprecated_method(deprecated_in((2, 4, 0)))
1622
 
    def get_default_format(klass):
1623
 
        """Return the current default format."""
1624
 
        return format_registry.get_default()
1625
 
 
1626
 
    @classmethod
1627
 
    @deprecated_method(deprecated_in((2, 4, 0)))
1628
 
    def get_formats(klass):
1629
 
        """Get all the known formats.
1630
 
 
1631
 
        Warning: This triggers a load of all lazy registered formats: do not
1632
 
        use except when that is desireed.
1633
 
        """
1634
 
        return format_registry._get_all()
1635
 
 
1636
1592
    def get_reference(self, controldir, name=None):
1637
1593
        """Get the target reference of the branch in controldir.
1638
1594
 
1726
1682
        """
1727
1683
        raise NotImplementedError(self.open)
1728
1684
 
1729
 
    @classmethod
1730
 
    @deprecated_method(deprecated_in((2, 4, 0)))
1731
 
    def register_format(klass, format):
1732
 
        """Register a metadir format.
1733
 
 
1734
 
        See MetaDirBranchFormatFactory for the ability to register a format
1735
 
        without loading the code the format needs until it is actually used.
1736
 
        """
1737
 
        format_registry.register(format)
1738
 
 
1739
 
    @classmethod
1740
 
    @deprecated_method(deprecated_in((2, 4, 0)))
1741
 
    def set_default_format(klass, format):
1742
 
        format_registry.set_default(format)
1743
 
 
1744
1685
    def supports_set_append_revisions_only(self):
1745
1686
        """True if this format supports set_append_revisions_only."""
1746
1687
        return False
1805
1746
class BranchHooks(Hooks):
1806
1747
    """A dictionary mapping hook name to a list of callables for branch hooks.
1807
1748
 
1808
 
    e.g. ['set_rh'] Is the list of items to be called when the
1809
 
    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.
1810
1751
    """
1811
1752
 
1812
1753
    def __init__(self):
1816
1757
        notified.
1817
1758
        """
1818
1759
        Hooks.__init__(self, "bzrlib.branch", "Branch.hooks")
1819
 
        self.add_hook('set_rh',
1820
 
            "Invoked whenever the revision history has been set via "
1821
 
            "set_revision_history. The api signature is (branch, "
1822
 
            "revision_history), and the branch will be write-locked. "
1823
 
            "The set_rh hook can be expensive for bzr to trigger, a better "
1824
 
            "hook to use is Branch.post_change_branch_tip.", (0, 15))
1825
1760
        self.add_hook('open',
1826
1761
            "Called with the Branch object that has been opened after a "
1827
1762
            "branch is opened.", (1, 8))
2045
1980
 
2046
1981
    def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
2047
1982
                           repository=None):
2048
 
        """Initialize a branch in a bzrdir, with specified files
 
1983
        """Initialize a branch in a control dir, with specified files
2049
1984
 
2050
1985
        :param a_bzrdir: The bzrdir to initialize the branch in
2051
1986
        :param utf8_files: The files to create as a list of
2481
2416
        self.control_files = _control_files
2482
2417
        self._transport = _control_files._transport
2483
2418
        self.repository = _repository
 
2419
        self.conf_store = None
2484
2420
        Branch.__init__(self, possible_transports)
2485
2421
 
2486
2422
    def __str__(self):
2502
2438
        return _mod_config.TransportConfig(self._transport, 'branch.conf')
2503
2439
 
2504
2440
    def _get_config_store(self):
2505
 
        return _mod_config.BranchStore(self)
 
2441
        if self.conf_store is None:
 
2442
            self.conf_store =  _mod_config.BranchStore(self)
 
2443
        return self.conf_store
2506
2444
 
2507
2445
    def is_locked(self):
2508
2446
        return self.control_files.is_locked()
2557
2495
 
2558
2496
    @only_raises(errors.LockNotHeld, errors.LockBroken)
2559
2497
    def unlock(self):
 
2498
        if self.control_files._lock_count == 1 and self.conf_store is not None:
 
2499
            self.conf_store.save_changes()
2560
2500
        try:
2561
2501
            self.control_files.unlock()
2562
2502
        finally:
2773
2713
        else:
2774
2714
            return (0, _mod_revision.NULL_REVISION)
2775
2715
 
2776
 
    @deprecated_method(deprecated_in((2, 4, 0)))
2777
 
    @needs_write_lock
2778
 
    def set_revision_history(self, rev_history):
2779
 
        """See Branch.set_revision_history."""
2780
 
        self._set_revision_history(rev_history)
2781
 
 
2782
2716
    def _set_revision_history(self, rev_history):
2783
2717
        if 'evil' in debug.debug_flags:
2784
2718
            mutter_callsite(3, "set_revision_history scales with history.")
2797
2731
        self._write_revision_history(rev_history)
2798
2732
        self._clear_cached_state()
2799
2733
        self._cache_revision_history(rev_history)
2800
 
        for hook in Branch.hooks['set_rh']:
2801
 
            hook(self, rev_history)
2802
2734
        if Branch.hooks['post_change_branch_tip']:
2803
2735
            self._run_post_change_branch_tip_hooks(old_revno, old_revid)
2804
2736
 
3142
3074
    :ivar tag_updates: A dict with new tags, see BasicTags.merge_to
3143
3075
    """
3144
3076
 
3145
 
    @deprecated_method(deprecated_in((2, 3, 0)))
3146
 
    def __int__(self):
3147
 
        """Return the relative change in revno.
3148
 
 
3149
 
        :deprecated: Use `new_revno` and `old_revno` instead.
3150
 
        """
3151
 
        return self.new_revno - self.old_revno
3152
 
 
3153
3077
    def report(self, to_file):
3154
3078
        tag_conflicts = getattr(self, "tag_conflicts", None)
3155
3079
        tag_updates = getattr(self, "tag_updates", None)
3185
3109
        target, otherwise it will be None.
3186
3110
    """
3187
3111
 
3188
 
    @deprecated_method(deprecated_in((2, 3, 0)))
3189
 
    def __int__(self):
3190
 
        """Return the relative change in revno.
3191
 
 
3192
 
        :deprecated: Use `new_revno` and `old_revno` instead.
3193
 
        """
3194
 
        return self.new_revno - self.old_revno
3195
 
 
3196
3112
    def report(self, to_file):
3197
3113
        # TODO: This function gets passed a to_file, but then
3198
3114
        # ignores it and calls note() instead. This is also
3245
3161
 
3246
3162
        # Copy source data into target
3247
3163
        new_branch._write_last_revision_info(*branch.last_revision_info())
3248
 
        new_branch.set_parent(branch.get_parent())
3249
 
        new_branch.set_bound_location(branch.get_bound_location())
3250
 
        new_branch.set_push_location(branch.get_push_location())
 
3164
        new_branch.lock_write()
 
3165
        try:
 
3166
            new_branch.set_parent(branch.get_parent())
 
3167
            new_branch.set_bound_location(branch.get_bound_location())
 
3168
            new_branch.set_push_location(branch.get_push_location())
 
3169
        finally:
 
3170
            new_branch.unlock()
3251
3171
 
3252
3172
        # New branch has no tags by default
3253
3173
        new_branch.tags._set_tag_dict({})
3259
3179
 
3260
3180
        # Clean up old files
3261
3181
        new_branch._transport.delete('revision-history')
 
3182
        branch.lock_write()
3262
3183
        try:
3263
 
            branch.set_parent(None)
3264
 
        except errors.NoSuchFile:
3265
 
            pass
3266
 
        branch.set_bound_location(None)
 
3184
            try:
 
3185
                branch.set_parent(None)
 
3186
            except errors.NoSuchFile:
 
3187
                pass
 
3188
            branch.set_bound_location(None)
 
3189
        finally:
 
3190
            branch.unlock()
3267
3191
 
3268
3192
 
3269
3193
class Converter6to7(object):