/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:
27
27
from bzrlib.foreign import foreign_vcs_registry
28
28
from bzrlib.lockable_files import TransportLock
29
29
from bzrlib.transport import register_lazy_transport
30
 
from bzrlib.commands import plugin_cmds
 
30
from bzrlib.commands import Command, register_command
 
31
from bzrlib.option import Option
31
32
from bzrlib.trace import warning
32
33
 
33
34
MINIMUM_DULWICH_VERSION = (0, 1, 0)
205
206
                        "foreign_git",
206
207
                        "Stupid content tracker")
207
208
 
208
 
plugin_cmds.register_lazy("cmd_git_serve", [], "bzrlib.plugins.git.commands")
209
 
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
 
210
279
 
211
280
def test_suite():
212
281
    from bzrlib.plugins.git import tests