22
22
"""A GIT branch and repository format implementation for bzr."""
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
36
34
MINIMUM_DULWICH_VERSION = (0, 1, 0)
37
35
COMPATIBLE_BZR_VERSIONS = [(1, 11, 0), (1, 12, 0)]
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')))
43
37
_versions_checked = False
44
38
def lazy_check_versions():
45
39
global _versions_checked
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")
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)
57
53
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
211
207
"Stupid content tracker")
213
plugin_cmds.register_lazy("cmd_git_serve", [], "bzrlib.plugins.git.commands")
214
plugin_cmds.register_lazy("cmd_git_import", [], "bzrlib.plugins.git.commands")
210
class cmd_git_serve(Command):
211
"""Provide access to a Bazaar branch using the git protocol.
213
This command is experimental and doesn't do much yet.
217
help='serve contents of directory',
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
228
warning("server support in bzr-git is experimental.")
230
if directory is None:
231
directory = os.getcwd()
233
backend = BzrBackend(directory)
235
server = TCPGitServer(backend, 'localhost')
236
server.serve_forever()
238
register_command(cmd_git_serve)
241
class cmd_git_import(Command):
242
"""Import all branches from a git repository.
246
takes_args = ["src_location", "dest_location"]
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')
255
target_bzrdir = BzrDir.open(dest_location)
256
except NotBranchError:
257
target_bzrdir = BzrDir.create(dest_location, format=format)
259
target_repo = target_bzrdir.open_repository()
260
except NoRepositoryPresent:
261
target_repo = target_bzrdir.create_repository(shared=True)
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)
267
head_bzrdir = BzrDir.open(head_loc)
268
except NotBranchError:
269
head_bzrdir = BzrDir.create(head_loc, format=format)
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))
277
register_command(cmd_git_import)
216
280
def test_suite():
217
281
from bzrlib.plugins.git import tests