/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 commands.py

Rely less on command-line git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
from bzrlib.plugins.git import (
32
32
    get_rich_root_format,
33
 
    lazy_check_versions,
34
33
    )
35
34
 
 
35
class cmd_git_serve(Command):
 
36
    """Provide access to a Bazaar branch using the git protocol.
 
37
 
 
38
    This command is experimental and doesn't do much yet.
 
39
    """
 
40
    takes_options = [
 
41
        Option('directory',
 
42
               short_name='d',
 
43
               help='serve contents of directory',
 
44
               type=unicode)
 
45
    ]
 
46
 
 
47
    def run(self, directory=None):
 
48
        lazy_check_versions()
 
49
        from dulwich.server import TCPGitServer
 
50
        from bzrlib.plugins.git.server import BzrBackend
 
51
        from bzrlib.trace import warning
 
52
        import os
 
53
 
 
54
        warning("server support in bzr-git is experimental.")
 
55
 
 
56
        if directory is None:
 
57
            directory = os.getcwd()
 
58
 
 
59
        backend = BzrBackend(directory)
 
60
 
 
61
        server = TCPGitServer(backend, 'localhost')
 
62
        server.serve_forever()
 
63
 
 
64
 
36
65
class cmd_git_import(Command):
37
66
    """Import all branches from a git repository.
38
67
 
101
130
                    head_branch = head_bzrdir.create_branch()
102
131
                revid = mapping.revision_id_foreign_to_bzr(ref)
103
132
                source_branch = GitBranch(source_repo.bzrdir, source_repo, 
104
 
                    name, None)
105
 
                source_branch.head = ref
 
133
                    name, ref, None)
106
134
                head_branch.generate_revision_history(revid)
107
135
                source_branch.tags.merge_to(head_branch.tags)
108
136
        finally:
109
137
            pb.finished()
110
138
 
111
139
 
 
140
def repo_get_object_store(repo):
 
141
    from bzrlib.plugins.git.converter import (
 
142
        BazaarObjectStore,
 
143
        )
 
144
    from bzrlib.plugins.git.mapping import (
 
145
        default_mapping,
 
146
        )
 
147
    from bzrlib.plugins.git.repository import (
 
148
        GitRepository,
 
149
        )
 
150
    if isinstance(repo, GitRepository):
 
151
        return repo._git.object_store
 
152
    else:
 
153
        return BazaarObjectStore(repo, default_mapping)
 
154
 
 
155
 
112
156
class cmd_git_object(Command):
113
157
    """List or display Git objects by SHA.
114
158
    
136
180
            )
137
181
        bzrdir, _ = BzrDir.open_containing(directory)
138
182
        repo = bzrdir.find_repository()
139
 
        from bzrlib.plugins.git.object_store import (
140
 
            get_object_store,
141
 
            )
142
 
        object_store = get_object_store(repo)
 
183
        object_store = repo_get_object_store(repo)
143
184
        repo.lock_read()
144
185
        try:
145
186
            if sha1 is not None:
146
187
                try:
147
 
                    obj = object_store[str(sha1)]
 
188
                    obj = object_store[sha1]
148
189
                except KeyError:
149
190
                    raise BzrCommandError("Object not found: %s" % sha1)
150
191
                if pretty: