/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/repository.py

  • Committer: Martin
  • Date: 2017-09-10 23:52:30 UTC
  • mto: This revision was merged to the branch mainline in revision 6789.
  • Revision ID: gzlist@googlemail.com-20170910235230-xzzqmm0l2locfjge
Make _rio_pyx compile and pass tests on Python 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005-2011 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
from __future__ import absolute_import
 
18
 
 
19
import itertools
 
20
 
 
21
from . import (
 
22
    bzrdir,
 
23
    )
 
24
from .. import (
 
25
    errors,
 
26
    lockdir,
 
27
    lockable_files,
 
28
    revision as _mod_revision,
 
29
    )
 
30
from ..decorators import needs_read_lock, needs_write_lock, only_raises
 
31
from ..repository import (
 
32
    format_registry,
 
33
    Repository,
 
34
    RepositoryFormat,
 
35
    )
 
36
from ..sixish import (
 
37
    viewvalues,
 
38
    )
 
39
 
 
40
 
 
41
class MetaDirRepository(Repository):
 
42
    """Repositories in the new meta-dir layout.
 
43
 
 
44
    :ivar _transport: Transport for access to repository control files,
 
45
        typically pointing to .bzr/repository.
 
46
    """
 
47
 
 
48
    def __init__(self, _format, a_bzrdir, control_files):
 
49
        super(MetaDirRepository, self).__init__(_format, a_bzrdir, control_files)
 
50
        self._transport = control_files._transport
 
51
 
 
52
    def is_shared(self):
 
53
        """Return True if this repository is flagged as a shared repository."""
 
54
        return self._transport.has('shared-storage')
 
55
 
 
56
    @needs_write_lock
 
57
    def set_make_working_trees(self, new_value):
 
58
        """Set the policy flag for making working trees when creating branches.
 
59
 
 
60
        This only applies to branches that use this repository.
 
61
 
 
62
        The default is 'True'.
 
63
        :param new_value: True to restore the default, False to disable making
 
64
                          working trees.
 
65
        """
 
66
        if new_value:
 
67
            try:
 
68
                self._transport.delete('no-working-trees')
 
69
            except errors.NoSuchFile:
 
70
                pass
 
71
        else:
 
72
            self._transport.put_bytes('no-working-trees', '',
 
73
                mode=self.controldir._get_file_mode())
 
74
 
 
75
    def make_working_trees(self):
 
76
        """Returns the policy for making working trees on new branches."""
 
77
        return not self._transport.has('no-working-trees')
 
78
 
 
79
    @needs_write_lock
 
80
    def update_feature_flags(self, updated_flags):
 
81
        """Update the feature flags for this branch.
 
82
 
 
83
        :param updated_flags: Dictionary mapping feature names to necessities
 
84
            A necessity can be None to indicate the feature should be removed
 
85
        """
 
86
        self._format._update_feature_flags(updated_flags)
 
87
        self.control_transport.put_bytes('format', self._format.as_string())
 
88
 
 
89
    def _find_parent_ids_of_revisions(self, revision_ids):
 
90
        """Find all parent ids that are mentioned in the revision graph.
 
91
 
 
92
        :return: set of revisions that are parents of revision_ids which are
 
93
            not part of revision_ids themselves
 
94
        """
 
95
        parent_ids = set(itertools.chain.from_iterable(viewvalues(
 
96
                self.get_parent_map(revision_ids))))
 
97
        parent_ids.difference_update(revision_ids)
 
98
        parent_ids.discard(_mod_revision.NULL_REVISION)
 
99
        return parent_ids
 
100
 
 
101
 
 
102
class RepositoryFormatMetaDir(bzrdir.BzrFormat, RepositoryFormat):
 
103
    """Common base class for the new repositories using the metadir layout."""
 
104
 
 
105
    rich_root_data = False
 
106
    supports_tree_reference = False
 
107
    supports_external_lookups = False
 
108
    supports_leaving_lock = True
 
109
    supports_nesting_repositories = True
 
110
 
 
111
    @property
 
112
    def _matchingcontroldir(self):
 
113
        matching = bzrdir.BzrDirMetaFormat1()
 
114
        matching.repository_format = self
 
115
        return matching
 
116
 
 
117
    def __init__(self):
 
118
        RepositoryFormat.__init__(self)
 
119
        bzrdir.BzrFormat.__init__(self)
 
120
 
 
121
    def _create_control_files(self, a_bzrdir):
 
122
        """Create the required files and the initial control_files object."""
 
123
        # FIXME: RBC 20060125 don't peek under the covers
 
124
        # NB: no need to escape relative paths that are url safe.
 
125
        repository_transport = a_bzrdir.get_repository_transport(self)
 
126
        control_files = lockable_files.LockableFiles(repository_transport,
 
127
                                'lock', lockdir.LockDir)
 
128
        control_files.create_lock()
 
129
        return control_files
 
130
 
 
131
    def _upload_blank_content(self, a_bzrdir, dirs, files, utf8_files, shared):
 
132
        """Upload the initial blank content."""
 
133
        control_files = self._create_control_files(a_bzrdir)
 
134
        control_files.lock_write()
 
135
        transport = control_files._transport
 
136
        if shared == True:
 
137
            utf8_files += [('shared-storage', b'')]
 
138
        try:
 
139
            transport.mkdir_multi(dirs, mode=a_bzrdir._get_dir_mode())
 
140
            for (filename, content_stream) in files:
 
141
                transport.put_file(filename, content_stream,
 
142
                    mode=a_bzrdir._get_file_mode())
 
143
            for (filename, content_bytes) in utf8_files:
 
144
                transport.put_bytes_non_atomic(filename, content_bytes,
 
145
                    mode=a_bzrdir._get_file_mode())
 
146
        finally:
 
147
            control_files.unlock()
 
148
 
 
149
    @classmethod
 
150
    def find_format(klass, a_bzrdir):
 
151
        """Return the format for the repository object in a_bzrdir.
 
152
 
 
153
        This is used by brz native formats that have a "format" file in
 
154
        the repository.  Other methods may be used by different types of
 
155
        control directory.
 
156
        """
 
157
        try:
 
158
            transport = a_bzrdir.get_repository_transport(None)
 
159
            format_string = transport.get_bytes("format")
 
160
            # GZ 2017-06-17: Where should format strings get decoded...
 
161
            format_text = format_string.decode("ascii")
 
162
        except errors.NoSuchFile:
 
163
            raise errors.NoRepositoryPresent(a_bzrdir)
 
164
        return klass._find_format(format_registry, 'repository', format_text)
 
165
 
 
166
    def check_support_status(self, allow_unsupported, recommend_upgrade=True,
 
167
            basedir=None):
 
168
        RepositoryFormat.check_support_status(self,
 
169
            allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
 
170
            basedir=basedir)
 
171
        bzrdir.BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
 
172
            recommend_upgrade=recommend_upgrade, basedir=basedir)
 
173