~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Aaron Bentley
  • Date: 2008-02-13 04:15:48 UTC
  • Revision ID: aaron@aaronbentley.com-20080213041548-r35d4icm9kblej3u
Unify patch invocation

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
from datetime import datetime
5
5
from errors import CommandError, PatchFailed, PatchInvokeError
6
6
from hunk_selector import ShelveHunkSelector, UnshelveHunkSelector
 
7
from patch import run_patch
7
8
from patchsource import PatchSource, FilePatchSource
8
9
from bzrlib.osutils import rename
9
10
 
244
245
                    "working tree!")
245
246
 
246
247
    def _run_patch(self, patches, strip=0, reverse=False, dry_run=False):
247
 
        args = ['patch', '-d', self.base, '-s', '-p%d' % strip, '-f']
248
 
 
249
 
        if sys.platform == "win32":
250
 
            args.append('--binary')
251
 
 
252
 
        if reverse:
253
 
            args.append('-R')
254
 
        if dry_run:
255
 
            if sys.platform.startswith('freebsd'):
256
 
                args.append('--check')
257
 
            else:
258
 
                args.append('--dry-run')
259
 
            stderr = subprocess.PIPE
260
 
        else:
261
 
            stderr = None
262
 
 
263
 
        try:
264
 
            process = subprocess.Popen(args, stdin=subprocess.PIPE,
265
 
                                       stdout=subprocess.PIPE, stderr=stderr)
266
 
            for patch in patches:
267
 
                process.stdin.write(str(patch))
268
 
            process.stdin.close()
269
 
 
270
 
        except IOError, e:
271
 
            raise PatchInvokeError(e, process.stderr.read())
272
 
 
273
 
        result = process.wait()
274
 
        if not dry_run:
275
 
            sys.stdout.write(process.stdout.read())
276
 
        if result != 0:
277
 
            raise PatchFailed()
278
 
 
279
 
        return result
 
248
        run_patch(self.base, patches, strip, reverse, dry_run)
280
249
 
281
250
    def _check_upgrade(self):
282
251
        if len(self._list_old_shelves()) > 0: