Show More
@@ -1,550 +1,550 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 or any later version. |
|
7 | 7 | |
|
8 | 8 | from i18n import _ |
|
9 | 9 | import os, sys, atexit, signal, pdb, socket, errno, shlex, time, traceback |
|
10 | 10 | import util, commands, hg, fancyopts, extensions, hook, error |
|
11 | 11 | import cmdutil, encoding |
|
12 | 12 | import ui as uimod |
|
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 = uimod.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 | if inst.hint: |
|
27 |
sys.std |
|
|
27 | sys.stderr.write(_("(%s)\n") % inst.hint) | |
|
28 | 28 | return -1 |
|
29 | 29 | except error.ParseError, inst: |
|
30 | 30 | if len(inst.args) > 1: |
|
31 | 31 | sys.stderr.write(_("hg: parse error at %s: %s\n") % |
|
32 | 32 | (inst.args[1], inst.args[0])) |
|
33 | 33 | else: |
|
34 | 34 | sys.stderr.write(_("hg: parse error: %s\n") % inst.args[0]) |
|
35 | 35 | return -1 |
|
36 | 36 | return _runcatch(u, args) |
|
37 | 37 | |
|
38 | 38 | def _runcatch(ui, args): |
|
39 | 39 | def catchterm(*args): |
|
40 | 40 | raise error.SignalInterrupt |
|
41 | 41 | |
|
42 | 42 | try: |
|
43 | 43 | for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': |
|
44 | 44 | num = getattr(signal, name, None) |
|
45 | 45 | if num: |
|
46 | 46 | signal.signal(num, catchterm) |
|
47 | 47 | except ValueError: |
|
48 | 48 | pass # happens if called in a thread |
|
49 | 49 | |
|
50 | 50 | try: |
|
51 | 51 | try: |
|
52 | 52 | # enter the debugger before command execution |
|
53 | 53 | if '--debugger' in args: |
|
54 | 54 | ui.warn(_("entering debugger - " |
|
55 | 55 | "type c to continue starting hg or h for help\n")) |
|
56 | 56 | pdb.set_trace() |
|
57 | 57 | try: |
|
58 | 58 | return _dispatch(ui, args) |
|
59 | 59 | finally: |
|
60 | 60 | ui.flush() |
|
61 | 61 | except: |
|
62 | 62 | # enter the debugger when we hit an exception |
|
63 | 63 | if '--debugger' in args: |
|
64 | 64 | traceback.print_exc() |
|
65 | 65 | pdb.post_mortem(sys.exc_info()[2]) |
|
66 | 66 | ui.traceback() |
|
67 | 67 | raise |
|
68 | 68 | |
|
69 | 69 | # Global exception handling, alphabetically |
|
70 | 70 | # Mercurial-specific first, followed by built-in and library exceptions |
|
71 | 71 | except error.AmbiguousCommand, inst: |
|
72 | 72 | ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
|
73 | 73 | (inst.args[0], " ".join(inst.args[1]))) |
|
74 | 74 | except error.ParseError, inst: |
|
75 | 75 | if len(inst.args) > 1: |
|
76 | 76 | ui.warn(_("hg: parse error at %s: %s\n") % |
|
77 | 77 | (inst.args[1], inst.args[0])) |
|
78 | 78 | else: |
|
79 | 79 | ui.warn(_("hg: parse error: %s\n") % inst.args[0]) |
|
80 | 80 | return -1 |
|
81 | 81 | except error.LockHeld, inst: |
|
82 | 82 | if inst.errno == errno.ETIMEDOUT: |
|
83 | 83 | reason = _('timed out waiting for lock held by %s') % inst.locker |
|
84 | 84 | else: |
|
85 | 85 | reason = _('lock held by %s') % inst.locker |
|
86 | 86 | ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) |
|
87 | 87 | except error.LockUnavailable, inst: |
|
88 | 88 | ui.warn(_("abort: could not lock %s: %s\n") % |
|
89 | 89 | (inst.desc or inst.filename, inst.strerror)) |
|
90 | 90 | except error.CommandError, inst: |
|
91 | 91 | if inst.args[0]: |
|
92 | 92 | ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
|
93 | 93 | commands.help_(ui, inst.args[0]) |
|
94 | 94 | else: |
|
95 | 95 | ui.warn(_("hg: %s\n") % inst.args[1]) |
|
96 | 96 | commands.help_(ui, 'shortlist') |
|
97 | 97 | except error.RepoError, inst: |
|
98 | 98 | ui.warn(_("abort: %s!\n") % inst) |
|
99 | 99 | except error.ResponseError, inst: |
|
100 | 100 | ui.warn(_("abort: %s") % inst.args[0]) |
|
101 | 101 | if not isinstance(inst.args[1], basestring): |
|
102 | 102 | ui.warn(" %r\n" % (inst.args[1],)) |
|
103 | 103 | elif not inst.args[1]: |
|
104 | 104 | ui.warn(_(" empty string\n")) |
|
105 | 105 | else: |
|
106 | 106 | ui.warn("\n%r\n" % util.ellipsis(inst.args[1])) |
|
107 | 107 | except error.RevlogError, inst: |
|
108 | 108 | ui.warn(_("abort: %s!\n") % inst) |
|
109 | 109 | except error.SignalInterrupt: |
|
110 | 110 | ui.warn(_("killed!\n")) |
|
111 | 111 | except error.UnknownCommand, inst: |
|
112 | 112 | ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
|
113 | 113 | try: |
|
114 | 114 | # check if the command is in a disabled extension |
|
115 | 115 | # (but don't check for extensions themselves) |
|
116 | 116 | commands.help_(ui, inst.args[0], unknowncmd=True) |
|
117 | 117 | except error.UnknownCommand: |
|
118 | 118 | commands.help_(ui, 'shortlist') |
|
119 | 119 | except util.Abort, inst: |
|
120 | 120 | ui.warn(_("abort: %s\n") % inst) |
|
121 | 121 | if inst.hint: |
|
122 |
ui. |
|
|
122 | ui.warn(_("(%s)\n") % inst.hint) | |
|
123 | 123 | except ImportError, inst: |
|
124 | 124 | ui.warn(_("abort: %s!\n") % inst) |
|
125 | 125 | m = str(inst).split()[-1] |
|
126 | 126 | if m in "mpatch bdiff".split(): |
|
127 | 127 | ui.warn(_("(did you forget to compile extensions?)\n")) |
|
128 | 128 | elif m in "zlib".split(): |
|
129 | 129 | ui.warn(_("(is your Python install correct?)\n")) |
|
130 | 130 | except IOError, inst: |
|
131 | 131 | if hasattr(inst, "code"): |
|
132 | 132 | ui.warn(_("abort: %s\n") % inst) |
|
133 | 133 | elif hasattr(inst, "reason"): |
|
134 | 134 | try: # usually it is in the form (errno, strerror) |
|
135 | 135 | reason = inst.reason.args[1] |
|
136 | 136 | except: # it might be anything, for example a string |
|
137 | 137 | reason = inst.reason |
|
138 | 138 | ui.warn(_("abort: error: %s\n") % reason) |
|
139 | 139 | elif hasattr(inst, "args") and inst.args[0] == errno.EPIPE: |
|
140 | 140 | if ui.debugflag: |
|
141 | 141 | ui.warn(_("broken pipe\n")) |
|
142 | 142 | elif getattr(inst, "strerror", None): |
|
143 | 143 | if getattr(inst, "filename", None): |
|
144 | 144 | ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
|
145 | 145 | else: |
|
146 | 146 | ui.warn(_("abort: %s\n") % inst.strerror) |
|
147 | 147 | else: |
|
148 | 148 | raise |
|
149 | 149 | except OSError, inst: |
|
150 | 150 | if getattr(inst, "filename", None): |
|
151 | 151 | ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
|
152 | 152 | else: |
|
153 | 153 | ui.warn(_("abort: %s\n") % inst.strerror) |
|
154 | 154 | except KeyboardInterrupt: |
|
155 | 155 | try: |
|
156 | 156 | ui.warn(_("interrupted!\n")) |
|
157 | 157 | except IOError, inst: |
|
158 | 158 | if inst.errno == errno.EPIPE: |
|
159 | 159 | if ui.debugflag: |
|
160 | 160 | ui.warn(_("\nbroken pipe\n")) |
|
161 | 161 | else: |
|
162 | 162 | raise |
|
163 | 163 | except MemoryError: |
|
164 | 164 | ui.warn(_("abort: out of memory\n")) |
|
165 | 165 | except SystemExit, inst: |
|
166 | 166 | # Commands shouldn't sys.exit directly, but give a return code. |
|
167 | 167 | # Just in case catch this and and pass exit code to caller. |
|
168 | 168 | return inst.code |
|
169 | 169 | except socket.error, inst: |
|
170 | 170 | ui.warn(_("abort: %s\n") % inst.args[-1]) |
|
171 | 171 | except: |
|
172 | 172 | ui.warn(_("** unknown exception encountered, details follow\n")) |
|
173 | 173 | ui.warn(_("** report bug details to " |
|
174 | 174 | "http://mercurial.selenic.com/bts/\n")) |
|
175 | 175 | ui.warn(_("** or mercurial@selenic.com\n")) |
|
176 | 176 | ui.warn(_("** Python %s\n") % sys.version.replace('\n', '')) |
|
177 | 177 | ui.warn(_("** Mercurial Distributed SCM (version %s)\n") |
|
178 | 178 | % util.version()) |
|
179 | 179 | ui.warn(_("** Extensions loaded: %s\n") |
|
180 | 180 | % ", ".join([x[0] for x in extensions.extensions()])) |
|
181 | 181 | raise |
|
182 | 182 | |
|
183 | 183 | return -1 |
|
184 | 184 | |
|
185 | 185 | def aliasargs(fn): |
|
186 | 186 | if hasattr(fn, 'args'): |
|
187 | 187 | return fn.args |
|
188 | 188 | return [] |
|
189 | 189 | |
|
190 | 190 | class cmdalias(object): |
|
191 | 191 | def __init__(self, name, definition, cmdtable): |
|
192 | 192 | self.name = name |
|
193 | 193 | self.definition = definition |
|
194 | 194 | self.args = [] |
|
195 | 195 | self.opts = [] |
|
196 | 196 | self.help = '' |
|
197 | 197 | self.norepo = True |
|
198 | 198 | self.badalias = False |
|
199 | 199 | |
|
200 | 200 | try: |
|
201 | 201 | cmdutil.findcmd(self.name, cmdtable, True) |
|
202 | 202 | self.shadows = True |
|
203 | 203 | except error.UnknownCommand: |
|
204 | 204 | self.shadows = False |
|
205 | 205 | |
|
206 | 206 | if not self.definition: |
|
207 | 207 | def fn(ui, *args): |
|
208 | 208 | ui.warn(_("no definition for alias '%s'\n") % self.name) |
|
209 | 209 | return 1 |
|
210 | 210 | self.fn = fn |
|
211 | 211 | self.badalias = True |
|
212 | 212 | |
|
213 | 213 | return |
|
214 | 214 | |
|
215 | 215 | if self.definition.startswith('!'): |
|
216 | 216 | def fn(ui, *args): |
|
217 | 217 | cmd = '%s %s' % (self.definition[1:], ' '.join(args)) |
|
218 | 218 | return util.system(cmd) |
|
219 | 219 | self.fn = fn |
|
220 | 220 | return |
|
221 | 221 | |
|
222 | 222 | args = shlex.split(self.definition) |
|
223 | 223 | cmd = args.pop(0) |
|
224 | 224 | args = map(util.expandpath, args) |
|
225 | 225 | |
|
226 | 226 | try: |
|
227 | 227 | tableentry = cmdutil.findcmd(cmd, cmdtable, False)[1] |
|
228 | 228 | if len(tableentry) > 2: |
|
229 | 229 | self.fn, self.opts, self.help = tableentry |
|
230 | 230 | else: |
|
231 | 231 | self.fn, self.opts = tableentry |
|
232 | 232 | |
|
233 | 233 | self.args = aliasargs(self.fn) + args |
|
234 | 234 | if cmd not in commands.norepo.split(' '): |
|
235 | 235 | self.norepo = False |
|
236 | 236 | if self.help.startswith("hg " + cmd): |
|
237 | 237 | # drop prefix in old-style help lines so hg shows the alias |
|
238 | 238 | self.help = self.help[4 + len(cmd):] |
|
239 | 239 | self.__doc__ = self.fn.__doc__ |
|
240 | 240 | |
|
241 | 241 | except error.UnknownCommand: |
|
242 | 242 | def fn(ui, *args): |
|
243 | 243 | ui.warn(_("alias '%s' resolves to unknown command '%s'\n") \ |
|
244 | 244 | % (self.name, cmd)) |
|
245 | 245 | try: |
|
246 | 246 | # check if the command is in a disabled extension |
|
247 | 247 | commands.help_(ui, cmd, unknowncmd=True) |
|
248 | 248 | except error.UnknownCommand: |
|
249 | 249 | pass |
|
250 | 250 | return 1 |
|
251 | 251 | self.fn = fn |
|
252 | 252 | self.badalias = True |
|
253 | 253 | except error.AmbiguousCommand: |
|
254 | 254 | def fn(ui, *args): |
|
255 | 255 | ui.warn(_("alias '%s' resolves to ambiguous command '%s'\n") \ |
|
256 | 256 | % (self.name, cmd)) |
|
257 | 257 | return 1 |
|
258 | 258 | self.fn = fn |
|
259 | 259 | self.badalias = True |
|
260 | 260 | |
|
261 | 261 | def __call__(self, ui, *args, **opts): |
|
262 | 262 | if self.shadows: |
|
263 | 263 | ui.debug("alias '%s' shadows command\n" % self.name) |
|
264 | 264 | |
|
265 | 265 | return self.fn(ui, *args, **opts) |
|
266 | 266 | |
|
267 | 267 | def addaliases(ui, cmdtable): |
|
268 | 268 | # aliases are processed after extensions have been loaded, so they |
|
269 | 269 | # may use extension commands. Aliases can also use other alias definitions, |
|
270 | 270 | # but only if they have been defined prior to the current definition. |
|
271 | 271 | for alias, definition in ui.configitems('alias'): |
|
272 | 272 | aliasdef = cmdalias(alias, definition, cmdtable) |
|
273 | 273 | cmdtable[alias] = (aliasdef, aliasdef.opts, aliasdef.help) |
|
274 | 274 | if aliasdef.norepo: |
|
275 | 275 | commands.norepo += ' %s' % alias |
|
276 | 276 | |
|
277 | 277 | def _parse(ui, args): |
|
278 | 278 | options = {} |
|
279 | 279 | cmdoptions = {} |
|
280 | 280 | |
|
281 | 281 | try: |
|
282 | 282 | args = fancyopts.fancyopts(args, commands.globalopts, options) |
|
283 | 283 | except fancyopts.getopt.GetoptError, inst: |
|
284 | 284 | raise error.CommandError(None, inst) |
|
285 | 285 | |
|
286 | 286 | if args: |
|
287 | 287 | cmd, args = args[0], args[1:] |
|
288 | 288 | aliases, entry = cmdutil.findcmd(cmd, commands.table, |
|
289 | 289 | ui.config("ui", "strict")) |
|
290 | 290 | cmd = aliases[0] |
|
291 | 291 | args = aliasargs(entry[0]) + args |
|
292 | 292 | defaults = ui.config("defaults", cmd) |
|
293 | 293 | if defaults: |
|
294 | 294 | args = map(util.expandpath, shlex.split(defaults)) + args |
|
295 | 295 | c = list(entry[1]) |
|
296 | 296 | else: |
|
297 | 297 | cmd = None |
|
298 | 298 | c = [] |
|
299 | 299 | |
|
300 | 300 | # combine global options into local |
|
301 | 301 | for o in commands.globalopts: |
|
302 | 302 | c.append((o[0], o[1], options[o[1]], o[3])) |
|
303 | 303 | |
|
304 | 304 | try: |
|
305 | 305 | args = fancyopts.fancyopts(args, c, cmdoptions, True) |
|
306 | 306 | except fancyopts.getopt.GetoptError, inst: |
|
307 | 307 | raise error.CommandError(cmd, inst) |
|
308 | 308 | |
|
309 | 309 | # separate global options back out |
|
310 | 310 | for o in commands.globalopts: |
|
311 | 311 | n = o[1] |
|
312 | 312 | options[n] = cmdoptions[n] |
|
313 | 313 | del cmdoptions[n] |
|
314 | 314 | |
|
315 | 315 | return (cmd, cmd and entry[0] or None, args, options, cmdoptions) |
|
316 | 316 | |
|
317 | 317 | def _parseconfig(ui, config): |
|
318 | 318 | """parse the --config options from the command line""" |
|
319 | 319 | for cfg in config: |
|
320 | 320 | try: |
|
321 | 321 | name, value = cfg.split('=', 1) |
|
322 | 322 | section, name = name.split('.', 1) |
|
323 | 323 | if not section or not name: |
|
324 | 324 | raise IndexError |
|
325 | 325 | ui.setconfig(section, name, value) |
|
326 | 326 | except (IndexError, ValueError): |
|
327 | 327 | raise util.Abort(_('malformed --config option: %r ' |
|
328 | 328 | '(use --config section.name=value)') % cfg) |
|
329 | 329 | |
|
330 | 330 | def _earlygetopt(aliases, args): |
|
331 | 331 | """Return list of values for an option (or aliases). |
|
332 | 332 | |
|
333 | 333 | The values are listed in the order they appear in args. |
|
334 | 334 | The options and values are removed from args. |
|
335 | 335 | """ |
|
336 | 336 | try: |
|
337 | 337 | argcount = args.index("--") |
|
338 | 338 | except ValueError: |
|
339 | 339 | argcount = len(args) |
|
340 | 340 | shortopts = [opt for opt in aliases if len(opt) == 2] |
|
341 | 341 | values = [] |
|
342 | 342 | pos = 0 |
|
343 | 343 | while pos < argcount: |
|
344 | 344 | if args[pos] in aliases: |
|
345 | 345 | if pos + 1 >= argcount: |
|
346 | 346 | # ignore and let getopt report an error if there is no value |
|
347 | 347 | break |
|
348 | 348 | del args[pos] |
|
349 | 349 | values.append(args.pop(pos)) |
|
350 | 350 | argcount -= 2 |
|
351 | 351 | elif args[pos][:2] in shortopts: |
|
352 | 352 | # short option can have no following space, e.g. hg log -Rfoo |
|
353 | 353 | values.append(args.pop(pos)[2:]) |
|
354 | 354 | argcount -= 1 |
|
355 | 355 | else: |
|
356 | 356 | pos += 1 |
|
357 | 357 | return values |
|
358 | 358 | |
|
359 | 359 | def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions): |
|
360 | 360 | # run pre-hook, and abort if it fails |
|
361 | 361 | ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs), |
|
362 | 362 | pats=cmdpats, opts=cmdoptions) |
|
363 | 363 | if ret: |
|
364 | 364 | return ret |
|
365 | 365 | ret = _runcommand(ui, options, cmd, d) |
|
366 | 366 | # run post-hook, passing command result |
|
367 | 367 | hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs), |
|
368 | 368 | result=ret, pats=cmdpats, opts=cmdoptions) |
|
369 | 369 | return ret |
|
370 | 370 | |
|
371 | 371 | _loaded = set() |
|
372 | 372 | def _dispatch(ui, args): |
|
373 | 373 | # read --config before doing anything else |
|
374 | 374 | # (e.g. to change trust settings for reading .hg/hgrc) |
|
375 | 375 | _parseconfig(ui, _earlygetopt(['--config'], args)) |
|
376 | 376 | |
|
377 | 377 | # check for cwd |
|
378 | 378 | cwd = _earlygetopt(['--cwd'], args) |
|
379 | 379 | if cwd: |
|
380 | 380 | os.chdir(cwd[-1]) |
|
381 | 381 | |
|
382 | 382 | # read the local repository .hgrc into a local ui object |
|
383 | 383 | path = cmdutil.findrepo(os.getcwd()) or "" |
|
384 | 384 | if not path: |
|
385 | 385 | lui = ui |
|
386 | 386 | else: |
|
387 | 387 | try: |
|
388 | 388 | lui = ui.copy() |
|
389 | 389 | lui.readconfig(os.path.join(path, ".hg", "hgrc")) |
|
390 | 390 | except IOError: |
|
391 | 391 | pass |
|
392 | 392 | |
|
393 | 393 | # now we can expand paths, even ones in .hg/hgrc |
|
394 | 394 | rpath = _earlygetopt(["-R", "--repository", "--repo"], args) |
|
395 | 395 | if rpath: |
|
396 | 396 | path = lui.expandpath(rpath[-1]) |
|
397 | 397 | lui = ui.copy() |
|
398 | 398 | lui.readconfig(os.path.join(path, ".hg", "hgrc")) |
|
399 | 399 | |
|
400 | 400 | # Configure extensions in phases: uisetup, extsetup, cmdtable, and |
|
401 | 401 | # reposetup. Programs like TortoiseHg will call _dispatch several |
|
402 | 402 | # times so we keep track of configured extensions in _loaded. |
|
403 | 403 | extensions.loadall(lui) |
|
404 | 404 | exts = [ext for ext in extensions.extensions() if ext[0] not in _loaded] |
|
405 | 405 | # Propagate any changes to lui.__class__ by extensions |
|
406 | 406 | ui.__class__ = lui.__class__ |
|
407 | 407 | |
|
408 | 408 | # (uisetup and extsetup are handled in extensions.loadall) |
|
409 | 409 | |
|
410 | 410 | for name, module in exts: |
|
411 | 411 | cmdtable = getattr(module, 'cmdtable', {}) |
|
412 | 412 | overrides = [cmd for cmd in cmdtable if cmd in commands.table] |
|
413 | 413 | if overrides: |
|
414 | 414 | ui.warn(_("extension '%s' overrides commands: %s\n") |
|
415 | 415 | % (name, " ".join(overrides))) |
|
416 | 416 | commands.table.update(cmdtable) |
|
417 | 417 | _loaded.add(name) |
|
418 | 418 | |
|
419 | 419 | # (reposetup is handled in hg.repository) |
|
420 | 420 | |
|
421 | 421 | addaliases(lui, commands.table) |
|
422 | 422 | |
|
423 | 423 | # check for fallback encoding |
|
424 | 424 | fallback = lui.config('ui', 'fallbackencoding') |
|
425 | 425 | if fallback: |
|
426 | 426 | encoding.fallbackencoding = fallback |
|
427 | 427 | |
|
428 | 428 | fullargs = args |
|
429 | 429 | cmd, func, args, options, cmdoptions = _parse(lui, args) |
|
430 | 430 | |
|
431 | 431 | if options["config"]: |
|
432 | 432 | raise util.Abort(_("Option --config may not be abbreviated!")) |
|
433 | 433 | if options["cwd"]: |
|
434 | 434 | raise util.Abort(_("Option --cwd may not be abbreviated!")) |
|
435 | 435 | if options["repository"]: |
|
436 | 436 | raise util.Abort(_( |
|
437 | 437 | "Option -R has to be separated from other options (e.g. not -qR) " |
|
438 | 438 | "and --repository may only be abbreviated as --repo!")) |
|
439 | 439 | |
|
440 | 440 | if options["encoding"]: |
|
441 | 441 | encoding.encoding = options["encoding"] |
|
442 | 442 | if options["encodingmode"]: |
|
443 | 443 | encoding.encodingmode = options["encodingmode"] |
|
444 | 444 | if options["time"]: |
|
445 | 445 | def get_times(): |
|
446 | 446 | t = os.times() |
|
447 | 447 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() |
|
448 | 448 | t = (t[0], t[1], t[2], t[3], time.clock()) |
|
449 | 449 | return t |
|
450 | 450 | s = get_times() |
|
451 | 451 | def print_time(): |
|
452 | 452 | t = get_times() |
|
453 | 453 | ui.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % |
|
454 | 454 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) |
|
455 | 455 | atexit.register(print_time) |
|
456 | 456 | |
|
457 | 457 | if options['verbose'] or options['debug'] or options['quiet']: |
|
458 | 458 | ui.setconfig('ui', 'verbose', str(bool(options['verbose']))) |
|
459 | 459 | ui.setconfig('ui', 'debug', str(bool(options['debug']))) |
|
460 | 460 | ui.setconfig('ui', 'quiet', str(bool(options['quiet']))) |
|
461 | 461 | if options['traceback']: |
|
462 | 462 | ui.setconfig('ui', 'traceback', 'on') |
|
463 | 463 | if options['noninteractive']: |
|
464 | 464 | ui.setconfig('ui', 'interactive', 'off') |
|
465 | 465 | |
|
466 | 466 | if options['help']: |
|
467 | 467 | return commands.help_(ui, cmd, options['version']) |
|
468 | 468 | elif options['version']: |
|
469 | 469 | return commands.version_(ui) |
|
470 | 470 | elif not cmd: |
|
471 | 471 | return commands.help_(ui, 'shortlist') |
|
472 | 472 | |
|
473 | 473 | repo = None |
|
474 | 474 | cmdpats = args[:] |
|
475 | 475 | if cmd not in commands.norepo.split(): |
|
476 | 476 | try: |
|
477 | 477 | repo = hg.repository(ui, path=path) |
|
478 | 478 | ui = repo.ui |
|
479 | 479 | if not repo.local(): |
|
480 | 480 | raise util.Abort(_("repository '%s' is not local") % path) |
|
481 | 481 | ui.setconfig("bundle", "mainreporoot", repo.root) |
|
482 | 482 | except error.RepoError: |
|
483 | 483 | if cmd not in commands.optionalrepo.split(): |
|
484 | 484 | if args and not path: # try to infer -R from command args |
|
485 | 485 | repos = map(cmdutil.findrepo, args) |
|
486 | 486 | guess = repos[0] |
|
487 | 487 | if guess and repos.count(guess) == len(repos): |
|
488 | 488 | return _dispatch(ui, ['--repository', guess] + fullargs) |
|
489 | 489 | if not path: |
|
490 | 490 | raise error.RepoError(_("There is no Mercurial repository" |
|
491 | 491 | " here (.hg not found)")) |
|
492 | 492 | raise |
|
493 | 493 | args.insert(0, repo) |
|
494 | 494 | elif rpath: |
|
495 | 495 | ui.warn(_("warning: --repository ignored\n")) |
|
496 | 496 | |
|
497 | 497 | d = lambda: util.checksignature(func)(ui, *args, **cmdoptions) |
|
498 | 498 | return runcommand(lui, repo, cmd, fullargs, ui, options, d, |
|
499 | 499 | cmdpats, cmdoptions) |
|
500 | 500 | |
|
501 | 501 | def _runcommand(ui, options, cmd, cmdfunc): |
|
502 | 502 | def checkargs(): |
|
503 | 503 | try: |
|
504 | 504 | return cmdfunc() |
|
505 | 505 | except error.SignatureError: |
|
506 | 506 | raise error.CommandError(cmd, _("invalid arguments")) |
|
507 | 507 | |
|
508 | 508 | if options['profile']: |
|
509 | 509 | format = ui.config('profiling', 'format', default='text') |
|
510 | 510 | |
|
511 | 511 | if not format in ['text', 'kcachegrind']: |
|
512 | 512 | ui.warn(_("unrecognized profiling format '%s'" |
|
513 | 513 | " - Ignored\n") % format) |
|
514 | 514 | format = 'text' |
|
515 | 515 | |
|
516 | 516 | output = ui.config('profiling', 'output') |
|
517 | 517 | |
|
518 | 518 | if output: |
|
519 | 519 | path = ui.expandpath(output) |
|
520 | 520 | ostream = open(path, 'wb') |
|
521 | 521 | else: |
|
522 | 522 | ostream = sys.stderr |
|
523 | 523 | |
|
524 | 524 | try: |
|
525 | 525 | from mercurial import lsprof |
|
526 | 526 | except ImportError: |
|
527 | 527 | raise util.Abort(_( |
|
528 | 528 | 'lsprof not available - install from ' |
|
529 | 529 | 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/')) |
|
530 | 530 | p = lsprof.Profiler() |
|
531 | 531 | p.enable(subcalls=True) |
|
532 | 532 | try: |
|
533 | 533 | return checkargs() |
|
534 | 534 | finally: |
|
535 | 535 | p.disable() |
|
536 | 536 | |
|
537 | 537 | if format == 'kcachegrind': |
|
538 | 538 | import lsprofcalltree |
|
539 | 539 | calltree = lsprofcalltree.KCacheGrind(p) |
|
540 | 540 | calltree.output(ostream) |
|
541 | 541 | else: |
|
542 | 542 | # format == 'text' |
|
543 | 543 | stats = lsprof.Stats(p.getstats()) |
|
544 | 544 | stats.sort() |
|
545 | 545 | stats.pprint(top=10, file=ostream, climit=5) |
|
546 | 546 | |
|
547 | 547 | if output: |
|
548 | 548 | ostream.close() |
|
549 | 549 | else: |
|
550 | 550 | return checkargs() |
@@ -1,303 +1,304 b'' | |||
|
1 | 1 | % first revision, no sub |
|
2 | 2 | adding a |
|
3 | 3 | % add first sub |
|
4 | 4 | abort: can't commit subrepos without .hgsub |
|
5 | 5 | adding a |
|
6 | 6 | parent: 0:f7b1eb17ad24 tip |
|
7 | 7 | 0 |
|
8 | 8 | branch: default |
|
9 | 9 | commit: 1 added, 1 subrepos |
|
10 | 10 | update: (current) |
|
11 | 11 | committing subrepository s |
|
12 | 12 | parent: 1:7cf8cfea66e4 tip |
|
13 | 13 | 1 |
|
14 | 14 | branch: default |
|
15 | 15 | commit: 1 subrepos |
|
16 | 16 | update: (current) |
|
17 | 17 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
18 | 18 | parent: 1:7cf8cfea66e4 tip |
|
19 | 19 | 1 |
|
20 | 20 | branch: default |
|
21 | 21 | commit: (clean) |
|
22 | 22 | update: (current) |
|
23 | 23 | % add sub sub |
|
24 | 24 | parent: 1:7cf8cfea66e4 tip |
|
25 | 25 | 1 |
|
26 | 26 | branch: default |
|
27 | 27 | commit: 1 subrepos |
|
28 | 28 | update: (current) |
|
29 | 29 | committing subrepository s |
|
30 | 30 | committing subrepository s/ss |
|
31 | 31 | parent: 2:df30734270ae tip |
|
32 | 32 | 2 |
|
33 | 33 | branch: default |
|
34 | 34 | commit: (clean) |
|
35 | 35 | update: (current) |
|
36 | 36 | % bump sub rev |
|
37 | 37 | committing subrepository s |
|
38 | 38 | % leave sub dirty |
|
39 | 39 | committing subrepository s |
|
40 | 40 | changeset: 3:1c833a7a9e3a |
|
41 | 41 | tag: tip |
|
42 | 42 | user: test |
|
43 | 43 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
44 | 44 | summary: 4 |
|
45 | 45 | |
|
46 | 46 | % check caching |
|
47 | 47 | 0 files updated, 0 files merged, 2 files removed, 0 files unresolved |
|
48 | 48 | % restore |
|
49 | 49 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
50 | 50 | path s |
|
51 | 51 | source s |
|
52 | 52 | revision 1c833a7a9e3a4445c711aaf0f012379cd0d4034e |
|
53 | 53 | % new branch for merge tests |
|
54 | 54 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
55 | 55 | adding t/t |
|
56 | 56 | % 5 |
|
57 | 57 | committing subrepository t |
|
58 | 58 | created new head |
|
59 | 59 | % 6 |
|
60 | 60 | committing subrepository t |
|
61 | 61 | path s |
|
62 | 62 | source s |
|
63 | 63 | revision e4ece1bf43360ddc8f6a96432201a37b7cd27ae4 |
|
64 | 64 | path t |
|
65 | 65 | source t |
|
66 | 66 | revision 6747d179aa9a688023c4b0cad32e4c92bb7f34ad |
|
67 | 67 | % 7 |
|
68 | 68 | committing subrepository t |
|
69 | 69 | % 8 |
|
70 | 70 | % merge tests |
|
71 | 71 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
72 | 72 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
73 | 73 | (branch merge, don't forget to commit) |
|
74 | 74 | path s |
|
75 | 75 | source s |
|
76 | 76 | revision fc627a69481fcbe5f1135069e8a3881c023e4cf5 |
|
77 | 77 | path t |
|
78 | 78 | source t |
|
79 | 79 | revision 60ca1237c19474e7a3978b0dc1ca4e6f36d51382 |
|
80 | 80 | created new head |
|
81 | 81 | searching for copies back to rev 2 |
|
82 | 82 | resolving manifests |
|
83 | 83 | overwrite None partial False |
|
84 | 84 | ancestor 1f14a2e2d3ec local f0d2028bf86d+ remote 1831e14459c4 |
|
85 | 85 | .hgsubstate: versions differ -> m |
|
86 | 86 | update: .hgsubstate 1/1 files (100.00%) |
|
87 | 87 | subrepo merge f0d2028bf86d+ 1831e14459c4 1f14a2e2d3ec |
|
88 | 88 | subrepo t: other changed, get t:6747d179aa9a688023c4b0cad32e4c92bb7f34ad:hg |
|
89 | 89 | getting subrepo t |
|
90 | 90 | resolving manifests |
|
91 | 91 | overwrite True partial False |
|
92 | 92 | ancestor 60ca1237c194+ local 60ca1237c194+ remote 6747d179aa9a |
|
93 | 93 | t: remote is newer -> g |
|
94 | 94 | update: t 1/1 files (100.00%) |
|
95 | 95 | getting t |
|
96 | 96 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
97 | 97 | (branch merge, don't forget to commit) |
|
98 | 98 | path s |
|
99 | 99 | source s |
|
100 | 100 | revision fc627a69481fcbe5f1135069e8a3881c023e4cf5 |
|
101 | 101 | path t |
|
102 | 102 | source t |
|
103 | 103 | revision 6747d179aa9a688023c4b0cad32e4c92bb7f34ad |
|
104 | 104 | committing subrepository t |
|
105 | 105 | searching for copies back to rev 2 |
|
106 | 106 | resolving manifests |
|
107 | 107 | overwrite None partial False |
|
108 | 108 | ancestor 1831e14459c4 local e45c8b14af55+ remote f94576341bcf |
|
109 | 109 | .hgsubstate: versions differ -> m |
|
110 | 110 | update: .hgsubstate 1/1 files (100.00%) |
|
111 | 111 | subrepo merge e45c8b14af55+ f94576341bcf 1831e14459c4 |
|
112 | 112 | subrepo t: both sides changed, merge with t:7af322bc1198a32402fe903e0b7ebcfc5c9bf8f4:hg |
|
113 | 113 | merging subrepo t |
|
114 | 114 | searching for copies back to rev 2 |
|
115 | 115 | resolving manifests |
|
116 | 116 | overwrite None partial False |
|
117 | 117 | ancestor 6747d179aa9a local 20a0db6fbf6c+ remote 7af322bc1198 |
|
118 | 118 | t: versions differ -> m |
|
119 | 119 | preserving t for resolve of t |
|
120 | 120 | update: t 1/1 files (100.00%) |
|
121 | 121 | picked tool 'internal:merge' for t (binary False symlink False) |
|
122 | 122 | merging t |
|
123 | 123 | my t@20a0db6fbf6c+ other t@7af322bc1198 ancestor t@6747d179aa9a |
|
124 | 124 | warning: conflicts during merge. |
|
125 | 125 | merging t failed! |
|
126 | 126 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
127 | 127 | use 'hg resolve' to retry unresolved file merges or 'hg update -C' to abandon |
|
128 | 128 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
129 | 129 | (branch merge, don't forget to commit) |
|
130 | 130 | % should conflict |
|
131 | 131 | <<<<<<< local |
|
132 | 132 | conflict |
|
133 | 133 | ======= |
|
134 | 134 | t3 |
|
135 | 135 | >>>>>>> other |
|
136 | 136 | % clone |
|
137 | 137 | updating to branch default |
|
138 | 138 | pulling subrepo s from .../sub/t/s |
|
139 | 139 | requesting all changes |
|
140 | 140 | adding changesets |
|
141 | 141 | adding manifests |
|
142 | 142 | adding file changes |
|
143 | 143 | added 4 changesets with 5 changes to 3 files |
|
144 | 144 | pulling subrepo s/ss from .../sub/t/s/ss |
|
145 | 145 | requesting all changes |
|
146 | 146 | adding changesets |
|
147 | 147 | adding manifests |
|
148 | 148 | adding file changes |
|
149 | 149 | added 1 changesets with 1 changes to 1 files |
|
150 | 150 | pulling subrepo t from .../sub/t/t |
|
151 | 151 | requesting all changes |
|
152 | 152 | adding changesets |
|
153 | 153 | adding manifests |
|
154 | 154 | adding file changes |
|
155 | 155 | added 4 changesets with 4 changes to 1 files (+1 heads) |
|
156 | 156 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
157 | 157 | path s |
|
158 | 158 | source s |
|
159 | 159 | revision fc627a69481fcbe5f1135069e8a3881c023e4cf5 |
|
160 | 160 | path t |
|
161 | 161 | source t |
|
162 | 162 | revision 20a0db6fbf6c3d2836e6519a642ae929bfc67c0e |
|
163 | 163 | % push |
|
164 | 164 | committing subrepository t |
|
165 | 165 | pushing ...sub/t |
|
166 | 166 | pushing ...sub/t/s/ss |
|
167 | 167 | searching for changes |
|
168 | 168 | no changes found |
|
169 | 169 | pushing ...sub/t/s |
|
170 | 170 | searching for changes |
|
171 | 171 | no changes found |
|
172 | 172 | pushing ...sub/t/t |
|
173 | 173 | searching for changes |
|
174 | 174 | adding changesets |
|
175 | 175 | adding manifests |
|
176 | 176 | adding file changes |
|
177 | 177 | added 1 changesets with 1 changes to 1 files |
|
178 | 178 | searching for changes |
|
179 | 179 | adding changesets |
|
180 | 180 | adding manifests |
|
181 | 181 | adding file changes |
|
182 | 182 | added 1 changesets with 1 changes to 1 files |
|
183 | 183 | % push -f |
|
184 | 184 | committing subrepository s |
|
185 | 185 | abort: push creates new remote heads on branch 'default'! |
|
186 | (did you forget to merge? use push -f to force) | |
|
186 | 187 | pushing ...sub/t |
|
187 | 188 | pushing ...sub/t/s/ss |
|
188 | 189 | searching for changes |
|
189 | 190 | no changes found |
|
190 | 191 | pushing ...sub/t/s |
|
191 | 192 | searching for changes |
|
192 | (did you forget to merge? use push -f to force) | |
|
193 | 193 | pushing ...sub/t |
|
194 | 194 | pushing ...sub/t/s/ss |
|
195 | 195 | searching for changes |
|
196 | 196 | no changes found |
|
197 | 197 | pushing ...sub/t/s |
|
198 | 198 | searching for changes |
|
199 | 199 | adding changesets |
|
200 | 200 | adding manifests |
|
201 | 201 | adding file changes |
|
202 | 202 | added 1 changesets with 1 changes to 1 files (+1 heads) |
|
203 | 203 | pushing ...sub/t/t |
|
204 | 204 | searching for changes |
|
205 | 205 | no changes found |
|
206 | 206 | searching for changes |
|
207 | 207 | adding changesets |
|
208 | 208 | adding manifests |
|
209 | 209 | adding file changes |
|
210 | 210 | added 1 changesets with 1 changes to 1 files |
|
211 | 211 | % update |
|
212 | 212 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
213 | 213 | committing subrepository t |
|
214 | 214 | % pull |
|
215 | 215 | pulling ...sub/t |
|
216 | 216 | searching for changes |
|
217 | 217 | adding changesets |
|
218 | 218 | adding manifests |
|
219 | 219 | adding file changes |
|
220 | 220 | added 1 changesets with 1 changes to 1 files |
|
221 | 221 | (run 'hg update' to get a working copy) |
|
222 | 222 | pulling subrepo t from .../sub/t/t |
|
223 | 223 | searching for changes |
|
224 | 224 | adding changesets |
|
225 | 225 | adding manifests |
|
226 | 226 | adding file changes |
|
227 | 227 | added 1 changesets with 1 changes to 1 files |
|
228 | 228 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
229 | 229 | blah |
|
230 | 230 | % bogus subrepo path aborts |
|
231 | 231 | abort: missing ] in subrepo source |
|
232 | 232 | % issue 1986 |
|
233 | 233 | adding a |
|
234 | 234 | marked working directory as branch br |
|
235 | 235 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
236 | 236 | adding b |
|
237 | 237 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
238 | 238 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
239 | 239 | (branch merge, don't forget to commit) |
|
240 | 240 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
241 | 241 | adding c |
|
242 | 242 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
243 | 243 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
244 | 244 | (branch merge, don't forget to commit) |
|
245 | 245 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
246 | 246 | adding .hgsub |
|
247 | 247 | committing subrepository s |
|
248 | 248 | marked working directory as branch br |
|
249 | 249 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
250 | 250 | adding b |
|
251 | 251 | committing subrepository s |
|
252 | 252 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
253 | 253 | adding c |
|
254 | 254 | 2 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
255 | 255 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
256 | 256 | (branch merge, don't forget to commit) |
|
257 | 257 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
258 | 258 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
259 | 259 | adding d |
|
260 | 260 | committing subrepository s |
|
261 | 261 | 2 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
262 | 262 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
263 | 263 | adding e |
|
264 | 264 | committing subrepository s |
|
265 | 265 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
266 | 266 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
267 | 267 | (branch merge, don't forget to commit) |
|
268 | 268 | % test subrepo delete from .hgsubstate |
|
269 | 269 | adding testdelete/nested/foo |
|
270 | 270 | adding testdelete/nested2/foo |
|
271 | 271 | adding testdelete/.hgsub |
|
272 | 272 | committing subrepository nested2 |
|
273 | 273 | committing subrepository nested |
|
274 | 274 | nested |
|
275 | 275 | % test repository cloning |
|
276 | 276 | adding nested_absolute/foo |
|
277 | 277 | adding nested_relative/foo2 |
|
278 | 278 | adding main/.hgsub |
|
279 | 279 | committing subrepository nested_relative |
|
280 | 280 | committing subrepository nested_absolute |
|
281 | 281 | updating to branch default |
|
282 | 282 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
283 | 283 | [paths] |
|
284 | 284 | default = $HGTMP/test-subrepo/sub/mercurial/nested_absolute |
|
285 | 285 | [paths] |
|
286 | 286 | default = $HGTMP/test-subrepo/sub/mercurial/nested_relative |
|
287 | 287 | % issue 1977 |
|
288 | 288 | adding a |
|
289 | 289 | adding .hgsub |
|
290 | 290 | committing subrepository s |
|
291 | 291 | updating to branch default |
|
292 | 292 | pulling subrepo s from .../sub/repo/s |
|
293 | 293 | requesting all changes |
|
294 | 294 | adding changesets |
|
295 | 295 | adding manifests |
|
296 | 296 | adding file changes |
|
297 | 297 | added 1 changesets with 1 changes to 1 files |
|
298 | 298 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
299 | 299 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
300 | 300 | created new head |
|
301 | 301 | committing subrepository s |
|
302 | 302 | abort: push creates new remote heads on branch 'default'! |
|
303 | (did you forget to merge? use push -f to force) | |
|
303 | 304 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
General Comments 0
You need to be logged in to leave comments.
Login now