~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shelf_ui.py

  • Committer: Vincent Ladeuil
  • Date: 2010-04-28 10:33:44 UTC
  • mfrom: (5171.2.3 401599-strict-warnings)
  • mto: This revision was merged to the branch mainline in revision 5191.
  • Revision ID: v.ladeuil+lp@free.fr-20100428103344-e32qf3cn1avdd2cb
Don't mention --no-strict when we just issue the warning about unclean trees

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    ui,
35
35
    workingtree,
36
36
)
37
 
from bzrlib.i18n import gettext
 
37
 
38
38
 
39
39
class UseEditor(Exception):
40
40
    """Use an editor instead of selecting hunks."""
42
42
 
43
43
class ShelfReporter(object):
44
44
 
45
 
    vocab = {'add file': gettext('Shelve adding file "%(path)s"?'),
46
 
             'binary': gettext('Shelve binary changes?'),
47
 
             'change kind': gettext('Shelve changing "%s" from %(other)s'
48
 
             ' to %(this)s?'),
49
 
             'delete file': gettext('Shelve removing file "%(path)s"?'),
50
 
             'final': gettext('Shelve %d change(s)?'),
51
 
             'hunk': gettext('Shelve?'),
52
 
             'modify target': gettext('Shelve changing target of'
53
 
             ' "%(path)s" from "%(other)s" to "%(this)s"?'),
54
 
             'rename': gettext('Shelve renaming "%(other)s" =>'
55
 
                        ' "%(this)s"?')
 
45
    vocab = {'add file': 'Shelve adding file "%(path)s"?',
 
46
             'binary': 'Shelve binary changes?',
 
47
             'change kind': 'Shelve changing "%s" from %(other)s'
 
48
             ' to %(this)s?',
 
49
             'delete file': 'Shelve removing file "%(path)s"?',
 
50
             'final': 'Shelve %d change(s)?',
 
51
             'hunk': 'Shelve?',
 
52
             'modify target': 'Shelve changing target of'
 
53
             ' "%(path)s" from "%(other)s" to "%(this)s"?',
 
54
             'rename': 'Shelve renaming "%(other)s" =>'
 
55
                        ' "%(this)s"?'
56
56
             }
57
57
 
58
58
    invert_diff = False
66
66
 
67
67
    def shelved_id(self, shelf_id):
68
68
        """Report the id changes were shelved to."""
69
 
        trace.note(gettext('Changes shelved with id "%d".') % shelf_id)
 
69
        trace.note('Changes shelved with id "%d".' % shelf_id)
70
70
 
71
71
    def changes_destroyed(self):
72
72
        """Report that changes were made without shelving."""
73
 
        trace.note(gettext('Selected changes destroyed.'))
 
73
        trace.note('Selected changes destroyed.')
74
74
 
75
75
    def selected_changes(self, transform):
76
76
        """Report the changes that were selected."""
77
 
        trace.note(gettext("Selected changes:"))
 
77
        trace.note("Selected changes:")
78
78
        changes = transform.iter_changes()
79
79
        delta.report_changes(changes, self.delta_reporter)
80
80
 
94
94
 
95
95
class ApplyReporter(ShelfReporter):
96
96
 
97
 
    vocab = {'add file': gettext('Delete file "%(path)s"?'),
98
 
             'binary': gettext('Apply binary changes?'),
99
 
             'change kind': gettext('Change "%(path)s" from %(this)s'
100
 
             ' to %(other)s?'),
101
 
             'delete file': gettext('Add file "%(path)s"?'),
102
 
             'final': gettext('Apply %d change(s)?'),
103
 
             'hunk': gettext('Apply change?'),
104
 
             'modify target': gettext('Change target of'
105
 
             ' "%(path)s" from "%(this)s" to "%(other)s"?'),
106
 
             'rename': gettext('Rename "%(this)s" => "%(other)s"?'),
 
97
    vocab = {'add file': 'Delete file "%(path)s"?',
 
98
             'binary': 'Apply binary changes?',
 
99
             'change kind': 'Change "%(path)s" from %(this)s'
 
100
             ' to %(other)s?',
 
101
             'delete file': 'Add file "%(path)s"?',
 
102
             'final': 'Apply %d change(s)?',
 
103
             'hunk': 'Apply change?',
 
104
             'modify target': 'Change target of'
 
105
             ' "%(path)s" from "%(this)s" to "%(other)s"?',
 
106
             'rename': 'Rename "%(this)s" => "%(other)s"?',
107
107
             }
108
108
 
109
109
    invert_diff = True
154
154
 
155
155
    @classmethod
156
156
    def from_args(klass, diff_writer, revision=None, all=False, file_list=None,
157
 
                  message=None, directory=None, destroy=False):
 
157
                  message=None, directory='.', destroy=False):
158
158
        """Create a shelver from commandline arguments.
159
159
 
160
160
        The returned shelver wil have a work_tree that is locked and should
168
168
        :param destroy: Change the working tree without storing the shelved
169
169
            changes.
170
170
        """
171
 
        if directory is None:
172
 
            directory = u'.'
173
 
        elif file_list:
174
 
            file_list = [osutils.pathjoin(directory, f) for f in file_list]
175
171
        tree, path = workingtree.WorkingTree.open_containing(directory)
176
172
        # Ensure that tree is locked for the lifetime of target_tree, as
177
173
        # target tree may be reading from the same dirstate.
179
175
        try:
180
176
            target_tree = builtins._get_one_revision_tree('shelf2', revision,
181
177
                tree.branch, tree)
182
 
            files = tree.safe_relpath_files(file_list)
 
178
            files = builtins.safe_relpath_files(tree, file_list)
183
179
            return klass(tree, target_tree, diff_writer, all, all, files,
184
180
                         message, destroy)
185
181
        finally:
245
241
            new_tree = self.work_tree
246
242
        old_path = old_tree.id2path(file_id)
247
243
        new_path = new_tree.id2path(file_id)
248
 
        text_differ = diff.DiffText(old_tree, new_tree, diff_file,
249
 
            path_encoding=osutils.get_terminal_encoding())
 
244
        text_differ = diff.DiffText(old_tree, new_tree, diff_file)
250
245
        patch = text_differ.diff(file_id, old_path, new_path, 'file', 'file')
251
246
        diff_file.seek(0)
252
247
        return patches.parse_patch(diff_file)
262
257
            # to prompt the user, better abort now.  See
263
258
            # https://code.launchpad.net/~bialix/bzr/shelve-no-tty/+merge/14905
264
259
            # for more context.
265
 
            raise errors.BzrError(gettext("You need a controlling terminal."))
 
260
            raise errors.BzrError("You need a controlling terminal.")
266
261
        sys.stdout.write(message)
267
262
        char = osutils.getchar()
268
263
        sys.stdout.write("\r" + ' ' * len(message) + '\r')
412
407
            else:
413
408
                shelf_id = manager.last_shelf()
414
409
                if shelf_id is None:
415
 
                    raise errors.BzrCommandError(gettext('No changes are shelved.'))
 
410
                    raise errors.BzrCommandError('No changes are shelved.')
416
411
            apply_changes = True
417
412
            delete_shelf = True
418
413
            read_shelf = True
470
465
        cleanups = [self.tree.unlock]
471
466
        try:
472
467
            if self.read_shelf:
473
 
                trace.note(gettext('Using changes with id "%d".') % self.shelf_id)
 
468
                trace.note('Using changes with id "%d".' % self.shelf_id)
474
469
                unshelver = self.manager.get_unshelver(self.shelf_id)
475
470
                cleanups.append(unshelver.finalize)
476
471
                if unshelver.message is not None:
477
 
                    trace.note(gettext('Message: %s') % unshelver.message)
 
472
                    trace.note('Message: %s' % unshelver.message)
478
473
                change_reporter = delta._ChangeReporter()
479
474
                merger = unshelver.make_merger(None)
480
475
                merger.change_reporter = change_reporter
486
481
                    self.show_changes(merger)
487
482
            if self.delete_shelf:
488
483
                self.manager.delete_shelf(self.shelf_id)
489
 
                trace.note(gettext('Deleted changes with id "%d".') % self.shelf_id)
 
484
                trace.note('Deleted changes with id "%d".' % self.shelf_id)
490
485
        finally:
491
486
            for cleanup in reversed(cleanups):
492
487
                cleanup()
497
492
        tt = tree_merger.make_preview_transform()
498
493
        new_tree = tt.get_preview_tree()
499
494
        if self.write_diff_to is None:
500
 
            self.write_diff_to = ui.ui_factory.make_output_stream(encoding_type='exact')
501
 
        path_encoding = osutils.get_diff_header_encoding()
502
 
        diff.show_diff_trees(merger.this_tree, new_tree, self.write_diff_to,
503
 
            path_encoding=path_encoding)
 
495
            self.write_diff_to = ui.ui_factory.make_output_stream()
 
496
        diff.show_diff_trees(merger.this_tree, new_tree, self.write_diff_to)
504
497
        tt.finalize()
505
498
 
506
499
    def show_changes(self, merger):