Show More
@@ -1,499 +1,500 b'' | |||
|
1 | 1 | # dispatch.py - command dispatching for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | from i18n import _ |
|
9 | 9 | import os, sys, atexit, signal, pdb, socket, errno, shlex, time |
|
10 | 10 | import util, commands, hg, fancyopts, extensions, hook, error |
|
11 | 11 | import cmdutil, encoding |
|
12 | 12 | import ui as _ui |
|
13 | 13 | |
|
14 | 14 | def run(): |
|
15 | 15 | "run the command in sys.argv" |
|
16 | 16 | sys.exit(dispatch(sys.argv[1:])) |
|
17 | 17 | |
|
18 | 18 | def dispatch(args): |
|
19 | 19 | "run the command specified in args" |
|
20 | 20 | try: |
|
21 | 21 | u = _ui.ui() |
|
22 | 22 | if '--traceback' in args: |
|
23 | 23 | u.setconfig('ui', 'traceback', 'on') |
|
24 | 24 | except util.Abort, inst: |
|
25 | 25 | sys.stderr.write(_("abort: %s\n") % inst) |
|
26 | 26 | return -1 |
|
27 | 27 | except error.ConfigError, inst: |
|
28 | 28 | sys.stderr.write(_("hg: %s\n") % inst) |
|
29 | 29 | return -1 |
|
30 | 30 | return _runcatch(u, args) |
|
31 | 31 | |
|
32 | 32 | def _runcatch(ui, args): |
|
33 | 33 | def catchterm(*args): |
|
34 | 34 | raise error.SignalInterrupt |
|
35 | 35 | |
|
36 | 36 | for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': |
|
37 | 37 | num = getattr(signal, name, None) |
|
38 | 38 | if num: signal.signal(num, catchterm) |
|
39 | 39 | |
|
40 | 40 | try: |
|
41 | 41 | try: |
|
42 | 42 | # enter the debugger before command execution |
|
43 | 43 | if '--debugger' in args: |
|
44 | 44 | pdb.set_trace() |
|
45 | 45 | try: |
|
46 | 46 | return _dispatch(ui, args) |
|
47 | 47 | finally: |
|
48 | 48 | ui.flush() |
|
49 | 49 | except: |
|
50 | 50 | # enter the debugger when we hit an exception |
|
51 | 51 | if '--debugger' in args: |
|
52 | 52 | pdb.post_mortem(sys.exc_info()[2]) |
|
53 | 53 | ui.traceback() |
|
54 | 54 | raise |
|
55 | 55 | |
|
56 | 56 | # Global exception handling, alphabetically |
|
57 | 57 | # Mercurial-specific first, followed by built-in and library exceptions |
|
58 | 58 | except error.AmbiguousCommand, inst: |
|
59 | 59 | ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
|
60 | 60 | (inst.args[0], " ".join(inst.args[1]))) |
|
61 | 61 | except error.ConfigError, inst: |
|
62 | 62 | ui.warn(_("hg: %s\n") % inst.args[0]) |
|
63 | 63 | except error.LockHeld, inst: |
|
64 | 64 | if inst.errno == errno.ETIMEDOUT: |
|
65 | 65 | reason = _('timed out waiting for lock held by %s') % inst.locker |
|
66 | 66 | else: |
|
67 | 67 | reason = _('lock held by %s') % inst.locker |
|
68 | 68 | ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) |
|
69 | 69 | except error.LockUnavailable, inst: |
|
70 | 70 | ui.warn(_("abort: could not lock %s: %s\n") % |
|
71 | 71 | (inst.desc or inst.filename, inst.strerror)) |
|
72 | 72 | except error.ParseError, inst: |
|
73 | 73 | if inst.args[0]: |
|
74 | 74 | ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
|
75 | 75 | commands.help_(ui, inst.args[0]) |
|
76 | 76 | else: |
|
77 | 77 | ui.warn(_("hg: %s\n") % inst.args[1]) |
|
78 | 78 | commands.help_(ui, 'shortlist') |
|
79 | 79 | except error.RepoError, inst: |
|
80 | 80 | ui.warn(_("abort: %s!\n") % inst) |
|
81 | 81 | except error.ResponseError, inst: |
|
82 | 82 | ui.warn(_("abort: %s") % inst.args[0]) |
|
83 | 83 | if not isinstance(inst.args[1], basestring): |
|
84 | 84 | ui.warn(" %r\n" % (inst.args[1],)) |
|
85 | 85 | elif not inst.args[1]: |
|
86 | 86 | ui.warn(_(" empty string\n")) |
|
87 | 87 | else: |
|
88 | 88 | ui.warn("\n%r\n" % util.ellipsis(inst.args[1])) |
|
89 | 89 | except error.RevlogError, inst: |
|
90 | 90 | ui.warn(_("abort: %s!\n") % inst) |
|
91 | 91 | except error.SignalInterrupt: |
|
92 | 92 | ui.warn(_("killed!\n")) |
|
93 | 93 | except error.UnknownCommand, inst: |
|
94 | 94 | ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
|
95 | 95 | commands.help_(ui, 'shortlist') |
|
96 | 96 | except util.Abort, inst: |
|
97 | 97 | ui.warn(_("abort: %s\n") % inst) |
|
98 | 98 | except ImportError, inst: |
|
99 | 99 | m = str(inst).split()[-1] |
|
100 | 100 | ui.warn(_("abort: could not import module %s!\n") % m) |
|
101 | 101 | if m in "mpatch bdiff".split(): |
|
102 | 102 | ui.warn(_("(did you forget to compile extensions?)\n")) |
|
103 | 103 | elif m in "zlib".split(): |
|
104 | 104 | ui.warn(_("(is your Python install correct?)\n")) |
|
105 | 105 | except IOError, inst: |
|
106 | 106 | if hasattr(inst, "code"): |
|
107 | 107 | ui.warn(_("abort: %s\n") % inst) |
|
108 | 108 | elif hasattr(inst, "reason"): |
|
109 | 109 | try: # usually it is in the form (errno, strerror) |
|
110 | 110 | reason = inst.reason.args[1] |
|
111 | 111 | except: # it might be anything, for example a string |
|
112 | 112 | reason = inst.reason |
|
113 | 113 | ui.warn(_("abort: error: %s\n") % reason) |
|
114 | 114 | elif hasattr(inst, "args") and inst.args[0] == errno.EPIPE: |
|
115 | 115 | if ui.debugflag: |
|
116 | 116 | ui.warn(_("broken pipe\n")) |
|
117 | 117 | elif getattr(inst, "strerror", None): |
|
118 | 118 | if getattr(inst, "filename", None): |
|
119 | 119 | ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
|
120 | 120 | else: |
|
121 | 121 | ui.warn(_("abort: %s\n") % inst.strerror) |
|
122 | 122 | else: |
|
123 | 123 | raise |
|
124 | 124 | except OSError, inst: |
|
125 | 125 | if getattr(inst, "filename", None): |
|
126 | 126 | ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
|
127 | 127 | else: |
|
128 | 128 | ui.warn(_("abort: %s\n") % inst.strerror) |
|
129 | 129 | except KeyboardInterrupt: |
|
130 | 130 | try: |
|
131 | 131 | ui.warn(_("interrupted!\n")) |
|
132 | 132 | except IOError, inst: |
|
133 | 133 | if inst.errno == errno.EPIPE: |
|
134 | 134 | if ui.debugflag: |
|
135 | 135 | ui.warn(_("\nbroken pipe\n")) |
|
136 | 136 | else: |
|
137 | 137 | raise |
|
138 | 138 | except MemoryError: |
|
139 | 139 | ui.warn(_("abort: out of memory\n")) |
|
140 | 140 | except SystemExit, inst: |
|
141 | 141 | # Commands shouldn't sys.exit directly, but give a return code. |
|
142 | 142 | # Just in case catch this and and pass exit code to caller. |
|
143 | 143 | return inst.code |
|
144 | 144 | except socket.error, inst: |
|
145 | 145 | ui.warn(_("abort: %s\n") % inst.args[-1]) |
|
146 | 146 | except: |
|
147 | 147 | ui.warn(_("** unknown exception encountered, details follow\n")) |
|
148 | 148 | ui.warn(_("** report bug details to " |
|
149 | 149 | "http://mercurial.selenic.com/bts/\n")) |
|
150 | 150 | ui.warn(_("** or mercurial@selenic.com\n")) |
|
151 | 151 | ui.warn(_("** Mercurial Distributed SCM (version %s)\n") |
|
152 | 152 | % util.version()) |
|
153 | 153 | ui.warn(_("** Extensions loaded: %s\n") |
|
154 | 154 | % ", ".join([x[0] for x in extensions.extensions()])) |
|
155 | 155 | raise |
|
156 | 156 | |
|
157 | 157 | return -1 |
|
158 | 158 | |
|
159 | 159 | def _findrepo(p): |
|
160 | 160 | while not os.path.isdir(os.path.join(p, ".hg")): |
|
161 | 161 | oldp, p = p, os.path.dirname(p) |
|
162 | 162 | if p == oldp: |
|
163 | 163 | return None |
|
164 | 164 | |
|
165 | 165 | return p |
|
166 | 166 | |
|
167 | 167 | def aliasargs(fn): |
|
168 | 168 | if hasattr(fn, 'args'): |
|
169 | 169 | return fn.args |
|
170 | 170 | return [] |
|
171 | 171 | |
|
172 | 172 | class cmdalias(object): |
|
173 | 173 | def __init__(self, name, definition, cmdtable): |
|
174 | 174 | self.name = name |
|
175 | 175 | self.definition = definition |
|
176 | 176 | self.args = [] |
|
177 | 177 | self.opts = [] |
|
178 | 178 | self.help = '' |
|
179 | 179 | self.norepo = True |
|
180 | 180 | |
|
181 | 181 | try: |
|
182 | 182 | cmdutil.findcmd(self.name, cmdtable, True) |
|
183 | 183 | self.shadows = True |
|
184 | 184 | except error.UnknownCommand: |
|
185 | 185 | self.shadows = False |
|
186 | 186 | |
|
187 | 187 | if not self.definition: |
|
188 | 188 | def fn(ui, *args): |
|
189 | 189 | ui.warn(_("no definition for alias '%s'\n") % self.name) |
|
190 | 190 | return 1 |
|
191 | 191 | self.fn = fn |
|
192 | 192 | |
|
193 | 193 | return |
|
194 | 194 | |
|
195 | 195 | args = shlex.split(self.definition) |
|
196 | 196 | cmd = args.pop(0) |
|
197 | 197 | |
|
198 | 198 | try: |
|
199 | 199 | self.fn, self.opts, self.help = cmdutil.findcmd(cmd, cmdtable, False)[1] |
|
200 | 200 | self.args = aliasargs(self.fn) + args |
|
201 | 201 | if cmd not in commands.norepo.split(' '): |
|
202 | 202 | self.norepo = False |
|
203 | 203 | except error.UnknownCommand: |
|
204 | 204 | def fn(ui, *args): |
|
205 | 205 | ui.warn(_("alias '%s' resolves to unknown command '%s'\n") \ |
|
206 | 206 | % (self.name, cmd)) |
|
207 | 207 | return 1 |
|
208 | 208 | self.fn = fn |
|
209 | 209 | except error.AmbiguousCommand: |
|
210 | 210 | def fn(ui, *args): |
|
211 | 211 | ui.warn(_("alias '%s' resolves to ambiguous command '%s'\n") \ |
|
212 | 212 | % (self.name, cmd)) |
|
213 | 213 | return 1 |
|
214 | 214 | self.fn = fn |
|
215 | 215 | |
|
216 | 216 | def __call__(self, ui, *args, **opts): |
|
217 | 217 | if self.shadows: |
|
218 | 218 | ui.debug("alias '%s' shadows command\n" % self.name) |
|
219 | 219 | |
|
220 | 220 | return self.fn(ui, *args, **opts) |
|
221 | 221 | |
|
222 | 222 | def addaliases(ui, cmdtable): |
|
223 | 223 | # aliases are processed after extensions have been loaded, so they |
|
224 | 224 | # may use extension commands. Aliases can also use other alias definitions, |
|
225 | 225 | # but only if they have been defined prior to the current definition. |
|
226 | 226 | for alias, definition in ui.configitems('alias'): |
|
227 | 227 | aliasdef = cmdalias(alias, definition, cmdtable) |
|
228 | 228 | cmdtable[alias] = (aliasdef, aliasdef.opts, aliasdef.help) |
|
229 | 229 | if aliasdef.norepo: |
|
230 | 230 | commands.norepo += ' %s' % alias |
|
231 | 231 | |
|
232 | 232 | def _parse(ui, args): |
|
233 | 233 | options = {} |
|
234 | 234 | cmdoptions = {} |
|
235 | 235 | |
|
236 | 236 | try: |
|
237 | 237 | args = fancyopts.fancyopts(args, commands.globalopts, options) |
|
238 | 238 | except fancyopts.getopt.GetoptError, inst: |
|
239 | 239 | raise error.ParseError(None, inst) |
|
240 | 240 | |
|
241 | 241 | if args: |
|
242 | 242 | cmd, args = args[0], args[1:] |
|
243 | 243 | aliases, i = cmdutil.findcmd(cmd, commands.table, |
|
244 | 244 | ui.config("ui", "strict")) |
|
245 | 245 | cmd = aliases[0] |
|
246 | 246 | args = aliasargs(i[0]) + args |
|
247 | 247 | defaults = ui.config("defaults", cmd) |
|
248 | 248 | if defaults: |
|
249 | 249 | args = map(util.expandpath, shlex.split(defaults)) + args |
|
250 | 250 | c = list(i[1]) |
|
251 | 251 | else: |
|
252 | 252 | cmd = None |
|
253 | 253 | c = [] |
|
254 | 254 | |
|
255 | 255 | # combine global options into local |
|
256 | 256 | for o in commands.globalopts: |
|
257 | 257 | c.append((o[0], o[1], options[o[1]], o[3])) |
|
258 | 258 | |
|
259 | 259 | try: |
|
260 | 260 | args = fancyopts.fancyopts(args, c, cmdoptions, True) |
|
261 | 261 | except fancyopts.getopt.GetoptError, inst: |
|
262 | 262 | raise error.ParseError(cmd, inst) |
|
263 | 263 | |
|
264 | 264 | # separate global options back out |
|
265 | 265 | for o in commands.globalopts: |
|
266 | 266 | n = o[1] |
|
267 | 267 | options[n] = cmdoptions[n] |
|
268 | 268 | del cmdoptions[n] |
|
269 | 269 | |
|
270 | 270 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) |
|
271 | 271 | |
|
272 | 272 | def _parseconfig(ui, config): |
|
273 | 273 | """parse the --config options from the command line""" |
|
274 | 274 | for cfg in config: |
|
275 | 275 | try: |
|
276 | 276 | name, value = cfg.split('=', 1) |
|
277 | 277 | section, name = name.split('.', 1) |
|
278 | 278 | if not section or not name: |
|
279 | 279 | raise IndexError |
|
280 | 280 | ui.setconfig(section, name, value) |
|
281 | 281 | except (IndexError, ValueError): |
|
282 |
raise util.Abort(_('malformed --config option: % |
|
|
282 | raise util.Abort(_('malformed --config option: %r ' | |
|
283 | '(use --config section.name=value)') % cfg) | |
|
283 | 284 | |
|
284 | 285 | def _earlygetopt(aliases, args): |
|
285 | 286 | """Return list of values for an option (or aliases). |
|
286 | 287 | |
|
287 | 288 | The values are listed in the order they appear in args. |
|
288 | 289 | The options and values are removed from args. |
|
289 | 290 | """ |
|
290 | 291 | try: |
|
291 | 292 | argcount = args.index("--") |
|
292 | 293 | except ValueError: |
|
293 | 294 | argcount = len(args) |
|
294 | 295 | shortopts = [opt for opt in aliases if len(opt) == 2] |
|
295 | 296 | values = [] |
|
296 | 297 | pos = 0 |
|
297 | 298 | while pos < argcount: |
|
298 | 299 | if args[pos] in aliases: |
|
299 | 300 | if pos + 1 >= argcount: |
|
300 | 301 | # ignore and let getopt report an error if there is no value |
|
301 | 302 | break |
|
302 | 303 | del args[pos] |
|
303 | 304 | values.append(args.pop(pos)) |
|
304 | 305 | argcount -= 2 |
|
305 | 306 | elif args[pos][:2] in shortopts: |
|
306 | 307 | # short option can have no following space, e.g. hg log -Rfoo |
|
307 | 308 | values.append(args.pop(pos)[2:]) |
|
308 | 309 | argcount -= 1 |
|
309 | 310 | else: |
|
310 | 311 | pos += 1 |
|
311 | 312 | return values |
|
312 | 313 | |
|
313 | 314 | def runcommand(lui, repo, cmd, fullargs, ui, options, d): |
|
314 | 315 | # run pre-hook, and abort if it fails |
|
315 | 316 | ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs)) |
|
316 | 317 | if ret: |
|
317 | 318 | return ret |
|
318 | 319 | ret = _runcommand(ui, options, cmd, d) |
|
319 | 320 | # run post-hook, passing command result |
|
320 | 321 | hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs), |
|
321 | 322 | result = ret) |
|
322 | 323 | return ret |
|
323 | 324 | |
|
324 | 325 | _loaded = set() |
|
325 | 326 | def _dispatch(ui, args): |
|
326 | 327 | # read --config before doing anything else |
|
327 | 328 | # (e.g. to change trust settings for reading .hg/hgrc) |
|
328 | 329 | _parseconfig(ui, _earlygetopt(['--config'], args)) |
|
329 | 330 | |
|
330 | 331 | # check for cwd |
|
331 | 332 | cwd = _earlygetopt(['--cwd'], args) |
|
332 | 333 | if cwd: |
|
333 | 334 | os.chdir(cwd[-1]) |
|
334 | 335 | |
|
335 | 336 | # read the local repository .hgrc into a local ui object |
|
336 | 337 | path = _findrepo(os.getcwd()) or "" |
|
337 | 338 | if not path: |
|
338 | 339 | lui = ui |
|
339 | 340 | else: |
|
340 | 341 | try: |
|
341 | 342 | lui = ui.copy() |
|
342 | 343 | lui.readconfig(os.path.join(path, ".hg", "hgrc")) |
|
343 | 344 | except IOError: |
|
344 | 345 | pass |
|
345 | 346 | |
|
346 | 347 | # now we can expand paths, even ones in .hg/hgrc |
|
347 | 348 | rpath = _earlygetopt(["-R", "--repository", "--repo"], args) |
|
348 | 349 | if rpath: |
|
349 | 350 | path = lui.expandpath(rpath[-1]) |
|
350 | 351 | lui = ui.copy() |
|
351 | 352 | lui.readconfig(os.path.join(path, ".hg", "hgrc")) |
|
352 | 353 | |
|
353 | 354 | # Configure extensions in phases: uisetup, extsetup, cmdtable, and |
|
354 | 355 | # reposetup. Programs like TortoiseHg will call _dispatch several |
|
355 | 356 | # times so we keep track of configured extensions in _loaded. |
|
356 | 357 | extensions.loadall(lui) |
|
357 | 358 | exts = [ext for ext in extensions.extensions() if ext[0] not in _loaded] |
|
358 | 359 | |
|
359 | 360 | # (uisetup and extsetup are handled in extensions.loadall) |
|
360 | 361 | |
|
361 | 362 | for name, module in exts: |
|
362 | 363 | cmdtable = getattr(module, 'cmdtable', {}) |
|
363 | 364 | overrides = [cmd for cmd in cmdtable if cmd in commands.table] |
|
364 | 365 | if overrides: |
|
365 | 366 | ui.warn(_("extension '%s' overrides commands: %s\n") |
|
366 | 367 | % (name, " ".join(overrides))) |
|
367 | 368 | commands.table.update(cmdtable) |
|
368 | 369 | _loaded.add(name) |
|
369 | 370 | |
|
370 | 371 | # (reposetup is handled in hg.repository) |
|
371 | 372 | |
|
372 | 373 | addaliases(lui, commands.table) |
|
373 | 374 | |
|
374 | 375 | # check for fallback encoding |
|
375 | 376 | fallback = lui.config('ui', 'fallbackencoding') |
|
376 | 377 | if fallback: |
|
377 | 378 | encoding.fallbackencoding = fallback |
|
378 | 379 | |
|
379 | 380 | fullargs = args |
|
380 | 381 | cmd, func, args, options, cmdoptions = _parse(lui, args) |
|
381 | 382 | |
|
382 | 383 | if options["config"]: |
|
383 | 384 | raise util.Abort(_("Option --config may not be abbreviated!")) |
|
384 | 385 | if options["cwd"]: |
|
385 | 386 | raise util.Abort(_("Option --cwd may not be abbreviated!")) |
|
386 | 387 | if options["repository"]: |
|
387 | 388 | raise util.Abort(_( |
|
388 | 389 | "Option -R has to be separated from other options (e.g. not -qR) " |
|
389 | 390 | "and --repository may only be abbreviated as --repo!")) |
|
390 | 391 | |
|
391 | 392 | if options["encoding"]: |
|
392 | 393 | encoding.encoding = options["encoding"] |
|
393 | 394 | if options["encodingmode"]: |
|
394 | 395 | encoding.encodingmode = options["encodingmode"] |
|
395 | 396 | if options["time"]: |
|
396 | 397 | def get_times(): |
|
397 | 398 | t = os.times() |
|
398 | 399 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() |
|
399 | 400 | t = (t[0], t[1], t[2], t[3], time.clock()) |
|
400 | 401 | return t |
|
401 | 402 | s = get_times() |
|
402 | 403 | def print_time(): |
|
403 | 404 | t = get_times() |
|
404 | 405 | ui.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % |
|
405 | 406 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) |
|
406 | 407 | atexit.register(print_time) |
|
407 | 408 | |
|
408 | 409 | if options['verbose'] or options['debug'] or options['quiet']: |
|
409 | 410 | ui.setconfig('ui', 'verbose', str(bool(options['verbose']))) |
|
410 | 411 | ui.setconfig('ui', 'debug', str(bool(options['debug']))) |
|
411 | 412 | ui.setconfig('ui', 'quiet', str(bool(options['quiet']))) |
|
412 | 413 | if options['traceback']: |
|
413 | 414 | ui.setconfig('ui', 'traceback', 'on') |
|
414 | 415 | if options['noninteractive']: |
|
415 | 416 | ui.setconfig('ui', 'interactive', 'off') |
|
416 | 417 | |
|
417 | 418 | if options['help']: |
|
418 | 419 | return commands.help_(ui, cmd, options['version']) |
|
419 | 420 | elif options['version']: |
|
420 | 421 | return commands.version_(ui) |
|
421 | 422 | elif not cmd: |
|
422 | 423 | return commands.help_(ui, 'shortlist') |
|
423 | 424 | |
|
424 | 425 | repo = None |
|
425 | 426 | if cmd not in commands.norepo.split(): |
|
426 | 427 | try: |
|
427 | 428 | repo = hg.repository(ui, path=path) |
|
428 | 429 | ui = repo.ui |
|
429 | 430 | if not repo.local(): |
|
430 | 431 | raise util.Abort(_("repository '%s' is not local") % path) |
|
431 | 432 | ui.setconfig("bundle", "mainreporoot", repo.root) |
|
432 | 433 | except error.RepoError: |
|
433 | 434 | if cmd not in commands.optionalrepo.split(): |
|
434 | 435 | if args and not path: # try to infer -R from command args |
|
435 | 436 | repos = map(_findrepo, args) |
|
436 | 437 | guess = repos[0] |
|
437 | 438 | if guess and repos.count(guess) == len(repos): |
|
438 | 439 | return _dispatch(ui, ['--repository', guess] + fullargs) |
|
439 | 440 | if not path: |
|
440 | 441 | raise error.RepoError(_("There is no Mercurial repository" |
|
441 | 442 | " here (.hg not found)")) |
|
442 | 443 | raise |
|
443 | 444 | args.insert(0, repo) |
|
444 | 445 | elif rpath: |
|
445 | 446 | ui.warn("warning: --repository ignored\n") |
|
446 | 447 | |
|
447 | 448 | d = lambda: util.checksignature(func)(ui, *args, **cmdoptions) |
|
448 | 449 | return runcommand(lui, repo, cmd, fullargs, ui, options, d) |
|
449 | 450 | |
|
450 | 451 | def _runcommand(ui, options, cmd, cmdfunc): |
|
451 | 452 | def checkargs(): |
|
452 | 453 | try: |
|
453 | 454 | return cmdfunc() |
|
454 | 455 | except error.SignatureError: |
|
455 | 456 | raise error.ParseError(cmd, _("invalid arguments")) |
|
456 | 457 | |
|
457 | 458 | if options['profile']: |
|
458 | 459 | format = ui.config('profiling', 'format', default='text') |
|
459 | 460 | |
|
460 | 461 | if not format in ['text', 'kcachegrind']: |
|
461 | 462 | ui.warn(_("unrecognized profiling format '%s'" |
|
462 | 463 | " - Ignored\n") % format) |
|
463 | 464 | format = 'text' |
|
464 | 465 | |
|
465 | 466 | output = ui.config('profiling', 'output') |
|
466 | 467 | |
|
467 | 468 | if output: |
|
468 | 469 | path = ui.expandpath(output) |
|
469 | 470 | ostream = open(path, 'wb') |
|
470 | 471 | else: |
|
471 | 472 | ostream = sys.stderr |
|
472 | 473 | |
|
473 | 474 | try: |
|
474 | 475 | from mercurial import lsprof |
|
475 | 476 | except ImportError: |
|
476 | 477 | raise util.Abort(_( |
|
477 | 478 | 'lsprof not available - install from ' |
|
478 | 479 | 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/')) |
|
479 | 480 | p = lsprof.Profiler() |
|
480 | 481 | p.enable(subcalls=True) |
|
481 | 482 | try: |
|
482 | 483 | return checkargs() |
|
483 | 484 | finally: |
|
484 | 485 | p.disable() |
|
485 | 486 | |
|
486 | 487 | if format == 'kcachegrind': |
|
487 | 488 | import lsprofcalltree |
|
488 | 489 | calltree = lsprofcalltree.KCacheGrind(p) |
|
489 | 490 | calltree.output(ostream) |
|
490 | 491 | else: |
|
491 | 492 | # format == 'text' |
|
492 | 493 | stats = lsprof.Stats(p.getstats()) |
|
493 | 494 | stats.sort() |
|
494 | 495 | stats.pprint(top=10, file=ostream, climit=5) |
|
495 | 496 | |
|
496 | 497 | if output: |
|
497 | 498 | ostream.close() |
|
498 | 499 | else: |
|
499 | 500 | return checkargs() |
@@ -1,286 +1,286 b'' | |||
|
1 | 1 | adding a |
|
2 | 2 | adding b |
|
3 | 3 | updating to branch default |
|
4 | 4 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
5 | 5 | pulling from ../b |
|
6 | 6 | searching for changes |
|
7 | 7 | warning: repository is unrelated |
|
8 | 8 | adding changesets |
|
9 | 9 | adding manifests |
|
10 | 10 | adding file changes |
|
11 | 11 | added 1 changesets with 1 changes to 1 files (+1 heads) |
|
12 | 12 | (run 'hg heads' to see heads, 'hg merge' to merge) |
|
13 | 13 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
14 | 14 | (branch merge, don't forget to commit) |
|
15 | 15 | %% -R/--repository |
|
16 | 16 | changeset: 0:8580ff50825a |
|
17 | 17 | tag: tip |
|
18 | 18 | user: test |
|
19 | 19 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
20 | 20 | summary: a |
|
21 | 21 | |
|
22 | 22 | changeset: 0:b6c483daf290 |
|
23 | 23 | tag: tip |
|
24 | 24 | user: test |
|
25 | 25 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
26 | 26 | summary: b |
|
27 | 27 | |
|
28 | 28 | %% implicit -R |
|
29 | 29 | 0: a |
|
30 | 30 | 0: a |
|
31 | 31 | abort: There is no Mercurial repository here (.hg not found)! |
|
32 | 32 | abort: a/a not under root |
|
33 | 33 | abort: There is no Mercurial repository here (.hg not found)! |
|
34 | 34 | %% abbrev of long option |
|
35 | 35 | changeset: 1:b6c483daf290 |
|
36 | 36 | tag: tip |
|
37 | 37 | parent: -1:000000000000 |
|
38 | 38 | user: test |
|
39 | 39 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
40 | 40 | summary: b |
|
41 | 41 | |
|
42 | 42 | %% earlygetopt with duplicate options (36d23de02da1) |
|
43 | 43 | changeset: 1:b6c483daf290 |
|
44 | 44 | tag: tip |
|
45 | 45 | parent: -1:000000000000 |
|
46 | 46 | user: test |
|
47 | 47 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
48 | 48 | summary: b |
|
49 | 49 | |
|
50 | 50 | changeset: 0:8580ff50825a |
|
51 | 51 | tag: tip |
|
52 | 52 | user: test |
|
53 | 53 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
54 | 54 | summary: a |
|
55 | 55 | |
|
56 | 56 | %% earlygetopt short option without following space |
|
57 | 57 | 0:b6c483daf290 |
|
58 | 58 | %% earlygetopt with illegal abbreviations |
|
59 | 59 | abort: Option --config may not be abbreviated! |
|
60 | 60 | abort: Option --cwd may not be abbreviated! |
|
61 | 61 | abort: Option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo! |
|
62 | 62 | abort: Option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo! |
|
63 | 63 | abort: Option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo! |
|
64 | 64 | abort: Option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo! |
|
65 | 65 | %% --cwd |
|
66 | 66 | changeset: 0:8580ff50825a |
|
67 | 67 | tag: tip |
|
68 | 68 | user: test |
|
69 | 69 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
70 | 70 | summary: a |
|
71 | 71 | |
|
72 | 72 | %% -y/--noninteractive - just be sure it is parsed |
|
73 | 73 | 0:8580ff50825a |
|
74 | 74 | 0:8580ff50825a |
|
75 | 75 | %% -q/--quiet |
|
76 | 76 | 0:8580ff50825a |
|
77 | 77 | 0:b6c483daf290 |
|
78 | 78 | 0:8580ff50825a |
|
79 | 79 | 1:b6c483daf290 |
|
80 | 80 | %% -v/--verbose |
|
81 | 81 | changeset: 1:b6c483daf290 |
|
82 | 82 | tag: tip |
|
83 | 83 | parent: -1:000000000000 |
|
84 | 84 | user: test |
|
85 | 85 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
86 | 86 | files: b |
|
87 | 87 | description: |
|
88 | 88 | b |
|
89 | 89 | |
|
90 | 90 | |
|
91 | 91 | changeset: 0:8580ff50825a |
|
92 | 92 | user: test |
|
93 | 93 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
94 | 94 | files: a |
|
95 | 95 | description: |
|
96 | 96 | a |
|
97 | 97 | |
|
98 | 98 | |
|
99 | 99 | changeset: 0:b6c483daf290 |
|
100 | 100 | tag: tip |
|
101 | 101 | user: test |
|
102 | 102 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
103 | 103 | files: b |
|
104 | 104 | description: |
|
105 | 105 | b |
|
106 | 106 | |
|
107 | 107 | |
|
108 | 108 | %% --config |
|
109 | 109 | quuxfoo |
|
110 | abort: malformed --config option: | |
|
111 | abort: malformed --config option: a.b | |
|
112 | abort: malformed --config option: a | |
|
113 | abort: malformed --config option: a.= | |
|
114 | abort: malformed --config option: .b= | |
|
110 | abort: malformed --config option: '' (use --config section.name=value) | |
|
111 | abort: malformed --config option: 'a.b' (use --config section.name=value) | |
|
112 | abort: malformed --config option: 'a' (use --config section.name=value) | |
|
113 | abort: malformed --config option: 'a.=' (use --config section.name=value) | |
|
114 | abort: malformed --config option: '.b=' (use --config section.name=value) | |
|
115 | 115 | %% --debug |
|
116 | 116 | changeset: 1:b6c483daf2907ce5825c0bb50f5716226281cc1a |
|
117 | 117 | tag: tip |
|
118 | 118 | parent: -1:0000000000000000000000000000000000000000 |
|
119 | 119 | parent: -1:0000000000000000000000000000000000000000 |
|
120 | 120 | manifest: 1:23226e7a252cacdc2d99e4fbdc3653441056de49 |
|
121 | 121 | user: test |
|
122 | 122 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
123 | 123 | files+: b |
|
124 | 124 | extra: branch=default |
|
125 | 125 | description: |
|
126 | 126 | b |
|
127 | 127 | |
|
128 | 128 | |
|
129 | 129 | changeset: 0:8580ff50825a50c8f716709acdf8de0deddcd6ab |
|
130 | 130 | parent: -1:0000000000000000000000000000000000000000 |
|
131 | 131 | parent: -1:0000000000000000000000000000000000000000 |
|
132 | 132 | manifest: 0:a0c8bcbbb45c63b90b70ad007bf38961f64f2af0 |
|
133 | 133 | user: test |
|
134 | 134 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
135 | 135 | files+: a |
|
136 | 136 | extra: branch=default |
|
137 | 137 | description: |
|
138 | 138 | a |
|
139 | 139 | |
|
140 | 140 | |
|
141 | 141 | %% --traceback |
|
142 | 142 | Traceback (most recent call last): |
|
143 | 143 | %% --time |
|
144 | 144 | Time: real x.x secs (user x.x+x.x sys x.x+x.x) |
|
145 | 145 | %% --version |
|
146 | 146 | Mercurial Distributed SCM (version xxx) |
|
147 | 147 | %% -h/--help |
|
148 | 148 | Mercurial Distributed SCM |
|
149 | 149 | |
|
150 | 150 | list of commands: |
|
151 | 151 | |
|
152 | 152 | add add the specified files on the next commit |
|
153 | 153 | addremove add all new files, delete all missing files |
|
154 | 154 | annotate show changeset information by line for each file |
|
155 | 155 | archive create an unversioned archive of a repository revision |
|
156 | 156 | backout reverse effect of earlier changeset |
|
157 | 157 | bisect subdivision search of changesets |
|
158 | 158 | branch set or show the current branch name |
|
159 | 159 | branches list repository named branches |
|
160 | 160 | bundle create a changegroup file |
|
161 | 161 | cat output the current or given revision of files |
|
162 | 162 | clone make a copy of an existing repository |
|
163 | 163 | commit commit the specified files or all outstanding changes |
|
164 | 164 | copy mark files as copied for the next commit |
|
165 | 165 | diff diff repository (or selected files) |
|
166 | 166 | export dump the header and diffs for one or more changesets |
|
167 | 167 | forget forget the specified files on the next commit |
|
168 | 168 | grep search for a pattern in specified files and revisions |
|
169 | 169 | heads show current repository heads or show branch heads |
|
170 | 170 | help show help for a given topic or a help overview |
|
171 | 171 | identify identify the working copy or specified revision |
|
172 | 172 | import import an ordered set of patches |
|
173 | 173 | incoming show new changesets found in source |
|
174 | 174 | init create a new repository in the given directory |
|
175 | 175 | locate locate files matching specific patterns |
|
176 | 176 | log show revision history of entire repository or files |
|
177 | 177 | manifest output the current or given revision of the project manifest |
|
178 | 178 | merge merge working directory with another revision |
|
179 | 179 | outgoing show changesets not found in destination |
|
180 | 180 | parents show the parents of the working directory or revision |
|
181 | 181 | paths show aliases for remote repositories |
|
182 | 182 | pull pull changes from the specified source |
|
183 | 183 | push push changes to the specified destination |
|
184 | 184 | recover roll back an interrupted transaction |
|
185 | 185 | remove remove the specified files on the next commit |
|
186 | 186 | rename rename files; equivalent of copy + remove |
|
187 | 187 | resolve retry file merges from a merge or update |
|
188 | 188 | revert restore individual files or directories to an earlier state |
|
189 | 189 | rollback roll back the last transaction |
|
190 | 190 | root print the root (top) of the current working directory |
|
191 | 191 | serve export the repository via HTTP |
|
192 | 192 | showconfig show combined config settings from all hgrc files |
|
193 | 193 | status show changed files in the working directory |
|
194 | 194 | summary summarize working directory state |
|
195 | 195 | tag add one or more tags for the current or given revision |
|
196 | 196 | tags list repository tags |
|
197 | 197 | tip show the tip revision |
|
198 | 198 | unbundle apply one or more changegroup files |
|
199 | 199 | update update working directory |
|
200 | 200 | verify verify the integrity of the repository |
|
201 | 201 | version output version and copyright information |
|
202 | 202 | |
|
203 | 203 | additional help topics: |
|
204 | 204 | |
|
205 | 205 | config Configuration Files |
|
206 | 206 | dates Date Formats |
|
207 | 207 | patterns File Name Patterns |
|
208 | 208 | environment Environment Variables |
|
209 | 209 | revisions Specifying Single Revisions |
|
210 | 210 | multirevs Specifying Multiple Revisions |
|
211 | 211 | diffs Diff Formats |
|
212 | 212 | templating Template Usage |
|
213 | 213 | urls URL Paths |
|
214 | 214 | extensions Using additional features |
|
215 | 215 | |
|
216 | 216 | use "hg -v help" to show aliases and global options |
|
217 | 217 | Mercurial Distributed SCM |
|
218 | 218 | |
|
219 | 219 | list of commands: |
|
220 | 220 | |
|
221 | 221 | add add the specified files on the next commit |
|
222 | 222 | addremove add all new files, delete all missing files |
|
223 | 223 | annotate show changeset information by line for each file |
|
224 | 224 | archive create an unversioned archive of a repository revision |
|
225 | 225 | backout reverse effect of earlier changeset |
|
226 | 226 | bisect subdivision search of changesets |
|
227 | 227 | branch set or show the current branch name |
|
228 | 228 | branches list repository named branches |
|
229 | 229 | bundle create a changegroup file |
|
230 | 230 | cat output the current or given revision of files |
|
231 | 231 | clone make a copy of an existing repository |
|
232 | 232 | commit commit the specified files or all outstanding changes |
|
233 | 233 | copy mark files as copied for the next commit |
|
234 | 234 | diff diff repository (or selected files) |
|
235 | 235 | export dump the header and diffs for one or more changesets |
|
236 | 236 | forget forget the specified files on the next commit |
|
237 | 237 | grep search for a pattern in specified files and revisions |
|
238 | 238 | heads show current repository heads or show branch heads |
|
239 | 239 | help show help for a given topic or a help overview |
|
240 | 240 | identify identify the working copy or specified revision |
|
241 | 241 | import import an ordered set of patches |
|
242 | 242 | incoming show new changesets found in source |
|
243 | 243 | init create a new repository in the given directory |
|
244 | 244 | locate locate files matching specific patterns |
|
245 | 245 | log show revision history of entire repository or files |
|
246 | 246 | manifest output the current or given revision of the project manifest |
|
247 | 247 | merge merge working directory with another revision |
|
248 | 248 | outgoing show changesets not found in destination |
|
249 | 249 | parents show the parents of the working directory or revision |
|
250 | 250 | paths show aliases for remote repositories |
|
251 | 251 | pull pull changes from the specified source |
|
252 | 252 | push push changes to the specified destination |
|
253 | 253 | recover roll back an interrupted transaction |
|
254 | 254 | remove remove the specified files on the next commit |
|
255 | 255 | rename rename files; equivalent of copy + remove |
|
256 | 256 | resolve retry file merges from a merge or update |
|
257 | 257 | revert restore individual files or directories to an earlier state |
|
258 | 258 | rollback roll back the last transaction |
|
259 | 259 | root print the root (top) of the current working directory |
|
260 | 260 | serve export the repository via HTTP |
|
261 | 261 | showconfig show combined config settings from all hgrc files |
|
262 | 262 | status show changed files in the working directory |
|
263 | 263 | summary summarize working directory state |
|
264 | 264 | tag add one or more tags for the current or given revision |
|
265 | 265 | tags list repository tags |
|
266 | 266 | tip show the tip revision |
|
267 | 267 | unbundle apply one or more changegroup files |
|
268 | 268 | update update working directory |
|
269 | 269 | verify verify the integrity of the repository |
|
270 | 270 | version output version and copyright information |
|
271 | 271 | |
|
272 | 272 | additional help topics: |
|
273 | 273 | |
|
274 | 274 | config Configuration Files |
|
275 | 275 | dates Date Formats |
|
276 | 276 | patterns File Name Patterns |
|
277 | 277 | environment Environment Variables |
|
278 | 278 | revisions Specifying Single Revisions |
|
279 | 279 | multirevs Specifying Multiple Revisions |
|
280 | 280 | diffs Diff Formats |
|
281 | 281 | templating Template Usage |
|
282 | 282 | urls URL Paths |
|
283 | 283 | extensions Using additional features |
|
284 | 284 | |
|
285 | 285 | use "hg -v help" to show aliases and global options |
|
286 | 286 | %% not tested: --debugger |
General Comments 0
You need to be logged in to leave comments.
Login now