138
class cmd_git_cat(Command):
139
"""Cat an object in a repository by Git SHA1."""
138
def repo_get_object_store(repo):
139
from bzrlib.plugins.git.converter import (
142
from bzrlib.plugins.git.mapping import (
145
from bzrlib.plugins.git.repository import (
148
if isinstance(repo, GitRepository):
149
return repo._git.object_store
151
return BazaarObjectStore(repo, default_mapping)
154
class cmd_git_object(Command):
155
"""List or display Git objects by SHA.
157
Cat a particular object's Git representation if a SHA is specified.
158
List all available SHAs otherwise.
143
takes_args = ["sha1"]
163
aliases = ["git-objects", "git-cat"]
164
takes_args = ["sha1?"]
144
165
takes_options = [Option('directory',
145
166
help='location of repository', type=unicode)]
147
def run(self, sha1, directory="."):
168
def run(self, sha1=None, directory="."):
148
169
from bzrlib.errors import (
151
172
from bzrlib.bzrdir import (
154
from bzrlib.repository import (
157
from bzrlib.plugins.git.converter import (
160
from bzrlib.plugins.git.mapping import (
163
from bzrlib.plugins.git.repository import (
166
175
bzrdir, _ = BzrDir.open_containing(directory)
167
176
repo = bzrdir.find_repository()
177
object_store = repo_get_object_store(repo)
170
if isinstance(repo, GitRepository):
171
object_store = repo._git.object_store
182
obj = object_store[sha1]
184
raise BzrCommandError("Object not found: %s" % sha1)
185
self.outf.write(obj.as_raw_string())
173
object_store = BazaarObjectStore(repo, default_mapping)
175
obj = object_store[sha1]
177
raise BzrCommandError("Object not found: %s" % sha1)
178
self.outf.write(obj.as_raw_string())
187
for sha1 in object_store:
188
self.outf.write("%s\n" % sha1)