/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 __init__.py

  • Committer: Jelmer Vernooij
  • Date: 2009-09-10 13:13:15 UTC
  • mto: (0.200.602 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090910131315-6890xg58pl2jseml
Allow serving remote URLs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
 
71
71
if getattr(sys, "frozen", None):
72
72
    # allow import additional libs from ./_lib for bzr.exe only
73
 
    sys.path.append(os.path.normpath(
74
 
        os.path.join(os.path.dirname(__file__), '_lib')))
 
73
    sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '_lib')))
75
74
 
76
75
_versions_checked = False
77
76
def lazy_check_versions():
82
81
    try:
83
82
        from dulwich import __version__ as dulwich_version
84
83
    except ImportError:
85
 
        raise bzr_errors.DependencyNotPresent("dulwich",
86
 
            "bzr-git: Please install dulwich, https://launchpad.net/dulwich")
 
84
        raise bzr_errors.DependencyNotPresent("dulwich", "bzr-git: Please install dulwich, https://launchpad.net/dulwich")
87
85
    else:
88
86
        if dulwich_version < dulwich_minimum_version:
89
 
            raise bzr_errors.DependencyNotPresent("dulwich",
90
 
                "bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
91
 
                    dulwich_minimum_version)
 
87
            raise bzr_errors.DependencyNotPresent("dulwich", "bzr-git: Dulwich is too old; at least %d.%d.%d is required" % dulwich_minimum_version)
92
88
 
93
 
bzrdir.format_registry.register_lazy('git',
 
89
bzrdir.format_registry.register_lazy('git', 
94
90
    "bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
95
91
    help='GIT repository.', native=False, experimental=True,
96
92
    )
97
93
 
98
94
from bzrlib.revisionspec import revspec_registry
99
 
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
 
95
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec", 
100
96
    "RevisionSpec_git")
101
97
 
102
 
try:
103
 
    from bzrlib.revisionspec import dwim_revspecs
104
 
except ImportError:
105
 
    pass
106
 
else:
107
 
    from bzrlib.plugins.git.revspec import RevisionSpec_git
108
 
    dwim_revspecs.append(RevisionSpec_git)
109
 
 
110
98
 
111
99
class GitBzrDirFormat(bzrdir.BzrDirFormat):
112
 
 
113
100
    _lock_class = TransportLock
114
101
 
115
 
    colocated_branches = True
116
 
 
117
102
    def is_supported(self):
118
103
        return True
119
104
 
132
117
        """Open this directory.
133
118
 
134
119
        """
135
 
        lazy_check_versions()
136
 
        from bzrlib.plugins.git.transportgit import TransportRepo
137
 
        gitrepo = TransportRepo(transport)
 
120
        import dulwich
 
121
        # we dont grok readonly - git isn't integrated with transport.
 
122
        url = transport.base
 
123
        if url.startswith('readonly+'):
 
124
            url = url[len('readonly+'):]
 
125
 
 
126
        try:
 
127
            gitrepo = dulwich.repo.Repo(transport.local_abspath(".").encode(osutils._fs_enc))
 
128
        except bzr_errors.NotLocalUrl:
 
129
            raise bzr_errors.NotBranchError(path=transport.base)
138
130
        from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
139
131
        lockfiles = GitLockableFiles(transport, GitLock())
140
132
        return LocalGitDir(transport, lockfiles, gitrepo, self)
141
133
 
142
134
    @classmethod
143
135
    def probe_transport(klass, transport):
144
 
        try:
145
 
            if not transport.has_any(['info/refs', '.git/branches',
146
 
                                      'branches']):
147
 
                raise bzr_errors.NotBranchError(path=transport.base)
148
 
        except bzr_errors.NoSuchFile:
149
 
            raise bzr_errors.NotBranchError(path=transport.base)
150
 
        from bzrlib import urlutils
151
 
        if urlutils.split(transport.base)[1] == ".git":
152
 
            raise bzr_errors.NotBranchError(path=transport.base)
153
 
        lazy_check_versions()
 
136
        """Our format is present if the transport ends in '.not/'."""
 
137
        from bzrlib.transport.local import LocalTransport
 
138
 
 
139
        if not isinstance(transport, LocalTransport):
 
140
            raise bzr_errors.NotBranchError(path=transport.base)
 
141
 
 
142
        # This should quickly filter out most things that are not 
 
143
        # git repositories, saving us the trouble from loading dulwich.
 
144
        if not transport.has(".git") and not transport.has("objects"):
 
145
            raise bzr_errors.NotBranchError(path=transport.base)
 
146
 
154
147
        import dulwich
155
148
        format = klass()
156
149
        try:
170
163
        from bzrlib.transport.local import LocalTransport
171
164
 
172
165
        if not isinstance(transport, LocalTransport):
173
 
            raise NotImplementedError(self.initialize,
 
166
            raise NotImplementedError(self.initialize, 
174
167
                "Can't create Git Repositories/branches on "
175
168
                "non-local transports")
176
 
        lazy_check_versions()
 
169
 
177
170
        from dulwich.repo import Repo
178
 
        Repo.init(transport.local_abspath(".").encode(osutils._fs_enc))
 
171
        Repo.create(transport.local_abspath(".").encode(osutils._fs_enc)) 
179
172
        return self.open(transport)
180
173
 
181
174
    def is_supported(self):
197
190
        url = transport.base
198
191
        if url.startswith('readonly+'):
199
192
            url = url[len('readonly+'):]
200
 
        if (not url.startswith("git://") and not url.startswith("git+")):
 
193
        if (not url.startswith("git://") and 
 
194
            not url.startswith("git+")):
201
195
            raise bzr_errors.NotBranchError(transport.base)
202
196
        from bzrlib.plugins.git.remote import RemoteGitDir, GitSmartTransport
203
197
        if not isinstance(transport, GitSmartTransport):
212
206
        url = transport.base
213
207
        if url.startswith('readonly+'):
214
208
            url = url[len('readonly+'):]
215
 
        if (not url.startswith("git://") and not url.startswith("git+")):
 
209
        if (not url.startswith("git://") and 
 
210
            not url.startswith("git+")):
216
211
            raise bzr_errors.NotBranchError(transport.base)
217
212
        # little ugly, but works
218
213
        format = klass()
234
229
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
235
230
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
236
231
 
237
 
register_transport_proto('git://',
 
232
register_transport_proto('git://', 
238
233
        help="Access using the Git smart server protocol.")
239
 
register_transport_proto('git+ssh://',
 
234
register_transport_proto('git+ssh://', 
240
235
        help="Access using the Git smart server protocol over SSH.")
241
236
 
242
237
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
244
239
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
245
240
                        'SSHGitSmartTransport')
246
241
 
247
 
foreign_vcs_registry.register_lazy("git",
 
242
foreign_vcs_registry.register_lazy("git", 
248
243
    "bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
249
244
 
250
245
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
251
 
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
 
246
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"], 
252
247
    "bzrlib.plugins.git.commands")
253
 
plugin_cmds.register_lazy("cmd_git_refs", [], "bzrlib.plugins.git.commands")
254
 
plugin_cmds.register_lazy("cmd_git_apply", [], "bzrlib.plugins.git.commands")
255
248
 
256
249
def update_stanza(rev, stanza):
257
250
    mapping = getattr(rev, "mapping", None)
266
259
 
267
260
from bzrlib.transport import transport_server_registry
268
261
transport_server_registry.register_lazy('git',
269
 
    'bzrlib.plugins.git.server',
 
262
    'bzrlib.plugins.git.server', 
270
263
    'serve_git',
271
264
    'Git Smart server protocol over TCP. (default port: 9418)')
272
265
 
273
266
 
274
 
from bzrlib.repository import (
275
 
    network_format_registry as repository_network_format_registry,
276
 
    )
277
 
repository_network_format_registry.register_lazy('git',
 
267
from bzrlib.repository import network_format_registry as repository_network_format_registry
 
268
repository_network_format_registry.register_lazy('git', 
278
269
    'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
279
270
 
280
 
from bzrlib.bzrdir import (
281
 
    network_format_registry as bzrdir_network_format_registry,
282
 
    )
 
271
from bzrlib.bzrdir import network_format_registry as bzrdir_network_format_registry
283
272
bzrdir_network_format_registry.register('git', GitBzrDirFormat)
284
273
 
 
274
 
 
275
def get_rich_root_format(stacked=False):
 
276
    if stacked:
 
277
        return bzrdir.format_registry.make_bzrdir("1.9-rich-root")
 
278
    else:
 
279
        return bzrdir.format_registry.make_bzrdir("default-rich-root")
 
280
 
285
281
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
286
282
                                   'send_git', 'Git am-style diff format')
287
283
 
288
 
try:
289
 
    from bzrlib.diff import format_registry as diff_format_registry
290
 
except ImportError:
291
 
    pass
292
 
else:
293
 
    diff_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
294
 
        'GitDiffTree', 'Git am-style diff format')
295
 
 
296
284
def test_suite():
297
285
    from bzrlib.plugins.git import tests
298
286
    return tests.test_suite()