44
43
class ShelfReporter(object):
46
vocab = {'add file': gettext('Shelve adding file "%(path)s"?'),
47
'binary': gettext('Shelve binary changes?'),
48
'change kind': gettext('Shelve changing "%s" from %(other)s'
50
'delete file': gettext('Shelve removing file "%(path)s"?'),
51
'final': gettext('Shelve %d change(s)?'),
52
'hunk': gettext('Shelve?'),
53
'modify target': gettext('Shelve changing target of'
54
' "%(path)s" from "%(other)s" to "%(this)s"?'),
55
'rename': gettext('Shelve renaming "%(other)s" =>'
45
vocab = {'add file': 'Shelve adding file "%(path)s"?',
46
'binary': 'Shelve binary changes?',
47
'change kind': 'Shelve changing "%s" from %(other)s'
49
'delete file': 'Shelve removing file "%(path)s"?',
50
'final': 'Shelve %d change(s)?',
52
'modify target': 'Shelve changing target of'
53
' "%(path)s" from "%(other)s" to "%(this)s"?',
54
'rename': 'Shelve renaming "%(other)s" =>'
59
58
invert_diff = False
68
67
def shelved_id(self, shelf_id):
69
68
"""Report the id changes were shelved to."""
70
trace.note(gettext('Changes shelved with id "%d".') % shelf_id)
69
trace.note('Changes shelved with id "%d".' % shelf_id)
72
71
def changes_destroyed(self):
73
72
"""Report that changes were made without shelving."""
74
trace.note(gettext('Selected changes destroyed.'))
73
trace.note('Selected changes destroyed.')
76
75
def selected_changes(self, transform):
77
76
"""Report the changes that were selected."""
78
trace.note(gettext("Selected changes:"))
77
trace.note("Selected changes:")
79
78
changes = transform.iter_changes()
80
79
delta.report_changes(changes, self.delta_reporter)
96
95
class ApplyReporter(ShelfReporter):
98
vocab = {'add file': gettext('Delete file "%(path)s"?'),
99
'binary': gettext('Apply binary changes?'),
100
'change kind': gettext('Change "%(path)s" from %(this)s'
102
'delete file': gettext('Add file "%(path)s"?'),
103
'final': gettext('Apply %d change(s)?'),
104
'hunk': gettext('Apply change?'),
105
'modify target': gettext('Change target of'
106
' "%(path)s" from "%(this)s" to "%(other)s"?'),
107
'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'
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"?',
110
109
invert_diff = True
252
251
diff_file.seek(0)
253
252
return patches.parse_patch(diff_file)
255
def _char_based(self):
256
# FIXME: A bit hackish to use INSIDE_EMACS here, but there is another
257
# work in progress moving this method (and more importantly prompt()
258
# below) into the ui area and address the issue in better ways.
260
return os.environ.get('INSIDE_EMACS', None) is None
262
254
def prompt(self, message):
263
255
"""Prompt the user for a character.
265
257
:param message: The message to prompt a user with.
266
258
:return: A character.
268
char_based = self._char_based()
269
if char_based and not sys.stdin.isatty():
270
# Since there is no controlling terminal we will hang when
271
# trying to prompt the user, better abort now. See
260
if not sys.stdin.isatty():
261
# Since there is no controlling terminal we will hang when trying
262
# to prompt the user, better abort now. See
272
263
# https://code.launchpad.net/~bialix/bzr/shelve-no-tty/+merge/14905
273
264
# for more context.
274
raise errors.BzrError(gettext("You need a controlling terminal."))
265
raise errors.BzrError("You need a controlling terminal.")
275
266
sys.stdout.write(message)
277
# We peek one char at a time which requires a real term here
278
char = osutils.getchar()
280
# While running tests (or under emacs) the input is line buffered
281
# so we must not use osutils.getchar(). Instead we switch to a mode
282
# where each line is terminated by a new line
283
line = sys.stdin.readline()
285
# XXX: Warn if more than one char is typed ?
288
# Empty input, callers handle it as enter
267
char = osutils.getchar()
290
268
sys.stdout.write("\r" + ' ' * len(message) + '\r')
291
269
sys.stdout.flush()
492
470
cleanups = [self.tree.unlock]
494
472
if self.read_shelf:
495
trace.note(gettext('Using changes with id "%d".') % self.shelf_id)
473
trace.note('Using changes with id "%d".' % self.shelf_id)
496
474
unshelver = self.manager.get_unshelver(self.shelf_id)
497
475
cleanups.append(unshelver.finalize)
498
476
if unshelver.message is not None:
499
trace.note(gettext('Message: %s') % unshelver.message)
477
trace.note('Message: %s' % unshelver.message)
500
478
change_reporter = delta._ChangeReporter()
501
479
merger = unshelver.make_merger(None)
502
480
merger.change_reporter = change_reporter
508
486
self.show_changes(merger)
509
487
if self.delete_shelf:
510
488
self.manager.delete_shelf(self.shelf_id)
511
trace.note(gettext('Deleted changes with id "%d".') % self.shelf_id)
489
trace.note('Deleted changes with id "%d".' % self.shelf_id)
513
491
for cleanup in reversed(cleanups):