/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

Add initial work on git-apply.

Show diffs side-by-side

added added

removed removed

Lines of Context:
199
199
                self.outf.write("%s -> %s\n" % (k, v))
200
200
        finally:
201
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()