~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Aaron Bentley
  • Date: 2009-07-10 04:05:24 UTC
  • Revision ID: aaron@aaronbentley.com-20090710040524-slufgm4he3fx1r4f
Mirror the child_submit_to setting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
1
import os
4
2
import sys
5
3
import subprocess
6
4
from datetime import datetime
7
 
from errors import CommandError, PatchFailed
 
5
from errors import CommandError, PatchFailed, PatchInvokeError
8
6
from hunk_selector import ShelveHunkSelector, UnshelveHunkSelector
 
7
from patch import run_patch
9
8
from patchsource import PatchSource, FilePatchSource
10
9
from bzrlib.osutils import rename
11
10
 
62
61
    def display(self, patch=None):
63
62
        if patch is None:
64
63
            path = self.last_patch()
 
64
            if path is None:
 
65
                raise CommandError("No patches on shelf.")
65
66
        else:
66
67
            path = self.__path_from_user(patch)
67
68
        sys.stdout.write(open(path).read())
134
135
            return None
135
136
        return patch[len(self.MESSAGE_PREFIX):patch.index('\n')]
136
137
 
137
 
    def unshelve(self, patch_source, patch_name=None, all=False, force=False):
 
138
    def unshelve(self, patch_source, patch_name=None, all=False, force=False,
 
139
                 no_color=False):
138
140
        self._check_upgrade()
139
141
 
 
142
        if no_color is False:
 
143
            color = None
 
144
        else:
 
145
            color = False
140
146
        if patch_name is None:
141
147
            patch_path = self.last_patch()
142
148
        else:
150
156
            to_unshelve = patches
151
157
            to_remain = []
152
158
        else:
153
 
            to_unshelve, to_remain = UnshelveHunkSelector(patches).select()
 
159
            hs = UnshelveHunkSelector(patches, color)
 
160
            to_unshelve, to_remain = hs.select()
154
161
 
155
162
        if len(to_unshelve) == 0:
156
163
            raise CommandError('Nothing to unshelve')
189
196
                f.write(str(patch))
190
197
            f.close()
191
198
 
192
 
    def shelve(self, patch_source, all=False, message=None):
 
199
    def shelve(self, patch_source, all=False, message=None, no_color=False):
193
200
        self._check_upgrade()
 
201
        if no_color is False:
 
202
            color = None
 
203
        else:
 
204
            color = False
194
205
 
195
206
        patches = patch_source.readpatches()
196
207
 
197
208
        if all:
198
209
            to_shelve = patches
199
210
        else:
200
 
            to_shelve = ShelveHunkSelector(patches).select()[0]
 
211
            to_shelve = ShelveHunkSelector(patches, color).select()[0]
201
212
 
202
213
        if len(to_shelve) == 0:
203
214
            raise CommandError('Nothing to shelve')
234
245
                    "working tree!")
235
246
 
236
247
    def _run_patch(self, patches, strip=0, reverse=False, dry_run=False):
237
 
        args = ['patch', '-d', self.base, '-s', '-p%d' % strip, '-f']
238
 
 
239
 
        if sys.platform == "win32":
240
 
            args.append('--binary')
241
 
 
242
 
        if reverse:
243
 
            args.append('-R')
244
 
        if dry_run:
245
 
            args.append('--dry-run')
246
 
            stdout = stderr = subprocess.PIPE
247
 
        else:
248
 
            stdout = stderr = None
249
 
 
250
 
        process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=stdout,
251
 
                        stderr=stderr)
252
 
        for patch in patches:
253
 
            process.stdin.write(str(patch))
254
 
 
255
 
        process.communicate()
256
 
 
257
 
        result = process.wait()
258
 
        if result != 0:
259
 
            raise PatchFailed()
260
 
 
261
 
        return result
 
248
        run_patch(self.base, patches, strip, reverse, dry_run)
262
249
 
263
250
    def _check_upgrade(self):
264
251
        if len(self._list_old_shelves()) > 0: