~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Aaron Bentley
  • Date: 2007-01-08 17:27:48 UTC
  • Revision ID: abentley@panoramicfeedback.com-20070108172748-1b22qtszaadoby89
Improve bzr import docs

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