/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
20
from bzrlib import (
0.239.13 by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed.
21
    errors as bzr_errors,
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
22
    lockable_files,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
23
    trace,
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
24
    urlutils,
0.200.768 by Jelmer Vernooij
Fix compatibility with older versions of bzrlib.
25
    version_info as bzrlib_version,
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
26
    )
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
27
from bzrlib.bzrdir import CreateRepository
28
from bzrlib.transport import do_catching_redirections
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
29
0.200.280 by Jelmer Vernooij
Support bzr.dev.
30
LockWarner = getattr(lockable_files, "_LockWarner", None)
31
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
32
from bzrlib.controldir import (
33
    ControlDir,
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
34
    ControlDirFormat,
0.200.1111 by Jelmer Vernooij
Drop support for Bazaar < 2.3.
35
    format_registry,
36
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
37
0.200.123 by Jelmer Vernooij
Use central git module.
38
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
39
class GitLock(object):
40
    """A lock that thunks through to Git."""
41
0.200.1130 by Jelmer Vernooij
Implement GitLock.lock_name.
42
    def __init__(self):
43
        self.lock_name = "git lock"
44
0.200.84 by Jelmer Vernooij
Fix lock_write argument.
45
    def lock_write(self, token=None):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
46
        pass
47
48
    def lock_read(self):
49
        pass
50
51
    def unlock(self):
52
        pass
53
0.200.73 by Jelmer Vernooij
Implement GitLock.peek().
54
    def peek(self):
55
        pass
56
0.200.130 by Jelmer Vernooij
Make most tree inspection tests succeed.
57
    def validate_token(self, token):
58
        pass
59
0.200.629 by Jelmer Vernooij
Add GitLock.break_lock().
60
    def break_lock(self):
61
        pass
62
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
63
64
class GitLockableFiles(lockable_files.LockableFiles):
65
    """Git specific lockable files abstraction."""
66
0.200.129 by Jelmer Vernooij
merge dulwich.
67
    def __init__(self, transport, lock):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
68
        self._lock = lock
69
        self._transaction = None
70
        self._lock_mode = None
0.200.129 by Jelmer Vernooij
merge dulwich.
71
        self._transport = transport
0.200.280 by Jelmer Vernooij
Support bzr.dev.
72
        if LockWarner is None:
73
            # Bzr 1.13
74
            self._lock_count = 0
75
        else:
76
            self._lock_warner = LockWarner(repr(self))
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
77
78
0.200.1026 by Jelmer Vernooij
Fix typo.
79
class GitDirConfig(object):
0.200.1025 by Jelmer Vernooij
Implement GitDir.get_config().
80
81
    def get_default_stack_on(self):
82
        return None
83
84
    def set_default_stack_on(self, value):
85
        raise bzr_errors.BzrError("Cannot set configuration")
86
87
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
88
class GitControlDirFormat(ControlDirFormat):
89
90
    _lock_class = lockable_files.TransportLock
91
92
    colocated_branches = True
93
    fixed_components = True
94
95
    def __eq__(self, other):
96
        return type(self) == type(other)
97
98
    def is_supported(self):
99
        return True
100
101
    def network_name(self):
102
        return "git"
103
104
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
105
class GitDir(ControlDir):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
106
    """An adapter to the '.git' dir used by git."""
107
0.200.148 by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir.
108
    def is_supported(self):
109
        return True
110
0.200.981 by Jelmer Vernooij
Mark git directories as not convertable (for now).
111
    def can_convert_format(self):
112
        return False
113
0.200.1025 by Jelmer Vernooij
Implement GitDir.get_config().
114
    def break_lock(self):
115
        pass
116
0.200.155 by Jelmer Vernooij
Fix formatting, remove catch-all for exceptions when opening local repositories.
117
    def cloning_metadir(self, stacked=False):
0.200.1013 by Jelmer Vernooij
More renames.
118
        return format_registry.make_bzrdir("default")
0.200.155 by Jelmer Vernooij
Fix formatting, remove catch-all for exceptions when opening local repositories.
119
0.200.729 by Jelmer Vernooij
Improve colocated branches support.
120
    def _branch_name_to_ref(self, name):
0.200.832 by Jelmer Vernooij
Update to newer version of Dulwich, saner branch names.
121
        raise NotImplementedError(self._branch_name_to_ref)
0.200.729 by Jelmer Vernooij
Improve colocated branches support.
122
0.200.1025 by Jelmer Vernooij
Implement GitDir.get_config().
123
    def get_config(self):
124
        return GitDirConfig()
125
0.259.1 by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility.
126
    def sprout(self, url, revision_id=None, force_new_repo=False,
127
               recurse='down', possible_transports=None,
128
               accelerator_tree=None, hardlink=False, stacked=False,
129
               source_branch=None, create_tree_if_local=True):
130
        from bzrlib.repository import InterRepository
131
        from bzrlib.transport.local import LocalTransport
132
        from bzrlib.transport import get_transport
133
        target_transport = get_transport(url, possible_transports)
134
        target_transport.ensure_base()
135
        cloning_format = self.cloning_metadir()
136
        # Create/update the result branch
137
        result = cloning_format.initialize_on_transport(target_transport)
138
        source_branch = self.open_branch()
139
        source_repository = self.find_repository()
140
        try:
141
            result_repo = result.find_repository()
142
        except bzr_errors.NoRepositoryPresent:
143
            result_repo = result.create_repository()
144
            target_is_empty = True
145
        else:
146
            target_is_empty = None # Unknown
147
        if stacked:
148
            raise bzr_errors.IncompatibleRepositories(source_repository, result_repo)
149
        interrepo = InterRepository.get(source_repository, result_repo)
150
151
        if revision_id is not None:
0.259.3 by Jelmer Vernooij
Rename determine_wants_and_revids.
152
            determine_wants = source_repository.determine_wants_revids_and_tags(
153
                [revision_id])
0.259.1 by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility.
154
        else:
155
            from bzrlib.plugins.git.object_store import get_object_store
156
            store = get_object_store(result_repo, source_branch.mapping)
157
            determine_wants = store.determine_wants_all
158
        interrepo.fetch_objects(determine_wants=determine_wants,
159
            mapping=source_branch.mapping)
160
        result_branch = source_branch.sprout(result,
161
            revision_id=revision_id, repository=result_repo)
162
        if (create_tree_if_local and isinstance(target_transport, LocalTransport)
163
            and (result_repo is None or result_repo.make_working_trees())):
164
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
165
                hardlink=hardlink, from_branch=result_branch)
166
            wt.lock_write()
167
            try:
168
                if wt.path2id('') is None:
169
                    try:
170
                        wt.set_root_id(self.open_workingtree.get_root_id())
171
                    except bzr_errors.NoWorkingTree:
172
                        pass
173
            finally:
174
                wt.unlock()
175
        return result
176
0.200.1117 by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport.
177
    def clone_on_transport(self, transport, revision_id=None,
178
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
179
        create_prefix=False, use_existing_dir=True, no_tree=False):
0.200.1121 by Jelmer Vernooij
Cope with ZERO_SHA in wants.
180
        from dulwich.protocol import ZERO_SHA
0.200.1117 by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport.
181
        """See ControlDir.clone_on_transport."""
0.200.1119 by Jelmer Vernooij
Refactor repository initialization.
182
        if no_tree:
183
            format = BareLocalGitControlDirFormat()
184
        else:
185
            format = LocalGitControlDirFormat()
186
        (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)
187
        target_git_repo = target_repo._git
0.200.1117 by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport.
188
        source_repo = self.open_repository()
189
        source_git_repo = source_repo._git
190
        if revision_id is not None:
0.259.1 by Jelmer Vernooij
Provide custom GitDir.sprout() for bzr 2.4 compatibility.
191
            determine_wants = source_repo.determine_wants_revid_and_tags(revision_id)
0.200.1117 by Jelmer Vernooij
Provide basic implementation of GitDir.clone_on_transport.
192
        else:
193
            determine_wants = target_git_repo.object_store.determine_wants_all
194
        refs = source_git_repo.fetch(target_git_repo, determine_wants)
195
        for name, val in refs.iteritems():
196
            target_git_repo.refs[name] = val
197
        lockfiles = GitLockableFiles(transport, GitLock())
198
        return self.__class__(transport, lockfiles, target_git_repo, format)
199
0.259.2 by Jelmer Vernooij
Make sure RemoteGitDir.find_repository works.
200
    def find_repository(self):
201
        """Find the repository that should be used.
202
203
        This does not require a branch as we use it to find the repo for
204
        new branches as well as to hook existing branches up to their
205
        repository.
206
        """
207
        return self.open_repository()
208
0.200.148 by Jelmer Vernooij
Share more infrastructure between LocalGitDir and RemoteGitDir.
209
0.200.1137 by Jelmer Vernooij
Support BzrProber.known_formats().
210
class LocalGitControlDirFormat(GitControlDirFormat):
211
    """The .git directory control format."""
212
213
    bare = False
214
215
    @classmethod
216
    def _known_formats(self):
217
        return set([LocalGitControlDirFormat()])
218
219
    @property
220
    def repository_format(self):
221
        from bzrlib.plugins.git.repository import GitRepositoryFormat
222
        return GitRepositoryFormat()
223
224
    def get_branch_format(self):
225
        from bzrlib.plugins.git.branch import GitBranchFormat
226
        return GitBranchFormat()
227
228
    def open(self, transport, _found=None):
229
        """Open this directory.
230
231
        """
232
        from bzrlib.plugins.git.transportgit import TransportRepo
233
        gitrepo = TransportRepo(transport)
234
        lockfiles = GitLockableFiles(transport, GitLock())
235
        return LocalGitDir(transport, lockfiles, gitrepo, self)
236
237
    def get_format_description(self):
238
        return "Local Git Repository"
239
240
    def initialize_on_transport(self, transport):
241
        from bzrlib.plugins.git.transportgit import TransportRepo
242
        TransportRepo.init(transport, bare=self.bare)
243
        return self.open(transport)
244
245
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
246
        create_prefix=False, force_new_repo=False, stacked_on=None,
247
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
248
        shared_repo=False, vfs_only=False):
249
        def make_directory(transport):
250
            transport.mkdir('.')
251
            return transport
252
        def redirected(transport, e, redirection_notice):
253
            trace.note(redirection_notice)
254
            return transport._redirected_to(e.source, e.target)
255
        try:
256
            transport = do_catching_redirections(make_directory, transport,
257
                redirected)
258
        except bzr_errors.FileExists:
259
            if not use_existing_dir:
260
                raise
261
        except bzr_errors.NoSuchFile:
262
            if not create_prefix:
263
                raise
264
            transport.create_prefix()
265
        controldir = self.initialize_on_transport(transport)
266
        repository = controldir.open_repository()
267
        repository.lock_write()
268
        return (repository, controldir, False, CreateRepository(controldir))
269
270
    def is_supported(self):
271
        return True
272
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):
287
        from bzrlib.plugins.git.repository import LocalGitRepository
288
        return LocalGitRepository
289
290
    _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.
291
0.200.1014 by Jelmer Vernooij
Fix tests.
292
    @property
293
    def user_transport(self):
294
        return self.root_transport
295
296
    @property
297
    def control_transport(self):
298
        return self.transport
299
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
300
    def __init__(self, transport, lockfiles, gitrepo, format):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
301
        self._format = format
302
        self.root_transport = transport
0.200.1018 by Jelmer Vernooij
Fix use with new control dir API.
303
        self._mode_check_done = False
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
304
        self._git = gitrepo
305
        if gitrepo.bare:
306
            self.transport = transport
307
        else:
308
            self.transport = transport.clone('.git')
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
309
        self._lockfiles = lockfiles
0.200.381 by Jelmer Vernooij
Support working trees properly, status and ls.
310
        self._mode_check_done = None
311
0.200.832 by Jelmer Vernooij
Update to newer version of Dulwich, saner branch names.
312
    def _branch_name_to_ref(self, name):
0.200.872 by Jelmer Vernooij
Move refs code to separate module.
313
        from bzrlib.plugins.git.refs import branch_name_to_ref
0.200.916 by Jelmer Vernooij
Set refs/heads/master if no ref is set yet.
314
        ref = branch_name_to_ref(name, None)
0.200.915 by Jelmer Vernooij
Cope with the fact that the old format didn't export file ids.
315
        if ref == "HEAD":
0.200.832 by Jelmer Vernooij
Update to newer version of Dulwich, saner branch names.
316
            from dulwich.repo import SYMREF
0.200.915 by Jelmer Vernooij
Cope with the fact that the old format didn't export file ids.
317
            refcontents = self._git.refs.read_ref(ref)
0.200.832 by Jelmer Vernooij
Update to newer version of Dulwich, saner branch names.
318
            if refcontents.startswith(SYMREF):
0.200.915 by Jelmer Vernooij
Cope with the fact that the old format didn't export file ids.
319
                ref = refcontents[len(SYMREF):]
320
        return ref
0.200.832 by Jelmer Vernooij
Update to newer version of Dulwich, saner branch names.
321
0.200.381 by Jelmer Vernooij
Support working trees properly, status and ls.
322
    def is_control_filename(self, filename):
0.200.1126 by Jelmer Vernooij
Fix GitDir.is_control_filename.
323
        return (filename == '.git' or filename.startswith('.git/'))
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
324
0.200.978 by Jelmer Vernooij
Allow name argument to get_branch_transport to be missing.
325
    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.
326
        if branch_format is None:
327
            return self.transport
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
328
        if isinstance(branch_format, LocalGitControlDirFormat):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
329
            return self.transport
0.239.13 by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed.
330
        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.
331
0.200.887 by Jelmer Vernooij
get_branch_transport takes a name argument.
332
    def get_repository_transport(self, format):
333
        if format is None:
334
            return self.transport
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
335
        if isinstance(format, LocalGitControlDirFormat):
0.200.887 by Jelmer Vernooij
get_branch_transport takes a name argument.
336
            return self.transport
337
        raise bzr_errors.IncompatibleFormat(format, self._format)
338
339
    def get_workingtree_transport(self, format):
340
        if format is None:
341
            return self.transport
0.200.1012 by Jelmer Vernooij
Rename BzrDir to ControlDir.
342
        if isinstance(format, LocalGitControlDirFormat):
0.200.887 by Jelmer Vernooij
get_branch_transport takes a name argument.
343
            return self.transport
344
        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.
345
0.200.1148 by Jelmer Vernooij
Remove no longer necessary compatibility code for open_branch.
346
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=None):
0.200.57 by Jelmer Vernooij
Fix more tests.
347
        """'create' a branch for this dir."""
348
        repo = self.open_repository()
0.239.13 by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed.
349
        from bzrlib.plugins.git.branch import LocalGitBranch
0.200.726 by Jelmer Vernooij
Factor out conversion of branch names to refs.
350
        return LocalGitBranch(self, repo, self._branch_name_to_ref(name),
351
            self._lockfiles)
0.200.722 by Jelmer Vernooij
Implement GitDir.list_branches() and support name argument to open_branch.
352
0.200.724 by Jelmer Vernooij
support destroy_branch
353
    def destroy_branch(self, name=None):
0.200.997 by Jelmer Vernooij
Implement BzrDir.needs_format_conversion.
354
        refname = self._branch_name_to_ref(name)
355
        if not refname in self._git.refs:
356
            raise bzr_errors.NotBranchError(self.root_transport.base,
357
                    bzrdir=self)
358
        del self._git.refs[refname]
0.200.724 by Jelmer Vernooij
support destroy_branch
359
0.200.980 by Jelmer Vernooij
Implement LocalGitBzrDir.destroy_repository().
360
    def destroy_repository(self):
361
        raise bzr_errors.UnsupportedOperation(self.destroy_repository, self)
362
0.200.986 by Jelmer Vernooij
Implement GitDir.destroy_workingtree.
363
    def destroy_workingtree(self):
364
        raise bzr_errors.UnsupportedOperation(self.destroy_workingtree, self)
365
0.200.997 by Jelmer Vernooij
Implement BzrDir.needs_format_conversion.
366
    def needs_format_conversion(self, format=None):
367
        return not isinstance(self._format, format.__class__)
368
0.200.722 by Jelmer Vernooij
Implement GitDir.list_branches() and support name argument to open_branch.
369
    def list_branches(self):
370
        ret = []
371
        for name in self._git.get_refs():
0.200.832 by Jelmer Vernooij
Update to newer version of Dulwich, saner branch names.
372
            if name.startswith("refs/heads/"):
0.200.766 by Jelmer Vernooij
Only list actual branches, not tags.
373
                ret.append(self.open_branch(name=name))
0.200.722 by Jelmer Vernooij
Implement GitDir.list_branches() and support name argument to open_branch.
374
        return ret
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
375
0.200.1114 by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True
376
    def open_repository(self):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
377
        """'open' a repository for this dir."""
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
378
        return self._gitrepository_class(self, self._lockfiles)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
379
0.203.1 by Aaron Bentley
Make checkouts work
380
    def open_workingtree(self, recommend_upgrade=True):
0.246.5 by Jelmer Vernooij
Cope with has_index not existing.
381
        if not self._git.bare:
382
            from dulwich.errors import NoIndexPresent
0.200.803 by Jelmer Vernooij
Default to non-bare repositories when initializing a control directory.
383
            repo = self.open_repository()
0.246.5 by Jelmer Vernooij
Cope with has_index not existing.
384
            try:
0.200.803 by Jelmer Vernooij
Default to non-bare repositories when initializing a control directory.
385
                index = repo._git.open_index()
0.246.5 by Jelmer Vernooij
Cope with has_index not existing.
386
            except NoIndexPresent:
387
                pass
0.200.803 by Jelmer Vernooij
Default to non-bare repositories when initializing a control directory.
388
            else:
389
                from bzrlib.plugins.git.workingtree import GitWorkingTree
0.200.921 by Jelmer Vernooij
fix init tests.
390
                try:
391
                    branch = self.open_branch()
392
                except bzr_errors.NotBranchError:
393
                    pass
394
                else:
395
                    return GitWorkingTree(self, repo, branch, index)
0.200.392 by Jelmer Vernooij
Fix some tests now that working trees are supported.
396
        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.
397
        raise bzr_errors.NoWorkingTree(loc)
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
398
0.200.108 by Jelmer Vernooij
Support bzr init --git.
399
    def create_repository(self, shared=False):
0.200.1114 by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True
400
        from bzrlib.plugins.git.repository import GitRepositoryFormat
401
        if shared:
402
            raise bzr_errors.IncompatibleFormat(GitRepositoryFormat(), self._format)
0.200.108 by Jelmer Vernooij
Support bzr init --git.
403
        return self.open_repository()
0.200.288 by Jelmer Vernooij
Add test for init-repo.
404
0.200.1132 by Jelmer Vernooij
Support repository argument to LocalGitDir.create_branch.
405
    def create_branch(self, name=None, repository=None):
0.200.726 by Jelmer Vernooij
Factor out conversion of branch names to refs.
406
        refname = self._branch_name_to_ref(name)
0.200.891 by Jelmer Vernooij
Use ZERO_SHA constant where possible.
407
        from dulwich.protocol import ZERO_SHA
0.200.920 by Jelmer Vernooij
Fix some more tests.
408
        self._git.refs[refname or "HEAD"] = ZERO_SHA
0.200.731 by Jelmer Vernooij
Handle unsupported flag to open_branch().
409
        return self.open_branch(name)
0.200.535 by Jelmer Vernooij
use standard version to check for index.
410
411
    def backup_bzrdir(self):
412
        if self._git.bare:
413
            self.root_transport.copy_tree(".git", ".git.backup")
414
            return (self.root_transport.abspath(".git"),
415
                    self.root_transport.abspath(".git.backup"))
416
        else:
0.239.13 by Jelmer Vernooij
Don't break "bzr info -v" when Dulwich is not installed.
417
            raise bzr_errors.BzrError("Unable to backup bare repositories")
0.200.535 by Jelmer Vernooij
use standard version to check for index.
418
419
    def create_workingtree(self, revision_id=None, from_branch=None,
420
        accelerator_tree=None, hardlink=False):
421
        if self._git.bare:
0.200.1038 by Jelmer Vernooij
Raise UnsupportedOperation on create_workingtree.
422
            raise bzr_errors.UnsupportedOperation(self.create_workingtree, self)
0.200.535 by Jelmer Vernooij
use standard version to check for index.
423
        from dulwich.index import write_index
0.200.613 by Jelmer Vernooij
Support creating working tree for existing git repo.
424
        from dulwich.pack import SHA1Writer
425
        f = open(self.transport.local_abspath("index"), 'w+')
426
        try:
427
            f = SHA1Writer(f)
428
            write_index(f, [])
429
        finally:
430
            f.close()
0.200.535 by Jelmer Vernooij
use standard version to check for index.
431
        return self.open_workingtree()
0.200.1015 by Jelmer Vernooij
Fix GitControlDir.find_repository().
432
0.200.1114 by Jelmer Vernooij
Properly raise exception when create_repository is called with shared=True
433
    def _find_or_create_repository(self, force_new_repo=None):
434
        return self.create_repository(shared=False)
435
0.200.1018 by Jelmer Vernooij
Fix use with new control dir API.
436
    def _find_creation_modes(self):
437
        """Determine the appropriate modes for files and directories.
438
439
        They're always set to be consistent with the base directory,
440
        assuming that this transport allows setting modes.
441
        """
442
        # TODO: Do we need or want an option (maybe a config setting) to turn
443
        # this off or override it for particular locations? -- mbp 20080512
444
        if self._mode_check_done:
445
            return
446
        self._mode_check_done = True
447
        try:
448
            st = self.transport.stat('.')
0.200.1116 by Jelmer Vernooij
Fix missing import.
449
        except bzr_errors.TransportNotPossible:
0.200.1018 by Jelmer Vernooij
Fix use with new control dir API.
450
            self._dir_mode = None
451
            self._file_mode = None
452
        else:
453
            # Check the directory mode, but also make sure the created
454
            # directories and files are read-write for this user. This is
455
            # mostly a workaround for filesystems which lie about being able to
456
            # write to a directory (cygwin & win32)
457
            if (st.st_mode & 07777 == 00000):
458
                # FTP allows stat but does not return dir/file modes
459
                self._dir_mode = None
460
                self._file_mode = None
461
            else:
462
                self._dir_mode = (st.st_mode & 07777) | 00700
463
                # Remove the sticky and execute bits for files
464
                self._file_mode = self._dir_mode & ~07111
465
466
    def _get_file_mode(self):
467
        """Return Unix mode for newly created files, or None.
468
        """
469
        if not self._mode_check_done:
470
            self._find_creation_modes()
471
        return self._file_mode
472
473
    def _get_dir_mode(self):
474
        """Return Unix mode for newly created directories, or None.
475
        """
476
        if not self._mode_check_done:
477
            self._find_creation_modes()
478
        return self._dir_mode
479