/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/bzr/fullhistory.py

  • Committer: Jelmer Vernooij
  • Date: 2020-05-24 00:39:50 UTC
  • mto: This revision was merged to the branch mainline in revision 7504.
  • Revision ID: jelmer@jelmer.uk-20200524003950-bbc545r76vc5yajg
Add github action.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006-2012 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Full history branch formats."""
 
18
 
 
19
from .. import (
 
20
    debug,
 
21
    errors,
 
22
    revision as _mod_revision,
 
23
    )
 
24
 
 
25
from ..branch import (
 
26
    Branch,
 
27
    )
 
28
from .branch import (
 
29
    BzrBranch,
 
30
    BranchFormatMetadir,
 
31
    )
 
32
 
 
33
from ..trace import mutter_callsite
 
34
 
 
35
 
 
36
class FullHistoryBzrBranch(BzrBranch):
 
37
    """Bzr branch which contains the full revision history."""
 
38
 
 
39
    def set_last_revision_info(self, revno, revision_id):
 
40
        if not revision_id or not isinstance(revision_id, bytes):
 
41
            raise errors.InvalidRevisionId(
 
42
                revision_id=revision_id, branch=self)
 
43
        revision_id = _mod_revision.ensure_null(revision_id)
 
44
        with self.lock_write():
 
45
            # this old format stores the full history, but this api doesn't
 
46
            # provide it, so we must generate, and might as well check it's
 
47
            # correct
 
48
            history = self._lefthand_history(revision_id)
 
49
            if len(history) != revno:
 
50
                raise AssertionError('%d != %d' % (len(history), revno))
 
51
            self._set_revision_history(history)
 
52
 
 
53
    def _read_last_revision_info(self):
 
54
        rh = self._revision_history()
 
55
        revno = len(rh)
 
56
        if revno:
 
57
            return (revno, rh[-1])
 
58
        else:
 
59
            return (0, _mod_revision.NULL_REVISION)
 
60
 
 
61
    def _set_revision_history(self, rev_history):
 
62
        if 'evil' in debug.debug_flags:
 
63
            mutter_callsite(3, "set_revision_history scales with history.")
 
64
        check_not_reserved_id = _mod_revision.check_not_reserved_id
 
65
        for rev_id in rev_history:
 
66
            check_not_reserved_id(rev_id)
 
67
        if Branch.hooks['post_change_branch_tip']:
 
68
            # Don't calculate the last_revision_info() if there are no hooks
 
69
            # that will use it.
 
70
            old_revno, old_revid = self.last_revision_info()
 
71
        if len(rev_history) == 0:
 
72
            revid = _mod_revision.NULL_REVISION
 
73
        else:
 
74
            revid = rev_history[-1]
 
75
        self._run_pre_change_branch_tip_hooks(len(rev_history), revid)
 
76
        self._write_revision_history(rev_history)
 
77
        self._clear_cached_state()
 
78
        self._cache_revision_history(rev_history)
 
79
        if Branch.hooks['post_change_branch_tip']:
 
80
            self._run_post_change_branch_tip_hooks(old_revno, old_revid)
 
81
 
 
82
    def _write_revision_history(self, history):
 
83
        """Factored out of set_revision_history.
 
84
 
 
85
        This performs the actual writing to disk.
 
86
        It is intended to be called by set_revision_history."""
 
87
        self._transport.put_bytes(
 
88
            'revision-history', b'\n'.join(history),
 
89
            mode=self.controldir._get_file_mode())
 
90
 
 
91
    def _gen_revision_history(self):
 
92
        history = self._transport.get_bytes('revision-history').split(b'\n')
 
93
        if history[-1:] == [b'']:
 
94
            # There shouldn't be a trailing newline, but just in case.
 
95
            history.pop()
 
96
        return history
 
97
 
 
98
    def _synchronize_history(self, destination, revision_id):
 
99
        if not isinstance(destination, FullHistoryBzrBranch):
 
100
            super(BzrBranch, self)._synchronize_history(
 
101
                destination, revision_id)
 
102
            return
 
103
        if revision_id == _mod_revision.NULL_REVISION:
 
104
            new_history = []
 
105
        else:
 
106
            new_history = self._revision_history()
 
107
        if revision_id is not None and new_history != []:
 
108
            try:
 
109
                new_history = new_history[:new_history.index(revision_id) + 1]
 
110
            except ValueError:
 
111
                rev = self.repository.get_revision(revision_id)
 
112
                new_history = rev.get_history(self.repository)[1:]
 
113
        destination._set_revision_history(new_history)
 
114
 
 
115
    def generate_revision_history(self, revision_id, last_rev=None,
 
116
                                  other_branch=None):
 
117
        """Create a new revision history that will finish with revision_id.
 
118
 
 
119
        :param revision_id: the new tip to use.
 
120
        :param last_rev: The previous last_revision. If not None, then this
 
121
            must be a ancestory of revision_id, or DivergedBranches is raised.
 
122
        :param other_branch: The other branch that DivergedBranches should
 
123
            raise with respect to.
 
124
        """
 
125
        with self.lock_write():
 
126
            self._set_revision_history(self._lefthand_history(revision_id,
 
127
                                                              last_rev, other_branch))
 
128
 
 
129
 
 
130
class BzrBranch5(FullHistoryBzrBranch):
 
131
    """A format 5 branch. This supports new features over plain branches.
 
132
 
 
133
    It has support for a master_branch which is the data for bound branches.
 
134
    """
 
135
 
 
136
 
 
137
class BzrBranchFormat5(BranchFormatMetadir):
 
138
    """Bzr branch format 5.
 
139
 
 
140
    This format has:
 
141
     - a revision-history file.
 
142
     - a format string
 
143
     - a lock dir guarding the branch itself
 
144
     - all of this stored in a branch/ subdirectory
 
145
     - works with shared repositories.
 
146
 
 
147
    This format is new in bzr 0.8.
 
148
    """
 
149
 
 
150
    def _branch_class(self):
 
151
        return BzrBranch5
 
152
 
 
153
    @classmethod
 
154
    def get_format_string(cls):
 
155
        """See BranchFormat.get_format_string()."""
 
156
        return b"Bazaar-NG branch format 5\n"
 
157
 
 
158
    def get_format_description(self):
 
159
        """See BranchFormat.get_format_description()."""
 
160
        return "Branch format 5"
 
161
 
 
162
    def initialize(self, a_controldir, name=None, repository=None,
 
163
                   append_revisions_only=None):
 
164
        """Create a branch of this format in a_controldir."""
 
165
        if append_revisions_only:
 
166
            raise errors.UpgradeRequired(a_controldir.user_url)
 
167
        utf8_files = [('revision-history', b''),
 
168
                      ('branch-name', b''),
 
169
                      ]
 
170
        return self._initialize_helper(a_controldir, utf8_files, name, repository)
 
171
 
 
172
    def supports_tags(self):
 
173
        return False
 
174
 
 
175
    supports_reference_locations = False