comparison mercurial/patch.py @ 34042:c0170d88ed2b

patch: take messages out of the function so that extensions can add entries Extensions will want to have interactive thing for more operations or particulary want to show more verbs. So this patch takes out the message thing from the function so that extensions can add verbs to this. The curses one is also not in any function so extensions can add more actions and verbs there. Differential Revision: https://phab.mercurial-scm.org/D567
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 30 Aug 2017 18:19:14 +0530
parents da07367d683b
children 871a58b5f428
comparison
equal deleted inserted replaced
34041:40313c63da87 34042:c0170d88ed2b
994 return self.header.filename() 994 return self.header.filename()
995 995
996 def __repr__(self): 996 def __repr__(self):
997 return '<hunk %r@%d>' % (self.filename(), self.fromline) 997 return '<hunk %r@%d>' % (self.filename(), self.fromline)
998 998
999 messages = {
1000 'multiple': {
1001 'discard': _("discard change %d/%d to '%s'?"),
1002 'record': _("record change %d/%d to '%s'?"),
1003 'revert': _("revert change %d/%d to '%s'?"),
1004 },
1005 'single': {
1006 'discard': _("discard this change to '%s'?"),
1007 'record': _("record this change to '%s'?"),
1008 'revert': _("revert this change to '%s'?"),
1009 },
1010 'help': {
1011 'discard': _('[Ynesfdaq?]'
1012 '$$ &Yes, discard this change'
1013 '$$ &No, skip this change'
1014 '$$ &Edit this change manually'
1015 '$$ &Skip remaining changes to this file'
1016 '$$ Discard remaining changes to this &file'
1017 '$$ &Done, skip remaining changes and files'
1018 '$$ Discard &all changes to all remaining files'
1019 '$$ &Quit, discarding no changes'
1020 '$$ &? (display help)'),
1021 'record': _('[Ynesfdaq?]'
1022 '$$ &Yes, record this change'
1023 '$$ &No, skip this change'
1024 '$$ &Edit this change manually'
1025 '$$ &Skip remaining changes to this file'
1026 '$$ Record remaining changes to this &file'
1027 '$$ &Done, skip remaining changes and files'
1028 '$$ Record &all changes to all remaining files'
1029 '$$ &Quit, recording no changes'
1030 '$$ &? (display help)'),
1031 'revert': _('[Ynesfdaq?]'
1032 '$$ &Yes, revert this change'
1033 '$$ &No, skip this change'
1034 '$$ &Edit this change manually'
1035 '$$ &Skip remaining changes to this file'
1036 '$$ Revert remaining changes to this &file'
1037 '$$ &Done, skip remaining changes and files'
1038 '$$ Revert &all changes to all remaining files'
1039 '$$ &Quit, reverting no changes'
1040 '$$ &? (display help)')
1041 }
1042 }
1043
999 def filterpatch(ui, headers, operation=None): 1044 def filterpatch(ui, headers, operation=None):
1000 """Interactively filter patch chunks into applied-only chunks""" 1045 """Interactively filter patch chunks into applied-only chunks"""
1001 if operation is None: 1046 if operation is None:
1002 operation = 'record' 1047 operation = 'record'
1003 messages = {
1004 'multiple': {
1005 'discard': _("discard change %d/%d to '%s'?"),
1006 'record': _("record change %d/%d to '%s'?"),
1007 'revert': _("revert change %d/%d to '%s'?"),
1008 }[operation],
1009 'single': {
1010 'discard': _("discard this change to '%s'?"),
1011 'record': _("record this change to '%s'?"),
1012 'revert': _("revert this change to '%s'?"),
1013 }[operation],
1014 'help': {
1015 'discard': _('[Ynesfdaq?]'
1016 '$$ &Yes, discard this change'
1017 '$$ &No, skip this change'
1018 '$$ &Edit this change manually'
1019 '$$ &Skip remaining changes to this file'
1020 '$$ Discard remaining changes to this &file'
1021 '$$ &Done, skip remaining changes and files'
1022 '$$ Discard &all changes to all remaining files'
1023 '$$ &Quit, discarding no changes'
1024 '$$ &? (display help)'),
1025 'record': _('[Ynesfdaq?]'
1026 '$$ &Yes, record this change'
1027 '$$ &No, skip this change'
1028 '$$ &Edit this change manually'
1029 '$$ &Skip remaining changes to this file'
1030 '$$ Record remaining changes to this &file'
1031 '$$ &Done, skip remaining changes and files'
1032 '$$ Record &all changes to all remaining files'
1033 '$$ &Quit, recording no changes'
1034 '$$ &? (display help)'),
1035 'revert': _('[Ynesfdaq?]'
1036 '$$ &Yes, revert this change'
1037 '$$ &No, skip this change'
1038 '$$ &Edit this change manually'
1039 '$$ &Skip remaining changes to this file'
1040 '$$ Revert remaining changes to this &file'
1041 '$$ &Done, skip remaining changes and files'
1042 '$$ Revert &all changes to all remaining files'
1043 '$$ &Quit, reverting no changes'
1044 '$$ &? (display help)')
1045 }[operation]
1046 }
1047 1048
1048 def prompt(skipfile, skipall, query, chunk): 1049 def prompt(skipfile, skipall, query, chunk):
1049 """prompt query, and process base inputs 1050 """prompt query, and process base inputs
1050 1051
1051 - y/n for the rest of file 1052 - y/n for the rest of file
1059 if skipall is not None: 1060 if skipall is not None:
1060 return skipall, skipfile, skipall, newpatches 1061 return skipall, skipfile, skipall, newpatches
1061 if skipfile is not None: 1062 if skipfile is not None:
1062 return skipfile, skipfile, skipall, newpatches 1063 return skipfile, skipfile, skipall, newpatches
1063 while True: 1064 while True:
1064 resps = messages['help'] 1065 resps = messages['help'][operation]
1065 r = ui.promptchoice("%s %s" % (query, resps)) 1066 r = ui.promptchoice("%s %s" % (query, resps))
1066 ui.write("\n") 1067 ui.write("\n")
1067 if r == 8: # ? 1068 if r == 8: # ?
1068 for c, t in ui.extractchoices(resps)[1]: 1069 for c, t in ui.extractchoices(resps)[1]:
1069 ui.write('%s - %s\n' % (c, encoding.lower(t))) 1070 ui.write('%s - %s\n' % (c, encoding.lower(t)))
1164 continue 1165 continue
1165 for i, chunk in enumerate(h.hunks): 1166 for i, chunk in enumerate(h.hunks):
1166 if skipfile is None and skipall is None: 1167 if skipfile is None and skipall is None:
1167 chunk.pretty(ui) 1168 chunk.pretty(ui)
1168 if total == 1: 1169 if total == 1:
1169 msg = messages['single'] % chunk.filename() 1170 msg = messages['single'][operation] % chunk.filename()
1170 else: 1171 else:
1171 idx = pos - len(h.hunks) + i 1172 idx = pos - len(h.hunks) + i
1172 msg = messages['multiple'] % (idx, total, chunk.filename()) 1173 msg = messages['multiple'][operation] % (idx, total,
1174 chunk.filename())
1173 r, skipfile, skipall, newpatches = prompt(skipfile, 1175 r, skipfile, skipall, newpatches = prompt(skipfile,
1174 skipall, msg, chunk) 1176 skipall, msg, chunk)
1175 if r: 1177 if r:
1176 if fixoffset: 1178 if fixoffset:
1177 chunk = copy.copy(chunk) 1179 chunk = copy.copy(chunk)