~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shelf_ui.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-06-26 03:32:27 UTC
  • mfrom: (4459.4.1 bzr.qpipe)
  • Revision ID: pqm@pqm.ubuntu.com-20090626033227-k6uokcs5iehqp80h
(abentley) Provide finer control over shelve and switch output.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
)
36
36
 
37
37
 
 
38
class ShelfReporter(object):
 
39
 
 
40
    def __init__(self):
 
41
        self.delta_reporter = delta._ChangeReporter()
 
42
 
 
43
    def no_changes(self):
 
44
        trace.warning('No changes to shelve.')
 
45
 
 
46
    def shelved_id(self, shelf_id):
 
47
        trace.note('Changes shelved with id "%d".' % shelf_id)
 
48
 
 
49
    def selected_changes(self, transform):
 
50
        trace.note("Selected changes:")
 
51
        changes = transform.iter_changes()
 
52
        delta.report_changes(changes, self.delta_reporter)
 
53
 
 
54
 
38
55
class Shelver(object):
39
56
    """Interactively shelve the changes in a working tree."""
40
57
 
41
58
    def __init__(self, work_tree, target_tree, diff_writer=None, auto=False,
42
59
                 auto_apply=False, file_list=None, message=None,
43
 
                 destroy=False):
 
60
                 destroy=False, reporter=None):
44
61
        """Constructor.
45
62
 
46
63
        :param work_tree: The working tree to shelve changes from.
64
81
        self.file_list = file_list
65
82
        self.message = message
66
83
        self.destroy = destroy
 
84
        if reporter is None:
 
85
            reporter = ShelfReporter()
 
86
        self.reporter = reporter
67
87
 
68
88
    @classmethod
69
89
    def from_args(klass, diff_writer, revision=None, all=False, file_list=None,
127
147
                        creator.shelve_modify_target(change[1])
128
148
                        changes_shelved += 1
129
149
            if changes_shelved > 0:
130
 
                trace.note("Selected changes:")
131
 
                changes = creator.work_transform.iter_changes()
132
 
                reporter = delta._ChangeReporter()
133
 
                delta.report_changes(changes, reporter)
 
150
                self.reporter.selected_changes(creator.work_transform)
134
151
                if (self.auto_apply or self.prompt_bool(
135
152
                    'Shelve %d change(s)?' % changes_shelved)):
136
153
                    if self.destroy:
139
156
                    else:
140
157
                        shelf_id = self.manager.shelve_changes(creator,
141
158
                                                               self.message)
142
 
                        trace.note('Changes shelved with id "%d".' % shelf_id)
 
159
                        self.reporter.shelved_id(shelf_id)
143
160
            else:
144
 
                trace.warning('No changes to shelve.')
 
161
                self.reporter.no_changes()
145
162
        finally:
146
163
            shutil.rmtree(self.tempdir)
147
164
            creator.finalize()