~bzr/ubuntu/karmic/bzr-git/bzr-ppa

« back to all changes in this revision

Viewing changes to commands.py

  • Committer: Jelmer Vernooij
  • Date: 2010-05-22 23:40:04 UTC
  • mfrom: (17.25.364 trunk)
  • Revision ID: jelmer@samba.org-20100522234004-48r0bfkodp3xspgv
* New upstream release.
* Bump standards version to 3.8.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
                    self.outf.write("%s\n" % sha1)
166
166
        finally:
167
167
            repo.unlock()
 
168
 
 
169
 
 
170
class cmd_git_refs(Command):
 
171
    """Output all of the virtual refs for a repository.
 
172
 
 
173
    """
 
174
 
 
175
    hidden = True
 
176
 
 
177
    takes_options = [Option('directory',
 
178
        short_name='d',
 
179
        help='Location of repository.', type=unicode)]
 
180
 
 
181
    @display_command
 
182
    def run(self, directory="."):
 
183
        from bzrlib.bzrdir import (
 
184
            BzrDir,
 
185
            )
 
186
        from bzrlib.plugins.git.refs import (
 
187
            BazaarRefsContainer,
 
188
            )
 
189
        from bzrlib.plugins.git.object_store import (
 
190
            get_object_store,
 
191
            )
 
192
        bzrdir, _ = BzrDir.open_containing(directory)
 
193
        repo = bzrdir.find_repository()
 
194
        repo.lock_read()
 
195
        try:
 
196
            object_store = get_object_store(repo)
 
197
            refs = BazaarRefsContainer(bzrdir, object_store)
 
198
            for k, v in refs.as_dict().iteritems():
 
199
                self.outf.write("%s -> %s\n" % (k, v))
 
200
        finally:
 
201
            repo.unlock()
 
202
 
 
203
 
 
204
class cmd_git_apply(Command):
 
205
    """Apply a series of git-am style patches.
 
206
 
 
207
    This command will in the future probably be integrated into 
 
208
    "bzr pull".
 
209
    """
 
210
 
 
211
    takes_args = ["patches*"]
 
212
 
 
213
    def _apply_patch(self, wt, f):
 
214
        from dulwich.patch import git_am_patch_split
 
215
        (c, diff, version) = git_am_patch_split(f)
 
216
        # FIXME: Process diff
 
217
        wt.commit(committer=c.committer,
 
218
                  message=c.message)
 
219
 
 
220
    def run(self, patches_list=None):
 
221
        from bzrlib.workingtree import WorkingTree
 
222
        if patches_list is None:
 
223
            patches_list = []
 
224
        
 
225
        tree, _ = WorkingTree.open_containing(".")
 
226
        tree.lock_write()
 
227
        try:
 
228
            for patch in patches_list:
 
229
                f = open(patch, 'r')
 
230
                try:
 
231
                    self._apply_patch(tree, f)
 
232
                finally:
 
233
                    f.close()
 
234
        finally:
 
235
            tree.unlock()