~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Max Bowsher
  • Date: 2009-11-13 00:43:08 UTC
  • mto: This revision was merged to the branch mainline in revision 739.
  • Revision ID: maxb@f2s.com-20091113004308-4dcwu1kwt3lhf1kp
Having discovered that bzr-builddeb import_dsc.py is a horrid copy-paste job of bzrtools upstream_import.py, restructure the change to minimize divergence from it.

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: