Show More
@@ -62,6 +62,7 b' from . import (' | |||||
62 | extensions, |
|
62 | extensions, | |
63 | node, |
|
63 | node, | |
64 | pycompat, |
|
64 | pycompat, | |
|
65 | scmutil, | |||
65 | util, |
|
66 | util, | |
66 | ) |
|
67 | ) | |
67 |
|
68 | |||
@@ -503,13 +504,11 b' class chgcmdserver(commandserver.server)' | |||||
503 | list, the client can continue with this server after completing all |
|
504 | list, the client can continue with this server after completing all | |
504 | the instructions. |
|
505 | the instructions. | |
505 | """ |
|
506 | """ | |
506 | from . import dispatch # avoid cycle |
|
|||
507 |
|
||||
508 | args = self._readlist() |
|
507 | args = self._readlist() | |
509 | try: |
|
508 | try: | |
510 | self.ui, lui = _loadnewui(self.ui, args, self.cdebug) |
|
509 | self.ui, lui = _loadnewui(self.ui, args, self.cdebug) | |
511 | except error.ParseError as inst: |
|
510 | except error.ParseError as inst: | |
512 |
|
|
511 | scmutil.formatparse(self.ui.warn, inst) | |
513 | self.ui.flush() |
|
512 | self.ui.flush() | |
514 | self.cresult.write(b'exit 255') |
|
513 | self.cresult.write(b'exit 255') | |
515 | return |
|
514 | return |
@@ -7,7 +7,6 b'' | |||||
7 |
|
7 | |||
8 | from __future__ import absolute_import, print_function |
|
8 | from __future__ import absolute_import, print_function | |
9 |
|
9 | |||
10 | import difflib |
|
|||
11 | import errno |
|
10 | import errno | |
12 | import getopt |
|
11 | import getopt | |
13 | import io |
|
12 | import io | |
@@ -226,38 +225,6 b' else:' | |||||
226 | pass |
|
225 | pass | |
227 |
|
226 | |||
228 |
|
227 | |||
229 | def _getsimilar(symbols, value): |
|
|||
230 | sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio() |
|
|||
231 | # The cutoff for similarity here is pretty arbitrary. It should |
|
|||
232 | # probably be investigated and tweaked. |
|
|||
233 | return [s for s in symbols if sim(s) > 0.6] |
|
|||
234 |
|
||||
235 |
|
||||
236 | def _reportsimilar(write, similar): |
|
|||
237 | if len(similar) == 1: |
|
|||
238 | write(_(b"(did you mean %s?)\n") % similar[0]) |
|
|||
239 | elif similar: |
|
|||
240 | ss = b", ".join(sorted(similar)) |
|
|||
241 | write(_(b"(did you mean one of %s?)\n") % ss) |
|
|||
242 |
|
||||
243 |
|
||||
244 | def _formatparse(write, inst): |
|
|||
245 | similar = [] |
|
|||
246 | if isinstance(inst, error.UnknownIdentifier): |
|
|||
247 | # make sure to check fileset first, as revset can invoke fileset |
|
|||
248 | similar = _getsimilar(inst.symbols, inst.function) |
|
|||
249 | if inst.location is not None: |
|
|||
250 | write( |
|
|||
251 | _(b"hg: parse error at %s: %s\n") |
|
|||
252 | % (pycompat.bytestr(inst.location), inst.message) |
|
|||
253 | ) |
|
|||
254 | else: |
|
|||
255 | write(_(b"hg: parse error: %s\n") % inst.message) |
|
|||
256 | _reportsimilar(write, similar) |
|
|||
257 | if inst.hint: |
|
|||
258 | write(_(b"(%s)\n") % inst.hint) |
|
|||
259 |
|
||||
260 |
|
||||
261 | def _formatargs(args): |
|
228 | def _formatargs(args): | |
262 | return b' '.join(procutil.shellquote(a) for a in args) |
|
229 | return b' '.join(procutil.shellquote(a) for a in args) | |
263 |
|
230 | |||
@@ -294,7 +261,7 b' def dispatch(req):' | |||||
294 | ferr.write(_(b"(%s)\n") % inst.hint) |
|
261 | ferr.write(_(b"(%s)\n") % inst.hint) | |
295 | return -1 |
|
262 | return -1 | |
296 | except error.ParseError as inst: |
|
263 | except error.ParseError as inst: | |
297 |
|
|
264 | scmutil.formatparse(ferr.write, inst) | |
298 | return -1 |
|
265 | return -1 | |
299 |
|
266 | |||
300 | msg = _formatargs(req.args) |
|
267 | msg = _formatargs(req.args) | |
@@ -502,7 +469,7 b' def _callcatch(ui, func):' | |||||
502 | ui.warn(_(b"hg: %s\n") % inst.message) |
|
469 | ui.warn(_(b"hg: %s\n") % inst.message) | |
503 | ui.warn(_(b"(use 'hg help -v' for a list of global options)\n")) |
|
470 | ui.warn(_(b"(use 'hg help -v' for a list of global options)\n")) | |
504 | except error.ParseError as inst: |
|
471 | except error.ParseError as inst: | |
505 |
|
|
472 | scmutil.formatparse(ui.warn, inst) | |
506 | return -1 |
|
473 | return -1 | |
507 | except error.UnknownCommand as inst: |
|
474 | except error.UnknownCommand as inst: | |
508 | nocmdmsg = _(b"hg: unknown command '%s'\n") % inst.command |
|
475 | nocmdmsg = _(b"hg: unknown command '%s'\n") % inst.command | |
@@ -517,10 +484,10 b' def _callcatch(ui, func):' | |||||
517 | except (error.UnknownCommand, error.Abort): |
|
484 | except (error.UnknownCommand, error.Abort): | |
518 | suggested = False |
|
485 | suggested = False | |
519 | if inst.all_commands: |
|
486 | if inst.all_commands: | |
520 |
sim = |
|
487 | sim = scmutil.getsimilar(inst.all_commands, inst.command) | |
521 | if sim: |
|
488 | if sim: | |
522 | ui.warn(nocmdmsg) |
|
489 | ui.warn(nocmdmsg) | |
523 |
|
|
490 | scmutil.reportsimilar(ui.warn, sim) | |
524 | suggested = True |
|
491 | suggested = True | |
525 | if not suggested: |
|
492 | if not suggested: | |
526 | ui.warn(nocmdmsg) |
|
493 | ui.warn(nocmdmsg) |
@@ -7,6 +7,7 b'' | |||||
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
|
10 | import difflib | |||
10 | import errno |
|
11 | import errno | |
11 | import glob |
|
12 | import glob | |
12 | import os |
|
13 | import os | |
@@ -142,6 +143,38 b' def nochangesfound(ui, repo, excluded=No' | |||||
142 | ui.status(_(b"no changes found\n")) |
|
143 | ui.status(_(b"no changes found\n")) | |
143 |
|
144 | |||
144 |
|
145 | |||
|
146 | def getsimilar(symbols, value): | |||
|
147 | sim = lambda x: difflib.SequenceMatcher(None, value, x).ratio() | |||
|
148 | # The cutoff for similarity here is pretty arbitrary. It should | |||
|
149 | # probably be investigated and tweaked. | |||
|
150 | return [s for s in symbols if sim(s) > 0.6] | |||
|
151 | ||||
|
152 | ||||
|
153 | def reportsimilar(write, similar): | |||
|
154 | if len(similar) == 1: | |||
|
155 | write(_(b"(did you mean %s?)\n") % similar[0]) | |||
|
156 | elif similar: | |||
|
157 | ss = b", ".join(sorted(similar)) | |||
|
158 | write(_(b"(did you mean one of %s?)\n") % ss) | |||
|
159 | ||||
|
160 | ||||
|
161 | def formatparse(write, inst): | |||
|
162 | similar = [] | |||
|
163 | if isinstance(inst, error.UnknownIdentifier): | |||
|
164 | # make sure to check fileset first, as revset can invoke fileset | |||
|
165 | similar = getsimilar(inst.symbols, inst.function) | |||
|
166 | if inst.location is not None: | |||
|
167 | write( | |||
|
168 | _(b"hg: parse error at %s: %s\n") | |||
|
169 | % (pycompat.bytestr(inst.location), inst.message) | |||
|
170 | ) | |||
|
171 | else: | |||
|
172 | write(_(b"hg: parse error: %s\n") % inst.message) | |||
|
173 | reportsimilar(write, similar) | |||
|
174 | if inst.hint: | |||
|
175 | write(_(b"(%s)\n") % inst.hint) | |||
|
176 | ||||
|
177 | ||||
145 | def callcatch(ui, func): |
|
178 | def callcatch(ui, func): | |
146 | """call func() with global exception handling |
|
179 | """call func() with global exception handling | |
147 |
|
180 |
General Comments 0
You need to be logged in to leave comments.
Login now