/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.1 by Robert Collins
Commit initial content.
1
# Copyright (C) 2006 Canonical Ltd
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
2
0.200.1 by Robert Collins
Commit initial content.
3
# Authors: Robert Collins <robert.collins@canonical.com>
0.200.184 by Jelmer Vernooij
Update authors: line.
4
#          Jelmer Vernooij <jelmer@samba.org>
5
#          John Carr <john.carr@unrouted.co.uk>
0.200.1 by Robert Collins
Commit initial content.
6
#
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21
22
"""A GIT branch and repository format implementation for bzr."""
23
0.200.199 by Jelmer Vernooij
Check for bzrlib API version.
24
import bzrlib
25
import bzrlib.api
0.200.203 by Jelmer Vernooij
Fix imports.
26
from bzrlib import bzrdir, errors as bzr_errors
0.200.195 by Jelmer Vernooij
Return mapping in revision_id_bzr_to_foreign() as required by the interface.
27
from bzrlib.foreign import foreign_vcs_registry
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
28
from bzrlib.lockable_files import TransportLock
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
29
from bzrlib.transport import register_lazy_transport
0.200.206 by Jelmer Vernooij
Move commands to a separate python module and register them lazily.
30
from bzrlib.commands import plugin_cmds
0.200.192 by Jelmer Vernooij
use system-provided dulwich, remove own copy.
31
from bzrlib.trace import warning
32
33
MINIMUM_DULWICH_VERSION = (0, 1, 0)
0.200.204 by Jelmer Vernooij
Support bzr 1.11.
34
COMPATIBLE_BZR_VERSIONS = [(1, 11, 0), (1, 12, 0)]
0.200.192 by Jelmer Vernooij
use system-provided dulwich, remove own copy.
35
0.200.200 by Jelmer Vernooij
Register lazily where possible.
36
_versions_checked = False
37
def lazy_check_versions():
38
    global _versions_checked
39
    if _versions_checked:
40
        return
41
    _versions_checked = True
42
    try:
43
        from dulwich import __version__ as dulwich_version
44
    except ImportError:
45
        warning("Please install dulwich, https://launchpad.net/dulwich")
46
        raise
47
    else:
48
        if dulwich_version < MINIMUM_DULWICH_VERSION:
49
            warning("Dulwich is too old; at least %d.%d.%d is required" % MINIMUM_DULWICH_VERSION)
50
            raise ImportError
0.200.199 by Jelmer Vernooij
Check for bzrlib API version.
51
52
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
53
0.200.200 by Jelmer Vernooij
Register lazily where possible.
54
bzrdir.format_registry.register_lazy('git', 
55
    "bzrlib.plugins.git.dir", "LocalGitBzrDirFormat",
56
    help='GIT repository.', native=False, experimental=True,
57
    )
0.200.204 by Jelmer Vernooij
Support bzr 1.11.
58
59
try:
60
    from bzrlib.revisionspec import revspec_registry
61
    revspec_registry.register_lazy("git:", "bzrlib.plugins.git.revspec", 
62
        "RevisionSpec_git")
63
except ImportError:
64
    lazy_check_versions()
65
    from bzrlib.revisionspec import SPEC_TYPES
66
    from bzrlib.plugins.git.revspec import RevisionSpec_git
67
    SPEC_TYPES.append(RevisionSpec_git)
0.200.200 by Jelmer Vernooij
Register lazily where possible.
68
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
69
class GitBzrDirFormat(bzrdir.BzrDirFormat):
70
    _lock_class = TransportLock
71
72
    def is_supported(self):
73
        return True
74
75
76
class LocalGitBzrDirFormat(GitBzrDirFormat):
77
    """The .git directory control format."""
78
79
    @classmethod
80
    def _known_formats(self):
81
        return set([LocalGitBzrDirFormat()])
82
83
    def open(self, transport, _found=None):
84
        """Open this directory.
85
86
        """
87
        import dulwich as git
88
        # we dont grok readonly - git isn't integrated with transport.
89
        url = transport.base
90
        if url.startswith('readonly+'):
91
            url = url[len('readonly+'):]
92
93
        try:
94
            gitrepo = git.repo.Repo(transport.local_abspath("."))
0.200.203 by Jelmer Vernooij
Fix imports.
95
        except bzr_errors.NotLocalUrl:
96
            raise bzr_errors.NotBranchError(path=transport.base)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
97
        from bzrlib.plugins.git.dir import LocalGitDir, GitLockableFiles, GitLock
98
        lockfiles = GitLockableFiles(transport, GitLock())
99
        return LocalGitDir(transport, lockfiles, gitrepo, self)
100
101
    @classmethod
102
    def probe_transport(klass, transport):
103
        """Our format is present if the transport ends in '.not/'."""
104
        from bzrlib.transport.local import LocalTransport
105
106
        if not isinstance(transport, LocalTransport):
0.200.203 by Jelmer Vernooij
Fix imports.
107
            raise bzr_errors.NotBranchError(path=transport.base)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
108
109
        # This should quickly filter out most things that are not 
110
        # git repositories, saving us the trouble from loading dulwich.
111
        if not transport.has(".git") and not transport.has("objects"):
0.200.203 by Jelmer Vernooij
Fix imports.
112
            raise bzr_errors.NotBranchError(path=transport.base)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
113
114
        import dulwich as git
115
        format = klass()
116
        try:
117
            format.open(transport)
118
            return format
119
        except git.errors.NotGitRepository, e:
0.200.203 by Jelmer Vernooij
Fix imports.
120
            raise bzr_errors.NotBranchError(path=transport.base)
121
        raise bzr_errors.NotBranchError(path=transport.base)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
122
123
    def get_format_description(self):
124
        return "Local Git Repository"
125
126
    def get_format_string(self):
127
        return "Local Git Repository"
128
129
    def initialize_on_transport(self, transport):
130
        from bzrlib.transport.local import LocalTransport
131
132
        if not isinstance(transport, LocalTransport):
133
            raise NotImplementedError(self.initialize, 
134
                "Can't create Git Repositories/branches on "
135
                "non-local transports")
136
137
        from dulwich.repo import Repo
138
        Repo.create(transport.local_abspath(".")) 
139
        return self.open(transport)
140
141
    def is_supported(self):
142
        return True
143
144
145
class RemoteGitBzrDirFormat(GitBzrDirFormat):
146
    """The .git directory control format."""
147
148
    @classmethod
149
    def _known_formats(self):
150
        return set([RemoteGitBzrDirFormat()])
151
152
    def open(self, transport, _found=None):
153
        """Open this directory.
154
155
        """
156
        from bzrlib.plugins.git.remote import RemoteGitDir, GitSmartTransport
157
        if not isinstance(transport, GitSmartTransport):
0.200.203 by Jelmer Vernooij
Fix imports.
158
            raise bzr_errors.NotBranchError(transport.base)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
159
        # we dont grok readonly - git isn't integrated with transport.
160
        url = transport.base
161
        if url.startswith('readonly+'):
162
            url = url[len('readonly+'):]
163
164
        from bzrlib.plugins.git.dir import GitLockableFiles, GitLock
165
        lockfiles = GitLockableFiles(transport, GitLock())
166
        return RemoteGitDir(transport, lockfiles, self)
167
168
    @classmethod
169
    def probe_transport(klass, transport):
170
        """Our format is present if the transport ends in '.not/'."""
171
        # little ugly, but works
172
        format = klass()
173
        from bzrlib.plugins.git.remote import GitSmartTransport
174
        if not isinstance(transport, GitSmartTransport):
0.200.203 by Jelmer Vernooij
Fix imports.
175
            raise bzr_errors.NotBranchError(transport.base)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
176
        # The only way to know a path exists and contains a valid repository 
177
        # is to do a request against it:
178
        try:
179
            transport.fetch_pack(lambda x: [], None, lambda x: None, 
180
                                 lambda x: mutter("git: %s" % x))
181
        except errors.git_errors.GitProtocolError:
0.200.203 by Jelmer Vernooij
Fix imports.
182
            raise bzr_errors.NotBranchError(path=transport.base)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
183
        else:
184
            return format
0.200.203 by Jelmer Vernooij
Fix imports.
185
        raise bzr_errors.NotBranchError(path=transport.base)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
186
187
    def get_format_description(self):
188
        return "Remote Git Repository"
189
190
    def get_format_string(self):
191
        return "Remote Git Repository"
192
193
    def initialize_on_transport(self, transport):
0.200.203 by Jelmer Vernooij
Fix imports.
194
        raise bzr_errors.UninitializableFormat(self)
0.200.201 by Jelmer Vernooij
Try to import nothing other than __init__ when not opening git repositories.
195
196
197
bzrdir.BzrDirFormat.register_control_format(LocalGitBzrDirFormat)
198
bzrdir.BzrDirFormat.register_control_format(RemoteGitBzrDirFormat)
0.200.138 by Jelmer Vernooij
Add initial infrastructure for accessing remote git repositories.
199
200
register_lazy_transport("git://", 'bzrlib.plugins.git.remote',
201
                        'GitSmartTransport')
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
202
0.200.195 by Jelmer Vernooij
Return mapping in revision_id_bzr_to_foreign() as required by the interface.
203
foreign_vcs_registry.register_lazy("git", 
204
                        "bzrlib.plugins.git.mapping", 
205
                        "foreign_git",
206
                        "Stupid content tracker")
0.208.5 by Jelmer Vernooij
Add log show function for git.
207
0.200.206 by Jelmer Vernooij
Move commands to a separate python module and register them lazily.
208
plugin_cmds.register_lazy("cmd_git_serve", [], "bzrlib.plugins.git.commands")
209
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
0.200.177 by Jelmer Vernooij
Add git-import command.
210
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
211
def test_suite():
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
212
    from bzrlib.plugins.git import tests
213
    return tests.test_suite()