/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

Update docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    get_rich_root_format,
33
33
    )
34
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
 
35
65
class cmd_git_import(Command):
36
66
    """Import all branches from a git repository.
37
67
 
47
77
            )
48
78
        from bzrlib.bzrdir import (
49
79
            BzrDir,
 
80
            format_registry,
50
81
            )
51
82
        from bzrlib.errors import (
52
83
            BzrCommandError,
57
88
            InterRepository,
58
89
            Repository,
59
90
            )
60
 
        from bzrlib.plugins.git.branch import (
61
 
            GitBranch,
62
 
            extract_tags,
63
 
            )
 
91
        from bzrlib.plugins.git.branch import GitBranch
64
92
        from bzrlib.plugins.git.repository import GitRepository
65
93
 
66
94
        if dest_location is None:
75
103
        except NotBranchError:
76
104
            target_bzrdir = BzrDir.create(dest_location, format=format)
77
105
        try:
78
 
            target_repo = target_bzrdir.find_repository()
 
106
            target_repo = target_bzrdir.open_repository()
79
107
        except NoRepositoryPresent:
80
108
            target_repo = target_bzrdir.create_repository(shared=True)
81
109
 
82
 
        if not target_repo.supports_rich_root():
83
 
            raise BzrCommandError("Target repository doesn't support rich roots")
84
 
 
85
110
        interrepo = InterRepository.get(source_repo, target_repo)
86
111
        mapping = source_repo.get_mapping()
87
112
        refs = interrepo.fetch_refs()
88
 
        tags = {}
89
 
        for k, v in extract_tags(refs).iteritems():
90
 
            tags[k] = mapping.revision_id_foreign_to_bzr(v)
91
113
        pb = ui.ui_factory.nested_progress_bar()
92
114
        try:
93
115
            for i, (name, ref) in enumerate(refs.iteritems()):
107
129
                except NotBranchError:
108
130
                    head_branch = head_bzrdir.create_branch()
109
131
                revid = mapping.revision_id_foreign_to_bzr(ref)
110
 
                source_branch = GitBranch(source_repo.bzrdir, source_repo,
111
 
                    name, None, tags)
112
 
                source_branch.head = ref
113
 
                if head_branch.last_revision() != revid:
114
 
                    head_branch.generate_revision_history(revid)
 
132
                source_branch = GitBranch(source_repo.bzrdir, source_repo, 
 
133
                    name, ref, None)
 
134
                head_branch.generate_revision_history(revid)
115
135
                source_branch.tags.merge_to(head_branch.tags)
116
136
        finally:
117
137
            pb.finished()
119
139
 
120
140
class cmd_git_object(Command):
121
141
    """List or display Git objects by SHA.
122
 
 
 
142
    
123
143
    Cat a particular object's Git representation if a SHA is specified.
124
144
    List all available SHAs otherwise.
125
145
    """
128
148
 
129
149
    aliases = ["git-objects", "git-cat"]
130
150
    takes_args = ["sha1?"]
131
 
    takes_options = [Option('directory',
 
151
    takes_options = [Option('directory', 
132
152
        short_name='d',
133
153
        help='Location of repository.', type=unicode),
134
154
        Option('pretty', help='Pretty-print objects.')]
152
172
        try:
153
173
            if sha1 is not None:
154
174
                try:
155
 
                    obj = object_store[str(sha1)]
 
175
                    obj = object_store[sha1]
156
176
                except KeyError:
157
177
                    raise BzrCommandError("Object not found: %s" % sha1)
158
178
                if pretty: