/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

Fix remote fetching.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
"""A GIT branch and repository format implementation for bzr."""
23
23
 
24
 
import os
25
 
import sys
26
 
 
27
24
import bzrlib
28
25
import bzrlib.api
29
26
from bzrlib import bzrdir, errors as bzr_errors
30
27
from bzrlib.foreign import foreign_vcs_registry
31
28
from bzrlib.lockable_files import TransportLock
32
29
from bzrlib.transport import register_lazy_transport
33
 
from bzrlib.commands import plugin_cmds
 
30
from bzrlib.commands import Command, register_command
 
31
from bzrlib.option import Option
34
32
from bzrlib.trace import warning
35
33
 
36
34
MINIMUM_DULWICH_VERSION = (0, 1, 0)
37
35
COMPATIBLE_BZR_VERSIONS = [(1, 11, 0), (1, 12, 0)]
38
36
 
39
 
if getattr(sys, "frozen", None):
40
 
    # allow import additional libs from ./_lib for bzr.exe only
41
 
    sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '_lib')))
42
 
 
43
37
_versions_checked = False
44
38
def lazy_check_versions():
45
39
    global _versions_checked
49
43
    try:
50
44
        from dulwich import __version__ as dulwich_version
51
45
    except ImportError:
52
 
        raise ImportError("bzr-git: Please install dulwich, https://launchpad.net/dulwich")
 
46
        warning("Please install dulwich, https://launchpad.net/dulwich")
 
47
        raise
53
48
    else:
54
49
        if dulwich_version < MINIMUM_DULWICH_VERSION:
55
 
            raise ImportError("bzr-git: Dulwich is too old; at least %d.%d.%d is required" % MINIMUM_DULWICH_VERSION)
 
50
            warning("Dulwich is too old; at least %d.%d.%d is required" % MINIMUM_DULWICH_VERSION)
 
51
            raise ImportError
56
52
 
57
53
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
58
54
 
210
206
                        "foreign_git",
211
207
                        "Stupid content tracker")
212
208
 
213
 
plugin_cmds.register_lazy("cmd_git_serve", [], "bzrlib.plugins.git.commands")
214
 
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
 
209
 
 
210
class cmd_git_serve(Command):
 
211
    """Provide access to a Bazaar branch using the git protocol.
 
212
 
 
213
    This command is experimental and doesn't do much yet.
 
214
    """
 
215
    takes_options = [
 
216
        Option('directory',
 
217
               help='serve contents of directory',
 
218
               type=unicode)
 
219
    ]
 
220
 
 
221
    def run(self, directory=None):
 
222
        lazy_check_versions()
 
223
        from dulwich.server import TCPGitServer
 
224
        from bzrlib.plugins.git.server import BzrBackend
 
225
        from bzrlib.trace import warning
 
226
        import os
 
227
 
 
228
        warning("server support in bzr-git is experimental.")
 
229
 
 
230
        if directory is None:
 
231
            directory = os.getcwd()
 
232
 
 
233
        backend = BzrBackend(directory)
 
234
 
 
235
        server = TCPGitServer(backend, 'localhost')
 
236
        server.serve_forever()
 
237
 
 
238
register_command(cmd_git_serve)
 
239
 
 
240
 
 
241
class cmd_git_import(Command):
 
242
    """Import all branches from a git repository.
 
243
 
 
244
    """
 
245
 
 
246
    takes_args = ["src_location", "dest_location"]
 
247
 
 
248
    def run(self, src_location, dest_location):
 
249
        from bzrlib.bzrdir import BzrDir, format_registry
 
250
        from bzrlib.errors import NoRepositoryPresent, NotBranchError
 
251
        from bzrlib.repository import Repository
 
252
        source_repo = Repository.open(src_location)
 
253
        format = format_registry.make_bzrdir('rich-root-pack')
 
254
        try:
 
255
            target_bzrdir = BzrDir.open(dest_location)
 
256
        except NotBranchError:
 
257
            target_bzrdir = BzrDir.create(dest_location, format=format)
 
258
        try:
 
259
            target_repo = target_bzrdir.open_repository()
 
260
        except NoRepositoryPresent:
 
261
            target_repo = target_bzrdir.create_repository(shared=True)
 
262
 
 
263
        target_repo.fetch(source_repo)
 
264
        for name, ref in source_repo._git.heads().iteritems():
 
265
            head_loc = os.path.join(dest_location, name)
 
266
            try:
 
267
                head_bzrdir = BzrDir.open(head_loc)
 
268
            except NotBranchError:
 
269
                head_bzrdir = BzrDir.create(head_loc, format=format)
 
270
            try:
 
271
                head_branch = head_bzrdir.open_branch()
 
272
            except NotBranchError:
 
273
                head_branch = head_bzrdir.create_branch()
 
274
            head_branch.generate_revision_history(source_repo.get_mapping().revision_id_foreign_to_bzr(ref))
 
275
 
 
276
 
 
277
register_command(cmd_git_import)
 
278
 
215
279
 
216
280
def test_suite():
217
281
    from bzrlib.plugins.git import tests