/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/shelf_ui.py

  • Committer: Aaron Bentley
  • Date: 2008-10-31 15:08:29 UTC
  • mto: This revision was merged to the branch mainline in revision 3823.
  • Revision ID: aaron@aaronbentley.com-20081031150829-pr859af4whdp849u
Turn diff_file and text_differ into instance variables.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
 
41
41
class Shelver(object):
 
42
    """Interactively shelve the changes in a working tree."""
42
43
 
43
 
    def __init__(self, work_tree, target_tree, path, auto=False,
 
44
    def __init__(self, work_tree, target_tree, auto=False,
44
45
                 auto_apply=False, file_list=None, message=None):
 
46
        """Constructor.
 
47
 
 
48
        :param work_tree: The working tree to shelve changes from.
 
49
        :param target_tree: The "unchanged" / old tree to compare the
 
50
            work_tree to.
 
51
        :param auto: If True, shelve each possible change.
 
52
        :param auto_apply: If True, shelve changes with no final prompt.
 
53
        :param file_list: If supplied, only files in this list may be  shelved.
 
54
        :param message: The message to associate with the shelved changes.
 
55
        """
45
56
        self.work_tree = work_tree
46
57
        self.target_tree = target_tree
47
 
        self.path = path
48
 
        self.diff_file = StringIO()
49
 
        self.text_differ = diff.DiffText(self.target_tree, self.work_tree,
50
 
                                         self.diff_file)
51
58
        if colordiff is not None:
52
59
            self.diff_writer = colordiff.DiffWriter(sys.stdout, False)
53
60
        else:
61
68
    @classmethod
62
69
    def from_args(klass, revision=None, all=False, file_list=None,
63
70
                  message=None, directory='.'):
 
71
        """Create a shelver from commandline arguments.
 
72
 
 
73
        :param revision: RevisionSpec of the revision to compare to.
 
74
        :param all: If True, shelve all changes without prompting.
 
75
        :param file_list: If supplied, only files in this list may be  shelved.
 
76
        :param message: The message to associate with the shelved changes.
 
77
        :param directory: The directory containing the working tree.
 
78
        """
64
79
        tree, path = workingtree.WorkingTree.open_containing(directory)
65
80
        target_tree = builtins._get_one_revision_tree('shelf2', revision,
66
81
            tree.branch, tree)
67
 
        return klass(tree, target_tree, path, all, all, file_list, message)
 
82
        return klass(tree, target_tree, all, all, file_list, message)
68
83
 
69
84
    def run(self):
 
85
        """Interactively shelve the changes."""
70
86
        creator = shelf.ShelfCreator(self.work_tree, self.target_tree,
71
87
                                     self.file_list)
72
88
        self.tempdir = tempfile.mkdtemp()
120
136
    def get_parsed_patch(self, file_id):
121
137
        old_path = self.target_tree.id2path(file_id)
122
138
        new_path = self.work_tree.id2path(file_id)
123
 
        try:
124
 
            patch = self.text_differ.diff(file_id, old_path, new_path, 'file',
125
 
                                          'file')
126
 
            self.diff_file.seek(0)
127
 
            return patches.parse_patch(self.diff_file)
128
 
        finally:
129
 
            self.diff_file.truncate(0)
 
139
        diff_file = StringIO()
 
140
        text_differ = diff.DiffText(self.target_tree, self.work_tree,
 
141
                                    diff_file)
 
142
        patch = text_differ.diff(file_id, old_path, new_path, 'file', 'file')
 
143
        diff_file.seek(0)
 
144
        return patches.parse_patch(diff_file)
130
145
 
131
146
    def prompt(self, message):
132
147
        sys.stdout.write(message)