~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Michael Ellerman
  • Date: 2006-03-10 04:30:56 UTC
  • mto: (325.1.2 bzrtools) (0.3.1 shelf-dev)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20060310043056-c3059be9260bf58a
Update for -p1 format diffs, steal some of Aaron's run_patch() from bzrtools.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
import os
4
4
import sys
 
5
import subprocess
5
6
from errors import CommandError
6
7
from hunk_selector import ShelveHunkSelector, UnshelveHunkSelector
7
8
from diffstat import DiffStat
150
151
            message = ""
151
152
        self.log('Reapplying shelved patches "%s"\n' % message)
152
153
 
153
 
        pipe = os.popen('patch -d %s -s -p0' % self.base, 'w')
154
 
        for hunk in to_unshelve:
155
 
            pipe.write(str(hunk))
156
 
        pipe.flush()
157
 
 
158
 
        if pipe.close() is not None:
159
 
            raise CommandError("Failed running patch!")
 
154
        self._run_patch(to_unshelve)
160
155
 
161
156
        if len(to_remain) == 0:
162
157
            os.remove(patch_name)
201
196
        os.fsync(patch.fileno())
202
197
        patch.close()
203
198
 
204
 
        pipe = os.popen('patch -d %s -sR -p0' % self.base, 'w')
205
 
        for hunk in to_shelve:
206
 
            pipe.write(str(hunk))
207
 
        pipe.flush()
208
 
 
209
 
        if pipe.close() is not None:
210
 
            raise CommandError("Failed running patch!")
211
 
 
 
199
        self._run_patch(to_shelve, reverse=True)
212
200
        self.__show_status(patch_source)
 
201
 
 
202
    def _run_patch(self, patches, reverse=False):
 
203
        args = ['patch', '-d', self.base, '-s', '-p1', '-f']
 
204
        if reverse:
 
205
            args.append('-R')
 
206
 
 
207
        process = subprocess.Popen(args, stdin=subprocess.PIPE)
 
208
        for patch in patches:
 
209
            process.stdin.write(str(patch))
 
210
        process.stdin.close()
 
211
 
 
212
        result = process.wait()
 
213
        if result != 0:
 
214
            raise CommandError("Failed applying patches!")
 
215
 
 
216
        return result