~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-30 05:12:27 UTC
  • mfrom: (4490.1.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090630051227-ncar0w60u6cbyydk
(mbp) force deletion of readonly files from TreeTransform

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, manager=None, reporter=None):
44
61
        """Constructor.
45
62
 
46
63
        :param work_tree: The working tree to shelve changes from.
52
69
        :param message: The message to associate with the shelved changes.
53
70
        :param destroy: Change the working tree without storing the shelved
54
71
            changes.
 
72
        :param manager: The shelf manager to use.
55
73
        """
56
74
        self.work_tree = work_tree
57
75
        self.target_tree = target_tree
58
76
        self.diff_writer = diff_writer
59
77
        if self.diff_writer is None:
60
78
            self.diff_writer = sys.stdout
61
 
        self.manager = work_tree.get_shelf_manager()
 
79
        if manager is None:
 
80
            manager = work_tree.get_shelf_manager()
 
81
        self.manager = manager
62
82
        self.auto = auto
63
83
        self.auto_apply = auto_apply
64
84
        self.file_list = file_list
65
85
        self.message = message
66
86
        self.destroy = destroy
 
87
        if reporter is None:
 
88
            reporter = ShelfReporter()
 
89
        self.reporter = reporter
67
90
 
68
91
    @classmethod
69
92
    def from_args(klass, diff_writer, revision=None, all=False, file_list=None,
127
150
                        creator.shelve_modify_target(change[1])
128
151
                        changes_shelved += 1
129
152
            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)
 
153
                self.reporter.selected_changes(creator.work_transform)
134
154
                if (self.auto_apply or self.prompt_bool(
135
155
                    'Shelve %d change(s)?' % changes_shelved)):
136
156
                    if self.destroy:
139
159
                    else:
140
160
                        shelf_id = self.manager.shelve_changes(creator,
141
161
                                                               self.message)
142
 
                        trace.note('Changes shelved with id "%d".' % shelf_id)
 
162
                        self.reporter.shelved_id(shelf_id)
143
163
            else:
144
 
                trace.warning('No changes to shelve.')
 
164
                self.reporter.no_changes()
145
165
        finally:
146
166
            shutil.rmtree(self.tempdir)
147
167
            creator.finalize()