##// END OF EJS Templates
dispatch: rename variables after code motion
Matt Mackall -
r4551:61e33f1d default
parent child Browse files
Show More
@@ -20,7 +20,7 b' class AmbiguousCommand(Exception):'
20 20 class ParseError(Exception):
21 21 """Exception raised on errors in parsing the command line."""
22 22
23 def runcatch(u, args):
23 def runcatch(ui, args):
24 24 def catchterm(*args):
25 25 raise util.SignalInterrupt
26 26
@@ -34,107 +34,107 b' def runcatch(u, args):'
34 34 if '--debugger' in args:
35 35 pdb.set_trace()
36 36 try:
37 return dispatch(u, args)
37 return dispatch(ui, args)
38 38 finally:
39 u.flush()
39 ui.flush()
40 40 except:
41 41 # enter the debugger when we hit an exception
42 42 if '--debugger' in args:
43 43 pdb.post_mortem(sys.exc_info()[2])
44 u.print_exc()
44 ui.print_exc()
45 45 raise
46 46
47 47 except ParseError, inst:
48 48 if inst.args[0]:
49 u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))
50 commands.help_(u, inst.args[0])
49 ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))
50 commands.help_(ui, inst.args[0])
51 51 else:
52 u.warn(_("hg: %s\n") % inst.args[1])
53 commands.help_(u, 'shortlist')
52 ui.warn(_("hg: %s\n") % inst.args[1])
53 commands.help_(ui, 'shortlist')
54 54 except AmbiguousCommand, inst:
55 u.warn(_("hg: command '%s' is ambiguous:\n %s\n") %
55 ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") %
56 56 (inst.args[0], " ".join(inst.args[1])))
57 57 except UnknownCommand, inst:
58 u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
59 commands.help_(u, 'shortlist')
58 ui.warn(_("hg: unknown command '%s'\n") % inst.args[0])
59 commands.help_(ui, 'shortlist')
60 60 except hg.RepoError, inst:
61 u.warn(_("abort: %s!\n") % inst)
61 ui.warn(_("abort: %s!\n") % inst)
62 62 except lock.LockHeld, inst:
63 63 if inst.errno == errno.ETIMEDOUT:
64 64 reason = _('timed out waiting for lock held by %s') % inst.locker
65 65 else:
66 66 reason = _('lock held by %s') % inst.locker
67 u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason))
67 ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason))
68 68 except lock.LockUnavailable, inst:
69 u.warn(_("abort: could not lock %s: %s\n") %
69 ui.warn(_("abort: could not lock %s: %s\n") %
70 70 (inst.desc or inst.filename, inst.strerror))
71 71 except revlog.RevlogError, inst:
72 u.warn(_("abort: %s!\n") % inst)
72 ui.warn(_("abort: %s!\n") % inst)
73 73 except util.SignalInterrupt:
74 u.warn(_("killed!\n"))
74 ui.warn(_("killed!\n"))
75 75 except KeyboardInterrupt:
76 76 try:
77 u.warn(_("interrupted!\n"))
77 ui.warn(_("interrupted!\n"))
78 78 except IOError, inst:
79 79 if inst.errno == errno.EPIPE:
80 if u.debugflag:
81 u.warn(_("\nbroken pipe\n"))
80 if ui.debugflag:
81 ui.warn(_("\nbroken pipe\n"))
82 82 else:
83 83 raise
84 84 except socket.error, inst:
85 u.warn(_("abort: %s\n") % inst[1])
85 ui.warn(_("abort: %s\n") % inst[1])
86 86 except IOError, inst:
87 87 if hasattr(inst, "code"):
88 u.warn(_("abort: %s\n") % inst)
88 ui.warn(_("abort: %s\n") % inst)
89 89 elif hasattr(inst, "reason"):
90 90 try: # usually it is in the form (errno, strerror)
91 91 reason = inst.reason.args[1]
92 92 except: # it might be anything, for example a string
93 93 reason = inst.reason
94 u.warn(_("abort: error: %s\n") % reason)
94 ui.warn(_("abort: error: %s\n") % reason)
95 95 elif hasattr(inst, "args") and inst[0] == errno.EPIPE:
96 if u.debugflag:
97 u.warn(_("broken pipe\n"))
96 if ui.debugflag:
97 ui.warn(_("broken pipe\n"))
98 98 elif getattr(inst, "strerror", None):
99 99 if getattr(inst, "filename", None):
100 u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
100 ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
101 101 else:
102 u.warn(_("abort: %s\n") % inst.strerror)
102 ui.warn(_("abort: %s\n") % inst.strerror)
103 103 else:
104 104 raise
105 105 except OSError, inst:
106 106 if getattr(inst, "filename", None):
107 u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
107 ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
108 108 else:
109 u.warn(_("abort: %s\n") % inst.strerror)
109 ui.warn(_("abort: %s\n") % inst.strerror)
110 110 except util.UnexpectedOutput, inst:
111 u.warn(_("abort: %s") % inst[0])
111 ui.warn(_("abort: %s") % inst[0])
112 112 if not isinstance(inst[1], basestring):
113 u.warn(" %r\n" % (inst[1],))
113 ui.warn(" %r\n" % (inst[1],))
114 114 elif not inst[1]:
115 u.warn(_(" empty string\n"))
115 ui.warn(_(" empty string\n"))
116 116 else:
117 u.warn("\n%r\n" % util.ellipsis(inst[1]))
117 ui.warn("\n%r\n" % util.ellipsis(inst[1]))
118 118 except util.Abort, inst:
119 u.warn(_("abort: %s\n") % inst)
119 ui.warn(_("abort: %s\n") % inst)
120 120 except TypeError, inst:
121 121 # was this an argument error?
122 122 tb = traceback.extract_tb(sys.exc_info()[2])
123 123 if len(tb) > 2: # no
124 124 raise
125 u.debug(inst, "\n")
126 u.warn(_("%s: invalid arguments\n") % cmd)
127 commands.help_(u, cmd)
125 ui.debug(inst, "\n")
126 ui.warn(_("%s: invalid arguments\n") % cmd)
127 commands.help_(ui, cmd)
128 128 except SystemExit, inst:
129 129 # Commands shouldn't sys.exit directly, but give a return code.
130 130 # Just in case catch this and and pass exit code to caller.
131 131 return inst.code
132 132 except:
133 u.warn(_("** unknown exception encountered, details follow\n"))
134 u.warn(_("** report bug details to "
133 ui.warn(_("** unknown exception encountered, details follow\n"))
134 ui.warn(_("** report bug details to "
135 135 "http://www.selenic.com/mercurial/bts\n"))
136 u.warn(_("** or mercurial@selenic.com\n"))
137 u.warn(_("** Mercurial Distributed SCM (version %s)\n")
136 ui.warn(_("** or mercurial@selenic.com\n"))
137 ui.warn(_("** Mercurial Distributed SCM (version %s)\n")
138 138 % version.get_version())
139 139 raise
140 140
@@ -238,11 +238,11 b' def parseconfig(config):'
238 238 raise util.Abort(_('malformed --config option: %s') % cfg)
239 239 return parsed
240 240
241 def dispatch(u, args):
242 extensions.loadall(u)
243 u.addreadhook(extensions.loadall)
241 def dispatch(ui, args):
242 extensions.loadall(ui)
243 ui.addreadhook(extensions.loadall)
244 244
245 cmd, func, args, options, cmdoptions = parse(u, args)
245 cmd, func, args, options, cmdoptions = parse(ui, args)
246 246
247 247 if options["encoding"]:
248 248 util._encoding = options["encoding"]
@@ -257,53 +257,53 b' def dispatch(u, args):'
257 257 s = get_times()
258 258 def print_time():
259 259 t = get_times()
260 u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") %
260 ui.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") %
261 261 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
262 262 atexit.register(print_time)
263 263
264 264 if options['cwd']:
265 265 os.chdir(options['cwd'])
266 266
267 u.updateopts(options["verbose"], options["debug"], options["quiet"],
267 ui.updateopts(options["verbose"], options["debug"], options["quiet"],
268 268 not options["noninteractive"], options["traceback"],
269 269 parseconfig(options["config"]))
270 270
271 path = u.expandpath(options["repository"]) or ""
272 repo = path and hg.repository(u, path=path) or None
271 path = ui.expandpath(options["repository"]) or ""
272 repo = path and hg.repository(ui, path=path) or None
273 273 if repo and not repo.local():
274 274 raise util.Abort(_("repository '%s' is not local") % path)
275 275
276 276 if options['help']:
277 return commands.help_(u, cmd, options['version'])
277 return commands.help_(ui, cmd, options['version'])
278 278 elif options['version']:
279 return commands.version_(u)
279 return commands.version_(ui)
280 280 elif not cmd:
281 return commands.help_(u, 'shortlist')
281 return commands.help_(ui, 'shortlist')
282 282
283 283 if cmd not in commands.norepo.split():
284 284 try:
285 285 if not repo:
286 repo = hg.repository(u, path=path)
287 u = repo.ui
286 repo = hg.repository(ui, path=path)
287 ui = repo.ui
288 288 except hg.RepoError:
289 289 if cmd not in commands.optionalrepo.split():
290 290 raise
291 d = lambda: func(u, repo, *args, **cmdoptions)
291 d = lambda: func(ui, repo, *args, **cmdoptions)
292 292 else:
293 d = lambda: func(u, *args, **cmdoptions)
293 d = lambda: func(ui, *args, **cmdoptions)
294 294
295 return runcommand(u, options, d)
295 return runcommand(ui, options, d)
296 296
297 def runcommand(u, options, d):
297 def runcommand(ui, options, cmdfunc):
298 298 if options['profile']:
299 299 import hotshot, hotshot.stats
300 300 prof = hotshot.Profile("hg.prof")
301 301 try:
302 302 try:
303 return prof.runcall(d)
303 return prof.runcall(cmdfunc)
304 304 except:
305 305 try:
306 u.warn(_('exception raised - generating '
306 ui.warn(_('exception raised - generating '
307 307 'profile anyway\n'))
308 308 except:
309 309 pass
@@ -324,14 +324,14 b' def runcommand(u, options, d):'
324 324 p = lsprof.Profiler()
325 325 p.enable(subcalls=True)
326 326 try:
327 return d()
327 return cmdfunc()
328 328 finally:
329 329 p.disable()
330 330 stats = lsprof.Stats(p.getstats())
331 331 stats.sort()
332 332 stats.pprint(top=10, file=sys.stderr, climit=5)
333 333 else:
334 return d()
334 return cmdfunc()
335 335
336 336 def bail_if_changed(repo):
337 337 modified, added, removed, deleted = repo.status()[:4]
General Comments 0
You need to be logged in to leave comments. Login now