/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 breezy/shelf_ui.py

  • Committer: Jelmer Vernooij
  • Date: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
import contextlib
18
 
import patiencediff
 
17
from __future__ import absolute_import
 
18
 
19
19
import shutil
20
20
import sys
21
21
import tempfile
22
22
 
23
 
from io import BytesIO
24
 
 
25
23
from . import (
26
24
    builtins,
27
25
    delta,
29
27
    errors,
30
28
    osutils,
31
29
    patches,
 
30
    patiencediff,
32
31
    shelf,
33
32
    textfile,
34
33
    trace,
36
35
    workingtree,
37
36
)
38
37
from .i18n import gettext
 
38
from .sixish import (
 
39
    BytesIO,
 
40
    )
39
41
 
40
42
 
41
43
class UseEditor(Exception):
47
49
    vocab = {'add file': gettext('Shelve adding file "%(path)s"?'),
48
50
             'binary': gettext('Shelve binary changes?'),
49
51
             'change kind': gettext('Shelve changing "%s" from %(other)s'
50
 
                                    ' to %(this)s?'),
 
52
             ' to %(this)s?'),
51
53
             'delete file': gettext('Shelve removing file "%(path)s"?'),
52
54
             'final': gettext('Shelve %d change(s)?'),
53
55
             'hunk': gettext('Shelve?'),
54
56
             'modify target': gettext('Shelve changing target of'
55
 
                                      ' "%(path)s" from "%(other)s" to "%(this)s"?'),
 
57
             ' "%(path)s" from "%(other)s" to "%(this)s"?'),
56
58
             'rename': gettext('Shelve renaming "%(other)s" =>'
57
 
                               ' "%(this)s"?')
 
59
                        ' "%(this)s"?')
58
60
             }
59
61
 
60
62
    invert_diff = False
99
101
    vocab = {'add file': gettext('Delete file "%(path)s"?'),
100
102
             'binary': gettext('Apply binary changes?'),
101
103
             'change kind': gettext('Change "%(path)s" from %(this)s'
102
 
                                    ' to %(other)s?'),
 
104
             ' to %(other)s?'),
103
105
             'delete file': gettext('Add file "%(path)s"?'),
104
106
             'final': gettext('Apply %d change(s)?'),
105
107
             'hunk': gettext('Apply change?'),
106
108
             'modify target': gettext('Change target of'
107
 
                                      ' "%(path)s" from "%(this)s" to "%(other)s"?'),
 
109
             ' "%(path)s" from "%(this)s" to "%(other)s"?'),
108
110
             'rename': gettext('Rename "%(this)s" => "%(other)s"?'),
109
111
             }
110
112
 
177
179
        tree, path = workingtree.WorkingTree.open_containing(directory)
178
180
        # Ensure that tree is locked for the lifetime of target_tree, as
179
181
        # target tree may be reading from the same dirstate.
180
 
        with tree.lock_tree_write():
 
182
        tree.lock_tree_write()
 
183
        try:
181
184
            target_tree = builtins._get_one_revision_tree('shelf2', revision,
182
 
                                                          tree.branch, tree)
 
185
                tree.branch, tree)
183
186
            files = tree.safe_relpath_files(file_list)
184
187
            return klass(tree, target_tree, diff_writer, all, all, files,
185
188
                         message, destroy)
 
189
        finally:
 
190
            tree.unlock()
186
191
 
187
192
    def run(self):
188
193
        """Interactively shelve the changes."""
207
212
            if changes_shelved > 0:
208
213
                self.reporter.selected_changes(creator.work_transform)
209
214
                if (self.auto_apply or self.prompt_bool(
210
 
                        self.reporter.vocab['final'] % changes_shelved)):
 
215
                    self.reporter.vocab['final'] % changes_shelved)):
211
216
                    if self.destroy:
212
217
                        creator.transform()
213
218
                        self.reporter.changes_destroyed()
243
248
            new_tree = self.work_tree
244
249
        old_path = old_tree.id2path(file_id)
245
250
        new_path = new_tree.id2path(file_id)
246
 
        path_encoding = osutils.get_terminal_encoding()
247
251
        text_differ = diff.DiffText(old_tree, new_tree, diff_file,
248
 
                                    path_encoding=path_encoding)
249
 
        patch = text_differ.diff(old_path, new_path, 'file', 'file')
 
252
            path_encoding=osutils.get_terminal_encoding())
 
253
        patch = text_differ.diff(file_id, old_path, new_path, 'file', 'file')
250
254
        diff_file.seek(0)
251
255
        return patches.parse_patch(diff_file)
252
256
 
320
324
        if self.reporter.invert_diff:
321
325
            target_lines = work_tree_lines
322
326
        else:
323
 
            path = self.target_tree.id2path(file_id)
324
 
            target_lines = self.target_tree.get_file_lines(path)
 
327
            path = self.target_tree.path2id(file_id)
 
328
            target_lines = self.target_tree.get_file_lines(path, file_id)
325
329
        textfile.check_text_lines(work_tree_lines)
326
330
        textfile.check_text_lines(target_lines)
327
331
        parsed = self.get_parsed_patch(file_id, self.reporter.invert_diff)
330
334
            offset = 0
331
335
            self.diff_writer.write(parsed.get_header())
332
336
            for hunk in parsed.hunks:
333
 
                self.diff_writer.write(hunk.as_bytes())
 
337
                self.diff_writer.write(str(hunk))
334
338
                selected = self.prompt_bool(self.reporter.vocab['hunk'],
335
339
                                            allow_editor=(self.change_editor
336
340
                                                          is not None))
361
365
        """
362
366
        lines = osutils.split_lines(self.change_editor.edit_file(
363
367
            self.change_editor.old_tree.id2path(file_id),
364
 
            self.change_editor.new_tree.id2path(file_id)))
 
368
            self.change_editor.new_tree.id2path(file_id),
 
369
            file_id=file_id))
365
370
        return lines, self._count_changed_regions(work_tree_lines, lines)
366
371
 
367
372
    @staticmethod
401
406
            else:
402
407
                shelf_id = manager.last_shelf()
403
408
                if shelf_id is None:
404
 
                    raise errors.CommandError(
405
 
                        gettext('No changes are shelved.'))
 
409
                    raise errors.BzrCommandError(gettext('No changes are shelved.'))
406
410
            apply_changes = True
407
411
            delete_shelf = True
408
412
            read_shelf = True
456
460
 
457
461
    def run(self):
458
462
        """Perform the unshelving operation."""
459
 
        with contextlib.ExitStack() as exit_stack:
460
 
            exit_stack.enter_context(self.tree.lock_tree_write())
 
463
        self.tree.lock_tree_write()
 
464
        cleanups = [self.tree.unlock]
 
465
        try:
461
466
            if self.read_shelf:
462
 
                trace.note(gettext('Using changes with id "%d".') %
463
 
                           self.shelf_id)
 
467
                trace.note(gettext('Using changes with id "%d".') % self.shelf_id)
464
468
                unshelver = self.manager.get_unshelver(self.shelf_id)
465
 
                exit_stack.callback(unshelver.finalize)
 
469
                cleanups.append(unshelver.finalize)
466
470
                if unshelver.message is not None:
467
471
                    trace.note(gettext('Message: %s') % unshelver.message)
468
472
                change_reporter = delta._ChangeReporter()
476
480
                    self.show_changes(merger)
477
481
            if self.delete_shelf:
478
482
                self.manager.delete_shelf(self.shelf_id)
479
 
                trace.note(gettext('Deleted changes with id "%d".') %
480
 
                           self.shelf_id)
 
483
                trace.note(gettext('Deleted changes with id "%d".') % self.shelf_id)
 
484
        finally:
 
485
            for cleanup in reversed(cleanups):
 
486
                cleanup()
481
487
 
482
488
    def write_diff(self, merger):
483
489
        """Write this operation's diff to self.write_diff_to."""
485
491
        tt = tree_merger.make_preview_transform()
486
492
        new_tree = tt.get_preview_tree()
487
493
        if self.write_diff_to is None:
488
 
            self.write_diff_to = ui.ui_factory.make_output_stream(
489
 
                encoding_type='exact')
 
494
            self.write_diff_to = ui.ui_factory.make_output_stream(encoding_type='exact')
490
495
        path_encoding = osutils.get_diff_header_encoding()
491
496
        diff.show_diff_trees(merger.this_tree, new_tree, self.write_diff_to,
492
 
                             path_encoding=path_encoding)
 
497
            path_encoding=path_encoding)
493
498
        tt.finalize()
494
499
 
495
500
    def show_changes(self, merger):