/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

Implement GitRepository.revision_graph_can_have_wrong_parents().

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from bzrlib.commands import (
24
24
    Command,
 
25
    display_command,
25
26
    )
26
27
from bzrlib.option import (
27
28
    Option,
29
30
 
30
31
from bzrlib.plugins.git import (
31
32
    get_rich_root_format,
 
33
    lazy_check_versions,
32
34
    )
33
35
 
34
 
class cmd_git_serve(Command):
35
 
    """Provide access to a Bazaar branch using the git protocol.
36
 
 
37
 
    This command is experimental and doesn't do much yet.
38
 
    """
39
 
    takes_options = [
40
 
        Option('directory',
41
 
               help='serve contents of directory',
42
 
               type=unicode)
43
 
    ]
44
 
 
45
 
    def run(self, directory=None):
46
 
        lazy_check_versions()
47
 
        from dulwich.server import TCPGitServer
48
 
        from bzrlib.plugins.git.server import BzrBackend
49
 
        from bzrlib.trace import warning
50
 
        import os
51
 
 
52
 
        warning("server support in bzr-git is experimental.")
53
 
 
54
 
        if directory is None:
55
 
            directory = os.getcwd()
56
 
 
57
 
        backend = BzrBackend(directory)
58
 
 
59
 
        server = TCPGitServer(backend, 'localhost')
60
 
        server.serve_forever()
61
 
 
62
 
 
63
36
class cmd_git_import(Command):
64
37
    """Import all branches from a git repository.
65
38
 
128
101
                    head_branch = head_bzrdir.create_branch()
129
102
                revid = mapping.revision_id_foreign_to_bzr(ref)
130
103
                source_branch = GitBranch(source_repo.bzrdir, source_repo, 
131
 
                    name, ref, None)
 
104
                    name, None)
 
105
                source_branch.head = ref
132
106
                head_branch.generate_revision_history(revid)
133
107
                source_branch.tags.merge_to(head_branch.tags)
134
108
        finally:
135
109
            pb.finished()
136
110
 
 
111
 
 
112
class cmd_git_object(Command):
 
113
    """List or display Git objects by SHA.
 
114
    
 
115
    Cat a particular object's Git representation if a SHA is specified.
 
116
    List all available SHAs otherwise.
 
117
    """
 
118
 
 
119
    hidden = True
 
120
 
 
121
    aliases = ["git-objects", "git-cat"]
 
122
    takes_args = ["sha1?"]
 
123
    takes_options = [Option('directory', 
 
124
        short_name='d',
 
125
        help='Location of repository.', type=unicode),
 
126
        Option('pretty', help='Pretty-print objects.')]
 
127
    encoding_type = 'exact'
 
128
 
 
129
    @display_command
 
130
    def run(self, sha1=None, directory=".", pretty=False):
 
131
        from bzrlib.errors import (
 
132
            BzrCommandError,
 
133
            )
 
134
        from bzrlib.bzrdir import (
 
135
            BzrDir,
 
136
            )
 
137
        bzrdir, _ = BzrDir.open_containing(directory)
 
138
        repo = bzrdir.find_repository()
 
139
        from bzrlib.plugins.git.object_store import (
 
140
            get_object_store,
 
141
            )
 
142
        object_store = get_object_store(repo)
 
143
        repo.lock_read()
 
144
        try:
 
145
            if sha1 is not None:
 
146
                try:
 
147
                    obj = object_store[str(sha1)]
 
148
                except KeyError:
 
149
                    raise BzrCommandError("Object not found: %s" % sha1)
 
150
                if pretty:
 
151
                    text = obj.as_pretty_string()
 
152
                else:
 
153
                    text = obj.as_raw_string()
 
154
                self.outf.write(text)
 
155
            else:
 
156
                for sha1 in object_store:
 
157
                    self.outf.write("%s\n" % sha1)
 
158
        finally:
 
159
            repo.unlock()