/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; fetching objects from local repository works now; they aren't converted yet though.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    )
37
37
""")
38
38
 
39
 
from bzrlib.plugins.git import LocalGitBzrDirFormat
40
 
 
41
39
 
42
40
 
43
41
class GitLock(object):
73
71
class GitDir(bzrdir.BzrDir):
74
72
    """An adapter to the '.git' dir used by git."""
75
73
 
76
 
    def is_supported(self):
77
 
        return True
78
 
 
79
 
    def cloning_metadir(self, stacked=False):
80
 
        return bzrlib.bzrdir.format_registry.make_bzrdir("1.9-rich-root")
81
 
 
82
 
 
83
 
class LocalGitDir(GitDir):
84
 
    """An adapter to the '.git' dir used by git."""
85
 
 
86
74
    _gitrepository_class = repository.LocalGitRepository
87
75
 
88
76
    def __init__(self, transport, lockfiles, gitrepo, format):
105
93
    get_repository_transport = get_branch_transport
106
94
    get_workingtree_transport = get_branch_transport
107
95
 
 
96
    def is_supported(self):
 
97
        return True
 
98
 
108
99
    def open_branch(self, ignored=None):
109
100
        """'create' a branch for this dir."""
110
101
        repo = self.open_repository()
115
106
        return self._gitrepository_class(self, self._lockfiles)
116
107
 
117
108
    def open_workingtree(self, recommend_upgrade=True):
118
 
        if (not self._git.bare and 
119
 
            os.path.exists(os.path.join(self._git.controldir(), "index"))):
 
109
        if self._git.bare:
 
110
            loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
 
111
            raise errors.bzr_errors.NoWorkingTree(loc)
 
112
        else:
120
113
            return workingtree.GitWorkingTree(self, self.open_repository(), 
121
114
                                                  self.open_branch())
122
 
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
123
 
        raise errors.bzr_errors.NoWorkingTree(loc)
 
115
 
 
116
    def cloning_metadir(self, stacked=False):
 
117
        if stacked:
 
118
            return bzrlib.bzrdir.format_registry.make_bzrdir("pack-0.92")
 
119
        else:
 
120
            return bzrlib.bzrdir.format_registry.make_bzrdir("1.6")
124
121
 
125
122
    def create_repository(self, shared=False):
126
123
        return self.open_repository()
 
124
 
 
125
 
 
126
class LocalGitBzrDirFormat(bzrdir.BzrDirFormat):
 
127
    """The .git directory control format."""
 
128
 
 
129
    _gitdir_class = GitDir
 
130
    _lock_class = TransportLock
 
131
 
 
132
    @classmethod
 
133
    def _known_formats(self):
 
134
        return set([LocalGitBzrDirFormat()])
 
135
 
 
136
    def open(self, transport, _found=None):
 
137
        """Open this directory.
 
138
 
 
139
        """
 
140
        from bzrlib.plugins.git import git
 
141
        # we dont grok readonly - git isn't integrated with transport.
 
142
        url = transport.base
 
143
        if url.startswith('readonly+'):
 
144
            url = url[len('readonly+'):]
 
145
 
 
146
        try:
 
147
            gitrepo = git.repo.Repo(transport.local_abspath("."))
 
148
        except errors.bzr_errors.NotLocalUrl:
 
149
            raise errors.bzr_errors.NotBranchError(path=transport.base)
 
150
        lockfiles = GitLockableFiles(transport, GitLock())
 
151
        return self._gitdir_class(transport, lockfiles, gitrepo, self)
 
152
 
 
153
    @classmethod
 
154
    def probe_transport(klass, transport):
 
155
        """Our format is present if the transport ends in '.not/'."""
 
156
        # little ugly, but works
 
157
        format = klass()
 
158
        # delegate to the main opening code. This pays a double rtt cost at the
 
159
        # moment, so perhaps we want probe_transport to return the opened thing
 
160
        # rather than an openener ? or we could return a curried thing with the
 
161
        # dir to open already instantiated ? Needs more thought.
 
162
        try:
 
163
            format.open(transport)
 
164
            return format
 
165
        except Exception, e:
 
166
            raise errors.bzr_errors.NotBranchError(path=transport.base)
 
167
        raise errors.bzr_errors.NotBranchError(path=transport.base)
 
168
 
 
169
    def get_format_description(self):
 
170
        return "Local Git Repository"
 
171
 
 
172
    def get_format_string(self):
 
173
        return "Local Git Repository"
 
174
 
 
175
    def initialize_on_transport(self, transport):
 
176
        from bzrlib.transport.local import LocalTransport
 
177
        from bzrlib.plugins.git import git
 
178
 
 
179
        if not isinstance(transport, LocalTransport):
 
180
            raise NotImplementedError(self.initialize, 
 
181
                "Can't create Git Repositories/branches on "
 
182
                "non-local transports")
 
183
 
 
184
        git.repo.Repo.create(transport.local_abspath(".")) 
 
185
        return self.open(transport)
 
186
 
 
187
    def is_supported(self):
 
188
        return True
 
189
 
 
190
 
 
191
class RemoteGitBzrDirFormat(bzrdir.BzrDirFormat):
 
192
    """The .git directory control format."""
 
193
 
 
194
    _lock_class = TransportLock
 
195
 
 
196
    @classmethod
 
197
    def _known_formats(self):
 
198
        return set([RemoteGitBzrDirFormat()])
 
199
 
 
200
    def open(self, transport, _found=None):
 
201
        """Open this directory.
 
202
 
 
203
        """
 
204
        from bzrlib.plugins.git.remote import RemoteGitDir, GitSmartTransport
 
205
        if not isinstance(transport, GitSmartTransport):
 
206
            raise errors.bzr_errors.NotBranchError(transport.base)
 
207
        # we dont grok readonly - git isn't integrated with transport.
 
208
        url = transport.base
 
209
        if url.startswith('readonly+'):
 
210
            url = url[len('readonly+'):]
 
211
 
 
212
        lockfiles = GitLockableFiles(transport, GitLock())
 
213
        return RemoteGitDir(transport, lockfiles, self)
 
214
 
 
215
    @classmethod
 
216
    def probe_transport(klass, transport):
 
217
        """Our format is present if the transport ends in '.not/'."""
 
218
        # little ugly, but works
 
219
        format = klass()
 
220
        from bzrlib.plugins.git.remote import GitSmartTransport
 
221
        if not isinstance(transport, GitSmartTransport):
 
222
            raise errors.bzr_errors.NotBranchError(transport.base)
 
223
        # The only way to know a path exists and contains a valid repository 
 
224
        # is to do a request against it:
 
225
        try:
 
226
            transport.fetch_pack(lambda x: [], None, lambda x: None, 
 
227
                                 lambda x: mutter("git: %s" % x))
 
228
        except GitProtocolException, e:
 
229
            raise errors.bzr_errors.NotBranchError(path=transport.base)
 
230
        else:
 
231
            return format
 
232
        raise errors.bzr_errors.NotBranchError(path=transport.base)
 
233
 
 
234
    def get_format_description(self):
 
235
        return "Remote Git Repository"
 
236
 
 
237
    def get_format_string(self):
 
238
        return "Remote Git Repository"
 
239
 
 
240
    def initialize_on_transport(self, transport):
 
241
        raise errors.bzr_errors.UninitializableFormat(self)
 
242
 
 
243
    def is_supported(self):
 
244
        return True