~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Aaron Bentley
  • Date: 2008-02-13 04:58:32 UTC
  • Revision ID: aaron@aaronbentley.com-20080213045832-ohymgqf0quamuhye
Update email address

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
 
60
61
    def display(self, patch=None):
61
62
        if patch is None:
62
63
            path = self.last_patch()
 
64
            if path is None:
 
65
                raise CommandError("No patches on shelf.")
63
66
        else:
64
67
            path = self.__path_from_user(patch)
65
68
        sys.stdout.write(open(path).read())
242
245
                    "working tree!")
243
246
 
244
247
    def _run_patch(self, patches, strip=0, reverse=False, dry_run=False):
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
        run_patch(self.base, patches, strip, reverse, dry_run)
274
249
 
275
250
    def _check_upgrade(self):
276
251
        if len(self._list_old_shelves()) > 0: