/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

Add some basic documentation in 'bzr help git'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import bzrlib
28
28
import bzrlib.api
29
29
 
30
 
# versions ending in 'exp' mean experimental mappings
31
 
# versions ending in 'dev' mean development version
32
 
# versions ending in 'final' mean release (well tested, etc)
33
 
version_info = (0, 3, 3, 'dev', 0)
 
30
from info import (
 
31
    bzr_compatible_versions,
 
32
    bzr_plugin_version as version_info,
 
33
    dulwich_minimum_version,
 
34
    )
34
35
 
35
36
if version_info[3] == 'final':
36
37
    version_string = '%d.%d.%d' % version_info[:3]
38
39
    version_string = '%d.%d.%d%s%d' % version_info
39
40
__version__ = version_string
40
41
 
41
 
MINIMUM_DULWICH_VERSION = (0, 3, 1)
42
 
COMPATIBLE_BZR_VERSIONS = [(1, 14, 0), (1, 15, 0)]
43
 
 
44
 
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
 
42
bzrlib.api.require_any_api(bzrlib, bzr_compatible_versions)
45
43
 
46
44
 
47
45
from bzrlib import (
52
50
from bzrlib.foreign import (
53
51
    foreign_vcs_registry,
54
52
    )
 
53
from bzrlib.help_topics import (
 
54
    topic_registry,
 
55
    )
55
56
from bzrlib.lockable_files import (
56
57
    TransportLock,
57
58
    )
62
63
from bzrlib.commands import (
63
64
    plugin_cmds,
64
65
    )
65
 
from bzrlib.trace import (
66
 
    warning,
67
 
    )
68
66
from bzrlib.version_info_formats.format_rio import (
69
67
    RioVersionInfoBuilder,
70
68
    )
 
69
from bzrlib.send import (
 
70
    format_registry as send_format_registry,
 
71
    )
71
72
 
72
73
 
73
74
if getattr(sys, "frozen", None):
74
75
    # allow import additional libs from ./_lib for bzr.exe only
75
 
    sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '_lib')))
 
76
    sys.path.append(os.path.normpath(
 
77
        os.path.join(os.path.dirname(__file__), '_lib')))
 
78
 
 
79
 
 
80
def import_dulwich():
 
81
    try:
 
82
        from dulwich import __version__ as dulwich_version
 
83
    except ImportError:
 
84
        raise bzr_errors.DependencyNotPresent("dulwich",
 
85
            "bzr-git: Please install dulwich, https://launchpad.net/dulwich")
 
86
    else:
 
87
        if dulwich_version < dulwich_minimum_version:
 
88
            raise bzr_errors.DependencyNotPresent("dulwich",
 
89
                "bzr-git: Dulwich is too old; at least %d.%d.%d is required" %
 
90
                    dulwich_minimum_version)
 
91
 
76
92
 
77
93
_versions_checked = False
78
94
def lazy_check_versions():
79
95
    global _versions_checked
80
96
    if _versions_checked:
81
97
        return
 
98
    import_dulwich()
82
99
    _versions_checked = True
83
 
    try:
84
 
        from dulwich import __version__ as dulwich_version
85
 
    except ImportError:
86
 
        raise ImportError("bzr-git: Please install dulwich, https://launchpad.net/dulwich")
87
 
    else:
88
 
        if dulwich_version < MINIMUM_DULWICH_VERSION:
89
 
            raise ImportError("bzr-git: Dulwich is too old; at least %d.%d.%d is required" % MINIMUM_DULWICH_VERSION)
90
100
 
91
 
bzrdir.format_registry.register_lazy('git', 
 
101
bzrdir.format_registry.register_lazy('git',
92
102
    "bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
93
103
    help='GIT repository.', native=False, experimental=True,
94
104
    )
95
105
 
96
106
from bzrlib.revisionspec import revspec_registry
97
 
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec", 
 
107
revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec",
98
108
    "RevisionSpec_git")
99
109
 
 
110
try:
 
111
    from bzrlib.revisionspec import dwim_revspecs
 
112
except ImportError:
 
113
    pass
 
114
else:
 
115
    from bzrlib.plugins.git.revspec import RevisionSpec_git
 
116
    dwim_revspecs.append(RevisionSpec_git)
 
117
 
100
118
 
101
119
class GitBzrDirFormat(bzrdir.BzrDirFormat):
 
120
 
102
121
    _lock_class = TransportLock
103
122
 
 
123
    colocated_branches = True
 
124
 
 
125
    def __eq__(self, other):
 
126
        return type(self) == type(other)
 
127
 
104
128
    def is_supported(self):
105
129
        return True
106
130
 
119
143
        """Open this directory.
120
144
 
121
145
        """
122
 
        import dulwich as git
123
 
        # we dont grok readonly - git isn't integrated with transport.
124
 
        url = transport.base
125
 
        if url.startswith('readonly+'):
126
 
            url = url[len('readonly+'):]
127
 
 
128
 
        try:
129
 
            gitrepo = git.repo.Repo(transport.local_abspath(".").encode(osutils._fs_enc))
130
 
        except bzr_errors.NotLocalUrl:
131
 
            raise bzr_errors.NotBranchError(path=transport.base)
 
146
        lazy_check_versions()
 
147
        from bzrlib.plugins.git.transportgit import TransportRepo
 
148
        gitrepo = TransportRepo(transport)
132
149
        from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
133
150
        lockfiles = GitLockableFiles(transport, GitLock())
134
151
        return LocalGitDir(transport, lockfiles, gitrepo, self)
135
152
 
136
153
    @classmethod
137
154
    def probe_transport(klass, transport):
138
 
        """Our format is present if the transport ends in '.not/'."""
139
 
        from bzrlib.transport.local import LocalTransport
140
 
 
141
 
        if not isinstance(transport, LocalTransport):
142
 
            raise bzr_errors.NotBranchError(path=transport.base)
143
 
 
144
 
        # This should quickly filter out most things that are not 
145
 
        # git repositories, saving us the trouble from loading dulwich.
146
 
        if not transport.has(".git") and not transport.has("objects"):
147
 
            raise bzr_errors.NotBranchError(path=transport.base)
148
 
 
149
 
        import dulwich as git
 
155
        try:
 
156
            if not transport.has_any(['info/refs', '.git/branches',
 
157
                                      'branches']):
 
158
                raise bzr_errors.NotBranchError(path=transport.base)
 
159
        except bzr_errors.NoSuchFile:
 
160
            raise bzr_errors.NotBranchError(path=transport.base)
 
161
        from bzrlib import urlutils
 
162
        if urlutils.split(transport.base)[1] == ".git":
 
163
            raise bzr_errors.NotBranchError(path=transport.base)
 
164
        lazy_check_versions()
 
165
        import dulwich
150
166
        format = klass()
151
167
        try:
152
168
            format.open(transport)
153
169
            return format
154
 
        except git.errors.NotGitRepository, e:
 
170
        except dulwich.errors.NotGitRepository, e:
155
171
            raise bzr_errors.NotBranchError(path=transport.base)
156
172
        raise bzr_errors.NotBranchError(path=transport.base)
157
173
 
165
181
        from bzrlib.transport.local import LocalTransport
166
182
 
167
183
        if not isinstance(transport, LocalTransport):
168
 
            raise NotImplementedError(self.initialize, 
 
184
            raise NotImplementedError(self.initialize,
169
185
                "Can't create Git Repositories/branches on "
170
186
                "non-local transports")
171
 
 
 
187
        lazy_check_versions()
172
188
        from dulwich.repo import Repo
173
 
        Repo.create(transport.local_abspath(".").encode(osutils._fs_enc)) 
 
189
        Repo.init(transport.local_abspath(".").encode(osutils._fs_enc))
174
190
        return self.open(transport)
175
191
 
176
192
    def is_supported(self):
192
208
        url = transport.base
193
209
        if url.startswith('readonly+'):
194
210
            url = url[len('readonly+'):]
195
 
        if (not url.startswith("git://") and 
196
 
            not url.startswith("git+")):
 
211
        if (not url.startswith("git://") and not url.startswith("git+")):
197
212
            raise bzr_errors.NotBranchError(transport.base)
198
213
        from bzrlib.plugins.git.remote import RemoteGitDir, GitSmartTransport
199
214
        if not isinstance(transport, GitSmartTransport):
208
223
        url = transport.base
209
224
        if url.startswith('readonly+'):
210
225
            url = url[len('readonly+'):]
211
 
        if (not url.startswith("git://") and 
212
 
            not url.startswith("git+")):
 
226
        if (not url.startswith("git://") and not url.startswith("git+")):
213
227
            raise bzr_errors.NotBranchError(transport.base)
214
228
        # little ugly, but works
215
229
        format = klass()
231
245
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
232
246
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
233
247
 
234
 
register_transport_proto('git://', 
 
248
register_transport_proto('git://',
235
249
        help="Access using the Git smart server protocol.")
236
 
register_transport_proto('git+ssh://', 
 
250
register_transport_proto('git+ssh://',
237
251
        help="Access using the Git smart server protocol over SSH.")
238
252
 
239
253
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
241
255
register_lazy_transport("git+ssh://", 'bzrlib.plugins.git.remote',
242
256
                        'SSHGitSmartTransport')
243
257
 
244
 
foreign_vcs_registry.register_lazy("git", 
 
258
foreign_vcs_registry.register_lazy("git",
245
259
    "bzrlib.plugins.git.mapping", "foreign_git", "Stupid content tracker")
246
260
 
247
261
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
248
 
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"], 
 
262
plugin_cmds.register_lazy("cmd_git_object", ["git-objects", "git-cat"],
249
263
    "bzrlib.plugins.git.commands")
 
264
plugin_cmds.register_lazy("cmd_git_refs", [], "bzrlib.plugins.git.commands")
 
265
plugin_cmds.register_lazy("cmd_git_apply", [], "bzrlib.plugins.git.commands")
250
266
 
251
267
def update_stanza(rev, stanza):
252
268
    mapping = getattr(rev, "mapping", None)
259
275
    rio_hooks.install_named_hook('revision', update_stanza, None)
260
276
 
261
277
 
262
 
try:
263
 
    from bzrlib.transport import transport_server_registry
264
 
except ImportError:
265
 
    pass
266
 
else:
267
 
    transport_server_registry.register_lazy('git',
268
 
        'bzrlib.plugins.git.server', 
269
 
        'serve_git',
270
 
        'Git Smart server protocol over TCP. (default port: 9418)')
271
 
 
272
 
 
273
 
from bzrlib.repository import network_format_registry as repository_network_format_registry
274
 
repository_network_format_registry.register_lazy('git', 
 
278
from bzrlib.transport import transport_server_registry
 
279
transport_server_registry.register_lazy('git',
 
280
    'bzrlib.plugins.git.server',
 
281
    'serve_git',
 
282
    'Git Smart server protocol over TCP. (default port: 9418)')
 
283
 
 
284
 
 
285
from bzrlib.repository import (
 
286
    network_format_registry as repository_network_format_registry,
 
287
    )
 
288
repository_network_format_registry.register_lazy('git',
275
289
    'bzrlib.plugins.git.repository', 'GitRepositoryFormat')
276
290
 
277
 
from bzrlib.bzrdir import network_format_registry as bzrdir_network_format_registry
 
291
from bzrlib.bzrdir import (
 
292
    network_format_registry as bzrdir_network_format_registry,
 
293
    )
278
294
bzrdir_network_format_registry.register('git', GitBzrDirFormat)
279
295
 
280
 
 
281
 
def get_rich_root_format(stacked=False):
282
 
    if stacked:
283
 
        return bzrdir.format_registry.make_bzrdir("1.9-rich-root")
284
 
    else:
285
 
        return bzrdir.format_registry.make_bzrdir("default-rich-root")
 
296
send_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
 
297
                                   'send_git', 'Git am-style diff format')
 
298
 
 
299
topic_registry.register_lazy('git',
 
300
                             'bzrlib.plugins.git.help',
 
301
                             'help_git', 'Using Bazaar with Git')
 
302
 
 
303
try:
 
304
    from bzrlib.diff import format_registry as diff_format_registry
 
305
except ImportError:
 
306
    pass
 
307
else:
 
308
    diff_format_registry.register_lazy('git', 'bzrlib.plugins.git.send',
 
309
        'GitDiffTree', 'Git am-style diff format')
286
310
 
287
311
def test_suite():
288
312
    from bzrlib.plugins.git import tests