~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to shelf_ui.py

  • Committer: Aaron Bentley
  • Date: 2008-10-11 19:55:18 UTC
  • mto: This revision was merged to the branch mainline in revision 3823.
  • Revision ID: aaron@aaronbentley.com-20081011195518-2pyomldupl2ve4dn
Implement dry-run option for Unshelve

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    errors,
28
28
    patches,
29
29
    trace,
 
30
    ui,
30
31
    workingtree)
31
32
from bzrlib.plugins.bzrtools import colordiff
32
33
from bzrlib.plugins.bzrtools.userinteractor import getchar
154
155
class Unshelver(object):
155
156
 
156
157
    @classmethod
157
 
    def from_args(klass, shelf_id):
 
158
    def from_args(klass, shelf_id=None, dry_run=False):
158
159
        tree, path = workingtree.WorkingTree.open_containing('.')
159
160
        manager = tree.get_shelf_manager()
160
161
        if shelf_id is not None:
164
165
            if shelf_id is None:
165
166
                raise errors.BzrCommandError('No changes are shelved.')
166
167
            trace.note('Unshelving changes with id "%d".' % shelf_id)
167
 
        return klass(tree, manager, shelf_id)
 
168
        apply_changes = True
 
169
        delete_shelf = True
 
170
        if dry_run:
 
171
            apply_changes = False
 
172
            delete_shelf = False
 
173
        return klass(tree, manager, shelf_id, apply_changes, delete_shelf)
168
174
 
169
 
    def __init__(self, tree, manager, shelf_id):
 
175
    def __init__(self, tree, manager, shelf_id, apply_changes, delete_shelf):
170
176
        self.tree = tree
171
177
        self.manager = manager
172
178
        self.shelf_id = shelf_id
 
179
        self.apply_changes = apply_changes
 
180
        self.delete_shelf = delete_shelf
173
181
 
174
182
    def run(self):
175
183
        self.tree.lock_write()
179
187
            cleanups.append(unshelver.finalize)
180
188
            if unshelver.message is not None:
181
189
                trace.note('Message: %s' % unshelver.message)
182
 
            unshelver.unshelve(delta._ChangeReporter())
183
 
            self.manager.delete_shelf(self.shelf_id)
 
190
            change_reporter = delta._ChangeReporter()
 
191
            merger = unshelver.get_merger()
 
192
            merger.change_reporter = change_reporter
 
193
            if self.apply_changes:
 
194
                pb = ui.ui_factory.nested_progress_bar()
 
195
                try:
 
196
                    merger.do_merge()
 
197
                finally:
 
198
                    pb.finished()
 
199
            else:
 
200
                self.show_changes(merger)
 
201
            if self.delete_shelf:
 
202
                self.manager.delete_shelf(self.shelf_id)
184
203
        finally:
185
204
            for cleanup in reversed(cleanups):
186
205
                cleanup()
 
206
 
 
207
    def show_changes(self, merger):
 
208
        tree_merger = merger.make_merger()
 
209
        # This implicitly shows the changes via the reporter, so we're done...
 
210
        tt = tree_merger.make_preview_transform()
 
211
        tt.finalize()