~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Jelmer Vernooij
  • Date: 2012-03-30 18:36:46 UTC
  • mto: This revision was merged to the branch mainline in revision 6535.
  • Revision ID: jelmer@samba.org-20120330183646-azkod5najbuewous
Move BzrBranchFormat5 into a separate file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2056
2056
            recommend_upgrade=recommend_upgrade, basedir=basedir)
2057
2057
 
2058
2058
 
2059
 
class BzrBranchFormat5(BranchFormatMetadir):
2060
 
    """Bzr branch format 5.
2061
 
 
2062
 
    This format has:
2063
 
     - a revision-history file.
2064
 
     - a format string
2065
 
     - a lock dir guarding the branch itself
2066
 
     - all of this stored in a branch/ subdirectory
2067
 
     - works with shared repositories.
2068
 
 
2069
 
    This format is new in bzr 0.8.
2070
 
    """
2071
 
 
2072
 
    def _branch_class(self):
2073
 
        return BzrBranch5
2074
 
 
2075
 
    @classmethod
2076
 
    def get_format_string(cls):
2077
 
        """See BranchFormat.get_format_string()."""
2078
 
        return "Bazaar-NG branch format 5\n"
2079
 
 
2080
 
    def get_format_description(self):
2081
 
        """See BranchFormat.get_format_description()."""
2082
 
        return "Branch format 5"
2083
 
 
2084
 
    def initialize(self, a_bzrdir, name=None, repository=None,
2085
 
                   append_revisions_only=None):
2086
 
        """Create a branch of this format in a_bzrdir."""
2087
 
        if append_revisions_only:
2088
 
            raise errors.UpgradeRequired(a_bzrdir.user_url)
2089
 
        utf8_files = [('revision-history', ''),
2090
 
                      ('branch-name', ''),
2091
 
                      ]
2092
 
        return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2093
 
 
2094
 
    def supports_tags(self):
2095
 
        return False
2096
 
 
2097
 
 
2098
2059
class BzrBranchFormat6(BranchFormatMetadir):
2099
2060
    """Branch format with last-revision and tags.
2100
2061
 
2349
2310
 
2350
2311
# formats which have no format string are not discoverable
2351
2312
# and not independently creatable, so are not registered.
2352
 
__format5 = BzrBranchFormat5()
2353
2313
__format6 = BzrBranchFormat6()
2354
2314
__format7 = BzrBranchFormat7()
2355
2315
__format8 = BzrBranchFormat8()
2356
 
format_registry.register(__format5)
 
2316
format_registry.register_lazy(
 
2317
    "Bazaar-NG branch format 5\n", "bzrlib.branchfmt.fullhistory", "BzrBranchFormat5")
2357
2318
format_registry.register(BranchReferenceFormat())
2358
2319
format_registry.register(__format6)
2359
2320
format_registry.register(__format7)
2689
2650
        self.control_transport.put_bytes('format', self._format.as_string())
2690
2651
 
2691
2652
 
2692
 
class FullHistoryBzrBranch(BzrBranch):
2693
 
    """Bzr branch which contains the full revision history."""
2694
 
 
2695
 
    @needs_write_lock
2696
 
    def set_last_revision_info(self, revno, revision_id):
2697
 
        if not revision_id or not isinstance(revision_id, basestring):
2698
 
            raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
2699
 
        revision_id = _mod_revision.ensure_null(revision_id)
2700
 
        # this old format stores the full history, but this api doesn't
2701
 
        # provide it, so we must generate, and might as well check it's
2702
 
        # correct
2703
 
        history = self._lefthand_history(revision_id)
2704
 
        if len(history) != revno:
2705
 
            raise AssertionError('%d != %d' % (len(history), revno))
2706
 
        self._set_revision_history(history)
2707
 
 
2708
 
    def _read_last_revision_info(self):
2709
 
        rh = self._revision_history()
2710
 
        revno = len(rh)
2711
 
        if revno:
2712
 
            return (revno, rh[-1])
2713
 
        else:
2714
 
            return (0, _mod_revision.NULL_REVISION)
2715
 
 
2716
 
    def _set_revision_history(self, rev_history):
2717
 
        if 'evil' in debug.debug_flags:
2718
 
            mutter_callsite(3, "set_revision_history scales with history.")
2719
 
        check_not_reserved_id = _mod_revision.check_not_reserved_id
2720
 
        for rev_id in rev_history:
2721
 
            check_not_reserved_id(rev_id)
2722
 
        if Branch.hooks['post_change_branch_tip']:
2723
 
            # Don't calculate the last_revision_info() if there are no hooks
2724
 
            # that will use it.
2725
 
            old_revno, old_revid = self.last_revision_info()
2726
 
        if len(rev_history) == 0:
2727
 
            revid = _mod_revision.NULL_REVISION
2728
 
        else:
2729
 
            revid = rev_history[-1]
2730
 
        self._run_pre_change_branch_tip_hooks(len(rev_history), revid)
2731
 
        self._write_revision_history(rev_history)
2732
 
        self._clear_cached_state()
2733
 
        self._cache_revision_history(rev_history)
2734
 
        if Branch.hooks['post_change_branch_tip']:
2735
 
            self._run_post_change_branch_tip_hooks(old_revno, old_revid)
2736
 
 
2737
 
    def _write_revision_history(self, history):
2738
 
        """Factored out of set_revision_history.
2739
 
 
2740
 
        This performs the actual writing to disk.
2741
 
        It is intended to be called by set_revision_history."""
2742
 
        self._transport.put_bytes(
2743
 
            'revision-history', '\n'.join(history),
2744
 
            mode=self.bzrdir._get_file_mode())
2745
 
 
2746
 
    def _gen_revision_history(self):
2747
 
        history = self._transport.get_bytes('revision-history').split('\n')
2748
 
        if history[-1:] == ['']:
2749
 
            # There shouldn't be a trailing newline, but just in case.
2750
 
            history.pop()
2751
 
        return history
2752
 
 
2753
 
    def _synchronize_history(self, destination, revision_id):
2754
 
        if not isinstance(destination, FullHistoryBzrBranch):
2755
 
            super(BzrBranch, self)._synchronize_history(
2756
 
                destination, revision_id)
2757
 
            return
2758
 
        if revision_id == _mod_revision.NULL_REVISION:
2759
 
            new_history = []
2760
 
        else:
2761
 
            new_history = self._revision_history()
2762
 
        if revision_id is not None and new_history != []:
2763
 
            try:
2764
 
                new_history = new_history[:new_history.index(revision_id) + 1]
2765
 
            except ValueError:
2766
 
                rev = self.repository.get_revision(revision_id)
2767
 
                new_history = rev.get_history(self.repository)[1:]
2768
 
        destination._set_revision_history(new_history)
2769
 
 
2770
 
    @needs_write_lock
2771
 
    def generate_revision_history(self, revision_id, last_rev=None,
2772
 
        other_branch=None):
2773
 
        """Create a new revision history that will finish with revision_id.
2774
 
 
2775
 
        :param revision_id: the new tip to use.
2776
 
        :param last_rev: The previous last_revision. If not None, then this
2777
 
            must be a ancestory of revision_id, or DivergedBranches is raised.
2778
 
        :param other_branch: The other branch that DivergedBranches should
2779
 
            raise with respect to.
2780
 
        """
2781
 
        self._set_revision_history(self._lefthand_history(revision_id,
2782
 
            last_rev, other_branch))
2783
 
 
2784
 
 
2785
 
class BzrBranch5(FullHistoryBzrBranch):
2786
 
    """A format 5 branch. This supports new features over plain branches.
2787
 
 
2788
 
    It has support for a master_branch which is the data for bound branches.
2789
 
    """
2790
 
 
2791
 
 
2792
2653
class BzrBranch8(BzrBranch):
2793
2654
    """A branch that stores tree-reference locations."""
2794
2655