~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Aaron Bentley
  • Date: 2007-12-22 02:01:03 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20071222020103-ggjszok7n974e1l2
Update branches, multi-pull to new APIs, create trees

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
8
7
from patchsource import PatchSource, FilePatchSource
9
8
from bzrlib.osutils import rename
10
9
 
245
244
                    "working tree!")
246
245
 
247
246
    def _run_patch(self, patches, strip=0, reverse=False, dry_run=False):
248
 
        run_patch(self.base, patches, strip, reverse, dry_run)
 
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
249
280
 
250
281
    def _check_upgrade(self):
251
282
        if len(self._list_old_shelves()) > 0: