Show More
@@ -62,6 +62,7 b' from . import (' | |||
|
62 | 62 | extensions, |
|
63 | 63 | node, |
|
64 | 64 | pycompat, |
|
65 | scmutil, | |
|
65 | 66 | util, |
|
66 | 67 | ) |
|
67 | 68 | |
@@ -503,13 +504,11 b' class chgcmdserver(commandserver.server)' | |||
|
503 | 504 | list, the client can continue with this server after completing all |
|
504 | 505 | the instructions. |
|
505 | 506 | """ |
|
506 | from . import dispatch # avoid cycle | |
|
507 | ||
|
508 | 507 | args = self._readlist() |
|
509 | 508 | try: |
|
510 | 509 | self.ui, lui = _loadnewui(self.ui, args, self.cdebug) |
|
511 | 510 | except error.ParseError as inst: |
|
512 |
|
|
|
511 | scmutil.formatparse(self.ui.warn, inst) | |
|
513 | 512 | self.ui.flush() |
|
514 | 513 | self.cresult.write(b'exit 255') |
|
515 | 514 | return |
@@ -7,7 +7,6 b'' | |||
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import, print_function |
|
9 | 9 | |
|
10 | import difflib | |
|
11 | 10 | import errno |
|
12 | 11 | import getopt |
|
13 | 12 | import io |
@@ -226,38 +225,6 b' else:' | |||
|
226 | 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 | 228 | def _formatargs(args): |
|
262 | 229 | return b' '.join(procutil.shellquote(a) for a in args) |
|
263 | 230 | |
@@ -294,7 +261,7 b' def dispatch(req):' | |||
|
294 | 261 | ferr.write(_(b"(%s)\n") % inst.hint) |
|
295 | 262 | return -1 |
|
296 | 263 | except error.ParseError as inst: |
|
297 |
|
|
|
264 | scmutil.formatparse(ferr.write, inst) | |
|
298 | 265 | return -1 |
|
299 | 266 | |
|
300 | 267 | msg = _formatargs(req.args) |
@@ -502,7 +469,7 b' def _callcatch(ui, func):' | |||
|
502 | 469 | ui.warn(_(b"hg: %s\n") % inst.message) |
|
503 | 470 | ui.warn(_(b"(use 'hg help -v' for a list of global options)\n")) |
|
504 | 471 | except error.ParseError as inst: |
|
505 |
|
|
|
472 | scmutil.formatparse(ui.warn, inst) | |
|
506 | 473 | return -1 |
|
507 | 474 | except error.UnknownCommand as inst: |
|
508 | 475 | nocmdmsg = _(b"hg: unknown command '%s'\n") % inst.command |
@@ -517,10 +484,10 b' def _callcatch(ui, func):' | |||
|
517 | 484 | except (error.UnknownCommand, error.Abort): |
|
518 | 485 | suggested = False |
|
519 | 486 | if inst.all_commands: |
|
520 |
sim = |
|
|
487 | sim = scmutil.getsimilar(inst.all_commands, inst.command) | |
|
521 | 488 | if sim: |
|
522 | 489 | ui.warn(nocmdmsg) |
|
523 |
|
|
|
490 | scmutil.reportsimilar(ui.warn, sim) | |
|
524 | 491 | suggested = True |
|
525 | 492 | if not suggested: |
|
526 | 493 | ui.warn(nocmdmsg) |
@@ -7,6 +7,7 b'' | |||
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | import difflib | |
|
10 | 11 | import errno |
|
11 | 12 | import glob |
|
12 | 13 | import os |
@@ -142,6 +143,38 b' def nochangesfound(ui, repo, excluded=No' | |||
|
142 | 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 | 178 | def callcatch(ui, func): |
|
146 | 179 | """call func() with global exception handling |
|
147 | 180 |
General Comments 0
You need to be logged in to leave comments.
Login now