/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

'bzr git-object' without arguments now prints the available git objects.

Show diffs side-by-side

added added

removed removed

Lines of Context:
135
135
            pb.finished()
136
136
 
137
137
 
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 (
 
140
        BazaarObjectStore,
 
141
        )
 
142
    from bzrlib.plugins.git.mapping import (
 
143
        default_mapping,
 
144
        )
 
145
    from bzrlib.plugins.git.repository import (
 
146
        GitRepository,
 
147
        )
 
148
    if isinstance(repo, GitRepository):
 
149
        return repo._git.object_store
 
150
    else:
 
151
        return BazaarObjectStore(repo, default_mapping)
 
152
 
 
153
 
 
154
class cmd_git_object(Command):
 
155
    """List or display Git objects by SHA.
 
156
    
 
157
    Cat a particular object's Git representation if a SHA is specified.
 
158
    List all available SHAs otherwise.
 
159
    """
140
160
 
141
161
    hidden = True
142
162
 
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)]
146
167
 
147
 
    def run(self, sha1, directory="."):
 
168
    def run(self, sha1=None, directory="."):
148
169
        from bzrlib.errors import (
149
170
            BzrCommandError,
150
171
            )
151
172
        from bzrlib.bzrdir import (
152
173
            BzrDir,
153
174
            )
154
 
        from bzrlib.repository import (
155
 
            Repository,
156
 
            )
157
 
        from bzrlib.plugins.git.converter import (
158
 
            BazaarObjectStore,
159
 
            )
160
 
        from bzrlib.plugins.git.mapping import (
161
 
            default_mapping,
162
 
            )
163
 
        from bzrlib.plugins.git.repository import (
164
 
            GitRepository,
165
 
            )
166
175
        bzrdir, _ = BzrDir.open_containing(directory)
167
176
        repo = bzrdir.find_repository()
 
177
        object_store = repo_get_object_store(repo)
168
178
        repo.lock_read()
169
179
        try:
170
 
            if isinstance(repo, GitRepository):
171
 
                object_store = repo._git.object_store
 
180
            if sha1 is not None:
 
181
                try:
 
182
                    obj = object_store[sha1]
 
183
                except KeyError:
 
184
                    raise BzrCommandError("Object not found: %s" % sha1)
 
185
                self.outf.write(obj.as_raw_string())
172
186
            else:
173
 
                object_store = BazaarObjectStore(repo, default_mapping)
174
 
            try:
175
 
                obj = object_store[sha1]
176
 
            except KeyError:
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)
179
189
        finally:
180
190
            repo.unlock()