~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to shelver.py

  • Committer: Aaron Bentley
  • Date: 2008-10-08 03:16:36 UTC
  • mto: This revision was merged to the branch mainline in revision 3823.
  • Revision ID: aaron@aaronbentley.com-20081008031636-fabpozftpuehz0et
Implement auto mode

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
class Shelver(object):
32
32
 
33
 
    def __init__(self, work_tree, target_tree, path):
 
33
    def __init__(self, work_tree, target_tree, path, auto=False):
34
34
        self.work_tree = work_tree
35
35
        self.target_tree = target_tree
36
36
        self.path = path
39
39
                                         self.diff_file)
40
40
        self.diff_writer = colordiff.DiffWriter(sys.stdout, False)
41
41
        self.manager = prepare_shelf.ShelfManager.for_tree(work_tree)
 
42
        self.auto = auto
42
43
 
43
44
    @classmethod
44
 
    def from_args(klass, revision=None):
 
45
    def from_args(klass, revision=None, all=False):
45
46
        tree, path = workingtree.WorkingTree.open_containing('.')
46
47
        target_tree = builtins._get_one_revision_tree('shelf2', revision,
47
48
            tree.branch, tree)
48
 
        return klass(tree, target_tree, path)
 
49
        return klass(tree, target_tree, path, all)
49
50
 
50
51
    def run(self):
51
52
        creator = prepare_shelf.ShelfCreator(self.work_tree, self.target_tree)
90
91
        return ch
91
92
 
92
93
    def prompt(self, question):
 
94
        if self.auto:
 
95
            return 'y'
93
96
        print question,
94
97
        char = self.__getchar()
95
98
        print ""
120
123
        selected_hunks = []
121
124
        final_patch = copy.copy(parsed)
122
125
        final_patch.hunks = []
123
 
        for hunk in parsed.hunks:
124
 
            self.diff_writer.write(str(hunk))
125
 
            char = self.prompt('Shelve? [y/n]')
126
 
            if char == 'n':
127
 
                final_patch.hunks.append(hunk)
 
126
        if not self.auto:
 
127
            for hunk in parsed.hunks:
 
128
                self.diff_writer.write(str(hunk))
 
129
                char = self.prompt('Shelve? [y/n]')
 
130
                if char == 'n':
 
131
                    final_patch.hunks.append(hunk)
128
132
        patched_text = self.get_patched_text(file_id, final_patch)
129
133
        creator.shelve_text(file_id, patched_text)
130
134