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