~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-03-12 07:52:22 UTC
  • mfrom: (4100.3.6 destructive-shelve)
  • Revision ID: pqm@pqm.ubuntu.com-20090312075222-g575i2pcrliafetw
(abentley) shelve now supports --destroy option.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
    """Interactively shelve the changes in a working tree."""
40
40
 
41
41
    def __init__(self, work_tree, target_tree, diff_writer=None, auto=False,
42
 
                 auto_apply=False, file_list=None, message=None):
 
42
                 auto_apply=False, file_list=None, message=None,
 
43
                 destroy=False):
43
44
        """Constructor.
44
45
 
45
46
        :param work_tree: The working tree to shelve changes from.
49
50
        :param auto_apply: If True, shelve changes with no final prompt.
50
51
        :param file_list: If supplied, only files in this list may be shelved.
51
52
        :param message: The message to associate with the shelved changes.
 
53
        :param destroy: Change the working tree without storing the shelved
 
54
            changes.
52
55
        """
53
56
        self.work_tree = work_tree
54
57
        self.target_tree = target_tree
60
63
        self.auto_apply = auto_apply
61
64
        self.file_list = file_list
62
65
        self.message = message
 
66
        self.destroy = destroy
63
67
 
64
68
    @classmethod
65
69
    def from_args(klass, diff_writer, revision=None, all=False, file_list=None,
66
 
                  message=None, directory='.'):
 
70
                  message=None, directory='.', destroy=False):
67
71
        """Create a shelver from commandline arguments.
68
72
 
69
73
        :param revision: RevisionSpec of the revision to compare to.
71
75
        :param file_list: If supplied, only files in this list may be  shelved.
72
76
        :param message: The message to associate with the shelved changes.
73
77
        :param directory: The directory containing the working tree.
 
78
        :param destroy: Change the working tree without storing the shelved
 
79
            changes.
74
80
        """
75
81
        tree, path = workingtree.WorkingTree.open_containing(directory)
76
82
        target_tree = builtins._get_one_revision_tree('shelf2', revision,
77
83
            tree.branch, tree)
78
84
        files = builtins.safe_relpath_files(tree, file_list)
79
 
        return klass(tree, target_tree, diff_writer, all, all, files, message)
 
85
        return klass(tree, target_tree, diff_writer, all, all, files, message,
 
86
                     destroy)
80
87
 
81
88
    def run(self):
82
89
        """Interactively shelve the changes."""
121
128
                delta.report_changes(changes, reporter)
122
129
                if (self.auto_apply or self.prompt_bool(
123
130
                    'Shelve %d change(s)?' % changes_shelved)):
124
 
                    shelf_id = self.manager.shelve_changes(creator,
125
 
                                                           self.message)
126
 
                    trace.note('Changes shelved with id "%d".' % shelf_id)
 
131
                    if self.destroy:
 
132
                        creator.transform()
 
133
                        trace.note('Selected changes destroyed.')
 
134
                    else:
 
135
                        shelf_id = self.manager.shelve_changes(creator,
 
136
                                                               self.message)
 
137
                        trace.note('Changes shelved with id "%d".' % shelf_id)
127
138
            else:
128
139
                trace.warning('No changes to shelve.')
129
140
        finally: