/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
1
# Copyright (C) 2007 Canonical Ltd
0.200.910 by Jelmer Vernooij
update copyright years
2
# Copyright (C) 2010 Jelmer Vernooij
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
18
"""An adapter between a Git control dir and a Bazaar ControlDir."""
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
19
0.200.1594 by Jelmer Vernooij
Use absolute_import everywhere.
20
from __future__ import absolute_import
21
0.200.1311 by Jelmer Vernooij
More work on colocated branch support.
22
import urllib
23
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
24
from ... import (
0.200.1688 by Jelmer Vernooij
Fix stacking tests.
25
    branch as _mod_branch,
0.239.13 by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed.
26
    errors as bzr_errors,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
27
    trace,
0.200.1172 by Jelmer Vernooij
Provide GitDir._available_backup_name.
28
    osutils,
0.200.1566 by Jelmer Vernooij
Basic implementation of LocalGitDir.destroy_workingtree.
29
    revision as _mod_revision,
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
30
    urlutils,
31
    )
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
32
from ...bzr.bzrdir import CreateRepository
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
33
from ...transport import do_catching_redirections
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
34
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
35
from ...controldir import (
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
36
    ControlDir,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
37
    ControlDirFormat,
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
38
    format_registry,
39
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
40
0.200.123 by Jelmer Vernooij
Use central git module.
41
0.200.1026 by Jelmer Vernooij
Fix typo.
42
class GitDirConfig(object):
0.200.1025 by Jelmer Vernooij
Implement GitDir.get_config().
43
44
    def get_default_stack_on(self):
45
        return None
46
47
    def set_default_stack_on(self, value):
48
        raise bzr_errors.BzrError("Cannot set configuration")
49
50
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
51
class GitControlDirFormat(ControlDirFormat):
52
53
    colocated_branches = True
54
    fixed_components = True
55
56
    def __eq__(self, other):
57
        return type(self) == type(other)
58
59
    def is_supported(self):
60
        return True
61
62
    def network_name(self):
63
        return "git"
64
65
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
66
class GitDir(ControlDir):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
67
    """An adapter to the '.git' dir used by git."""
68
0.200.148 by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir.
69
    def is_supported(self):
70
        return True
71
0.200.981 by Jelmer Vernooij
Mark git directories as not convertable (for now).
72
    def can_convert_format(self):
73
        return False
74
0.200.1025 by Jelmer Vernooij
Implement GitDir.get_config().
75
    def break_lock(self):
76
        pass
77
0.200.155 by Jelmer Vernooij
Fix formatting, remove catch-all for exceptions when opening local repositories.
78
    def cloning_metadir(self, stacked=False):
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
79
        return format_registry.make_controldir("default")
0.200.155 by Jelmer Vernooij
Fix formatting, remove catch-all for exceptions when opening local repositories.
80
0.200.1165 by Jelmer Vernooij
Implement GitDir.checkout_metadir.
81
    def checkout_metadir(self, stacked=False):
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
82
        return format_registry.make_controldir("default")
0.200.1165 by Jelmer Vernooij
Implement GitDir.checkout_metadir.
83
0.200.1561 by Jelmer Vernooij
Some fixes for colocated branch handling.
84
    def _get_default_ref(self):
85
        return "HEAD"
86
0.269.8 by Jelmer Vernooij
Support push in git-remote-bzr.
87
    def _get_selected_ref(self, branch, ref=None):
88
        if ref is not None and branch is not None:
89
            raise bzr_errors.BzrError("can't specify both ref and branch")
90
        if ref is not None:
91
            return ref
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
92
        segment_parameters = getattr(
93
            self.user_transport, "get_segment_parameters", lambda: {})()
94
        ref = segment_parameters.get("ref")
95
        if ref is not None:
96
            return urlutils.unescape(ref)
0.200.1310 by Jelmer Vernooij
Add _get_selected_ref method.
97
        if branch is None and getattr(self, "_get_selected_branch", False):
98
            branch = self._get_selected_branch()
99
        if branch is not None:
0.200.1644 by Jelmer Vernooij
More relative imports.
100
            from .refs import branch_name_to_ref
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
101
            return branch_name_to_ref(branch)
0.200.1561 by Jelmer Vernooij
Some fixes for colocated branch handling.
102
        return self._get_default_ref()
0.200.1310 by Jelmer Vernooij
Add _get_selected_ref method.
103
0.200.1025 by Jelmer Vernooij
Implement GitDir.get_config().
104
    def get_config(self):
105
        return GitDirConfig()
106
0.200.1172 by Jelmer Vernooij
Provide GitDir._available_backup_name.
107
    def _available_backup_name(self, base):
108
        return osutils.available_backup_name(base, self.root_transport.has)
109
0.259.1 by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility.
110
    def sprout(self, url, revision_id=None, force_new_repo=False,
111
               recurse='down', possible_transports=None,
112
               accelerator_tree=None, hardlink=False, stacked=False,
113
               source_branch=None, create_tree_if_local=True):
0.200.1644 by Jelmer Vernooij
More relative imports.
114
        from ...repository import InterRepository
115
        from ...transport.local import LocalTransport
116
        from ...transport import get_transport
0.259.1 by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility.
117
        target_transport = get_transport(url, possible_transports)
118
        target_transport.ensure_base()
119
        cloning_format = self.cloning_metadir()
120
        # Create/update the result branch
121
        result = cloning_format.initialize_on_transport(target_transport)
0.200.1373 by Jelmer Vernooij
Prevent accidentally removing branch.
122
        source_branch = self.open_branch()
0.259.1 by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility.
123
        source_repository = self.find_repository()
124
        try:
125
            result_repo = result.find_repository()
126
        except bzr_errors.NoRepositoryPresent:
127
            result_repo = result.create_repository()
128
            target_is_empty = True
129
        else:
130
            target_is_empty = None # Unknown
131
        if stacked:
0.200.1688 by Jelmer Vernooij
Fix stacking tests.
132
            raise _mod_branch.UnstackableBranchFormat(self._format, self.user_url)
0.259.1 by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility.
133
        interrepo = InterRepository.get(source_repository, result_repo)
134
135
        if revision_id is not None:
0.259.4 by Jelmer Vernooij
Put determine_wants methods on InterRepo.
136
            determine_wants = interrepo.get_determine_wants_revids(
0.200.1520 by Jelmer Vernooij
Don't fetch tag contents by default.
137
                [revision_id], include_tags=False)
0.259.1 by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility.
138
        else:
0.259.4 by Jelmer Vernooij
Put determine_wants methods on InterRepo.
139
            determine_wants = interrepo.determine_wants_all
0.259.1 by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility.
140
        interrepo.fetch_objects(determine_wants=determine_wants,
141
            mapping=source_branch.mapping)
142
        result_branch = source_branch.sprout(result,
143
            revision_id=revision_id, repository=result_repo)
0.200.1372 by Jelmer Vernooij
Fix formatting.
144
        if (create_tree_if_local
145
            and isinstance(target_transport, LocalTransport)
0.259.1 by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility.
146
            and (result_repo is None or result_repo.make_working_trees())):
147
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
148
                hardlink=hardlink, from_branch=result_branch)
149
            wt.lock_write()
150
            try:
151
                if wt.path2id('') is None:
152
                    try:
153
                        wt.set_root_id(self.open_workingtree.get_root_id())
154
                    except bzr_errors.NoWorkingTree:
155
                        pass
156
            finally:
157
                wt.unlock()
158
        return result
159
0.200.1117 by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport.
160
    def clone_on_transport(self, transport, revision_id=None,
161
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
162
        create_prefix=False, use_existing_dir=True, no_tree=False):
163
        """See ControlDir.clone_on_transport."""
0.200.1644 by Jelmer Vernooij
More relative imports.
164
        from ...repository import InterRepository
165
        from .mapping import default_mapping
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
166
        if no_tree:
167
            format = BareLocalGitControlDirFormat()
168
        else:
169
            format = LocalGitControlDirFormat()
170
        (target_repo, target_controldir, stacking, repo_policy) = format.initialize_on_transport_ex(transport, use_existing_dir=use_existing_dir, create_prefix=create_prefix, force_new_repo=force_new_repo)
171
        target_git_repo = target_repo._git
0.200.1117 by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport.
172
        source_repo = self.open_repository()
173
        source_git_repo = source_repo._git
0.200.1171 by Jelmer Vernooij
Fix some more tests.
174
        interrepo = InterRepository.get(source_repo, target_repo)
0.200.1117 by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport.
175
        if revision_id is not None:
0.200.1171 by Jelmer Vernooij
Fix some more tests.
176
            determine_wants = interrepo.get_determine_wants_revids([revision_id], include_tags=True)
0.200.1117 by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport.
177
        else:
0.200.1171 by Jelmer Vernooij
Fix some more tests.
178
            determine_wants = interrepo.determine_wants_all
179
        (pack_hint, _, refs) = interrepo.fetch_objects(determine_wants,
180
            mapping=default_mapping)
0.200.1117 by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport.
181
        for name, val in refs.iteritems():
182
            target_git_repo.refs[name] = val
0.200.1411 by Jelmer Vernooij
Fix control files.
183
        return self.__class__(transport, target_git_repo, format)
0.200.1117 by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport.
184
0.259.2 by Jelmer Vernooij
Make sure RemoteGitDir.find_repository works.
185
    def find_repository(self):
186
        """Find the repository that should be used.
187
188
        This does not require a branch as we use it to find the repo for
189
        new branches as well as to hook existing branches up to their
190
        repository.
191
        """
192
        return self.open_repository()
193
0.200.1487 by Jelmer Vernooij
Use peeling.
194
    def get_refs_container(self):
195
        """Retrieve the refs container.
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
196
        """
0.200.1487 by Jelmer Vernooij
Use peeling.
197
        raise NotImplementedError(self.get_refs_container)
0.200.1434 by Jelmer Vernooij
Move refs access to control dir.
198
0.200.148 by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir.
199
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
200
class LocalGitControlDirFormat(GitControlDirFormat):
201
    """The .git directory control format."""
202
203
    bare = False
204
205
    @classmethod
206
    def _known_formats(self):
207
        return set([LocalGitControlDirFormat()])
208
209
    @property
210
    def repository_format(self):
0.200.1644 by Jelmer Vernooij
More relative imports.
211
        from .repository import GitRepositoryFormat
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
212
        return GitRepositoryFormat()
213
214
    def get_branch_format(self):
0.200.1644 by Jelmer Vernooij
More relative imports.
215
        from .branch import GitBranchFormat
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
216
        return GitBranchFormat()
217
218
    def open(self, transport, _found=None):
219
        """Open this directory.
220
221
        """
0.200.1644 by Jelmer Vernooij
More relative imports.
222
        from .transportgit import TransportRepo
0.200.1485 by Jelmer Vernooij
Keep track of refs text when opening bare repository.
223
        gitrepo = TransportRepo(transport, self.bare,
224
                refs_text=getattr(self, "_refs_text", None))
0.200.1411 by Jelmer Vernooij
Fix control files.
225
        return LocalGitDir(transport, gitrepo, self)
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
226
227
    def get_format_description(self):
228
        return "Local Git Repository"
229
230
    def initialize_on_transport(self, transport):
0.200.1644 by Jelmer Vernooij
More relative imports.
231
        from .transportgit import TransportRepo
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
232
        repo = TransportRepo.init(transport, bare=self.bare)
233
        del repo.refs["HEAD"]
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
234
        return self.open(transport)
235
236
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
237
        create_prefix=False, force_new_repo=False, stacked_on=None,
238
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
239
        shared_repo=False, vfs_only=False):
240
        def make_directory(transport):
241
            transport.mkdir('.')
242
            return transport
243
        def redirected(transport, e, redirection_notice):
244
            trace.note(redirection_notice)
245
            return transport._redirected_to(e.source, e.target)
246
        try:
247
            transport = do_catching_redirections(make_directory, transport,
248
                redirected)
249
        except bzr_errors.FileExists:
250
            if not use_existing_dir:
251
                raise
252
        except bzr_errors.NoSuchFile:
253
            if not create_prefix:
254
                raise
255
            transport.create_prefix()
256
        controldir = self.initialize_on_transport(transport)
257
        repository = controldir.open_repository()
258
        repository.lock_write()
259
        return (repository, controldir, False, CreateRepository(controldir))
260
261
    def is_supported(self):
262
        return True
263
0.200.1412 by Jelmer Vernooij
Implement GitControlDirFormat.supports_transport.
264
    def supports_transport(self, transport):
265
        try:
266
            external_url = transport.external_url()
267
        except bzr_errors.InProcessTransport:
268
            raise bzr_errors.NotBranchError(path=transport.base)
269
        return (external_url.startswith("http:") or
270
                external_url.startswith("https:") or
271
                external_url.startswith("file:"))
272
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
273
274
class BareLocalGitControlDirFormat(LocalGitControlDirFormat):
275
276
    bare = True
277
    supports_workingtrees = False
278
279
    def get_format_description(self):
280
        return "Local Git Repository (bare)"
281
282
0.200.148 by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir.
283
class LocalGitDir(GitDir):
284
    """An adapter to the '.git' dir used by git."""
285
0.239.13 by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed.
286
    def _get_gitrepository_class(self):
0.200.1644 by Jelmer Vernooij
More relative imports.
287
        from .repository import LocalGitRepository
0.239.13 by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed.
288
        return LocalGitRepository
289
0.200.1313 by Jelmer Vernooij
Add __repr__
290
    def __repr__(self):
291
        return "<%s at %r>" % (
292
            self.__class__.__name__, self.root_transport.base)
293
0.239.13 by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed.
294
    _gitrepository_class = property(_get_gitrepository_class)
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
295
0.200.1014 by Jelmer Vernooij
Fix tests.
296
    @property
297
    def user_transport(self):
298
        return self.root_transport
299
300
    @property
301
    def control_transport(self):
302
        return self.transport
303
0.200.1411 by Jelmer Vernooij
Fix control files.
304
    def __init__(self, transport, gitrepo, format):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
305
        self._format = format
306
        self.root_transport = transport
0.200.1018 by Jelmer Vernooij
Fix use with new control dir API.
307
        self._mode_check_done = False
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
308
        self._git = gitrepo
309
        if gitrepo.bare:
310
            self.transport = transport
311
        else:
312
            self.transport = transport.clone('.git')
0.200.381 by Jelmer Vernooij
Support working trees properly, status and ls.
313
        self._mode_check_done = None
314
315
    def is_control_filename(self, filename):
0.200.1603 by Jelmer Vernooij
Ignore control directory filenames on Windows, too.
316
        return (filename == '.git' or
317
                filename.startswith('.git/') or
318
                filename.startswith('.git\\'))
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
319
0.200.1311 by Jelmer Vernooij
More work on colocated branch support.
320
    def _get_symref(self, ref):
321
        from dulwich.repo import SYMREF
322
        refcontents = self._git.refs.read_ref(ref)
323
        if refcontents is None: # no such ref
324
            return None
325
        if refcontents.startswith(SYMREF):
326
            return refcontents[len(SYMREF):].rstrip("\n")
327
        return None
328
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
329
    def set_branch_reference(self, target, name=None):
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
330
        if self.control_transport.base != target.controldir.control_transport.base:
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
331
            raise bzr_errors.IncompatibleFormat(target._format, self._format)
0.200.1311 by Jelmer Vernooij
More work on colocated branch support.
332
        ref = self._get_selected_ref(name)
333
        self._git.refs.set_symbolic_ref(ref, target.ref)
334
335
    def get_branch_reference(self, name=None):
336
        ref = self._get_selected_ref(name)
337
        target_ref = self._get_symref(ref)
338
        if target_ref is not None:
0.200.1377 by Jelmer Vernooij
Fix get_branch_reference.
339
            return urlutils.join_segment_parameters(
0.200.1379 by Jelmer Vernooij
Escape slashes.
340
                self.user_url.rstrip("/"), {"ref": urllib.quote(target_ref, '')})
0.200.1311 by Jelmer Vernooij
More work on colocated branch support.
341
        return None
342
343
    def find_branch_format(self, name=None):
0.200.1644 by Jelmer Vernooij
More relative imports.
344
        from .branch import (
0.200.1311 by Jelmer Vernooij
More work on colocated branch support.
345
            GitBranchFormat,
346
            GitSymrefBranchFormat,
347
            )
348
        ref = self._get_selected_ref(name)
349
        if self._get_symref(ref) is not None:
350
            return GitSymrefBranchFormat()
351
        else:
352
            return GitBranchFormat()
353
0.200.978 by Jelmer Vernooij
Allow name argument to get_branch_transport to be missing.
354
    def get_branch_transport(self, branch_format, name=None):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
355
        if branch_format is None:
356
            return self.transport
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
357
        if isinstance(branch_format, LocalGitControlDirFormat):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
358
            return self.transport
0.239.13 by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed.
359
        raise bzr_errors.IncompatibleFormat(branch_format, self._format)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
360
0.200.887 by Jelmer Vernooij
get_branch_transport takes a name argument.
361
    def get_repository_transport(self, format):
362
        if format is None:
363
            return self.transport
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
364
        if isinstance(format, LocalGitControlDirFormat):
0.200.887 by Jelmer Vernooij
get_branch_transport takes a name argument.
365
            return self.transport
366
        raise bzr_errors.IncompatibleFormat(format, self._format)
367
368
    def get_workingtree_transport(self, format):
369
        if format is None:
370
            return self.transport
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
371
        if isinstance(format, LocalGitControlDirFormat):
0.200.887 by Jelmer Vernooij
get_branch_transport takes a name argument.
372
            return self.transport
373
        raise bzr_errors.IncompatibleFormat(format, self._format)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
374
0.269.8 by Jelmer Vernooij
Support push in git-remote-bzr.
375
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=None,
0.200.1475 by Jelmer Vernooij
Cope with new possible_transports argument to open_branch().
376
            ref=None, possible_transports=None):
0.200.57 by Jelmer Vernooij
Fix more tests.
377
        """'create' a branch for this dir."""
378
        repo = self.open_repository()
0.200.1644 by Jelmer Vernooij
More relative imports.
379
        from .branch import LocalGitBranch
0.269.8 by Jelmer Vernooij
Support push in git-remote-bzr.
380
        ref = self._get_selected_ref(name, ref)
0.284.3 by Jelmer Vernooij
Use new RefsContainer.follow().
381
        ref_chain, sha = self._git.refs.follow(ref)
382
        if sha is None:
0.200.1311 by Jelmer Vernooij
More work on colocated branch support.
383
            raise bzr_errors.NotBranchError(self.root_transport.base,
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
384
                    controldir=self)
0.200.1411 by Jelmer Vernooij
Fix control files.
385
        return LocalGitBranch(self, repo, ref)
0.200.722 by Jelmer Vernooij
Implement GitDir.list_branches() and support name argument to open_branch.
386
0.200.724 by Jelmer Vernooij
support destroy_branch
387
    def destroy_branch(self, name=None):
0.200.1310 by Jelmer Vernooij
Add _get_selected_ref method.
388
        refname = self._get_selected_ref(name)
0.200.1364 by Jelmer Vernooij
Fix .destroy_branch.
389
        try:
390
            del self._git.refs[refname]
391
        except KeyError:
0.200.997 by Jelmer Vernooij
Implement BzrDir.needs_format_conversion.
392
            raise bzr_errors.NotBranchError(self.root_transport.base,
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
393
                    controldir=self)
0.200.724 by Jelmer Vernooij
support destroy_branch
394
0.200.980 by Jelmer Vernooij
Implement LocalGitBzrDir.destroy_repository().
395
    def destroy_repository(self):
396
        raise bzr_errors.UnsupportedOperation(self.destroy_repository, self)
397
0.200.986 by Jelmer Vernooij
Implement GitDir.destroy_workingtree.
398
    def destroy_workingtree(self):
0.200.1566 by Jelmer Vernooij
Basic implementation of LocalGitDir.destroy_workingtree.
399
        wt = self.open_workingtree(recommend_upgrade=False)
400
        repository = wt.branch.repository
401
        empty = repository.revision_tree(_mod_revision.NULL_REVISION)
402
        # We ignore the conflicts returned by wt.revert since we're about to
403
        # delete the wt metadata anyway, all that should be left here are
404
        # detritus. But see bug #634470 about subtree .bzr dirs.
405
        conflicts = wt.revert(old_tree=empty)
406
        self.destroy_workingtree_metadata()
407
408
    def destroy_workingtree_metadata(self):
409
        self.transport.delete('index')
0.200.986 by Jelmer Vernooij
Implement GitDir.destroy_workingtree.
410
0.200.997 by Jelmer Vernooij
Implement BzrDir.needs_format_conversion.
411
    def needs_format_conversion(self, format=None):
412
        return not isinstance(self._format, format.__class__)
413
0.200.722 by Jelmer Vernooij
Implement GitDir.list_branches() and support name argument to open_branch.
414
    def list_branches(self):
0.200.1501 by Jelmer Vernooij
Provide ControlDir.get_branches.
415
        return self.get_branches().values()
416
417
    def get_branches(self):
0.200.1644 by Jelmer Vernooij
More relative imports.
418
        from .refs import ref_to_branch_name
0.200.1501 by Jelmer Vernooij
Provide ControlDir.get_branches.
419
        ret = {}
420
        for ref in self._git.refs.keys():
421
            try:
422
                branch_name = ref_to_branch_name(ref)
423
            except ValueError:
424
                continue
425
            except UnicodeDecodeError:
426
                trace.warning("Ignoring branch %r with unicode error ref", ref)
427
                continue
428
            ret[branch_name] = self.open_branch(ref=ref)
0.200.722 by Jelmer Vernooij
Implement GitDir.list_branches() and support name argument to open_branch.
429
        return ret
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
430
0.200.1114 by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True
431
    def open_repository(self):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
432
        """'open' a repository for this dir."""
0.200.1411 by Jelmer Vernooij
Fix control files.
433
        return self._gitrepository_class(self)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
434
0.200.1537 by Jelmer Vernooij
Support unsupported= argument.
435
    def open_workingtree(self, recommend_upgrade=True, unsupported=False):
0.246.5 by Jelmer Vernooij
Cope with has_index not existing.
436
        if not self._git.bare:
437
            from dulwich.errors import NoIndexPresent
0.200.803 by Jelmer Vernooij
Default to non-bare repositories when initializing a control directory.
438
            repo = self.open_repository()
0.246.5 by Jelmer Vernooij
Cope with has_index not existing.
439
            try:
0.200.803 by Jelmer Vernooij
Default to non-bare repositories when initializing a control directory.
440
                index = repo._git.open_index()
0.246.5 by Jelmer Vernooij
Cope with has_index not existing.
441
            except NoIndexPresent:
442
                pass
0.200.803 by Jelmer Vernooij
Default to non-bare repositories when initializing a control directory.
443
            else:
0.200.1644 by Jelmer Vernooij
More relative imports.
444
                from .workingtree import GitWorkingTree
0.200.921 by Jelmer Vernooij
fix init tests.
445
                try:
446
                    branch = self.open_branch()
447
                except bzr_errors.NotBranchError:
448
                    pass
449
                else:
450
                    return GitWorkingTree(self, repo, branch, index)
0.200.392 by Jelmer Vernooij
Fix some tests now that working trees are supported.
451
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
0.239.13 by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed.
452
        raise bzr_errors.NoWorkingTree(loc)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
453
0.200.108 by Jelmer Vernooij
Support bzr init --git.
454
    def create_repository(self, shared=False):
0.200.1644 by Jelmer Vernooij
More relative imports.
455
        from .repository import GitRepositoryFormat
0.200.1114 by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True
456
        if shared:
457
            raise bzr_errors.IncompatibleFormat(GitRepositoryFormat(), self._format)
0.200.108 by Jelmer Vernooij
Support bzr init --git.
458
        return self.open_repository()
0.200.288 by Jelmer Vernooij
Add test for init-repo.
459
0.200.1377 by Jelmer Vernooij
Fix get_branch_reference.
460
    def create_branch(self, name=None, repository=None,
0.269.8 by Jelmer Vernooij
Support push in git-remote-bzr.
461
                      append_revisions_only=None, ref=None):
462
        refname = self._get_selected_ref(name, ref)
0.200.891 by Jelmer Vernooij
Use ZERO_SHA constant where possible.
463
        from dulwich.protocol import ZERO_SHA
0.200.1373 by Jelmer Vernooij
Prevent accidentally removing branch.
464
        if refname in self._git.refs:
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
465
            raise bzr_errors.AlreadyBranchError(self.user_url)
0.200.1373 by Jelmer Vernooij
Prevent accidentally removing branch.
466
        self._git.refs[refname] = ZERO_SHA
0.200.1377 by Jelmer Vernooij
Fix get_branch_reference.
467
        branch = self.open_branch(name)
0.200.1378 by Jelmer Vernooij
Fix branch.
468
        if append_revisions_only:
0.200.1377 by Jelmer Vernooij
Fix get_branch_reference.
469
            branch.set_append_revisions_only(append_revisions_only)
470
        return branch
0.200.535 by Jelmer Vernooij
use standard version to check for index.
471
472
    def backup_bzrdir(self):
0.200.1549 by Jelmer Vernooij
Support backing up bare repositories.
473
        if not self._git.bare:
0.200.535 by Jelmer Vernooij
use standard version to check for index.
474
            self.root_transport.copy_tree(".git", ".git.backup")
475
            return (self.root_transport.abspath(".git"),
476
                    self.root_transport.abspath(".git.backup"))
477
        else:
0.200.1549 by Jelmer Vernooij
Support backing up bare repositories.
478
            basename = urlutils.basename(self.root_transport.base)
479
            parent = self.root_transport.clone('..')
480
            parent.copy_tree(basename, basename + ".backup")
0.200.535 by Jelmer Vernooij
use standard version to check for index.
481
482
    def create_workingtree(self, revision_id=None, from_branch=None,
483
        accelerator_tree=None, hardlink=False):
484
        if self._git.bare:
0.200.1038 by Jelmer Vernooij
Raise UnsupportedOperation on create_workingtree.
485
            raise bzr_errors.UnsupportedOperation(self.create_workingtree, self)
0.200.535 by Jelmer Vernooij
use standard version to check for index.
486
        from dulwich.index import write_index
0.200.613 by Jelmer Vernooij
Support creating working tree for existing git repo.
487
        from dulwich.pack import SHA1Writer
488
        f = open(self.transport.local_abspath("index"), 'w+')
489
        try:
490
            f = SHA1Writer(f)
491
            write_index(f, [])
492
        finally:
493
            f.close()
0.200.535 by Jelmer Vernooij
use standard version to check for index.
494
        return self.open_workingtree()
0.200.1015 by Jelmer Vernooij
Fix GitControlDir.find_repository().
495
0.200.1114 by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True
496
    def _find_or_create_repository(self, force_new_repo=None):
497
        return self.create_repository(shared=False)
498
0.200.1018 by Jelmer Vernooij
Fix use with new control dir API.
499
    def _find_creation_modes(self):
500
        """Determine the appropriate modes for files and directories.
501
502
        They're always set to be consistent with the base directory,
503
        assuming that this transport allows setting modes.
504
        """
505
        # TODO: Do we need or want an option (maybe a config setting) to turn
506
        # this off or override it for particular locations? -- mbp 20080512
507
        if self._mode_check_done:
508
            return
509
        self._mode_check_done = True
510
        try:
511
            st = self.transport.stat('.')
0.200.1116 by Jelmer Vernooij
Fix missing import.
512
        except bzr_errors.TransportNotPossible:
0.200.1018 by Jelmer Vernooij
Fix use with new control dir API.
513
            self._dir_mode = None
514
            self._file_mode = None
515
        else:
516
            # Check the directory mode, but also make sure the created
517
            # directories and files are read-write for this user. This is
518
            # mostly a workaround for filesystems which lie about being able to
519
            # write to a directory (cygwin & win32)
520
            if (st.st_mode & 07777 == 00000):
521
                # FTP allows stat but does not return dir/file modes
522
                self._dir_mode = None
523
                self._file_mode = None
524
            else:
525
                self._dir_mode = (st.st_mode & 07777) | 00700
526
                # Remove the sticky and execute bits for files
527
                self._file_mode = self._dir_mode & ~07111
528
529
    def _get_file_mode(self):
530
        """Return Unix mode for newly created files, or None.
531
        """
532
        if not self._mode_check_done:
533
            self._find_creation_modes()
534
        return self._file_mode
535
536
    def _get_dir_mode(self):
537
        """Return Unix mode for newly created directories, or None.
538
        """
539
        if not self._mode_check_done:
540
            self._find_creation_modes()
541
        return self._dir_mode
542
0.200.1487 by Jelmer Vernooij
Use peeling.
543
    def get_refs_container(self):
544
        return self._git.refs
0.200.1489 by Jelmer Vernooij
More fixes to peel handling.
545
546
    def get_peeled(self, ref):
547
        return self._git.get_peeled(ref)