/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to dir.py

Merge new dulwich.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""An adapter between a Git control dir and a Bazaar BzrDir"""
18
18
 
19
 
import git
 
19
import os
20
20
 
 
21
import bzrlib
21
22
from bzrlib.lazy_import import lazy_import
22
23
from bzrlib import (
23
24
    bzrdir,
26
27
    )
27
28
 
28
29
lazy_import(globals(), """
 
30
from bzrlib.lockable_files import TransportLock
29
31
from bzrlib.plugins.git import (
30
32
    errors,
31
 
    git_branch,
32
 
    git_repository,
33
 
    git_workingtree,
 
33
    branch,
 
34
    repository,
 
35
    workingtree,
34
36
    )
35
37
""")
36
38
 
37
39
 
 
40
 
38
41
class GitLock(object):
39
42
    """A lock that thunks through to Git."""
40
43
 
64
67
class GitDir(bzrdir.BzrDir):
65
68
    """An adapter to the '.git' dir used by git."""
66
69
 
67
 
    _gitrepository_class = git_repository.GitRepository
 
70
    _gitrepository_class = repository.GitRepository
68
71
 
69
72
    def __init__(self, transport, lockfiles, gitrepo, format):
70
73
        self._format = format
95
98
        if repo._git.heads == []:
96
99
            head = None
97
100
        else:
98
 
            head = repo._git.heads[0].commit.id
99
 
        return git_branch.GitBranch(self, repo, head, 
 
101
            head = repo._git.head()
 
102
        return branch.GitBranch(self, repo, head, 
100
103
                                    self.root_transport.base, self._lockfiles)
101
104
 
102
105
    def open_repository(self, shared=False):
108
111
            loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
109
112
            raise errors.bzr_errors.NoWorkingTree(loc)
110
113
        else:
111
 
            return git_workingtree.GitWorkingTree(self, self.open_repository(), 
 
114
            return workingtree.GitWorkingTree(self, self.open_repository(), 
112
115
                                                  self.open_branch())
113
116
 
114
 
    def cloning_metadir(self):
115
 
        return bzrdir.BzrDirFormat.get_default_format()
 
117
    def cloning_metadir(self, stacked=False):
 
118
        if stacked:
 
119
            return bzrlib.bzrdir.format_registry.make_bzrdir("pack-0.92")
 
120
        else:
 
121
            return bzrlib.bzrdir.format_registry.make_bzrdir("1.6")
 
122
 
 
123
    def create_repository(self, shared=False):
 
124
        return self.open_repository()
116
125
 
117
126
 
118
127
class GitBzrDirFormat(bzrdir.BzrDirFormat):
119
128
    """The .git directory control format."""
120
129
 
121
130
    _gitdir_class = GitDir
 
131
    _lock_class = TransportLock
122
132
 
123
133
    @classmethod
124
134
    def _known_formats(self):
128
138
        """Open this directory.
129
139
 
130
140
        """
 
141
        from bzrlib.plugins.git import git
131
142
        # we dont grok readonly - git isn't integrated with transport.
132
143
        url = transport.base
133
144
        if url.startswith('readonly+'):
159
170
    def get_format_description(self):
160
171
        return "Local Git Repository"
161
172
 
 
173
    def get_format_string(self):
 
174
        return "Local Git Repository"
 
175
 
 
176
    def initialize_on_transport(self, transport):
 
177
        from bzrlib.transport.local import LocalTransport
 
178
        from bzrlib.plugins.git import git
 
179
 
 
180
        if not isinstance(transport, LocalTransport):
 
181
            raise NotImplementedError(self.initialize, 
 
182
                "Can't create Git Repositories/branches on "
 
183
                "non-local transports")
 
184
 
 
185
        git.repo.Repo.create(transport.local_abspath(".")) 
 
186
        return self.open(transport)
 
187
 
162
188
 
163
189
bzrdir.BzrDirFormat.register_control_format(GitBzrDirFormat)