/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: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

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