/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/branchfmt/fullhistory.py

  • Committer: Martin
  • Date: 2017-06-09 16:31:49 UTC
  • mto: This revision was merged to the branch mainline in revision 6673.
  • Revision ID: gzlist@googlemail.com-20170609163149-liveiasey25480q6
Make InventoryDeltaError use string formatting, and repr for fileids

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 __future__ import absolute_import
 
20
 
 
21
from .. import (
 
22
    debug,
 
23
    errors,
 
24
    revision as _mod_revision,
 
25
    )
 
26
 
 
27
from ..branch import (
 
28
    Branch,
 
29
    )
 
30
from ..bzrbranch import (
 
31
    BzrBranch,
 
32
    BranchFormatMetadir,
 
33
    )
 
34
 
 
35
from ..decorators import (
 
36
    needs_write_lock,
 
37
    )
 
38
from ..trace import mutter_callsite
 
39
 
 
40
 
 
41
class FullHistoryBzrBranch(BzrBranch):
 
42
    """Bzr branch which contains the full revision history."""
 
43
 
 
44
    @needs_write_lock
 
45
    def set_last_revision_info(self, revno, revision_id):
 
46
        if not revision_id or not isinstance(revision_id, basestring):
 
47
            raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
 
48
        revision_id = _mod_revision.ensure_null(revision_id)
 
49
        # this old format stores the full history, but this api doesn't
 
50
        # provide it, so we must generate, and might as well check it's
 
51
        # correct
 
52
        history = self._lefthand_history(revision_id)
 
53
        if len(history) != revno:
 
54
            raise AssertionError('%d != %d' % (len(history), revno))
 
55
        self._set_revision_history(history)
 
56
 
 
57
    def _read_last_revision_info(self):
 
58
        rh = self._revision_history()
 
59
        revno = len(rh)
 
60
        if revno:
 
61
            return (revno, rh[-1])
 
62
        else:
 
63
            return (0, _mod_revision.NULL_REVISION)
 
64
 
 
65
    def _set_revision_history(self, rev_history):
 
66
        if 'evil' in debug.debug_flags:
 
67
            mutter_callsite(3, "set_revision_history scales with history.")
 
68
        check_not_reserved_id = _mod_revision.check_not_reserved_id
 
69
        for rev_id in rev_history:
 
70
            check_not_reserved_id(rev_id)
 
71
        if Branch.hooks['post_change_branch_tip']:
 
72
            # Don't calculate the last_revision_info() if there are no hooks
 
73
            # that will use it.
 
74
            old_revno, old_revid = self.last_revision_info()
 
75
        if len(rev_history) == 0:
 
76
            revid = _mod_revision.NULL_REVISION
 
77
        else:
 
78
            revid = rev_history[-1]
 
79
        self._run_pre_change_branch_tip_hooks(len(rev_history), revid)
 
80
        self._write_revision_history(rev_history)
 
81
        self._clear_cached_state()
 
82
        self._cache_revision_history(rev_history)
 
83
        if Branch.hooks['post_change_branch_tip']:
 
84
            self._run_post_change_branch_tip_hooks(old_revno, old_revid)
 
85
 
 
86
    def _write_revision_history(self, history):
 
87
        """Factored out of set_revision_history.
 
88
 
 
89
        This performs the actual writing to disk.
 
90
        It is intended to be called by set_revision_history."""
 
91
        self._transport.put_bytes(
 
92
            'revision-history', '\n'.join(history),
 
93
            mode=self.bzrdir._get_file_mode())
 
94
 
 
95
    def _gen_revision_history(self):
 
96
        history = self._transport.get_bytes('revision-history').split('\n')
 
97
        if history[-1:] == ['']:
 
98
            # There shouldn't be a trailing newline, but just in case.
 
99
            history.pop()
 
100
        return history
 
101
 
 
102
    def _synchronize_history(self, destination, revision_id):
 
103
        if not isinstance(destination, FullHistoryBzrBranch):
 
104
            super(BzrBranch, self)._synchronize_history(
 
105
                destination, revision_id)
 
106
            return
 
107
        if revision_id == _mod_revision.NULL_REVISION:
 
108
            new_history = []
 
109
        else:
 
110
            new_history = self._revision_history()
 
111
        if revision_id is not None and new_history != []:
 
112
            try:
 
113
                new_history = new_history[:new_history.index(revision_id) + 1]
 
114
            except ValueError:
 
115
                rev = self.repository.get_revision(revision_id)
 
116
                new_history = rev.get_history(self.repository)[1:]
 
117
        destination._set_revision_history(new_history)
 
118
 
 
119
    @needs_write_lock
 
120
    def generate_revision_history(self, revision_id, last_rev=None,
 
121
        other_branch=None):
 
122
        """Create a new revision history that will finish with revision_id.
 
123
 
 
124
        :param revision_id: the new tip to use.
 
125
        :param last_rev: The previous last_revision. If not None, then this
 
126
            must be a ancestory of revision_id, or DivergedBranches is raised.
 
127
        :param other_branch: The other branch that DivergedBranches should
 
128
            raise with respect to.
 
129
        """
 
130
        self._set_revision_history(self._lefthand_history(revision_id,
 
131
            last_rev, other_branch))
 
132
 
 
133
 
 
134
class BzrBranch5(FullHistoryBzrBranch):
 
135
    """A format 5 branch. This supports new features over plain branches.
 
136
 
 
137
    It has support for a master_branch which is the data for bound branches.
 
138
    """
 
139
 
 
140
 
 
141
class BzrBranchFormat5(BranchFormatMetadir):
 
142
    """Bzr branch format 5.
 
143
 
 
144
    This format has:
 
145
     - a revision-history file.
 
146
     - a format string
 
147
     - a lock dir guarding the branch itself
 
148
     - all of this stored in a branch/ subdirectory
 
149
     - works with shared repositories.
 
150
 
 
151
    This format is new in bzr 0.8.
 
152
    """
 
153
 
 
154
    def _branch_class(self):
 
155
        return BzrBranch5
 
156
 
 
157
    @classmethod
 
158
    def get_format_string(cls):
 
159
        """See BranchFormat.get_format_string()."""
 
160
        return "Bazaar-NG branch format 5\n"
 
161
 
 
162
    def get_format_description(self):
 
163
        """See BranchFormat.get_format_description()."""
 
164
        return "Branch format 5"
 
165
 
 
166
    def initialize(self, a_bzrdir, name=None, repository=None,
 
167
                   append_revisions_only=None):
 
168
        """Create a branch of this format in a_bzrdir."""
 
169
        if append_revisions_only:
 
170
            raise errors.UpgradeRequired(a_bzrdir.user_url)
 
171
        utf8_files = [('revision-history', ''),
 
172
                      ('branch-name', ''),
 
173
                      ]
 
174
        return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
 
175
 
 
176
    def supports_tags(self):
 
177
        return False
 
178
 
 
179
 
 
180