~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Jelmer Vernooij
  • Date: 2012-06-18 11:43:07 UTC
  • mfrom: (6437.54.10 2.5)
  • mto: This revision was merged to the branch mainline in revision 6525.
  • Revision ID: jelmer@samba.org-20120618114307-zeazlym311p38m98
MergeĀ 2.5.

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.")
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
2560
2495
 
2561
2496
    @only_raises(errors.LockNotHeld, errors.LockBroken)
2562
2497
    def unlock(self):
2563
 
        if self.conf_store is not None:
 
2498
        if self.control_files._lock_count == 1 and self.conf_store is not None:
2564
2499
            self.conf_store.save_changes()
2565
2500
        try:
2566
2501
            self.control_files.unlock()
2778
2713
        else:
2779
2714
            return (0, _mod_revision.NULL_REVISION)
2780
2715
 
2781
 
    @deprecated_method(deprecated_in((2, 4, 0)))
2782
 
    @needs_write_lock
2783
 
    def set_revision_history(self, rev_history):
2784
 
        """See Branch.set_revision_history."""
2785
 
        self._set_revision_history(rev_history)
2786
 
 
2787
2716
    def _set_revision_history(self, rev_history):
2788
2717
        if 'evil' in debug.debug_flags:
2789
2718
            mutter_callsite(3, "set_revision_history scales with history.")
2802
2731
        self._write_revision_history(rev_history)
2803
2732
        self._clear_cached_state()
2804
2733
        self._cache_revision_history(rev_history)
2805
 
        for hook in Branch.hooks['set_rh']:
2806
 
            hook(self, rev_history)
2807
2734
        if Branch.hooks['post_change_branch_tip']:
2808
2735
            self._run_post_change_branch_tip_hooks(old_revno, old_revid)
2809
2736
 
3147
3074
    :ivar tag_updates: A dict with new tags, see BasicTags.merge_to
3148
3075
    """
3149
3076
 
3150
 
    @deprecated_method(deprecated_in((2, 3, 0)))
3151
 
    def __int__(self):
3152
 
        """Return the relative change in revno.
3153
 
 
3154
 
        :deprecated: Use `new_revno` and `old_revno` instead.
3155
 
        """
3156
 
        return self.new_revno - self.old_revno
3157
 
 
3158
3077
    def report(self, to_file):
3159
3078
        tag_conflicts = getattr(self, "tag_conflicts", None)
3160
3079
        tag_updates = getattr(self, "tag_updates", None)
3190
3109
        target, otherwise it will be None.
3191
3110
    """
3192
3111
 
3193
 
    @deprecated_method(deprecated_in((2, 3, 0)))
3194
 
    def __int__(self):
3195
 
        """Return the relative change in revno.
3196
 
 
3197
 
        :deprecated: Use `new_revno` and `old_revno` instead.
3198
 
        """
3199
 
        return self.new_revno - self.old_revno
3200
 
 
3201
3112
    def report(self, to_file):
3202
3113
        # TODO: This function gets passed a to_file, but then
3203
3114
        # ignores it and calls note() instead. This is also
3359
3270
        raise NotImplementedError(self.fetch)
3360
3271
 
3361
3272
 
 
3273
def _fix_overwrite_type(overwrite):
 
3274
    if isinstance(overwrite, bool):
 
3275
        if overwrite:
 
3276
            return ["history", "tags"]
 
3277
        else:
 
3278
            return []
 
3279
    return overwrite
 
3280
 
 
3281
 
3362
3282
class GenericInterBranch(InterBranch):
3363
3283
    """InterBranch implementation that uses public Branch functions."""
3364
3284
 
3529
3449
        result.target_branch = self.target
3530
3450
        result.old_revno, result.old_revid = self.target.last_revision_info()
3531
3451
        self.source.update_references(self.target)
 
3452
        overwrite = _fix_overwrite_type(overwrite)
3532
3453
        if result.old_revid != stop_revision:
3533
3454
            # We assume that during 'push' this repository is closer than
3534
3455
            # the target.
3535
3456
            graph = self.source.repository.get_graph(self.target.repository)
3536
 
            self._update_revisions(stop_revision, overwrite=overwrite,
3537
 
                    graph=graph)
 
3457
            self._update_revisions(stop_revision,
 
3458
                overwrite=("history" in overwrite),
 
3459
                graph=graph)
3538
3460
        if self.source._push_should_merge_tags():
3539
3461
            result.tag_updates, result.tag_conflicts = (
3540
 
                self.source.tags.merge_to(self.target.tags, overwrite))
 
3462
                self.source.tags.merge_to(
 
3463
                self.target.tags, "tags" in overwrite))
3541
3464
        result.new_revno, result.new_revid = self.target.last_revision_info()
3542
3465
        return result
3543
3466
 
3621
3544
            # -- JRV20090506
3622
3545
            result.old_revno, result.old_revid = \
3623
3546
                self.target.last_revision_info()
3624
 
            self._update_revisions(stop_revision, overwrite=overwrite,
 
3547
            overwrite = _fix_overwrite_type(overwrite)
 
3548
            self._update_revisions(stop_revision,
 
3549
                overwrite=("history" in overwrite),
3625
3550
                graph=graph)
3626
3551
            # TODO: The old revid should be specified when merging tags, 
3627
3552
            # so a tags implementation that versions tags can only 
3628
3553
            # pull in the most recent changes. -- JRV20090506
3629
3554
            result.tag_updates, result.tag_conflicts = (
3630
 
                self.source.tags.merge_to(self.target.tags, overwrite,
 
3555
                self.source.tags.merge_to(self.target.tags,
 
3556
                    "tags" in overwrite,
3631
3557
                    ignore_master=not merge_tags_to_master))
3632
3558
            result.new_revno, result.new_revid = self.target.last_revision_info()
3633
3559
            if _hook_master: