~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Aaron Bentley
  • Date: 2006-07-24 15:18:40 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060724151840-cf9270c1afbdfa27
Add runtime ignores for shelf

Show diffs side-by-side

added added

removed removed

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