~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Aaron Bentley
  • Date: 2006-12-13 06:53:20 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20061213065320-33dwsj7qqbdkuuqo
Tolerate commit ids with no email

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import os
2
2
import sys
 
3
import subprocess
3
4
from datetime import datetime
4
 
from errors import CommandError, PatchFailed
 
5
from errors import CommandError, PatchFailed, PatchInvokeError
5
6
from hunk_selector import ShelveHunkSelector, UnshelveHunkSelector
6
 
from patch import run_patch
7
 
from patchsource import FilePatchSource
 
7
from patchsource import PatchSource, FilePatchSource
8
8
from bzrlib.osutils import rename
9
9
 
10
10
class Shelf(object):
60
60
    def display(self, patch=None):
61
61
        if patch is None:
62
62
            path = self.last_patch()
63
 
            if path is None:
64
 
                raise CommandError("No patches on shelf.")
65
63
        else:
66
64
            path = self.__path_from_user(patch)
67
65
        sys.stdout.write(open(path).read())
244
242
                    "working tree!")
245
243
 
246
244
    def _run_patch(self, patches, strip=0, reverse=False, dry_run=False):
247
 
        run_patch(self.base, patches, strip, reverse, dry_run)
 
245
        args = ['patch', '-d', self.base, '-s', '-p%d' % strip, '-f']
 
246
 
 
247
        if sys.platform == "win32":
 
248
            args.append('--binary')
 
249
 
 
250
        if reverse:
 
251
            args.append('-R')
 
252
        if dry_run:
 
253
            args.append('--dry-run')
 
254
            stdout = stderr = subprocess.PIPE
 
255
        else:
 
256
            stdout = stderr = None
 
257
 
 
258
        try:
 
259
            process = subprocess.Popen(args, stdin=subprocess.PIPE,
 
260
                                       stdout=stdout, stderr=stderr)
 
261
            for patch in patches:
 
262
                process.stdin.write(str(patch))
 
263
 
 
264
        except IOError, e:
 
265
            raise PatchInvokeError(e, process.stderr.read())
 
266
 
 
267
        process.communicate()
 
268
 
 
269
        result = process.wait()
 
270
        if result != 0:
 
271
            raise PatchFailed()
 
272
 
 
273
        return result
248
274
 
249
275
    def _check_upgrade(self):
250
276
        if len(self._list_old_shelves()) > 0: