##// END OF EJS Templates
Give a response to unknown SSH commands
Matt Mackall -
r2363:fa4c1175 default
parent child Browse files
Show More
@@ -1,3481 +1,3484 b''
1 1 # commands.py - command processing for mercurial
2 2 #
3 3 # Copyright 2005 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 from demandload import demandload
9 9 from node import *
10 10 from i18n import gettext as _
11 11 demandload(globals(), "os re sys signal shutil imp urllib pdb")
12 12 demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo")
13 13 demandload(globals(), "fnmatch mdiff random signal tempfile time")
14 14 demandload(globals(), "traceback errno socket version struct atexit sets bz2")
15 15 demandload(globals(), "archival changegroup")
16 16 demandload(globals(), "mercurial.hgweb.server:create_server")
17 17 demandload(globals(), "mercurial.hgweb:hgweb,hgwebdir")
18 18
19 19 class UnknownCommand(Exception):
20 20 """Exception raised if command is not in the command table."""
21 21 class AmbiguousCommand(Exception):
22 22 """Exception raised if command shortcut matches more than one command."""
23 23
24 24 def bail_if_changed(repo):
25 25 modified, added, removed, deleted, unknown = repo.changes()
26 26 if modified or added or removed or deleted:
27 27 raise util.Abort(_("outstanding uncommitted changes"))
28 28
29 29 def filterfiles(filters, files):
30 30 l = [x for x in files if x in filters]
31 31
32 32 for t in filters:
33 33 if t and t[-1] != "/":
34 34 t += "/"
35 35 l += [x for x in files if x.startswith(t)]
36 36 return l
37 37
38 38 def relpath(repo, args):
39 39 cwd = repo.getcwd()
40 40 if cwd:
41 41 return [util.normpath(os.path.join(cwd, x)) for x in args]
42 42 return args
43 43
44 44 def matchpats(repo, pats=[], opts={}, head=''):
45 45 cwd = repo.getcwd()
46 46 if not pats and cwd:
47 47 opts['include'] = [os.path.join(cwd, i) for i in opts['include']]
48 48 opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']]
49 49 cwd = ''
50 50 return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'),
51 51 opts.get('exclude'), head)
52 52
53 53 def makewalk(repo, pats, opts, node=None, head='', badmatch=None):
54 54 files, matchfn, anypats = matchpats(repo, pats, opts, head)
55 55 exact = dict(zip(files, files))
56 56 def walk():
57 57 for src, fn in repo.walk(node=node, files=files, match=matchfn,
58 58 badmatch=badmatch):
59 59 yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact
60 60 return files, matchfn, walk()
61 61
62 62 def walk(repo, pats, opts, node=None, head='', badmatch=None):
63 63 files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch)
64 64 for r in results:
65 65 yield r
66 66
67 67 def walkchangerevs(ui, repo, pats, opts):
68 68 '''Iterate over files and the revs they changed in.
69 69
70 70 Callers most commonly need to iterate backwards over the history
71 71 it is interested in. Doing so has awful (quadratic-looking)
72 72 performance, so we use iterators in a "windowed" way.
73 73
74 74 We walk a window of revisions in the desired order. Within the
75 75 window, we first walk forwards to gather data, then in the desired
76 76 order (usually backwards) to display it.
77 77
78 78 This function returns an (iterator, getchange, matchfn) tuple. The
79 79 getchange function returns the changelog entry for a numeric
80 80 revision. The iterator yields 3-tuples. They will be of one of
81 81 the following forms:
82 82
83 83 "window", incrementing, lastrev: stepping through a window,
84 84 positive if walking forwards through revs, last rev in the
85 85 sequence iterated over - use to reset state for the current window
86 86
87 87 "add", rev, fns: out-of-order traversal of the given file names
88 88 fns, which changed during revision rev - use to gather data for
89 89 possible display
90 90
91 91 "iter", rev, None: in-order traversal of the revs earlier iterated
92 92 over with "add" - use to display data'''
93 93
94 94 def increasing_windows(start, end, windowsize=8, sizelimit=512):
95 95 if start < end:
96 96 while start < end:
97 97 yield start, min(windowsize, end-start)
98 98 start += windowsize
99 99 if windowsize < sizelimit:
100 100 windowsize *= 2
101 101 else:
102 102 while start > end:
103 103 yield start, min(windowsize, start-end-1)
104 104 start -= windowsize
105 105 if windowsize < sizelimit:
106 106 windowsize *= 2
107 107
108 108
109 109 files, matchfn, anypats = matchpats(repo, pats, opts)
110 110
111 111 if repo.changelog.count() == 0:
112 112 return [], False, matchfn
113 113
114 114 revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0']))
115 115 wanted = {}
116 116 slowpath = anypats
117 117 fncache = {}
118 118
119 119 chcache = {}
120 120 def getchange(rev):
121 121 ch = chcache.get(rev)
122 122 if ch is None:
123 123 chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev)))
124 124 return ch
125 125
126 126 if not slowpath and not files:
127 127 # No files, no patterns. Display all revs.
128 128 wanted = dict(zip(revs, revs))
129 129 if not slowpath:
130 130 # Only files, no patterns. Check the history of each file.
131 131 def filerevgen(filelog):
132 132 for i, window in increasing_windows(filelog.count()-1, -1):
133 133 revs = []
134 134 for j in xrange(i - window, i + 1):
135 135 revs.append(filelog.linkrev(filelog.node(j)))
136 136 revs.reverse()
137 137 for rev in revs:
138 138 yield rev
139 139
140 140 minrev, maxrev = min(revs), max(revs)
141 141 for file_ in files:
142 142 filelog = repo.file(file_)
143 143 # A zero count may be a directory or deleted file, so
144 144 # try to find matching entries on the slow path.
145 145 if filelog.count() == 0:
146 146 slowpath = True
147 147 break
148 148 for rev in filerevgen(filelog):
149 149 if rev <= maxrev:
150 150 if rev < minrev:
151 151 break
152 152 fncache.setdefault(rev, [])
153 153 fncache[rev].append(file_)
154 154 wanted[rev] = 1
155 155 if slowpath:
156 156 # The slow path checks files modified in every changeset.
157 157 def changerevgen():
158 158 for i, window in increasing_windows(repo.changelog.count()-1, -1):
159 159 for j in xrange(i - window, i + 1):
160 160 yield j, getchange(j)[3]
161 161
162 162 for rev, changefiles in changerevgen():
163 163 matches = filter(matchfn, changefiles)
164 164 if matches:
165 165 fncache[rev] = matches
166 166 wanted[rev] = 1
167 167
168 168 def iterate():
169 169 for i, window in increasing_windows(0, len(revs)):
170 170 yield 'window', revs[0] < revs[-1], revs[-1]
171 171 nrevs = [rev for rev in revs[i:i+window]
172 172 if rev in wanted]
173 173 srevs = list(nrevs)
174 174 srevs.sort()
175 175 for rev in srevs:
176 176 fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3])
177 177 yield 'add', rev, fns
178 178 for rev in nrevs:
179 179 yield 'iter', rev, None
180 180 return iterate(), getchange, matchfn
181 181
182 182 revrangesep = ':'
183 183
184 184 def revfix(repo, val, defval):
185 185 '''turn user-level id of changeset into rev number.
186 186 user-level id can be tag, changeset, rev number, or negative rev
187 187 number relative to number of revs (-1 is tip, etc).'''
188 188 if not val:
189 189 return defval
190 190 try:
191 191 num = int(val)
192 192 if str(num) != val:
193 193 raise ValueError
194 194 if num < 0:
195 195 num += repo.changelog.count()
196 196 if num < 0:
197 197 num = 0
198 198 elif num >= repo.changelog.count():
199 199 raise ValueError
200 200 except ValueError:
201 201 try:
202 202 num = repo.changelog.rev(repo.lookup(val))
203 203 except KeyError:
204 204 raise util.Abort(_('invalid revision identifier %s'), val)
205 205 return num
206 206
207 207 def revpair(ui, repo, revs):
208 208 '''return pair of nodes, given list of revisions. second item can
209 209 be None, meaning use working dir.'''
210 210 if not revs:
211 211 return repo.dirstate.parents()[0], None
212 212 end = None
213 213 if len(revs) == 1:
214 214 start = revs[0]
215 215 if revrangesep in start:
216 216 start, end = start.split(revrangesep, 1)
217 217 start = revfix(repo, start, 0)
218 218 end = revfix(repo, end, repo.changelog.count() - 1)
219 219 else:
220 220 start = revfix(repo, start, None)
221 221 elif len(revs) == 2:
222 222 if revrangesep in revs[0] or revrangesep in revs[1]:
223 223 raise util.Abort(_('too many revisions specified'))
224 224 start = revfix(repo, revs[0], None)
225 225 end = revfix(repo, revs[1], None)
226 226 else:
227 227 raise util.Abort(_('too many revisions specified'))
228 228 if end is not None: end = repo.lookup(str(end))
229 229 return repo.lookup(str(start)), end
230 230
231 231 def revrange(ui, repo, revs):
232 232 """Yield revision as strings from a list of revision specifications."""
233 233 seen = {}
234 234 for spec in revs:
235 235 if spec.find(revrangesep) >= 0:
236 236 start, end = spec.split(revrangesep, 1)
237 237 start = revfix(repo, start, 0)
238 238 end = revfix(repo, end, repo.changelog.count() - 1)
239 239 step = start > end and -1 or 1
240 240 for rev in xrange(start, end+step, step):
241 241 if rev in seen:
242 242 continue
243 243 seen[rev] = 1
244 244 yield str(rev)
245 245 else:
246 246 rev = revfix(repo, spec, None)
247 247 if rev in seen:
248 248 continue
249 249 seen[rev] = 1
250 250 yield str(rev)
251 251
252 252 def make_filename(repo, r, pat, node=None,
253 253 total=None, seqno=None, revwidth=None, pathname=None):
254 254 node_expander = {
255 255 'H': lambda: hex(node),
256 256 'R': lambda: str(r.rev(node)),
257 257 'h': lambda: short(node),
258 258 }
259 259 expander = {
260 260 '%': lambda: '%',
261 261 'b': lambda: os.path.basename(repo.root),
262 262 }
263 263
264 264 try:
265 265 if node:
266 266 expander.update(node_expander)
267 267 if node and revwidth is not None:
268 268 expander['r'] = lambda: str(r.rev(node)).zfill(revwidth)
269 269 if total is not None:
270 270 expander['N'] = lambda: str(total)
271 271 if seqno is not None:
272 272 expander['n'] = lambda: str(seqno)
273 273 if total is not None and seqno is not None:
274 274 expander['n'] = lambda:str(seqno).zfill(len(str(total)))
275 275 if pathname is not None:
276 276 expander['s'] = lambda: os.path.basename(pathname)
277 277 expander['d'] = lambda: os.path.dirname(pathname) or '.'
278 278 expander['p'] = lambda: pathname
279 279
280 280 newname = []
281 281 patlen = len(pat)
282 282 i = 0
283 283 while i < patlen:
284 284 c = pat[i]
285 285 if c == '%':
286 286 i += 1
287 287 c = pat[i]
288 288 c = expander[c]()
289 289 newname.append(c)
290 290 i += 1
291 291 return ''.join(newname)
292 292 except KeyError, inst:
293 293 raise util.Abort(_("invalid format spec '%%%s' in output file name"),
294 294 inst.args[0])
295 295
296 296 def make_file(repo, r, pat, node=None,
297 297 total=None, seqno=None, revwidth=None, mode='wb', pathname=None):
298 298 if not pat or pat == '-':
299 299 return 'w' in mode and sys.stdout or sys.stdin
300 300 if hasattr(pat, 'write') and 'w' in mode:
301 301 return pat
302 302 if hasattr(pat, 'read') and 'r' in mode:
303 303 return pat
304 304 return open(make_filename(repo, r, pat, node, total, seqno, revwidth,
305 305 pathname),
306 306 mode)
307 307
308 308 def write_bundle(cg, filename=None, compress=True):
309 309 """Write a bundle file and return its filename.
310 310
311 311 Existing files will not be overwritten.
312 312 If no filename is specified, a temporary file is created.
313 313 bz2 compression can be turned off.
314 314 The bundle file will be deleted in case of errors.
315 315 """
316 316 class nocompress(object):
317 317 def compress(self, x):
318 318 return x
319 319 def flush(self):
320 320 return ""
321 321
322 322 fh = None
323 323 cleanup = None
324 324 try:
325 325 if filename:
326 326 if os.path.exists(filename):
327 327 raise util.Abort(_("file '%s' already exists"), filename)
328 328 fh = open(filename, "wb")
329 329 else:
330 330 fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
331 331 fh = os.fdopen(fd, "wb")
332 332 cleanup = filename
333 333
334 334 if compress:
335 335 fh.write("HG10")
336 336 z = bz2.BZ2Compressor(9)
337 337 else:
338 338 fh.write("HG10UN")
339 339 z = nocompress()
340 340 # parse the changegroup data, otherwise we will block
341 341 # in case of sshrepo because we don't know the end of the stream
342 342
343 343 # an empty chunkiter is the end of the changegroup
344 344 empty = False
345 345 while not empty:
346 346 empty = True
347 347 for chunk in changegroup.chunkiter(cg):
348 348 empty = False
349 349 fh.write(z.compress(changegroup.genchunk(chunk)))
350 350 fh.write(z.compress(changegroup.closechunk()))
351 351 fh.write(z.flush())
352 352 cleanup = None
353 353 return filename
354 354 finally:
355 355 if fh is not None:
356 356 fh.close()
357 357 if cleanup is not None:
358 358 os.unlink(cleanup)
359 359
360 360 def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
361 361 changes=None, text=False, opts={}):
362 362 if not node1:
363 363 node1 = repo.dirstate.parents()[0]
364 364 # reading the data for node1 early allows it to play nicely
365 365 # with repo.changes and the revlog cache.
366 366 change = repo.changelog.read(node1)
367 367 mmap = repo.manifest.read(change[0])
368 368 date1 = util.datestr(change[2])
369 369
370 370 if not changes:
371 371 changes = repo.changes(node1, node2, files, match=match)
372 372 modified, added, removed, deleted, unknown = changes
373 373 if files:
374 374 modified, added, removed = map(lambda x: filterfiles(files, x),
375 375 (modified, added, removed))
376 376
377 377 if not modified and not added and not removed:
378 378 return
379 379
380 380 if node2:
381 381 change = repo.changelog.read(node2)
382 382 mmap2 = repo.manifest.read(change[0])
383 383 date2 = util.datestr(change[2])
384 384 def read(f):
385 385 return repo.file(f).read(mmap2[f])
386 386 else:
387 387 date2 = util.datestr()
388 388 def read(f):
389 389 return repo.wread(f)
390 390
391 391 if ui.quiet:
392 392 r = None
393 393 else:
394 394 hexfunc = ui.verbose and hex or short
395 395 r = [hexfunc(node) for node in [node1, node2] if node]
396 396
397 397 diffopts = ui.diffopts()
398 398 showfunc = opts.get('show_function') or diffopts['showfunc']
399 399 ignorews = opts.get('ignore_all_space') or diffopts['ignorews']
400 400 for f in modified:
401 401 to = None
402 402 if f in mmap:
403 403 to = repo.file(f).read(mmap[f])
404 404 tn = read(f)
405 405 fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text,
406 406 showfunc=showfunc, ignorews=ignorews))
407 407 for f in added:
408 408 to = None
409 409 tn = read(f)
410 410 fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text,
411 411 showfunc=showfunc, ignorews=ignorews))
412 412 for f in removed:
413 413 to = repo.file(f).read(mmap[f])
414 414 tn = None
415 415 fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text,
416 416 showfunc=showfunc, ignorews=ignorews))
417 417
418 418 def trimuser(ui, name, rev, revcache):
419 419 """trim the name of the user who committed a change"""
420 420 user = revcache.get(rev)
421 421 if user is None:
422 422 user = revcache[rev] = ui.shortuser(name)
423 423 return user
424 424
425 425 class changeset_printer(object):
426 426 '''show changeset information when templating not requested.'''
427 427
428 428 def __init__(self, ui, repo):
429 429 self.ui = ui
430 430 self.repo = repo
431 431
432 432 def show(self, rev=0, changenode=None, brinfo=None):
433 433 '''show a single changeset or file revision'''
434 434 log = self.repo.changelog
435 435 if changenode is None:
436 436 changenode = log.node(rev)
437 437 elif not rev:
438 438 rev = log.rev(changenode)
439 439
440 440 if self.ui.quiet:
441 441 self.ui.write("%d:%s\n" % (rev, short(changenode)))
442 442 return
443 443
444 444 changes = log.read(changenode)
445 445 date = util.datestr(changes[2])
446 446
447 447 parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p))
448 448 for p in log.parents(changenode)
449 449 if self.ui.debugflag or p != nullid]
450 450 if (not self.ui.debugflag and len(parents) == 1 and
451 451 parents[0][0] == rev-1):
452 452 parents = []
453 453
454 454 if self.ui.verbose:
455 455 self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode)))
456 456 else:
457 457 self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode)))
458 458
459 459 for tag in self.repo.nodetags(changenode):
460 460 self.ui.status(_("tag: %s\n") % tag)
461 461 for parent in parents:
462 462 self.ui.write(_("parent: %d:%s\n") % parent)
463 463
464 464 if brinfo and changenode in brinfo:
465 465 br = brinfo[changenode]
466 466 self.ui.write(_("branch: %s\n") % " ".join(br))
467 467
468 468 self.ui.debug(_("manifest: %d:%s\n") %
469 469 (self.repo.manifest.rev(changes[0]), hex(changes[0])))
470 470 self.ui.status(_("user: %s\n") % changes[1])
471 471 self.ui.status(_("date: %s\n") % date)
472 472
473 473 if self.ui.debugflag:
474 474 files = self.repo.changes(log.parents(changenode)[0], changenode)
475 475 for key, value in zip([_("files:"), _("files+:"), _("files-:")],
476 476 files):
477 477 if value:
478 478 self.ui.note("%-12s %s\n" % (key, " ".join(value)))
479 479 else:
480 480 self.ui.note(_("files: %s\n") % " ".join(changes[3]))
481 481
482 482 description = changes[4].strip()
483 483 if description:
484 484 if self.ui.verbose:
485 485 self.ui.status(_("description:\n"))
486 486 self.ui.status(description)
487 487 self.ui.status("\n\n")
488 488 else:
489 489 self.ui.status(_("summary: %s\n") %
490 490 description.splitlines()[0])
491 491 self.ui.status("\n")
492 492
493 493 def show_changeset(ui, repo, opts):
494 494 '''show one changeset. uses template or regular display. caller
495 495 can pass in 'style' and 'template' options in opts.'''
496 496
497 497 tmpl = opts.get('template')
498 498 if tmpl:
499 499 tmpl = templater.parsestring(tmpl, quoted=False)
500 500 else:
501 501 tmpl = ui.config('ui', 'logtemplate')
502 502 if tmpl: tmpl = templater.parsestring(tmpl)
503 503 mapfile = opts.get('style') or ui.config('ui', 'style')
504 504 if tmpl or mapfile:
505 505 if mapfile:
506 506 if not os.path.isfile(mapfile):
507 507 mapname = templater.templatepath('map-cmdline.' + mapfile)
508 508 if not mapname: mapname = templater.templatepath(mapfile)
509 509 if mapname: mapfile = mapname
510 510 try:
511 511 t = templater.changeset_templater(ui, repo, mapfile)
512 512 except SyntaxError, inst:
513 513 raise util.Abort(inst.args[0])
514 514 if tmpl: t.use_template(tmpl)
515 515 return t
516 516 return changeset_printer(ui, repo)
517 517
518 518 def show_version(ui):
519 519 """output version and copyright information"""
520 520 ui.write(_("Mercurial Distributed SCM (version %s)\n")
521 521 % version.get_version())
522 522 ui.status(_(
523 523 "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n"
524 524 "This is free software; see the source for copying conditions. "
525 525 "There is NO\nwarranty; "
526 526 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
527 527 ))
528 528
529 529 def help_(ui, cmd=None, with_version=False):
530 530 """show help for a given command or all commands"""
531 531 option_lists = []
532 532 if cmd and cmd != 'shortlist':
533 533 if with_version:
534 534 show_version(ui)
535 535 ui.write('\n')
536 536 aliases, i = find(cmd)
537 537 # synopsis
538 538 ui.write("%s\n\n" % i[2])
539 539
540 540 # description
541 541 doc = i[0].__doc__
542 542 if not doc:
543 543 doc = _("(No help text available)")
544 544 if ui.quiet:
545 545 doc = doc.splitlines(0)[0]
546 546 ui.write("%s\n" % doc.rstrip())
547 547
548 548 if not ui.quiet:
549 549 # aliases
550 550 if len(aliases) > 1:
551 551 ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
552 552
553 553 # options
554 554 if i[1]:
555 555 option_lists.append(("options", i[1]))
556 556
557 557 else:
558 558 # program name
559 559 if ui.verbose or with_version:
560 560 show_version(ui)
561 561 else:
562 562 ui.status(_("Mercurial Distributed SCM\n"))
563 563 ui.status('\n')
564 564
565 565 # list of commands
566 566 if cmd == "shortlist":
567 567 ui.status(_('basic commands (use "hg help" '
568 568 'for the full list or option "-v" for details):\n\n'))
569 569 elif ui.verbose:
570 570 ui.status(_('list of commands:\n\n'))
571 571 else:
572 572 ui.status(_('list of commands (use "hg help -v" '
573 573 'to show aliases and global options):\n\n'))
574 574
575 575 h = {}
576 576 cmds = {}
577 577 for c, e in table.items():
578 578 f = c.split("|")[0]
579 579 if cmd == "shortlist" and not f.startswith("^"):
580 580 continue
581 581 f = f.lstrip("^")
582 582 if not ui.debugflag and f.startswith("debug"):
583 583 continue
584 584 doc = e[0].__doc__
585 585 if not doc:
586 586 doc = _("(No help text available)")
587 587 h[f] = doc.splitlines(0)[0].rstrip()
588 588 cmds[f] = c.lstrip("^")
589 589
590 590 fns = h.keys()
591 591 fns.sort()
592 592 m = max(map(len, fns))
593 593 for f in fns:
594 594 if ui.verbose:
595 595 commands = cmds[f].replace("|",", ")
596 596 ui.write(" %s:\n %s\n"%(commands, h[f]))
597 597 else:
598 598 ui.write(' %-*s %s\n' % (m, f, h[f]))
599 599
600 600 # global options
601 601 if ui.verbose:
602 602 option_lists.append(("global options", globalopts))
603 603
604 604 # list all option lists
605 605 opt_output = []
606 606 for title, options in option_lists:
607 607 opt_output.append(("\n%s:\n" % title, None))
608 608 for shortopt, longopt, default, desc in options:
609 609 opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt,
610 610 longopt and " --%s" % longopt),
611 611 "%s%s" % (desc,
612 612 default
613 613 and _(" (default: %s)") % default
614 614 or "")))
615 615
616 616 if opt_output:
617 617 opts_len = max([len(line[0]) for line in opt_output if line[1]])
618 618 for first, second in opt_output:
619 619 if second:
620 620 ui.write(" %-*s %s\n" % (opts_len, first, second))
621 621 else:
622 622 ui.write("%s\n" % first)
623 623
624 624 # Commands start here, listed alphabetically
625 625
626 626 def add(ui, repo, *pats, **opts):
627 627 """add the specified files on the next commit
628 628
629 629 Schedule files to be version controlled and added to the repository.
630 630
631 631 The files will be added to the repository at the next commit.
632 632
633 633 If no names are given, add all files in the repository.
634 634 """
635 635
636 636 names = []
637 637 for src, abs, rel, exact in walk(repo, pats, opts):
638 638 if exact:
639 639 if ui.verbose:
640 640 ui.status(_('adding %s\n') % rel)
641 641 names.append(abs)
642 642 elif repo.dirstate.state(abs) == '?':
643 643 ui.status(_('adding %s\n') % rel)
644 644 names.append(abs)
645 645 repo.add(names)
646 646
647 647 def addremove(ui, repo, *pats, **opts):
648 648 """add all new files, delete all missing files (DEPRECATED)
649 649
650 650 (DEPRECATED)
651 651 Add all new files and remove all missing files from the repository.
652 652
653 653 New files are ignored if they match any of the patterns in .hgignore. As
654 654 with add, these changes take effect at the next commit.
655 655
656 656 This command is now deprecated and will be removed in a future
657 657 release. Please use add and remove --after instead.
658 658 """
659 659 ui.warn(_('(the addremove command is deprecated; use add and remove '
660 660 '--after instead)\n'))
661 661 return addremove_lock(ui, repo, pats, opts)
662 662
663 663 def addremove_lock(ui, repo, pats, opts, wlock=None):
664 664 add, remove = [], []
665 665 for src, abs, rel, exact in walk(repo, pats, opts):
666 666 if src == 'f' and repo.dirstate.state(abs) == '?':
667 667 add.append(abs)
668 668 if ui.verbose or not exact:
669 669 ui.status(_('adding %s\n') % ((pats and rel) or abs))
670 670 if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel):
671 671 remove.append(abs)
672 672 if ui.verbose or not exact:
673 673 ui.status(_('removing %s\n') % ((pats and rel) or abs))
674 674 repo.add(add, wlock=wlock)
675 675 repo.remove(remove, wlock=wlock)
676 676
677 677 def annotate(ui, repo, *pats, **opts):
678 678 """show changeset information per file line
679 679
680 680 List changes in files, showing the revision id responsible for each line
681 681
682 682 This command is useful to discover who did a change or when a change took
683 683 place.
684 684
685 685 Without the -a option, annotate will avoid processing files it
686 686 detects as binary. With -a, annotate will generate an annotation
687 687 anyway, probably with undesirable results.
688 688 """
689 689 def getnode(rev):
690 690 return short(repo.changelog.node(rev))
691 691
692 692 ucache = {}
693 693 def getname(rev):
694 694 cl = repo.changelog.read(repo.changelog.node(rev))
695 695 return trimuser(ui, cl[1], rev, ucache)
696 696
697 697 dcache = {}
698 698 def getdate(rev):
699 699 datestr = dcache.get(rev)
700 700 if datestr is None:
701 701 cl = repo.changelog.read(repo.changelog.node(rev))
702 702 datestr = dcache[rev] = util.datestr(cl[2])
703 703 return datestr
704 704
705 705 if not pats:
706 706 raise util.Abort(_('at least one file name or pattern required'))
707 707
708 708 opmap = [['user', getname], ['number', str], ['changeset', getnode],
709 709 ['date', getdate]]
710 710 if not opts['user'] and not opts['changeset'] and not opts['date']:
711 711 opts['number'] = 1
712 712
713 713 if opts['rev']:
714 714 node = repo.changelog.lookup(opts['rev'])
715 715 else:
716 716 node = repo.dirstate.parents()[0]
717 717 change = repo.changelog.read(node)
718 718 mmap = repo.manifest.read(change[0])
719 719
720 720 for src, abs, rel, exact in walk(repo, pats, opts, node=node):
721 721 f = repo.file(abs)
722 722 if not opts['text'] and util.binary(f.read(mmap[abs])):
723 723 ui.write(_("%s: binary file\n") % ((pats and rel) or abs))
724 724 continue
725 725
726 726 lines = f.annotate(mmap[abs])
727 727 pieces = []
728 728
729 729 for o, f in opmap:
730 730 if opts[o]:
731 731 l = [f(n) for n, dummy in lines]
732 732 if l:
733 733 m = max(map(len, l))
734 734 pieces.append(["%*s" % (m, x) for x in l])
735 735
736 736 if pieces:
737 737 for p, l in zip(zip(*pieces), lines):
738 738 ui.write("%s: %s" % (" ".join(p), l[1]))
739 739
740 740 def archive(ui, repo, dest, **opts):
741 741 '''create unversioned archive of a repository revision
742 742
743 743 By default, the revision used is the parent of the working
744 744 directory; use "-r" to specify a different revision.
745 745
746 746 To specify the type of archive to create, use "-t". Valid
747 747 types are:
748 748
749 749 "files" (default): a directory full of files
750 750 "tar": tar archive, uncompressed
751 751 "tbz2": tar archive, compressed using bzip2
752 752 "tgz": tar archive, compressed using gzip
753 753 "uzip": zip archive, uncompressed
754 754 "zip": zip archive, compressed using deflate
755 755
756 756 The exact name of the destination archive or directory is given
757 757 using a format string; see "hg help export" for details.
758 758
759 759 Each member added to an archive file has a directory prefix
760 760 prepended. Use "-p" to specify a format string for the prefix.
761 761 The default is the basename of the archive, with suffixes removed.
762 762 '''
763 763
764 764 if opts['rev']:
765 765 node = repo.lookup(opts['rev'])
766 766 else:
767 767 node, p2 = repo.dirstate.parents()
768 768 if p2 != nullid:
769 769 raise util.Abort(_('uncommitted merge - please provide a '
770 770 'specific revision'))
771 771
772 772 dest = make_filename(repo, repo.changelog, dest, node)
773 773 prefix = make_filename(repo, repo.changelog, opts['prefix'], node)
774 774 if os.path.realpath(dest) == repo.root:
775 775 raise util.Abort(_('repository root cannot be destination'))
776 776 dummy, matchfn, dummy = matchpats(repo, [], opts)
777 777 archival.archive(repo, dest, node, opts.get('type') or 'files',
778 778 not opts['no_decode'], matchfn, prefix)
779 779
780 780 def backout(ui, repo, rev, **opts):
781 781 '''reverse effect of earlier changeset
782 782
783 783 Commit the backed out changes as a new changeset. The new
784 784 changeset is a child of the backed out changeset.
785 785
786 786 If you back out a changeset other than the tip, a new head is
787 787 created. This head is the parent of the working directory. If
788 788 you back out an old changeset, your working directory will appear
789 789 old after the backout. You should merge the backout changeset
790 790 with another head.
791 791
792 792 The --merge option remembers the parent of the working directory
793 793 before starting the backout, then merges the new head with that
794 794 changeset afterwards. This saves you from doing the merge by
795 795 hand. The result of this merge is not committed, as for a normal
796 796 merge.'''
797 797
798 798 bail_if_changed(repo)
799 799 op1, op2 = repo.dirstate.parents()
800 800 if op2 != nullid:
801 801 raise util.Abort(_('outstanding uncommitted merge'))
802 802 node = repo.lookup(rev)
803 803 parent, p2 = repo.changelog.parents(node)
804 804 if parent == nullid:
805 805 raise util.Abort(_('cannot back out a change with no parents'))
806 806 if p2 != nullid:
807 807 raise util.Abort(_('cannot back out a merge'))
808 808 repo.update(node, force=True, show_stats=False)
809 809 revert_opts = opts.copy()
810 810 revert_opts['rev'] = hex(parent)
811 811 revert(ui, repo, **revert_opts)
812 812 commit_opts = opts.copy()
813 813 commit_opts['addremove'] = False
814 814 if not commit_opts['message'] and not commit_opts['logfile']:
815 815 commit_opts['message'] = _("Backed out changeset %s") % (hex(node))
816 816 commit_opts['force_editor'] = True
817 817 commit(ui, repo, **commit_opts)
818 818 def nice(node):
819 819 return '%d:%s' % (repo.changelog.rev(node), short(node))
820 820 ui.status(_('changeset %s backs out changeset %s\n') %
821 821 (nice(repo.changelog.tip()), nice(node)))
822 822 if opts['merge'] and op1 != node:
823 823 ui.status(_('merging with changeset %s\n') % nice(op1))
824 824 doupdate(ui, repo, hex(op1), **opts)
825 825
826 826 def bundle(ui, repo, fname, dest="default-push", **opts):
827 827 """create a changegroup file
828 828
829 829 Generate a compressed changegroup file collecting all changesets
830 830 not found in the other repository.
831 831
832 832 This file can then be transferred using conventional means and
833 833 applied to another repository with the unbundle command. This is
834 834 useful when native push and pull are not available or when
835 835 exporting an entire repository is undesirable. The standard file
836 836 extension is ".hg".
837 837
838 838 Unlike import/export, this exactly preserves all changeset
839 839 contents including permissions, rename data, and revision history.
840 840 """
841 841 dest = ui.expandpath(dest)
842 842 other = hg.repository(ui, dest)
843 843 o = repo.findoutgoing(other, force=opts['force'])
844 844 cg = repo.changegroup(o, 'bundle')
845 845 write_bundle(cg, fname)
846 846
847 847 def cat(ui, repo, file1, *pats, **opts):
848 848 """output the latest or given revisions of files
849 849
850 850 Print the specified files as they were at the given revision.
851 851 If no revision is given then the tip is used.
852 852
853 853 Output may be to a file, in which case the name of the file is
854 854 given using a format string. The formatting rules are the same as
855 855 for the export command, with the following additions:
856 856
857 857 %s basename of file being printed
858 858 %d dirname of file being printed, or '.' if in repo root
859 859 %p root-relative path name of file being printed
860 860 """
861 861 mf = {}
862 862 rev = opts['rev']
863 863 if rev:
864 864 node = repo.lookup(rev)
865 865 else:
866 866 node = repo.changelog.tip()
867 867 change = repo.changelog.read(node)
868 868 mf = repo.manifest.read(change[0])
869 869 for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node):
870 870 r = repo.file(abs)
871 871 n = mf[abs]
872 872 fp = make_file(repo, r, opts['output'], node=n, pathname=abs)
873 873 fp.write(r.read(n))
874 874
875 875 def clone(ui, source, dest=None, **opts):
876 876 """make a copy of an existing repository
877 877
878 878 Create a copy of an existing repository in a new directory.
879 879
880 880 If no destination directory name is specified, it defaults to the
881 881 basename of the source.
882 882
883 883 The location of the source is added to the new repository's
884 884 .hg/hgrc file, as the default to be used for future pulls.
885 885
886 886 For efficiency, hardlinks are used for cloning whenever the source
887 887 and destination are on the same filesystem. Some filesystems,
888 888 such as AFS, implement hardlinking incorrectly, but do not report
889 889 errors. In these cases, use the --pull option to avoid
890 890 hardlinking.
891 891
892 892 See pull for valid source format details.
893 893 """
894 894 if dest is None:
895 895 dest = os.path.basename(os.path.normpath(source))
896 896
897 897 if os.path.exists(dest):
898 898 raise util.Abort(_("destination '%s' already exists"), dest)
899 899
900 900 dest = os.path.realpath(dest)
901 901
902 902 class Dircleanup(object):
903 903 def __init__(self, dir_):
904 904 self.rmtree = shutil.rmtree
905 905 self.dir_ = dir_
906 906 os.mkdir(dir_)
907 907 def close(self):
908 908 self.dir_ = None
909 909 def __del__(self):
910 910 if self.dir_:
911 911 self.rmtree(self.dir_, True)
912 912
913 913 if opts['ssh']:
914 914 ui.setconfig("ui", "ssh", opts['ssh'])
915 915 if opts['remotecmd']:
916 916 ui.setconfig("ui", "remotecmd", opts['remotecmd'])
917 917
918 918 source = ui.expandpath(source)
919 919
920 920 d = Dircleanup(dest)
921 921 abspath = source
922 922 other = hg.repository(ui, source)
923 923
924 924 copy = False
925 925 if other.dev() != -1:
926 926 abspath = os.path.abspath(source)
927 927 if not opts['pull'] and not opts['rev']:
928 928 copy = True
929 929
930 930 if copy:
931 931 try:
932 932 # we use a lock here because if we race with commit, we
933 933 # can end up with extra data in the cloned revlogs that's
934 934 # not pointed to by changesets, thus causing verify to
935 935 # fail
936 936 l1 = other.lock()
937 937 except lock.LockException:
938 938 copy = False
939 939
940 940 if copy:
941 941 # we lock here to avoid premature writing to the target
942 942 os.mkdir(os.path.join(dest, ".hg"))
943 943 l2 = lock.lock(os.path.join(dest, ".hg", "lock"))
944 944
945 945 files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i"
946 946 for f in files.split():
947 947 src = os.path.join(source, ".hg", f)
948 948 dst = os.path.join(dest, ".hg", f)
949 949 try:
950 950 util.copyfiles(src, dst)
951 951 except OSError, inst:
952 952 if inst.errno != errno.ENOENT:
953 953 raise
954 954
955 955 repo = hg.repository(ui, dest)
956 956
957 957 else:
958 958 revs = None
959 959 if opts['rev']:
960 960 if not other.local():
961 961 error = _("clone -r not supported yet for remote repositories.")
962 962 raise util.Abort(error)
963 963 else:
964 964 revs = [other.lookup(rev) for rev in opts['rev']]
965 965 repo = hg.repository(ui, dest, create=1)
966 966 repo.pull(other, heads = revs)
967 967
968 968 f = repo.opener("hgrc", "w", text=True)
969 969 f.write("[paths]\n")
970 970 f.write("default = %s\n" % abspath)
971 971 f.close()
972 972
973 973 if not opts['noupdate']:
974 974 doupdate(repo.ui, repo)
975 975
976 976 d.close()
977 977
978 978 def commit(ui, repo, *pats, **opts):
979 979 """commit the specified files or all outstanding changes
980 980
981 981 Commit changes to the given files into the repository.
982 982
983 983 If a list of files is omitted, all changes reported by "hg status"
984 984 will be committed.
985 985
986 986 If no commit message is specified, the editor configured in your hgrc
987 987 or in the EDITOR environment variable is started to enter a message.
988 988 """
989 989 message = opts['message']
990 990 logfile = opts['logfile']
991 991
992 992 if message and logfile:
993 993 raise util.Abort(_('options --message and --logfile are mutually '
994 994 'exclusive'))
995 995 if not message and logfile:
996 996 try:
997 997 if logfile == '-':
998 998 message = sys.stdin.read()
999 999 else:
1000 1000 message = open(logfile).read()
1001 1001 except IOError, inst:
1002 1002 raise util.Abort(_("can't read commit message '%s': %s") %
1003 1003 (logfile, inst.strerror))
1004 1004
1005 1005 if opts['addremove']:
1006 1006 addremove_lock(ui, repo, pats, opts)
1007 1007 fns, match, anypats = matchpats(repo, pats, opts)
1008 1008 if pats:
1009 1009 modified, added, removed, deleted, unknown = (
1010 1010 repo.changes(files=fns, match=match))
1011 1011 files = modified + added + removed
1012 1012 else:
1013 1013 files = []
1014 1014 try:
1015 1015 repo.commit(files, message, opts['user'], opts['date'], match,
1016 1016 force_editor=opts.get('force_editor'))
1017 1017 except ValueError, inst:
1018 1018 raise util.Abort(str(inst))
1019 1019
1020 1020 def docopy(ui, repo, pats, opts, wlock):
1021 1021 # called with the repo lock held
1022 1022 cwd = repo.getcwd()
1023 1023 errors = 0
1024 1024 copied = []
1025 1025 targets = {}
1026 1026
1027 1027 def okaytocopy(abs, rel, exact):
1028 1028 reasons = {'?': _('is not managed'),
1029 1029 'a': _('has been marked for add'),
1030 1030 'r': _('has been marked for remove')}
1031 1031 state = repo.dirstate.state(abs)
1032 1032 reason = reasons.get(state)
1033 1033 if reason:
1034 1034 if state == 'a':
1035 1035 origsrc = repo.dirstate.copied(abs)
1036 1036 if origsrc is not None:
1037 1037 return origsrc
1038 1038 if exact:
1039 1039 ui.warn(_('%s: not copying - file %s\n') % (rel, reason))
1040 1040 else:
1041 1041 return abs
1042 1042
1043 1043 def copy(origsrc, abssrc, relsrc, target, exact):
1044 1044 abstarget = util.canonpath(repo.root, cwd, target)
1045 1045 reltarget = util.pathto(cwd, abstarget)
1046 1046 prevsrc = targets.get(abstarget)
1047 1047 if prevsrc is not None:
1048 1048 ui.warn(_('%s: not overwriting - %s collides with %s\n') %
1049 1049 (reltarget, abssrc, prevsrc))
1050 1050 return
1051 1051 if (not opts['after'] and os.path.exists(reltarget) or
1052 1052 opts['after'] and repo.dirstate.state(abstarget) not in '?r'):
1053 1053 if not opts['force']:
1054 1054 ui.warn(_('%s: not overwriting - file exists\n') %
1055 1055 reltarget)
1056 1056 return
1057 1057 if not opts['after']:
1058 1058 os.unlink(reltarget)
1059 1059 if opts['after']:
1060 1060 if not os.path.exists(reltarget):
1061 1061 return
1062 1062 else:
1063 1063 targetdir = os.path.dirname(reltarget) or '.'
1064 1064 if not os.path.isdir(targetdir):
1065 1065 os.makedirs(targetdir)
1066 1066 try:
1067 1067 restore = repo.dirstate.state(abstarget) == 'r'
1068 1068 if restore:
1069 1069 repo.undelete([abstarget], wlock)
1070 1070 try:
1071 1071 shutil.copyfile(relsrc, reltarget)
1072 1072 shutil.copymode(relsrc, reltarget)
1073 1073 restore = False
1074 1074 finally:
1075 1075 if restore:
1076 1076 repo.remove([abstarget], wlock)
1077 1077 except shutil.Error, inst:
1078 1078 raise util.Abort(str(inst))
1079 1079 except IOError, inst:
1080 1080 if inst.errno == errno.ENOENT:
1081 1081 ui.warn(_('%s: deleted in working copy\n') % relsrc)
1082 1082 else:
1083 1083 ui.warn(_('%s: cannot copy - %s\n') %
1084 1084 (relsrc, inst.strerror))
1085 1085 errors += 1
1086 1086 return
1087 1087 if ui.verbose or not exact:
1088 1088 ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
1089 1089 targets[abstarget] = abssrc
1090 1090 if abstarget != origsrc:
1091 1091 repo.copy(origsrc, abstarget, wlock)
1092 1092 copied.append((abssrc, relsrc, exact))
1093 1093
1094 1094 def targetpathfn(pat, dest, srcs):
1095 1095 if os.path.isdir(pat):
1096 1096 abspfx = util.canonpath(repo.root, cwd, pat)
1097 1097 if destdirexists:
1098 1098 striplen = len(os.path.split(abspfx)[0])
1099 1099 else:
1100 1100 striplen = len(abspfx)
1101 1101 if striplen:
1102 1102 striplen += len(os.sep)
1103 1103 res = lambda p: os.path.join(dest, p[striplen:])
1104 1104 elif destdirexists:
1105 1105 res = lambda p: os.path.join(dest, os.path.basename(p))
1106 1106 else:
1107 1107 res = lambda p: dest
1108 1108 return res
1109 1109
1110 1110 def targetpathafterfn(pat, dest, srcs):
1111 1111 if util.patkind(pat, None)[0]:
1112 1112 # a mercurial pattern
1113 1113 res = lambda p: os.path.join(dest, os.path.basename(p))
1114 1114 else:
1115 1115 abspfx = util.canonpath(repo.root, cwd, pat)
1116 1116 if len(abspfx) < len(srcs[0][0]):
1117 1117 # A directory. Either the target path contains the last
1118 1118 # component of the source path or it does not.
1119 1119 def evalpath(striplen):
1120 1120 score = 0
1121 1121 for s in srcs:
1122 1122 t = os.path.join(dest, s[0][striplen:])
1123 1123 if os.path.exists(t):
1124 1124 score += 1
1125 1125 return score
1126 1126
1127 1127 striplen = len(abspfx)
1128 1128 if striplen:
1129 1129 striplen += len(os.sep)
1130 1130 if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])):
1131 1131 score = evalpath(striplen)
1132 1132 striplen1 = len(os.path.split(abspfx)[0])
1133 1133 if striplen1:
1134 1134 striplen1 += len(os.sep)
1135 1135 if evalpath(striplen1) > score:
1136 1136 striplen = striplen1
1137 1137 res = lambda p: os.path.join(dest, p[striplen:])
1138 1138 else:
1139 1139 # a file
1140 1140 if destdirexists:
1141 1141 res = lambda p: os.path.join(dest, os.path.basename(p))
1142 1142 else:
1143 1143 res = lambda p: dest
1144 1144 return res
1145 1145
1146 1146
1147 1147 pats = list(pats)
1148 1148 if not pats:
1149 1149 raise util.Abort(_('no source or destination specified'))
1150 1150 if len(pats) == 1:
1151 1151 raise util.Abort(_('no destination specified'))
1152 1152 dest = pats.pop()
1153 1153 destdirexists = os.path.isdir(dest)
1154 1154 if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists:
1155 1155 raise util.Abort(_('with multiple sources, destination must be an '
1156 1156 'existing directory'))
1157 1157 if opts['after']:
1158 1158 tfn = targetpathafterfn
1159 1159 else:
1160 1160 tfn = targetpathfn
1161 1161 copylist = []
1162 1162 for pat in pats:
1163 1163 srcs = []
1164 1164 for tag, abssrc, relsrc, exact in walk(repo, [pat], opts):
1165 1165 origsrc = okaytocopy(abssrc, relsrc, exact)
1166 1166 if origsrc:
1167 1167 srcs.append((origsrc, abssrc, relsrc, exact))
1168 1168 if not srcs:
1169 1169 continue
1170 1170 copylist.append((tfn(pat, dest, srcs), srcs))
1171 1171 if not copylist:
1172 1172 raise util.Abort(_('no files to copy'))
1173 1173
1174 1174 for targetpath, srcs in copylist:
1175 1175 for origsrc, abssrc, relsrc, exact in srcs:
1176 1176 copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact)
1177 1177
1178 1178 if errors:
1179 1179 ui.warn(_('(consider using --after)\n'))
1180 1180 return errors, copied
1181 1181
1182 1182 def copy(ui, repo, *pats, **opts):
1183 1183 """mark files as copied for the next commit
1184 1184
1185 1185 Mark dest as having copies of source files. If dest is a
1186 1186 directory, copies are put in that directory. If dest is a file,
1187 1187 there can only be one source.
1188 1188
1189 1189 By default, this command copies the contents of files as they
1190 1190 stand in the working directory. If invoked with --after, the
1191 1191 operation is recorded, but no copying is performed.
1192 1192
1193 1193 This command takes effect in the next commit.
1194 1194
1195 1195 NOTE: This command should be treated as experimental. While it
1196 1196 should properly record copied files, this information is not yet
1197 1197 fully used by merge, nor fully reported by log.
1198 1198 """
1199 1199 wlock = repo.wlock(0)
1200 1200 errs, copied = docopy(ui, repo, pats, opts, wlock)
1201 1201 return errs
1202 1202
1203 1203 def debugancestor(ui, index, rev1, rev2):
1204 1204 """find the ancestor revision of two revisions in a given index"""
1205 1205 r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "", 0)
1206 1206 a = r.ancestor(r.lookup(rev1), r.lookup(rev2))
1207 1207 ui.write("%d:%s\n" % (r.rev(a), hex(a)))
1208 1208
1209 1209 def debugcomplete(ui, cmd='', **opts):
1210 1210 """returns the completion list associated with the given command"""
1211 1211
1212 1212 if opts['options']:
1213 1213 options = []
1214 1214 otables = [globalopts]
1215 1215 if cmd:
1216 1216 aliases, entry = find(cmd)
1217 1217 otables.append(entry[1])
1218 1218 for t in otables:
1219 1219 for o in t:
1220 1220 if o[0]:
1221 1221 options.append('-%s' % o[0])
1222 1222 options.append('--%s' % o[1])
1223 1223 ui.write("%s\n" % "\n".join(options))
1224 1224 return
1225 1225
1226 1226 clist = findpossible(cmd).keys()
1227 1227 clist.sort()
1228 1228 ui.write("%s\n" % "\n".join(clist))
1229 1229
1230 1230 def debugrebuildstate(ui, repo, rev=None):
1231 1231 """rebuild the dirstate as it would look like for the given revision"""
1232 1232 if not rev:
1233 1233 rev = repo.changelog.tip()
1234 1234 else:
1235 1235 rev = repo.lookup(rev)
1236 1236 change = repo.changelog.read(rev)
1237 1237 n = change[0]
1238 1238 files = repo.manifest.readflags(n)
1239 1239 wlock = repo.wlock()
1240 1240 repo.dirstate.rebuild(rev, files.iteritems())
1241 1241
1242 1242 def debugcheckstate(ui, repo):
1243 1243 """validate the correctness of the current dirstate"""
1244 1244 parent1, parent2 = repo.dirstate.parents()
1245 1245 repo.dirstate.read()
1246 1246 dc = repo.dirstate.map
1247 1247 keys = dc.keys()
1248 1248 keys.sort()
1249 1249 m1n = repo.changelog.read(parent1)[0]
1250 1250 m2n = repo.changelog.read(parent2)[0]
1251 1251 m1 = repo.manifest.read(m1n)
1252 1252 m2 = repo.manifest.read(m2n)
1253 1253 errors = 0
1254 1254 for f in dc:
1255 1255 state = repo.dirstate.state(f)
1256 1256 if state in "nr" and f not in m1:
1257 1257 ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
1258 1258 errors += 1
1259 1259 if state in "a" and f in m1:
1260 1260 ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state))
1261 1261 errors += 1
1262 1262 if state in "m" and f not in m1 and f not in m2:
1263 1263 ui.warn(_("%s in state %s, but not in either manifest\n") %
1264 1264 (f, state))
1265 1265 errors += 1
1266 1266 for f in m1:
1267 1267 state = repo.dirstate.state(f)
1268 1268 if state not in "nrm":
1269 1269 ui.warn(_("%s in manifest1, but listed as state %s") % (f, state))
1270 1270 errors += 1
1271 1271 if errors:
1272 1272 error = _(".hg/dirstate inconsistent with current parent's manifest")
1273 1273 raise util.Abort(error)
1274 1274
1275 1275 def debugconfig(ui, repo):
1276 1276 """show combined config settings from all hgrc files"""
1277 1277 for section, name, value in ui.walkconfig():
1278 1278 ui.write('%s.%s=%s\n' % (section, name, value))
1279 1279
1280 1280 def debugsetparents(ui, repo, rev1, rev2=None):
1281 1281 """manually set the parents of the current working directory
1282 1282
1283 1283 This is useful for writing repository conversion tools, but should
1284 1284 be used with care.
1285 1285 """
1286 1286
1287 1287 if not rev2:
1288 1288 rev2 = hex(nullid)
1289 1289
1290 1290 repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2))
1291 1291
1292 1292 def debugstate(ui, repo):
1293 1293 """show the contents of the current dirstate"""
1294 1294 repo.dirstate.read()
1295 1295 dc = repo.dirstate.map
1296 1296 keys = dc.keys()
1297 1297 keys.sort()
1298 1298 for file_ in keys:
1299 1299 ui.write("%c %3o %10d %s %s\n"
1300 1300 % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2],
1301 1301 time.strftime("%x %X",
1302 1302 time.localtime(dc[file_][3])), file_))
1303 1303 for f in repo.dirstate.copies:
1304 1304 ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f))
1305 1305
1306 1306 def debugdata(ui, file_, rev):
1307 1307 """dump the contents of an data file revision"""
1308 1308 r = revlog.revlog(util.opener(os.getcwd(), audit=False),
1309 1309 file_[:-2] + ".i", file_, 0)
1310 1310 try:
1311 1311 ui.write(r.revision(r.lookup(rev)))
1312 1312 except KeyError:
1313 1313 raise util.Abort(_('invalid revision identifier %s'), rev)
1314 1314
1315 1315 def debugindex(ui, file_):
1316 1316 """dump the contents of an index file"""
1317 1317 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0)
1318 1318 ui.write(" rev offset length base linkrev" +
1319 1319 " nodeid p1 p2\n")
1320 1320 for i in range(r.count()):
1321 1321 node = r.node(i)
1322 1322 pp = r.parents(node)
1323 1323 ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % (
1324 1324 i, r.start(i), r.length(i), r.base(i), r.linkrev(node),
1325 1325 short(node), short(pp[0]), short(pp[1])))
1326 1326
1327 1327 def debugindexdot(ui, file_):
1328 1328 """dump an index DAG as a .dot file"""
1329 1329 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0)
1330 1330 ui.write("digraph G {\n")
1331 1331 for i in range(r.count()):
1332 1332 node = r.node(i)
1333 1333 pp = r.parents(node)
1334 1334 ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
1335 1335 if pp[1] != nullid:
1336 1336 ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
1337 1337 ui.write("}\n")
1338 1338
1339 1339 def debugrename(ui, repo, file, rev=None):
1340 1340 """dump rename information"""
1341 1341 r = repo.file(relpath(repo, [file])[0])
1342 1342 if rev:
1343 1343 try:
1344 1344 # assume all revision numbers are for changesets
1345 1345 n = repo.lookup(rev)
1346 1346 change = repo.changelog.read(n)
1347 1347 m = repo.manifest.read(change[0])
1348 1348 n = m[relpath(repo, [file])[0]]
1349 1349 except (hg.RepoError, KeyError):
1350 1350 n = r.lookup(rev)
1351 1351 else:
1352 1352 n = r.tip()
1353 1353 m = r.renamed(n)
1354 1354 if m:
1355 1355 ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1])))
1356 1356 else:
1357 1357 ui.write(_("not renamed\n"))
1358 1358
1359 1359 def debugwalk(ui, repo, *pats, **opts):
1360 1360 """show how files match on given patterns"""
1361 1361 items = list(walk(repo, pats, opts))
1362 1362 if not items:
1363 1363 return
1364 1364 fmt = '%%s %%-%ds %%-%ds %%s' % (
1365 1365 max([len(abs) for (src, abs, rel, exact) in items]),
1366 1366 max([len(rel) for (src, abs, rel, exact) in items]))
1367 1367 for src, abs, rel, exact in items:
1368 1368 line = fmt % (src, abs, rel, exact and 'exact' or '')
1369 1369 ui.write("%s\n" % line.rstrip())
1370 1370
1371 1371 def diff(ui, repo, *pats, **opts):
1372 1372 """diff repository (or selected files)
1373 1373
1374 1374 Show differences between revisions for the specified files.
1375 1375
1376 1376 Differences between files are shown using the unified diff format.
1377 1377
1378 1378 When two revision arguments are given, then changes are shown
1379 1379 between those revisions. If only one revision is specified then
1380 1380 that revision is compared to the working directory, and, when no
1381 1381 revisions are specified, the working directory files are compared
1382 1382 to its parent.
1383 1383
1384 1384 Without the -a option, diff will avoid generating diffs of files
1385 1385 it detects as binary. With -a, diff will generate a diff anyway,
1386 1386 probably with undesirable results.
1387 1387 """
1388 1388 node1, node2 = revpair(ui, repo, opts['rev'])
1389 1389
1390 1390 fns, matchfn, anypats = matchpats(repo, pats, opts)
1391 1391
1392 1392 dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn,
1393 1393 text=opts['text'], opts=opts)
1394 1394
1395 1395 def doexport(ui, repo, changeset, seqno, total, revwidth, opts):
1396 1396 node = repo.lookup(changeset)
1397 1397 parents = [p for p in repo.changelog.parents(node) if p != nullid]
1398 1398 if opts['switch_parent']:
1399 1399 parents.reverse()
1400 1400 prev = (parents and parents[0]) or nullid
1401 1401 change = repo.changelog.read(node)
1402 1402
1403 1403 fp = make_file(repo, repo.changelog, opts['output'],
1404 1404 node=node, total=total, seqno=seqno,
1405 1405 revwidth=revwidth)
1406 1406 if fp != sys.stdout:
1407 1407 ui.note("%s\n" % fp.name)
1408 1408
1409 1409 fp.write("# HG changeset patch\n")
1410 1410 fp.write("# User %s\n" % change[1])
1411 1411 fp.write("# Date %d %d\n" % change[2])
1412 1412 fp.write("# Node ID %s\n" % hex(node))
1413 1413 fp.write("# Parent %s\n" % hex(prev))
1414 1414 if len(parents) > 1:
1415 1415 fp.write("# Parent %s\n" % hex(parents[1]))
1416 1416 fp.write(change[4].rstrip())
1417 1417 fp.write("\n\n")
1418 1418
1419 1419 dodiff(fp, ui, repo, prev, node, text=opts['text'])
1420 1420 if fp != sys.stdout:
1421 1421 fp.close()
1422 1422
1423 1423 def export(ui, repo, *changesets, **opts):
1424 1424 """dump the header and diffs for one or more changesets
1425 1425
1426 1426 Print the changeset header and diffs for one or more revisions.
1427 1427
1428 1428 The information shown in the changeset header is: author,
1429 1429 changeset hash, parent and commit comment.
1430 1430
1431 1431 Output may be to a file, in which case the name of the file is
1432 1432 given using a format string. The formatting rules are as follows:
1433 1433
1434 1434 %% literal "%" character
1435 1435 %H changeset hash (40 bytes of hexadecimal)
1436 1436 %N number of patches being generated
1437 1437 %R changeset revision number
1438 1438 %b basename of the exporting repository
1439 1439 %h short-form changeset hash (12 bytes of hexadecimal)
1440 1440 %n zero-padded sequence number, starting at 1
1441 1441 %r zero-padded changeset revision number
1442 1442
1443 1443 Without the -a option, export will avoid generating diffs of files
1444 1444 it detects as binary. With -a, export will generate a diff anyway,
1445 1445 probably with undesirable results.
1446 1446
1447 1447 With the --switch-parent option, the diff will be against the second
1448 1448 parent. It can be useful to review a merge.
1449 1449 """
1450 1450 if not changesets:
1451 1451 raise util.Abort(_("export requires at least one changeset"))
1452 1452 seqno = 0
1453 1453 revs = list(revrange(ui, repo, changesets))
1454 1454 total = len(revs)
1455 1455 revwidth = max(map(len, revs))
1456 1456 msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n")
1457 1457 ui.note(msg)
1458 1458 for cset in revs:
1459 1459 seqno += 1
1460 1460 doexport(ui, repo, cset, seqno, total, revwidth, opts)
1461 1461
1462 1462 def forget(ui, repo, *pats, **opts):
1463 1463 """don't add the specified files on the next commit (DEPRECATED)
1464 1464
1465 1465 (DEPRECATED)
1466 1466 Undo an 'hg add' scheduled for the next commit.
1467 1467
1468 1468 This command is now deprecated and will be removed in a future
1469 1469 release. Please use revert instead.
1470 1470 """
1471 1471 ui.warn(_("(the forget command is deprecated; use revert instead)\n"))
1472 1472 forget = []
1473 1473 for src, abs, rel, exact in walk(repo, pats, opts):
1474 1474 if repo.dirstate.state(abs) == 'a':
1475 1475 forget.append(abs)
1476 1476 if ui.verbose or not exact:
1477 1477 ui.status(_('forgetting %s\n') % ((pats and rel) or abs))
1478 1478 repo.forget(forget)
1479 1479
1480 1480 def grep(ui, repo, pattern, *pats, **opts):
1481 1481 """search for a pattern in specified files and revisions
1482 1482
1483 1483 Search revisions of files for a regular expression.
1484 1484
1485 1485 This command behaves differently than Unix grep. It only accepts
1486 1486 Python/Perl regexps. It searches repository history, not the
1487 1487 working directory. It always prints the revision number in which
1488 1488 a match appears.
1489 1489
1490 1490 By default, grep only prints output for the first revision of a
1491 1491 file in which it finds a match. To get it to print every revision
1492 1492 that contains a change in match status ("-" for a match that
1493 1493 becomes a non-match, or "+" for a non-match that becomes a match),
1494 1494 use the --all flag.
1495 1495 """
1496 1496 reflags = 0
1497 1497 if opts['ignore_case']:
1498 1498 reflags |= re.I
1499 1499 regexp = re.compile(pattern, reflags)
1500 1500 sep, eol = ':', '\n'
1501 1501 if opts['print0']:
1502 1502 sep = eol = '\0'
1503 1503
1504 1504 fcache = {}
1505 1505 def getfile(fn):
1506 1506 if fn not in fcache:
1507 1507 fcache[fn] = repo.file(fn)
1508 1508 return fcache[fn]
1509 1509
1510 1510 def matchlines(body):
1511 1511 begin = 0
1512 1512 linenum = 0
1513 1513 while True:
1514 1514 match = regexp.search(body, begin)
1515 1515 if not match:
1516 1516 break
1517 1517 mstart, mend = match.span()
1518 1518 linenum += body.count('\n', begin, mstart) + 1
1519 1519 lstart = body.rfind('\n', begin, mstart) + 1 or begin
1520 1520 lend = body.find('\n', mend)
1521 1521 yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
1522 1522 begin = lend + 1
1523 1523
1524 1524 class linestate(object):
1525 1525 def __init__(self, line, linenum, colstart, colend):
1526 1526 self.line = line
1527 1527 self.linenum = linenum
1528 1528 self.colstart = colstart
1529 1529 self.colend = colend
1530 1530 def __eq__(self, other):
1531 1531 return self.line == other.line
1532 1532 def __hash__(self):
1533 1533 return hash(self.line)
1534 1534
1535 1535 matches = {}
1536 1536 def grepbody(fn, rev, body):
1537 1537 matches[rev].setdefault(fn, {})
1538 1538 m = matches[rev][fn]
1539 1539 for lnum, cstart, cend, line in matchlines(body):
1540 1540 s = linestate(line, lnum, cstart, cend)
1541 1541 m[s] = s
1542 1542
1543 1543 # FIXME: prev isn't used, why ?
1544 1544 prev = {}
1545 1545 ucache = {}
1546 1546 def display(fn, rev, states, prevstates):
1547 1547 diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates)))
1548 1548 diff.sort(lambda x, y: cmp(x.linenum, y.linenum))
1549 1549 counts = {'-': 0, '+': 0}
1550 1550 filerevmatches = {}
1551 1551 for l in diff:
1552 1552 if incrementing or not opts['all']:
1553 1553 change = ((l in prevstates) and '-') or '+'
1554 1554 r = rev
1555 1555 else:
1556 1556 change = ((l in states) and '-') or '+'
1557 1557 r = prev[fn]
1558 1558 cols = [fn, str(rev)]
1559 1559 if opts['line_number']:
1560 1560 cols.append(str(l.linenum))
1561 1561 if opts['all']:
1562 1562 cols.append(change)
1563 1563 if opts['user']:
1564 1564 cols.append(trimuser(ui, getchange(rev)[1], rev,
1565 1565 ucache))
1566 1566 if opts['files_with_matches']:
1567 1567 c = (fn, rev)
1568 1568 if c in filerevmatches:
1569 1569 continue
1570 1570 filerevmatches[c] = 1
1571 1571 else:
1572 1572 cols.append(l.line)
1573 1573 ui.write(sep.join(cols), eol)
1574 1574 counts[change] += 1
1575 1575 return counts['+'], counts['-']
1576 1576
1577 1577 fstate = {}
1578 1578 skip = {}
1579 1579 changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts)
1580 1580 count = 0
1581 1581 incrementing = False
1582 1582 for st, rev, fns in changeiter:
1583 1583 if st == 'window':
1584 1584 incrementing = rev
1585 1585 matches.clear()
1586 1586 elif st == 'add':
1587 1587 change = repo.changelog.read(repo.lookup(str(rev)))
1588 1588 mf = repo.manifest.read(change[0])
1589 1589 matches[rev] = {}
1590 1590 for fn in fns:
1591 1591 if fn in skip:
1592 1592 continue
1593 1593 fstate.setdefault(fn, {})
1594 1594 try:
1595 1595 grepbody(fn, rev, getfile(fn).read(mf[fn]))
1596 1596 except KeyError:
1597 1597 pass
1598 1598 elif st == 'iter':
1599 1599 states = matches[rev].items()
1600 1600 states.sort()
1601 1601 for fn, m in states:
1602 1602 if fn in skip:
1603 1603 continue
1604 1604 if incrementing or not opts['all'] or fstate[fn]:
1605 1605 pos, neg = display(fn, rev, m, fstate[fn])
1606 1606 count += pos + neg
1607 1607 if pos and not opts['all']:
1608 1608 skip[fn] = True
1609 1609 fstate[fn] = m
1610 1610 prev[fn] = rev
1611 1611
1612 1612 if not incrementing:
1613 1613 fstate = fstate.items()
1614 1614 fstate.sort()
1615 1615 for fn, state in fstate:
1616 1616 if fn in skip:
1617 1617 continue
1618 1618 display(fn, rev, {}, state)
1619 1619 return (count == 0 and 1) or 0
1620 1620
1621 1621 def heads(ui, repo, **opts):
1622 1622 """show current repository heads
1623 1623
1624 1624 Show all repository head changesets.
1625 1625
1626 1626 Repository "heads" are changesets that don't have children
1627 1627 changesets. They are where development generally takes place and
1628 1628 are the usual targets for update and merge operations.
1629 1629 """
1630 1630 if opts['rev']:
1631 1631 heads = repo.heads(repo.lookup(opts['rev']))
1632 1632 else:
1633 1633 heads = repo.heads()
1634 1634 br = None
1635 1635 if opts['branches']:
1636 1636 br = repo.branchlookup(heads)
1637 1637 displayer = show_changeset(ui, repo, opts)
1638 1638 for n in heads:
1639 1639 displayer.show(changenode=n, brinfo=br)
1640 1640
1641 1641 def identify(ui, repo):
1642 1642 """print information about the working copy
1643 1643
1644 1644 Print a short summary of the current state of the repo.
1645 1645
1646 1646 This summary identifies the repository state using one or two parent
1647 1647 hash identifiers, followed by a "+" if there are uncommitted changes
1648 1648 in the working directory, followed by a list of tags for this revision.
1649 1649 """
1650 1650 parents = [p for p in repo.dirstate.parents() if p != nullid]
1651 1651 if not parents:
1652 1652 ui.write(_("unknown\n"))
1653 1653 return
1654 1654
1655 1655 hexfunc = ui.verbose and hex or short
1656 1656 modified, added, removed, deleted, unknown = repo.changes()
1657 1657 output = ["%s%s" %
1658 1658 ('+'.join([hexfunc(parent) for parent in parents]),
1659 1659 (modified or added or removed or deleted) and "+" or "")]
1660 1660
1661 1661 if not ui.quiet:
1662 1662 # multiple tags for a single parent separated by '/'
1663 1663 parenttags = ['/'.join(tags)
1664 1664 for tags in map(repo.nodetags, parents) if tags]
1665 1665 # tags for multiple parents separated by ' + '
1666 1666 if parenttags:
1667 1667 output.append(' + '.join(parenttags))
1668 1668
1669 1669 ui.write("%s\n" % ' '.join(output))
1670 1670
1671 1671 def import_(ui, repo, patch1, *patches, **opts):
1672 1672 """import an ordered set of patches
1673 1673
1674 1674 Import a list of patches and commit them individually.
1675 1675
1676 1676 If there are outstanding changes in the working directory, import
1677 1677 will abort unless given the -f flag.
1678 1678
1679 1679 If a patch looks like a mail message (its first line starts with
1680 1680 "From " or looks like an RFC822 header), it will not be applied
1681 1681 unless the -f option is used. The importer neither parses nor
1682 1682 discards mail headers, so use -f only to override the "mailness"
1683 1683 safety check, not to import a real mail message.
1684 1684 """
1685 1685 patches = (patch1,) + patches
1686 1686
1687 1687 if not opts['force']:
1688 1688 bail_if_changed(repo)
1689 1689
1690 1690 d = opts["base"]
1691 1691 strip = opts["strip"]
1692 1692
1693 1693 mailre = re.compile(r'(?:From |[\w-]+:)')
1694 1694
1695 1695 # attempt to detect the start of a patch
1696 1696 # (this heuristic is borrowed from quilt)
1697 1697 diffre = re.compile(r'(?:Index:[ \t]|diff[ \t]|RCS file: |' +
1698 1698 'retrieving revision [0-9]+(\.[0-9]+)*$|' +
1699 1699 '(---|\*\*\*)[ \t])')
1700 1700
1701 1701 for patch in patches:
1702 1702 ui.status(_("applying %s\n") % patch)
1703 1703 pf = os.path.join(d, patch)
1704 1704
1705 1705 message = []
1706 1706 user = None
1707 1707 date = None
1708 1708 hgpatch = False
1709 1709 for line in file(pf):
1710 1710 line = line.rstrip()
1711 1711 if (not message and not hgpatch and
1712 1712 mailre.match(line) and not opts['force']):
1713 1713 if len(line) > 35:
1714 1714 line = line[:32] + '...'
1715 1715 raise util.Abort(_('first line looks like a '
1716 1716 'mail header: ') + line)
1717 1717 if diffre.match(line):
1718 1718 break
1719 1719 elif hgpatch:
1720 1720 # parse values when importing the result of an hg export
1721 1721 if line.startswith("# User "):
1722 1722 user = line[7:]
1723 1723 ui.debug(_('User: %s\n') % user)
1724 1724 elif line.startswith("# Date "):
1725 1725 date = line[7:]
1726 1726 elif not line.startswith("# ") and line:
1727 1727 message.append(line)
1728 1728 hgpatch = False
1729 1729 elif line == '# HG changeset patch':
1730 1730 hgpatch = True
1731 1731 message = [] # We may have collected garbage
1732 1732 elif message or line:
1733 1733 message.append(line)
1734 1734
1735 1735 # make sure message isn't empty
1736 1736 if not message:
1737 1737 message = _("imported patch %s\n") % patch
1738 1738 else:
1739 1739 message = '\n'.join(message).rstrip()
1740 1740 ui.debug(_('message:\n%s\n') % message)
1741 1741
1742 1742 files = util.patch(strip, pf, ui)
1743 1743
1744 1744 if len(files) > 0:
1745 1745 addremove_lock(ui, repo, files, {})
1746 1746 repo.commit(files, message, user, date)
1747 1747
1748 1748 def incoming(ui, repo, source="default", **opts):
1749 1749 """show new changesets found in source
1750 1750
1751 1751 Show new changesets found in the specified path/URL or the default
1752 1752 pull location. These are the changesets that would be pulled if a pull
1753 1753 was requested.
1754 1754
1755 1755 For remote repository, using --bundle avoids downloading the changesets
1756 1756 twice if the incoming is followed by a pull.
1757 1757
1758 1758 See pull for valid source format details.
1759 1759 """
1760 1760 source = ui.expandpath(source)
1761 1761 if opts['ssh']:
1762 1762 ui.setconfig("ui", "ssh", opts['ssh'])
1763 1763 if opts['remotecmd']:
1764 1764 ui.setconfig("ui", "remotecmd", opts['remotecmd'])
1765 1765
1766 1766 other = hg.repository(ui, source)
1767 1767 incoming = repo.findincoming(other, force=opts["force"])
1768 1768 if not incoming:
1769 1769 ui.status(_("no changes found\n"))
1770 1770 return
1771 1771
1772 1772 cleanup = None
1773 1773 try:
1774 1774 fname = opts["bundle"]
1775 1775 if fname or not other.local():
1776 1776 # create a bundle (uncompressed if other repo is not local)
1777 1777 cg = other.changegroup(incoming, "incoming")
1778 1778 fname = cleanup = write_bundle(cg, fname, compress=other.local())
1779 1779 # keep written bundle?
1780 1780 if opts["bundle"]:
1781 1781 cleanup = None
1782 1782 if not other.local():
1783 1783 # use the created uncompressed bundlerepo
1784 1784 other = bundlerepo.bundlerepository(ui, repo.root, fname)
1785 1785
1786 1786 o = other.changelog.nodesbetween(incoming)[0]
1787 1787 if opts['newest_first']:
1788 1788 o.reverse()
1789 1789 displayer = show_changeset(ui, other, opts)
1790 1790 for n in o:
1791 1791 parents = [p for p in other.changelog.parents(n) if p != nullid]
1792 1792 if opts['no_merges'] and len(parents) == 2:
1793 1793 continue
1794 1794 displayer.show(changenode=n)
1795 1795 if opts['patch']:
1796 1796 prev = (parents and parents[0]) or nullid
1797 1797 dodiff(ui, ui, other, prev, n)
1798 1798 ui.write("\n")
1799 1799 finally:
1800 1800 if hasattr(other, 'close'):
1801 1801 other.close()
1802 1802 if cleanup:
1803 1803 os.unlink(cleanup)
1804 1804
1805 1805 def init(ui, dest="."):
1806 1806 """create a new repository in the given directory
1807 1807
1808 1808 Initialize a new repository in the given directory. If the given
1809 1809 directory does not exist, it is created.
1810 1810
1811 1811 If no directory is given, the current directory is used.
1812 1812 """
1813 1813 if not os.path.exists(dest):
1814 1814 os.mkdir(dest)
1815 1815 hg.repository(ui, dest, create=1)
1816 1816
1817 1817 def locate(ui, repo, *pats, **opts):
1818 1818 """locate files matching specific patterns
1819 1819
1820 1820 Print all files under Mercurial control whose names match the
1821 1821 given patterns.
1822 1822
1823 1823 This command searches the current directory and its
1824 1824 subdirectories. To search an entire repository, move to the root
1825 1825 of the repository.
1826 1826
1827 1827 If no patterns are given to match, this command prints all file
1828 1828 names.
1829 1829
1830 1830 If you want to feed the output of this command into the "xargs"
1831 1831 command, use the "-0" option to both this command and "xargs".
1832 1832 This will avoid the problem of "xargs" treating single filenames
1833 1833 that contain white space as multiple filenames.
1834 1834 """
1835 1835 end = opts['print0'] and '\0' or '\n'
1836 1836 rev = opts['rev']
1837 1837 if rev:
1838 1838 node = repo.lookup(rev)
1839 1839 else:
1840 1840 node = None
1841 1841
1842 1842 for src, abs, rel, exact in walk(repo, pats, opts, node=node,
1843 1843 head='(?:.*/|)'):
1844 1844 if not node and repo.dirstate.state(abs) == '?':
1845 1845 continue
1846 1846 if opts['fullpath']:
1847 1847 ui.write(os.path.join(repo.root, abs), end)
1848 1848 else:
1849 1849 ui.write(((pats and rel) or abs), end)
1850 1850
1851 1851 def log(ui, repo, *pats, **opts):
1852 1852 """show revision history of entire repository or files
1853 1853
1854 1854 Print the revision history of the specified files or the entire project.
1855 1855
1856 1856 By default this command outputs: changeset id and hash, tags,
1857 1857 non-trivial parents, user, date and time, and a summary for each
1858 1858 commit. When the -v/--verbose switch is used, the list of changed
1859 1859 files and full commit message is shown.
1860 1860 """
1861 1861 class dui(object):
1862 1862 # Implement and delegate some ui protocol. Save hunks of
1863 1863 # output for later display in the desired order.
1864 1864 def __init__(self, ui):
1865 1865 self.ui = ui
1866 1866 self.hunk = {}
1867 1867 self.header = {}
1868 1868 def bump(self, rev):
1869 1869 self.rev = rev
1870 1870 self.hunk[rev] = []
1871 1871 self.header[rev] = []
1872 1872 def note(self, *args):
1873 1873 if self.verbose:
1874 1874 self.write(*args)
1875 1875 def status(self, *args):
1876 1876 if not self.quiet:
1877 1877 self.write(*args)
1878 1878 def write(self, *args):
1879 1879 self.hunk[self.rev].append(args)
1880 1880 def write_header(self, *args):
1881 1881 self.header[self.rev].append(args)
1882 1882 def debug(self, *args):
1883 1883 if self.debugflag:
1884 1884 self.write(*args)
1885 1885 def __getattr__(self, key):
1886 1886 return getattr(self.ui, key)
1887 1887
1888 1888 changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts)
1889 1889
1890 1890 if opts['limit']:
1891 1891 try:
1892 1892 limit = int(opts['limit'])
1893 1893 except ValueError:
1894 1894 raise util.Abort(_('limit must be a positive integer'))
1895 1895 if limit <= 0: raise util.Abort(_('limit must be positive'))
1896 1896 else:
1897 1897 limit = sys.maxint
1898 1898 count = 0
1899 1899
1900 1900 displayer = show_changeset(ui, repo, opts)
1901 1901 for st, rev, fns in changeiter:
1902 1902 if st == 'window':
1903 1903 du = dui(ui)
1904 1904 displayer.ui = du
1905 1905 elif st == 'add':
1906 1906 du.bump(rev)
1907 1907 changenode = repo.changelog.node(rev)
1908 1908 parents = [p for p in repo.changelog.parents(changenode)
1909 1909 if p != nullid]
1910 1910 if opts['no_merges'] and len(parents) == 2:
1911 1911 continue
1912 1912 if opts['only_merges'] and len(parents) != 2:
1913 1913 continue
1914 1914
1915 1915 if opts['keyword']:
1916 1916 changes = getchange(rev)
1917 1917 miss = 0
1918 1918 for k in [kw.lower() for kw in opts['keyword']]:
1919 1919 if not (k in changes[1].lower() or
1920 1920 k in changes[4].lower() or
1921 1921 k in " ".join(changes[3][:20]).lower()):
1922 1922 miss = 1
1923 1923 break
1924 1924 if miss:
1925 1925 continue
1926 1926
1927 1927 br = None
1928 1928 if opts['branches']:
1929 1929 br = repo.branchlookup([repo.changelog.node(rev)])
1930 1930
1931 1931 displayer.show(rev, brinfo=br)
1932 1932 if opts['patch']:
1933 1933 prev = (parents and parents[0]) or nullid
1934 1934 dodiff(du, du, repo, prev, changenode, match=matchfn)
1935 1935 du.write("\n\n")
1936 1936 elif st == 'iter':
1937 1937 if count == limit: break
1938 1938 if du.header[rev]:
1939 1939 for args in du.header[rev]:
1940 1940 ui.write_header(*args)
1941 1941 if du.hunk[rev]:
1942 1942 count += 1
1943 1943 for args in du.hunk[rev]:
1944 1944 ui.write(*args)
1945 1945
1946 1946 def manifest(ui, repo, rev=None):
1947 1947 """output the latest or given revision of the project manifest
1948 1948
1949 1949 Print a list of version controlled files for the given revision.
1950 1950
1951 1951 The manifest is the list of files being version controlled. If no revision
1952 1952 is given then the tip is used.
1953 1953 """
1954 1954 if rev:
1955 1955 try:
1956 1956 # assume all revision numbers are for changesets
1957 1957 n = repo.lookup(rev)
1958 1958 change = repo.changelog.read(n)
1959 1959 n = change[0]
1960 1960 except hg.RepoError:
1961 1961 n = repo.manifest.lookup(rev)
1962 1962 else:
1963 1963 n = repo.manifest.tip()
1964 1964 m = repo.manifest.read(n)
1965 1965 mf = repo.manifest.readflags(n)
1966 1966 files = m.keys()
1967 1967 files.sort()
1968 1968
1969 1969 for f in files:
1970 1970 ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f))
1971 1971
1972 1972 def merge(ui, repo, node=None, **opts):
1973 1973 """Merge working directory with another revision
1974 1974
1975 1975 Merge the contents of the current working directory and the
1976 1976 requested revision. Files that changed between either parent are
1977 1977 marked as changed for the next commit and a commit must be
1978 1978 performed before any further updates are allowed.
1979 1979 """
1980 1980 return doupdate(ui, repo, node=node, merge=True, **opts)
1981 1981
1982 1982 def outgoing(ui, repo, dest="default-push", **opts):
1983 1983 """show changesets not found in destination
1984 1984
1985 1985 Show changesets not found in the specified destination repository or
1986 1986 the default push location. These are the changesets that would be pushed
1987 1987 if a push was requested.
1988 1988
1989 1989 See pull for valid destination format details.
1990 1990 """
1991 1991 dest = ui.expandpath(dest)
1992 1992 if opts['ssh']:
1993 1993 ui.setconfig("ui", "ssh", opts['ssh'])
1994 1994 if opts['remotecmd']:
1995 1995 ui.setconfig("ui", "remotecmd", opts['remotecmd'])
1996 1996
1997 1997 other = hg.repository(ui, dest)
1998 1998 o = repo.findoutgoing(other, force=opts['force'])
1999 1999 if not o:
2000 2000 ui.status(_("no changes found\n"))
2001 2001 return
2002 2002 o = repo.changelog.nodesbetween(o)[0]
2003 2003 if opts['newest_first']:
2004 2004 o.reverse()
2005 2005 displayer = show_changeset(ui, repo, opts)
2006 2006 for n in o:
2007 2007 parents = [p for p in repo.changelog.parents(n) if p != nullid]
2008 2008 if opts['no_merges'] and len(parents) == 2:
2009 2009 continue
2010 2010 displayer.show(changenode=n)
2011 2011 if opts['patch']:
2012 2012 prev = (parents and parents[0]) or nullid
2013 2013 dodiff(ui, ui, repo, prev, n)
2014 2014 ui.write("\n")
2015 2015
2016 2016 def parents(ui, repo, rev=None, branches=None, **opts):
2017 2017 """show the parents of the working dir or revision
2018 2018
2019 2019 Print the working directory's parent revisions.
2020 2020 """
2021 2021 if rev:
2022 2022 p = repo.changelog.parents(repo.lookup(rev))
2023 2023 else:
2024 2024 p = repo.dirstate.parents()
2025 2025
2026 2026 br = None
2027 2027 if branches is not None:
2028 2028 br = repo.branchlookup(p)
2029 2029 displayer = show_changeset(ui, repo, opts)
2030 2030 for n in p:
2031 2031 if n != nullid:
2032 2032 displayer.show(changenode=n, brinfo=br)
2033 2033
2034 2034 def paths(ui, repo, search=None):
2035 2035 """show definition of symbolic path names
2036 2036
2037 2037 Show definition of symbolic path name NAME. If no name is given, show
2038 2038 definition of available names.
2039 2039
2040 2040 Path names are defined in the [paths] section of /etc/mercurial/hgrc
2041 2041 and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too.
2042 2042 """
2043 2043 if search:
2044 2044 for name, path in ui.configitems("paths"):
2045 2045 if name == search:
2046 2046 ui.write("%s\n" % path)
2047 2047 return
2048 2048 ui.warn(_("not found!\n"))
2049 2049 return 1
2050 2050 else:
2051 2051 for name, path in ui.configitems("paths"):
2052 2052 ui.write("%s = %s\n" % (name, path))
2053 2053
2054 2054 def postincoming(ui, repo, modheads, optupdate):
2055 2055 if modheads == 0:
2056 2056 return
2057 2057 if optupdate:
2058 2058 if modheads == 1:
2059 2059 return doupdate(ui, repo)
2060 2060 else:
2061 2061 ui.status(_("not updating, since new heads added\n"))
2062 2062 if modheads > 1:
2063 2063 ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n"))
2064 2064 else:
2065 2065 ui.status(_("(run 'hg update' to get a working copy)\n"))
2066 2066
2067 2067 def pull(ui, repo, source="default", **opts):
2068 2068 """pull changes from the specified source
2069 2069
2070 2070 Pull changes from a remote repository to a local one.
2071 2071
2072 2072 This finds all changes from the repository at the specified path
2073 2073 or URL and adds them to the local repository. By default, this
2074 2074 does not update the copy of the project in the working directory.
2075 2075
2076 2076 Valid URLs are of the form:
2077 2077
2078 2078 local/filesystem/path
2079 2079 http://[user@]host[:port][/path]
2080 2080 https://[user@]host[:port][/path]
2081 2081 ssh://[user@]host[:port][/path]
2082 2082
2083 2083 Some notes about using SSH with Mercurial:
2084 2084 - SSH requires an accessible shell account on the destination machine
2085 2085 and a copy of hg in the remote path or specified with as remotecmd.
2086 2086 - /path is relative to the remote user's home directory by default.
2087 2087 Use two slashes at the start of a path to specify an absolute path.
2088 2088 - Mercurial doesn't use its own compression via SSH; the right thing
2089 2089 to do is to configure it in your ~/.ssh/ssh_config, e.g.:
2090 2090 Host *.mylocalnetwork.example.com
2091 2091 Compression off
2092 2092 Host *
2093 2093 Compression on
2094 2094 Alternatively specify "ssh -C" as your ssh command in your hgrc or
2095 2095 with the --ssh command line option.
2096 2096 """
2097 2097 source = ui.expandpath(source)
2098 2098 ui.status(_('pulling from %s\n') % (source))
2099 2099
2100 2100 if opts['ssh']:
2101 2101 ui.setconfig("ui", "ssh", opts['ssh'])
2102 2102 if opts['remotecmd']:
2103 2103 ui.setconfig("ui", "remotecmd", opts['remotecmd'])
2104 2104
2105 2105 other = hg.repository(ui, source)
2106 2106 revs = None
2107 2107 if opts['rev'] and not other.local():
2108 2108 raise util.Abort(_("pull -r doesn't work for remote repositories yet"))
2109 2109 elif opts['rev']:
2110 2110 revs = [other.lookup(rev) for rev in opts['rev']]
2111 2111 modheads = repo.pull(other, heads=revs, force=opts['force'])
2112 2112 return postincoming(ui, repo, modheads, opts['update'])
2113 2113
2114 2114 def push(ui, repo, dest="default-push", **opts):
2115 2115 """push changes to the specified destination
2116 2116
2117 2117 Push changes from the local repository to the given destination.
2118 2118
2119 2119 This is the symmetrical operation for pull. It helps to move
2120 2120 changes from the current repository to a different one. If the
2121 2121 destination is local this is identical to a pull in that directory
2122 2122 from the current one.
2123 2123
2124 2124 By default, push will refuse to run if it detects the result would
2125 2125 increase the number of remote heads. This generally indicates the
2126 2126 the client has forgotten to sync and merge before pushing.
2127 2127
2128 2128 Valid URLs are of the form:
2129 2129
2130 2130 local/filesystem/path
2131 2131 ssh://[user@]host[:port][/path]
2132 2132
2133 2133 Look at the help text for the pull command for important details
2134 2134 about ssh:// URLs.
2135 2135 """
2136 2136 dest = ui.expandpath(dest)
2137 2137 ui.status('pushing to %s\n' % (dest))
2138 2138
2139 2139 if opts['ssh']:
2140 2140 ui.setconfig("ui", "ssh", opts['ssh'])
2141 2141 if opts['remotecmd']:
2142 2142 ui.setconfig("ui", "remotecmd", opts['remotecmd'])
2143 2143
2144 2144 other = hg.repository(ui, dest)
2145 2145 revs = None
2146 2146 if opts['rev']:
2147 2147 revs = [repo.lookup(rev) for rev in opts['rev']]
2148 2148 r = repo.push(other, opts['force'], revs=revs)
2149 2149 return r == 0
2150 2150
2151 2151 def rawcommit(ui, repo, *flist, **rc):
2152 2152 """raw commit interface (DEPRECATED)
2153 2153
2154 2154 (DEPRECATED)
2155 2155 Lowlevel commit, for use in helper scripts.
2156 2156
2157 2157 This command is not intended to be used by normal users, as it is
2158 2158 primarily useful for importing from other SCMs.
2159 2159
2160 2160 This command is now deprecated and will be removed in a future
2161 2161 release, please use debugsetparents and commit instead.
2162 2162 """
2163 2163
2164 2164 ui.warn(_("(the rawcommit command is deprecated)\n"))
2165 2165
2166 2166 message = rc['message']
2167 2167 if not message and rc['logfile']:
2168 2168 try:
2169 2169 message = open(rc['logfile']).read()
2170 2170 except IOError:
2171 2171 pass
2172 2172 if not message and not rc['logfile']:
2173 2173 raise util.Abort(_("missing commit message"))
2174 2174
2175 2175 files = relpath(repo, list(flist))
2176 2176 if rc['files']:
2177 2177 files += open(rc['files']).read().splitlines()
2178 2178
2179 2179 rc['parent'] = map(repo.lookup, rc['parent'])
2180 2180
2181 2181 try:
2182 2182 repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent'])
2183 2183 except ValueError, inst:
2184 2184 raise util.Abort(str(inst))
2185 2185
2186 2186 def recover(ui, repo):
2187 2187 """roll back an interrupted transaction
2188 2188
2189 2189 Recover from an interrupted commit or pull.
2190 2190
2191 2191 This command tries to fix the repository status after an interrupted
2192 2192 operation. It should only be necessary when Mercurial suggests it.
2193 2193 """
2194 2194 if repo.recover():
2195 2195 return repo.verify()
2196 2196 return 1
2197 2197
2198 2198 def remove(ui, repo, *pats, **opts):
2199 2199 """remove the specified files on the next commit
2200 2200
2201 2201 Schedule the indicated files for removal from the repository.
2202 2202
2203 2203 This command schedules the files to be removed at the next commit.
2204 2204 This only removes files from the current branch, not from the
2205 2205 entire project history. If the files still exist in the working
2206 2206 directory, they will be deleted from it. If invoked with --after,
2207 2207 files that have been manually deleted are marked as removed.
2208 2208
2209 2209 Modified files and added files are not removed by default. To
2210 2210 remove them, use the -f/--force option.
2211 2211 """
2212 2212 names = []
2213 2213 if not opts['after'] and not pats:
2214 2214 raise util.Abort(_('no files specified'))
2215 2215 files, matchfn, anypats = matchpats(repo, pats, opts)
2216 2216 exact = dict.fromkeys(files)
2217 2217 mardu = map(dict.fromkeys, repo.changes(files=files, match=matchfn))
2218 2218 modified, added, removed, deleted, unknown = mardu
2219 2219 remove, forget = [], []
2220 2220 for src, abs, rel, exact in walk(repo, pats, opts):
2221 2221 reason = None
2222 2222 if abs not in deleted and opts['after']:
2223 2223 reason = _('is still present')
2224 2224 elif abs in modified and not opts['force']:
2225 2225 reason = _('is modified (use -f to force removal)')
2226 2226 elif abs in added:
2227 2227 if opts['force']:
2228 2228 forget.append(abs)
2229 2229 continue
2230 2230 reason = _('has been marked for add (use -f to force removal)')
2231 2231 elif abs in unknown:
2232 2232 reason = _('is not managed')
2233 2233 elif abs in removed:
2234 2234 continue
2235 2235 if reason:
2236 2236 if exact:
2237 2237 ui.warn(_('not removing %s: file %s\n') % (rel, reason))
2238 2238 else:
2239 2239 if ui.verbose or not exact:
2240 2240 ui.status(_('removing %s\n') % rel)
2241 2241 remove.append(abs)
2242 2242 repo.forget(forget)
2243 2243 repo.remove(remove, unlink=not opts['after'])
2244 2244
2245 2245 def rename(ui, repo, *pats, **opts):
2246 2246 """rename files; equivalent of copy + remove
2247 2247
2248 2248 Mark dest as copies of sources; mark sources for deletion. If
2249 2249 dest is a directory, copies are put in that directory. If dest is
2250 2250 a file, there can only be one source.
2251 2251
2252 2252 By default, this command copies the contents of files as they
2253 2253 stand in the working directory. If invoked with --after, the
2254 2254 operation is recorded, but no copying is performed.
2255 2255
2256 2256 This command takes effect in the next commit.
2257 2257
2258 2258 NOTE: This command should be treated as experimental. While it
2259 2259 should properly record rename files, this information is not yet
2260 2260 fully used by merge, nor fully reported by log.
2261 2261 """
2262 2262 wlock = repo.wlock(0)
2263 2263 errs, copied = docopy(ui, repo, pats, opts, wlock)
2264 2264 names = []
2265 2265 for abs, rel, exact in copied:
2266 2266 if ui.verbose or not exact:
2267 2267 ui.status(_('removing %s\n') % rel)
2268 2268 names.append(abs)
2269 2269 repo.remove(names, True, wlock)
2270 2270 return errs
2271 2271
2272 2272 def revert(ui, repo, *pats, **opts):
2273 2273 """revert files or dirs to their states as of some revision
2274 2274
2275 2275 With no revision specified, revert the named files or directories
2276 2276 to the contents they had in the parent of the working directory.
2277 2277 This restores the contents of the affected files to an unmodified
2278 2278 state. If the working directory has two parents, you must
2279 2279 explicitly specify the revision to revert to.
2280 2280
2281 2281 Modified files are saved with a .orig suffix before reverting.
2282 2282 To disable these backups, use --no-backup.
2283 2283
2284 2284 Using the -r option, revert the given files or directories to
2285 2285 their contents as of a specific revision. This can be helpful to"roll
2286 2286 back" some or all of a change that should not have been committed.
2287 2287
2288 2288 Revert modifies the working directory. It does not commit any
2289 2289 changes, or change the parent of the working directory. If you
2290 2290 revert to a revision other than the parent of the working
2291 2291 directory, the reverted files will thus appear modified
2292 2292 afterwards.
2293 2293
2294 2294 If a file has been deleted, it is recreated. If the executable
2295 2295 mode of a file was changed, it is reset.
2296 2296
2297 2297 If names are given, all files matching the names are reverted.
2298 2298
2299 2299 If no arguments are given, all files in the repository are reverted.
2300 2300 """
2301 2301 parent, p2 = repo.dirstate.parents()
2302 2302 if opts['rev']:
2303 2303 node = repo.lookup(opts['rev'])
2304 2304 elif p2 != nullid:
2305 2305 raise util.Abort(_('working dir has two parents; '
2306 2306 'you must specify the revision to revert to'))
2307 2307 else:
2308 2308 node = parent
2309 2309 pmf = None
2310 2310 mf = repo.manifest.read(repo.changelog.read(node)[0])
2311 2311
2312 2312 wlock = repo.wlock()
2313 2313
2314 2314 # need all matching names in dirstate and manifest of target rev,
2315 2315 # so have to walk both. do not print errors if files exist in one
2316 2316 # but not other.
2317 2317
2318 2318 names = {}
2319 2319 target_only = {}
2320 2320
2321 2321 # walk dirstate.
2322 2322
2323 2323 for src, abs, rel, exact in walk(repo, pats, opts, badmatch=mf.has_key):
2324 2324 names[abs] = (rel, exact)
2325 2325 if src == 'b':
2326 2326 target_only[abs] = True
2327 2327
2328 2328 # walk target manifest.
2329 2329
2330 2330 for src, abs, rel, exact in walk(repo, pats, opts, node=node,
2331 2331 badmatch=names.has_key):
2332 2332 if abs in names: continue
2333 2333 names[abs] = (rel, exact)
2334 2334 target_only[abs] = True
2335 2335
2336 2336 changes = repo.changes(match=names.has_key, wlock=wlock)
2337 2337 modified, added, removed, deleted, unknown = map(dict.fromkeys, changes)
2338 2338
2339 2339 revert = ([], _('reverting %s\n'))
2340 2340 add = ([], _('adding %s\n'))
2341 2341 remove = ([], _('removing %s\n'))
2342 2342 forget = ([], _('forgetting %s\n'))
2343 2343 undelete = ([], _('undeleting %s\n'))
2344 2344 update = {}
2345 2345
2346 2346 disptable = (
2347 2347 # dispatch table:
2348 2348 # file state
2349 2349 # action if in target manifest
2350 2350 # action if not in target manifest
2351 2351 # make backup if in target manifest
2352 2352 # make backup if not in target manifest
2353 2353 (modified, revert, remove, True, True),
2354 2354 (added, revert, forget, True, False),
2355 2355 (removed, undelete, None, False, False),
2356 2356 (deleted, revert, remove, False, False),
2357 2357 (unknown, add, None, True, False),
2358 2358 (target_only, add, None, False, False),
2359 2359 )
2360 2360
2361 2361 entries = names.items()
2362 2362 entries.sort()
2363 2363
2364 2364 for abs, (rel, exact) in entries:
2365 2365 in_mf = abs in mf
2366 2366 def handle(xlist, dobackup):
2367 2367 xlist[0].append(abs)
2368 2368 if dobackup and not opts['no_backup'] and os.path.exists(rel):
2369 2369 bakname = "%s.orig" % rel
2370 2370 ui.note(_('saving current version of %s as %s\n') %
2371 2371 (rel, bakname))
2372 2372 shutil.copyfile(rel, bakname)
2373 2373 shutil.copymode(rel, bakname)
2374 2374 if ui.verbose or not exact:
2375 2375 ui.status(xlist[1] % rel)
2376 2376 for table, hitlist, misslist, backuphit, backupmiss in disptable:
2377 2377 if abs not in table: continue
2378 2378 # file has changed in dirstate
2379 2379 if in_mf:
2380 2380 handle(hitlist, backuphit)
2381 2381 elif misslist is not None:
2382 2382 handle(misslist, backupmiss)
2383 2383 else:
2384 2384 if exact: ui.warn(_('file not managed: %s\n' % rel))
2385 2385 break
2386 2386 else:
2387 2387 # file has not changed in dirstate
2388 2388 if node == parent:
2389 2389 if exact: ui.warn(_('no changes needed to %s\n' % rel))
2390 2390 continue
2391 2391 if not in_mf:
2392 2392 if pmf is None:
2393 2393 # only need parent manifest in this unlikely case,
2394 2394 # so do not read by default
2395 2395 pmf = repo.manifest.read(repo.changelog.read(parent)[0])
2396 2396 if abs in pmf:
2397 2397 handle(remove, False)
2398 2398 update[abs] = True
2399 2399
2400 2400 repo.dirstate.forget(forget[0])
2401 2401 r = repo.update(node, False, True, update.has_key, False, wlock=wlock,
2402 2402 show_stats=False)
2403 2403 repo.dirstate.update(add[0], 'a')
2404 2404 repo.dirstate.update(undelete[0], 'n')
2405 2405 repo.dirstate.update(remove[0], 'r')
2406 2406 return r
2407 2407
2408 2408 def rollback(ui, repo):
2409 2409 """roll back the last transaction in this repository
2410 2410
2411 2411 Roll back the last transaction in this repository, restoring the
2412 2412 project to its state prior to the transaction.
2413 2413
2414 2414 Transactions are used to encapsulate the effects of all commands
2415 2415 that create new changesets or propagate existing changesets into a
2416 2416 repository. For example, the following commands are transactional,
2417 2417 and their effects can be rolled back:
2418 2418
2419 2419 commit
2420 2420 import
2421 2421 pull
2422 2422 push (with this repository as destination)
2423 2423 unbundle
2424 2424
2425 2425 This command should be used with care. There is only one level of
2426 2426 rollback, and there is no way to undo a rollback.
2427 2427
2428 2428 This command is not intended for use on public repositories. Once
2429 2429 changes are visible for pull by other users, rolling a transaction
2430 2430 back locally is ineffective (someone else may already have pulled
2431 2431 the changes). Furthermore, a race is possible with readers of the
2432 2432 repository; for example an in-progress pull from the repository
2433 2433 may fail if a rollback is performed.
2434 2434 """
2435 2435 repo.rollback()
2436 2436
2437 2437 def root(ui, repo):
2438 2438 """print the root (top) of the current working dir
2439 2439
2440 2440 Print the root directory of the current repository.
2441 2441 """
2442 2442 ui.write(repo.root + "\n")
2443 2443
2444 2444 def serve(ui, repo, **opts):
2445 2445 """export the repository via HTTP
2446 2446
2447 2447 Start a local HTTP repository browser and pull server.
2448 2448
2449 2449 By default, the server logs accesses to stdout and errors to
2450 2450 stderr. Use the "-A" and "-E" options to log to files.
2451 2451 """
2452 2452
2453 2453 if opts["stdio"]:
2454 2454 if repo is None:
2455 2455 raise hg.RepoError(_('no repo found'))
2456 2456 fin, fout = sys.stdin, sys.stdout
2457 2457 sys.stdout = sys.stderr
2458 2458
2459 2459 # Prevent insertion/deletion of CRs
2460 2460 util.set_binary(fin)
2461 2461 util.set_binary(fout)
2462 2462
2463 2463 def getarg():
2464 2464 argline = fin.readline()[:-1]
2465 2465 arg, l = argline.split()
2466 2466 val = fin.read(int(l))
2467 2467 return arg, val
2468 2468 def respond(v):
2469 2469 fout.write("%d\n" % len(v))
2470 2470 fout.write(v)
2471 2471 fout.flush()
2472 2472
2473 2473 lock = None
2474 2474
2475 2475 while 1:
2476 2476 cmd = fin.readline()[:-1]
2477 2477 if cmd == '':
2478 2478 return
2479 if cmd == "heads":
2479 elif cmd == "heads":
2480 2480 h = repo.heads()
2481 2481 respond(" ".join(map(hex, h)) + "\n")
2482 if cmd == "lock":
2482 elif cmd == "lock":
2483 2483 lock = repo.lock()
2484 2484 respond("")
2485 if cmd == "unlock":
2485 elif cmd == "unlock":
2486 2486 if lock:
2487 2487 lock.release()
2488 2488 lock = None
2489 2489 respond("")
2490 2490 elif cmd == "branches":
2491 2491 arg, nodes = getarg()
2492 2492 nodes = map(bin, nodes.split(" "))
2493 2493 r = []
2494 2494 for b in repo.branches(nodes):
2495 2495 r.append(" ".join(map(hex, b)) + "\n")
2496 2496 respond("".join(r))
2497 2497 elif cmd == "between":
2498 2498 arg, pairs = getarg()
2499 2499 pairs = [map(bin, p.split("-")) for p in pairs.split(" ")]
2500 2500 r = []
2501 2501 for b in repo.between(pairs):
2502 2502 r.append(" ".join(map(hex, b)) + "\n")
2503 2503 respond("".join(r))
2504 2504 elif cmd == "changegroup":
2505 2505 nodes = []
2506 2506 arg, roots = getarg()
2507 2507 nodes = map(bin, roots.split(" "))
2508 2508
2509 2509 cg = repo.changegroup(nodes, 'serve')
2510 2510 while 1:
2511 2511 d = cg.read(4096)
2512 2512 if not d:
2513 2513 break
2514 2514 fout.write(d)
2515 2515
2516 2516 fout.flush()
2517 2517
2518 2518 elif cmd == "addchangegroup":
2519 2519 if not lock:
2520 2520 respond("not locked")
2521 2521 continue
2522 2522 respond("")
2523 2523
2524 2524 r = repo.addchangegroup(fin, 'serve')
2525 2525 respond(str(r))
2526 2526
2527 else:
2528 respond("")
2529
2527 2530 optlist = ("name templates style address port ipv6"
2528 2531 " accesslog errorlog webdir_conf")
2529 2532 for o in optlist.split():
2530 2533 if opts[o]:
2531 2534 ui.setconfig("web", o, opts[o])
2532 2535
2533 2536 if repo is None and not ui.config("web", "webdir_conf"):
2534 2537 raise hg.RepoError(_('no repo found'))
2535 2538
2536 2539 if opts['daemon'] and not opts['daemon_pipefds']:
2537 2540 rfd, wfd = os.pipe()
2538 2541 args = sys.argv[:]
2539 2542 args.append('--daemon-pipefds=%d,%d' % (rfd, wfd))
2540 2543 pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0),
2541 2544 args[0], args)
2542 2545 os.close(wfd)
2543 2546 os.read(rfd, 1)
2544 2547 os._exit(0)
2545 2548
2546 2549 try:
2547 2550 httpd = create_server(ui, repo, hgwebdir, hgweb)
2548 2551 except socket.error, inst:
2549 2552 raise util.Abort(_('cannot start server: ') + inst.args[1])
2550 2553
2551 2554 if ui.verbose:
2552 2555 addr, port = httpd.socket.getsockname()
2553 2556 if addr == '0.0.0.0':
2554 2557 addr = socket.gethostname()
2555 2558 else:
2556 2559 try:
2557 2560 addr = socket.gethostbyaddr(addr)[0]
2558 2561 except socket.error:
2559 2562 pass
2560 2563 if port != 80:
2561 2564 ui.status(_('listening at http://%s:%d/\n') % (addr, port))
2562 2565 else:
2563 2566 ui.status(_('listening at http://%s/\n') % addr)
2564 2567
2565 2568 if opts['pid_file']:
2566 2569 fp = open(opts['pid_file'], 'w')
2567 2570 fp.write(str(os.getpid()))
2568 2571 fp.close()
2569 2572
2570 2573 if opts['daemon_pipefds']:
2571 2574 rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')]
2572 2575 os.close(rfd)
2573 2576 os.write(wfd, 'y')
2574 2577 os.close(wfd)
2575 2578 sys.stdout.flush()
2576 2579 sys.stderr.flush()
2577 2580 fd = os.open(util.nulldev, os.O_RDWR)
2578 2581 if fd != 0: os.dup2(fd, 0)
2579 2582 if fd != 1: os.dup2(fd, 1)
2580 2583 if fd != 2: os.dup2(fd, 2)
2581 2584 if fd not in (0, 1, 2): os.close(fd)
2582 2585
2583 2586 httpd.serve_forever()
2584 2587
2585 2588 def status(ui, repo, *pats, **opts):
2586 2589 """show changed files in the working directory
2587 2590
2588 2591 Show changed files in the repository. If names are
2589 2592 given, only files that match are shown.
2590 2593
2591 2594 The codes used to show the status of files are:
2592 2595 M = modified
2593 2596 A = added
2594 2597 R = removed
2595 2598 ! = deleted, but still tracked
2596 2599 ? = not tracked
2597 2600 I = ignored (not shown by default)
2598 2601 """
2599 2602
2600 2603 show_ignored = opts['ignored'] and True or False
2601 2604 files, matchfn, anypats = matchpats(repo, pats, opts)
2602 2605 cwd = (pats and repo.getcwd()) or ''
2603 2606 modified, added, removed, deleted, unknown, ignored = [
2604 2607 [util.pathto(cwd, x) for x in n]
2605 2608 for n in repo.changes(files=files, match=matchfn,
2606 2609 show_ignored=show_ignored)]
2607 2610
2608 2611 changetypes = [('modified', 'M', modified),
2609 2612 ('added', 'A', added),
2610 2613 ('removed', 'R', removed),
2611 2614 ('deleted', '!', deleted),
2612 2615 ('unknown', '?', unknown),
2613 2616 ('ignored', 'I', ignored)]
2614 2617
2615 2618 end = opts['print0'] and '\0' or '\n'
2616 2619
2617 2620 for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]]
2618 2621 or changetypes):
2619 2622 if opts['no_status']:
2620 2623 format = "%%s%s" % end
2621 2624 else:
2622 2625 format = "%s %%s%s" % (char, end)
2623 2626
2624 2627 for f in changes:
2625 2628 ui.write(format % f)
2626 2629
2627 2630 def tag(ui, repo, name, rev_=None, **opts):
2628 2631 """add a tag for the current tip or a given revision
2629 2632
2630 2633 Name a particular revision using <name>.
2631 2634
2632 2635 Tags are used to name particular revisions of the repository and are
2633 2636 very useful to compare different revision, to go back to significant
2634 2637 earlier versions or to mark branch points as releases, etc.
2635 2638
2636 2639 If no revision is given, the tip is used.
2637 2640
2638 2641 To facilitate version control, distribution, and merging of tags,
2639 2642 they are stored as a file named ".hgtags" which is managed
2640 2643 similarly to other project files and can be hand-edited if
2641 2644 necessary. The file '.hg/localtags' is used for local tags (not
2642 2645 shared among repositories).
2643 2646 """
2644 2647 if name == "tip":
2645 2648 raise util.Abort(_("the name 'tip' is reserved"))
2646 2649 if rev_ is not None:
2647 2650 ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, "
2648 2651 "please use 'hg tag [-r REV] NAME' instead\n"))
2649 2652 if opts['rev']:
2650 2653 raise util.Abort(_("use only one form to specify the revision"))
2651 2654 if opts['rev']:
2652 2655 rev_ = opts['rev']
2653 2656 if rev_:
2654 2657 r = hex(repo.lookup(rev_))
2655 2658 else:
2656 2659 r = hex(repo.changelog.tip())
2657 2660
2658 2661 disallowed = (revrangesep, '\r', '\n')
2659 2662 for c in disallowed:
2660 2663 if name.find(c) >= 0:
2661 2664 raise util.Abort(_("%s cannot be used in a tag name") % repr(c))
2662 2665
2663 2666 repo.hook('pretag', throw=True, node=r, tag=name,
2664 2667 local=int(not not opts['local']))
2665 2668
2666 2669 if opts['local']:
2667 2670 repo.opener("localtags", "a").write("%s %s\n" % (r, name))
2668 2671 repo.hook('tag', node=r, tag=name, local=1)
2669 2672 return
2670 2673
2671 2674 for x in repo.changes():
2672 2675 if ".hgtags" in x:
2673 2676 raise util.Abort(_("working copy of .hgtags is changed "
2674 2677 "(please commit .hgtags manually)"))
2675 2678
2676 2679 repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name))
2677 2680 if repo.dirstate.state(".hgtags") == '?':
2678 2681 repo.add([".hgtags"])
2679 2682
2680 2683 message = (opts['message'] or
2681 2684 _("Added tag %s for changeset %s") % (name, r))
2682 2685 try:
2683 2686 repo.commit([".hgtags"], message, opts['user'], opts['date'])
2684 2687 repo.hook('tag', node=r, tag=name, local=0)
2685 2688 except ValueError, inst:
2686 2689 raise util.Abort(str(inst))
2687 2690
2688 2691 def tags(ui, repo):
2689 2692 """list repository tags
2690 2693
2691 2694 List the repository tags.
2692 2695
2693 2696 This lists both regular and local tags.
2694 2697 """
2695 2698
2696 2699 l = repo.tagslist()
2697 2700 l.reverse()
2698 2701 for t, n in l:
2699 2702 try:
2700 2703 r = "%5d:%s" % (repo.changelog.rev(n), hex(n))
2701 2704 except KeyError:
2702 2705 r = " ?:?"
2703 2706 if ui.quiet:
2704 2707 ui.write("%s\n" % t)
2705 2708 else:
2706 2709 ui.write("%-30s %s\n" % (t, r))
2707 2710
2708 2711 def tip(ui, repo, **opts):
2709 2712 """show the tip revision
2710 2713
2711 2714 Show the tip revision.
2712 2715 """
2713 2716 n = repo.changelog.tip()
2714 2717 br = None
2715 2718 if opts['branches']:
2716 2719 br = repo.branchlookup([n])
2717 2720 show_changeset(ui, repo, opts).show(changenode=n, brinfo=br)
2718 2721 if opts['patch']:
2719 2722 dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n)
2720 2723
2721 2724 def unbundle(ui, repo, fname, **opts):
2722 2725 """apply a changegroup file
2723 2726
2724 2727 Apply a compressed changegroup file generated by the bundle
2725 2728 command.
2726 2729 """
2727 2730 f = urllib.urlopen(fname)
2728 2731
2729 2732 header = f.read(6)
2730 2733 if not header.startswith("HG"):
2731 2734 raise util.Abort(_("%s: not a Mercurial bundle file") % fname)
2732 2735 elif not header.startswith("HG10"):
2733 2736 raise util.Abort(_("%s: unknown bundle version") % fname)
2734 2737 elif header == "HG10BZ":
2735 2738 def generator(f):
2736 2739 zd = bz2.BZ2Decompressor()
2737 2740 zd.decompress("BZ")
2738 2741 for chunk in f:
2739 2742 yield zd.decompress(chunk)
2740 2743 elif header == "HG10UN":
2741 2744 def generator(f):
2742 2745 for chunk in f:
2743 2746 yield chunk
2744 2747 else:
2745 2748 raise util.Abort(_("%s: unknown bundle compression type")
2746 2749 % fname)
2747 2750 gen = generator(util.filechunkiter(f, 4096))
2748 2751 modheads = repo.addchangegroup(util.chunkbuffer(gen), 'unbundle')
2749 2752 return postincoming(ui, repo, modheads, opts['update'])
2750 2753
2751 2754 def undo(ui, repo):
2752 2755 """undo the last commit or pull (DEPRECATED)
2753 2756
2754 2757 (DEPRECATED)
2755 2758 This command is now deprecated and will be removed in a future
2756 2759 release. Please use the rollback command instead. For usage
2757 2760 instructions, see the rollback command.
2758 2761 """
2759 2762 ui.warn(_('(the undo command is deprecated; use rollback instead)\n'))
2760 2763 repo.rollback()
2761 2764
2762 2765 def update(ui, repo, node=None, merge=False, clean=False, force=None,
2763 2766 branch=None, **opts):
2764 2767 """update or merge working directory
2765 2768
2766 2769 Update the working directory to the specified revision.
2767 2770
2768 2771 If there are no outstanding changes in the working directory and
2769 2772 there is a linear relationship between the current version and the
2770 2773 requested version, the result is the requested version.
2771 2774
2772 2775 To merge the working directory with another revision, use the
2773 2776 merge command.
2774 2777
2775 2778 By default, update will refuse to run if doing so would require
2776 2779 merging or discarding local changes.
2777 2780 """
2778 2781 if merge:
2779 2782 ui.warn(_('(the -m/--merge option is deprecated; '
2780 2783 'use the merge command instead)\n'))
2781 2784 return doupdate(ui, repo, node, merge, clean, force, branch, **opts)
2782 2785
2783 2786 def doupdate(ui, repo, node=None, merge=False, clean=False, force=None,
2784 2787 branch=None, **opts):
2785 2788 if branch:
2786 2789 br = repo.branchlookup(branch=branch)
2787 2790 found = []
2788 2791 for x in br:
2789 2792 if branch in br[x]:
2790 2793 found.append(x)
2791 2794 if len(found) > 1:
2792 2795 ui.warn(_("Found multiple heads for %s\n") % branch)
2793 2796 for x in found:
2794 2797 show_changeset(ui, repo, opts).show(changenode=x, brinfo=br)
2795 2798 return 1
2796 2799 if len(found) == 1:
2797 2800 node = found[0]
2798 2801 ui.warn(_("Using head %s for branch %s\n") % (short(node), branch))
2799 2802 else:
2800 2803 ui.warn(_("branch %s not found\n") % (branch))
2801 2804 return 1
2802 2805 else:
2803 2806 node = node and repo.lookup(node) or repo.changelog.tip()
2804 2807 return repo.update(node, allow=merge, force=clean, forcemerge=force)
2805 2808
2806 2809 def verify(ui, repo):
2807 2810 """verify the integrity of the repository
2808 2811
2809 2812 Verify the integrity of the current repository.
2810 2813
2811 2814 This will perform an extensive check of the repository's
2812 2815 integrity, validating the hashes and checksums of each entry in
2813 2816 the changelog, manifest, and tracked files, as well as the
2814 2817 integrity of their crosslinks and indices.
2815 2818 """
2816 2819 return repo.verify()
2817 2820
2818 2821 # Command options and aliases are listed here, alphabetically
2819 2822
2820 2823 table = {
2821 2824 "^add":
2822 2825 (add,
2823 2826 [('I', 'include', [], _('include names matching the given patterns')),
2824 2827 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2825 2828 _('hg add [OPTION]... [FILE]...')),
2826 2829 "debugaddremove|addremove":
2827 2830 (addremove,
2828 2831 [('I', 'include', [], _('include names matching the given patterns')),
2829 2832 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2830 2833 _('hg addremove [OPTION]... [FILE]...')),
2831 2834 "^annotate":
2832 2835 (annotate,
2833 2836 [('r', 'rev', '', _('annotate the specified revision')),
2834 2837 ('a', 'text', None, _('treat all files as text')),
2835 2838 ('u', 'user', None, _('list the author')),
2836 2839 ('d', 'date', None, _('list the date')),
2837 2840 ('n', 'number', None, _('list the revision number (default)')),
2838 2841 ('c', 'changeset', None, _('list the changeset')),
2839 2842 ('I', 'include', [], _('include names matching the given patterns')),
2840 2843 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2841 2844 _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')),
2842 2845 "archive":
2843 2846 (archive,
2844 2847 [('', 'no-decode', None, _('do not pass files through decoders')),
2845 2848 ('p', 'prefix', '', _('directory prefix for files in archive')),
2846 2849 ('r', 'rev', '', _('revision to distribute')),
2847 2850 ('t', 'type', '', _('type of distribution to create')),
2848 2851 ('I', 'include', [], _('include names matching the given patterns')),
2849 2852 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2850 2853 _('hg archive [OPTION]... DEST')),
2851 2854 "backout":
2852 2855 (backout,
2853 2856 [('', 'merge', None,
2854 2857 _('merge with old dirstate parent after backout')),
2855 2858 ('m', 'message', '', _('use <text> as commit message')),
2856 2859 ('l', 'logfile', '', _('read commit message from <file>')),
2857 2860 ('d', 'date', '', _('record datecode as commit date')),
2858 2861 ('u', 'user', '', _('record user as committer')),
2859 2862 ('I', 'include', [], _('include names matching the given patterns')),
2860 2863 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2861 2864 _('hg backout [OPTION]... REV')),
2862 2865 "bundle":
2863 2866 (bundle,
2864 2867 [('f', 'force', None,
2865 2868 _('run even when remote repository is unrelated'))],
2866 2869 _('hg bundle FILE DEST')),
2867 2870 "cat":
2868 2871 (cat,
2869 2872 [('o', 'output', '', _('print output to file with formatted name')),
2870 2873 ('r', 'rev', '', _('print the given revision')),
2871 2874 ('I', 'include', [], _('include names matching the given patterns')),
2872 2875 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2873 2876 _('hg cat [OPTION]... FILE...')),
2874 2877 "^clone":
2875 2878 (clone,
2876 2879 [('U', 'noupdate', None, _('do not update the new working directory')),
2877 2880 ('r', 'rev', [],
2878 2881 _('a changeset you would like to have after cloning')),
2879 2882 ('', 'pull', None, _('use pull protocol to copy metadata')),
2880 2883 ('e', 'ssh', '', _('specify ssh command to use')),
2881 2884 ('', 'remotecmd', '',
2882 2885 _('specify hg command to run on the remote side'))],
2883 2886 _('hg clone [OPTION]... SOURCE [DEST]')),
2884 2887 "^commit|ci":
2885 2888 (commit,
2886 2889 [('A', 'addremove', None,
2887 2890 _('mark new/missing files as added/removed before committing')),
2888 2891 ('m', 'message', '', _('use <text> as commit message')),
2889 2892 ('l', 'logfile', '', _('read the commit message from <file>')),
2890 2893 ('d', 'date', '', _('record datecode as commit date')),
2891 2894 ('u', 'user', '', _('record user as commiter')),
2892 2895 ('I', 'include', [], _('include names matching the given patterns')),
2893 2896 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2894 2897 _('hg commit [OPTION]... [FILE]...')),
2895 2898 "copy|cp":
2896 2899 (copy,
2897 2900 [('A', 'after', None, _('record a copy that has already occurred')),
2898 2901 ('f', 'force', None,
2899 2902 _('forcibly copy over an existing managed file')),
2900 2903 ('I', 'include', [], _('include names matching the given patterns')),
2901 2904 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2902 2905 _('hg copy [OPTION]... [SOURCE]... DEST')),
2903 2906 "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')),
2904 2907 "debugcomplete":
2905 2908 (debugcomplete,
2906 2909 [('o', 'options', None, _('show the command options'))],
2907 2910 _('debugcomplete [-o] CMD')),
2908 2911 "debugrebuildstate":
2909 2912 (debugrebuildstate,
2910 2913 [('r', 'rev', '', _('revision to rebuild to'))],
2911 2914 _('debugrebuildstate [-r REV] [REV]')),
2912 2915 "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')),
2913 2916 "debugconfig": (debugconfig, [], _('debugconfig')),
2914 2917 "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')),
2915 2918 "debugstate": (debugstate, [], _('debugstate')),
2916 2919 "debugdata": (debugdata, [], _('debugdata FILE REV')),
2917 2920 "debugindex": (debugindex, [], _('debugindex FILE')),
2918 2921 "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')),
2919 2922 "debugrename": (debugrename, [], _('debugrename FILE [REV]')),
2920 2923 "debugwalk":
2921 2924 (debugwalk,
2922 2925 [('I', 'include', [], _('include names matching the given patterns')),
2923 2926 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2924 2927 _('debugwalk [OPTION]... [FILE]...')),
2925 2928 "^diff":
2926 2929 (diff,
2927 2930 [('r', 'rev', [], _('revision')),
2928 2931 ('a', 'text', None, _('treat all files as text')),
2929 2932 ('p', 'show-function', None,
2930 2933 _('show which function each change is in')),
2931 2934 ('w', 'ignore-all-space', None,
2932 2935 _('ignore white space when comparing lines')),
2933 2936 ('I', 'include', [], _('include names matching the given patterns')),
2934 2937 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2935 2938 _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')),
2936 2939 "^export":
2937 2940 (export,
2938 2941 [('o', 'output', '', _('print output to file with formatted name')),
2939 2942 ('a', 'text', None, _('treat all files as text')),
2940 2943 ('', 'switch-parent', None, _('diff against the second parent'))],
2941 2944 _('hg export [-a] [-o OUTFILESPEC] REV...')),
2942 2945 "debugforget|forget":
2943 2946 (forget,
2944 2947 [('I', 'include', [], _('include names matching the given patterns')),
2945 2948 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2946 2949 _('hg forget [OPTION]... FILE...')),
2947 2950 "grep":
2948 2951 (grep,
2949 2952 [('0', 'print0', None, _('end fields with NUL')),
2950 2953 ('', 'all', None, _('print all revisions that match')),
2951 2954 ('i', 'ignore-case', None, _('ignore case when matching')),
2952 2955 ('l', 'files-with-matches', None,
2953 2956 _('print only filenames and revs that match')),
2954 2957 ('n', 'line-number', None, _('print matching line numbers')),
2955 2958 ('r', 'rev', [], _('search in given revision range')),
2956 2959 ('u', 'user', None, _('print user who committed change')),
2957 2960 ('I', 'include', [], _('include names matching the given patterns')),
2958 2961 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
2959 2962 _('hg grep [OPTION]... PATTERN [FILE]...')),
2960 2963 "heads":
2961 2964 (heads,
2962 2965 [('b', 'branches', None, _('show branches')),
2963 2966 ('', 'style', '', _('display using template map file')),
2964 2967 ('r', 'rev', '', _('show only heads which are descendants of rev')),
2965 2968 ('', 'template', '', _('display with template'))],
2966 2969 _('hg heads [-b] [-r <rev>]')),
2967 2970 "help": (help_, [], _('hg help [COMMAND]')),
2968 2971 "identify|id": (identify, [], _('hg identify')),
2969 2972 "import|patch":
2970 2973 (import_,
2971 2974 [('p', 'strip', 1,
2972 2975 _('directory strip option for patch. This has the same\n'
2973 2976 'meaning as the corresponding patch option')),
2974 2977 ('b', 'base', '', _('base path')),
2975 2978 ('f', 'force', None,
2976 2979 _('skip check for outstanding uncommitted changes'))],
2977 2980 _('hg import [-p NUM] [-b BASE] [-f] PATCH...')),
2978 2981 "incoming|in": (incoming,
2979 2982 [('M', 'no-merges', None, _('do not show merges')),
2980 2983 ('f', 'force', None,
2981 2984 _('run even when remote repository is unrelated')),
2982 2985 ('', 'style', '', _('display using template map file')),
2983 2986 ('n', 'newest-first', None, _('show newest record first')),
2984 2987 ('', 'bundle', '', _('file to store the bundles into')),
2985 2988 ('p', 'patch', None, _('show patch')),
2986 2989 ('', 'template', '', _('display with template')),
2987 2990 ('e', 'ssh', '', _('specify ssh command to use')),
2988 2991 ('', 'remotecmd', '',
2989 2992 _('specify hg command to run on the remote side'))],
2990 2993 _('hg incoming [-p] [-n] [-M] [--bundle FILENAME] [SOURCE]')),
2991 2994 "^init": (init, [], _('hg init [DEST]')),
2992 2995 "locate":
2993 2996 (locate,
2994 2997 [('r', 'rev', '', _('search the repository as it stood at rev')),
2995 2998 ('0', 'print0', None,
2996 2999 _('end filenames with NUL, for use with xargs')),
2997 3000 ('f', 'fullpath', None,
2998 3001 _('print complete paths from the filesystem root')),
2999 3002 ('I', 'include', [], _('include names matching the given patterns')),
3000 3003 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
3001 3004 _('hg locate [OPTION]... [PATTERN]...')),
3002 3005 "^log|history":
3003 3006 (log,
3004 3007 [('b', 'branches', None, _('show branches')),
3005 3008 ('k', 'keyword', [], _('search for a keyword')),
3006 3009 ('l', 'limit', '', _('limit number of changes displayed')),
3007 3010 ('r', 'rev', [], _('show the specified revision or range')),
3008 3011 ('M', 'no-merges', None, _('do not show merges')),
3009 3012 ('', 'style', '', _('display using template map file')),
3010 3013 ('m', 'only-merges', None, _('show only merges')),
3011 3014 ('p', 'patch', None, _('show patch')),
3012 3015 ('', 'template', '', _('display with template')),
3013 3016 ('I', 'include', [], _('include names matching the given patterns')),
3014 3017 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
3015 3018 _('hg log [OPTION]... [FILE]')),
3016 3019 "manifest": (manifest, [], _('hg manifest [REV]')),
3017 3020 "merge":
3018 3021 (merge,
3019 3022 [('b', 'branch', '', _('merge with head of a specific branch')),
3020 3023 ('f', 'force', None, _('force a merge with outstanding changes'))],
3021 3024 _('hg merge [-b TAG] [-f] [REV]')),
3022 3025 "outgoing|out": (outgoing,
3023 3026 [('M', 'no-merges', None, _('do not show merges')),
3024 3027 ('f', 'force', None,
3025 3028 _('run even when remote repository is unrelated')),
3026 3029 ('p', 'patch', None, _('show patch')),
3027 3030 ('', 'style', '', _('display using template map file')),
3028 3031 ('n', 'newest-first', None, _('show newest record first')),
3029 3032 ('', 'template', '', _('display with template')),
3030 3033 ('e', 'ssh', '', _('specify ssh command to use')),
3031 3034 ('', 'remotecmd', '',
3032 3035 _('specify hg command to run on the remote side'))],
3033 3036 _('hg outgoing [-M] [-p] [-n] [DEST]')),
3034 3037 "^parents":
3035 3038 (parents,
3036 3039 [('b', 'branches', None, _('show branches')),
3037 3040 ('', 'style', '', _('display using template map file')),
3038 3041 ('', 'template', '', _('display with template'))],
3039 3042 _('hg parents [-b] [REV]')),
3040 3043 "paths": (paths, [], _('hg paths [NAME]')),
3041 3044 "^pull":
3042 3045 (pull,
3043 3046 [('u', 'update', None,
3044 3047 _('update the working directory to tip after pull')),
3045 3048 ('e', 'ssh', '', _('specify ssh command to use')),
3046 3049 ('f', 'force', None,
3047 3050 _('run even when remote repository is unrelated')),
3048 3051 ('r', 'rev', [], _('a specific revision you would like to pull')),
3049 3052 ('', 'remotecmd', '',
3050 3053 _('specify hg command to run on the remote side'))],
3051 3054 _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')),
3052 3055 "^push":
3053 3056 (push,
3054 3057 [('f', 'force', None, _('force push')),
3055 3058 ('e', 'ssh', '', _('specify ssh command to use')),
3056 3059 ('r', 'rev', [], _('a specific revision you would like to push')),
3057 3060 ('', 'remotecmd', '',
3058 3061 _('specify hg command to run on the remote side'))],
3059 3062 _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')),
3060 3063 "debugrawcommit|rawcommit":
3061 3064 (rawcommit,
3062 3065 [('p', 'parent', [], _('parent')),
3063 3066 ('d', 'date', '', _('date code')),
3064 3067 ('u', 'user', '', _('user')),
3065 3068 ('F', 'files', '', _('file list')),
3066 3069 ('m', 'message', '', _('commit message')),
3067 3070 ('l', 'logfile', '', _('commit message file'))],
3068 3071 _('hg debugrawcommit [OPTION]... [FILE]...')),
3069 3072 "recover": (recover, [], _('hg recover')),
3070 3073 "^remove|rm":
3071 3074 (remove,
3072 3075 [('A', 'after', None, _('record remove that has already occurred')),
3073 3076 ('f', 'force', None, _('remove file even if modified')),
3074 3077 ('I', 'include', [], _('include names matching the given patterns')),
3075 3078 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
3076 3079 _('hg remove [OPTION]... FILE...')),
3077 3080 "rename|mv":
3078 3081 (rename,
3079 3082 [('A', 'after', None, _('record a rename that has already occurred')),
3080 3083 ('f', 'force', None,
3081 3084 _('forcibly copy over an existing managed file')),
3082 3085 ('I', 'include', [], _('include names matching the given patterns')),
3083 3086 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
3084 3087 _('hg rename [OPTION]... SOURCE... DEST')),
3085 3088 "^revert":
3086 3089 (revert,
3087 3090 [('r', 'rev', '', _('revision to revert to')),
3088 3091 ('', 'no-backup', None, _('do not save backup copies of files')),
3089 3092 ('I', 'include', [], _('include names matching given patterns')),
3090 3093 ('X', 'exclude', [], _('exclude names matching given patterns'))],
3091 3094 _('hg revert [-r REV] [NAME]...')),
3092 3095 "rollback": (rollback, [], _('hg rollback')),
3093 3096 "root": (root, [], _('hg root')),
3094 3097 "^serve":
3095 3098 (serve,
3096 3099 [('A', 'accesslog', '', _('name of access log file to write to')),
3097 3100 ('d', 'daemon', None, _('run server in background')),
3098 3101 ('', 'daemon-pipefds', '', _('used internally by daemon mode')),
3099 3102 ('E', 'errorlog', '', _('name of error log file to write to')),
3100 3103 ('p', 'port', 0, _('port to use (default: 8000)')),
3101 3104 ('a', 'address', '', _('address to use')),
3102 3105 ('n', 'name', '',
3103 3106 _('name to show in web pages (default: working dir)')),
3104 3107 ('', 'webdir-conf', '', _('name of the webdir config file'
3105 3108 ' (serve more than one repo)')),
3106 3109 ('', 'pid-file', '', _('name of file to write process ID to')),
3107 3110 ('', 'stdio', None, _('for remote clients')),
3108 3111 ('t', 'templates', '', _('web templates to use')),
3109 3112 ('', 'style', '', _('template style to use')),
3110 3113 ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))],
3111 3114 _('hg serve [OPTION]...')),
3112 3115 "^status|st":
3113 3116 (status,
3114 3117 [('m', 'modified', None, _('show only modified files')),
3115 3118 ('a', 'added', None, _('show only added files')),
3116 3119 ('r', 'removed', None, _('show only removed files')),
3117 3120 ('d', 'deleted', None, _('show only deleted (but tracked) files')),
3118 3121 ('u', 'unknown', None, _('show only unknown (not tracked) files')),
3119 3122 ('i', 'ignored', None, _('show ignored files')),
3120 3123 ('n', 'no-status', None, _('hide status prefix')),
3121 3124 ('0', 'print0', None,
3122 3125 _('end filenames with NUL, for use with xargs')),
3123 3126 ('I', 'include', [], _('include names matching the given patterns')),
3124 3127 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
3125 3128 _('hg status [OPTION]... [FILE]...')),
3126 3129 "tag":
3127 3130 (tag,
3128 3131 [('l', 'local', None, _('make the tag local')),
3129 3132 ('m', 'message', '', _('message for tag commit log entry')),
3130 3133 ('d', 'date', '', _('record datecode as commit date')),
3131 3134 ('u', 'user', '', _('record user as commiter')),
3132 3135 ('r', 'rev', '', _('revision to tag'))],
3133 3136 _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')),
3134 3137 "tags": (tags, [], _('hg tags')),
3135 3138 "tip":
3136 3139 (tip,
3137 3140 [('b', 'branches', None, _('show branches')),
3138 3141 ('', 'style', '', _('display using template map file')),
3139 3142 ('p', 'patch', None, _('show patch')),
3140 3143 ('', 'template', '', _('display with template'))],
3141 3144 _('hg tip [-b] [-p]')),
3142 3145 "unbundle":
3143 3146 (unbundle,
3144 3147 [('u', 'update', None,
3145 3148 _('update the working directory to tip after unbundle'))],
3146 3149 _('hg unbundle [-u] FILE')),
3147 3150 "debugundo|undo": (undo, [], _('hg undo')),
3148 3151 "^update|up|checkout|co":
3149 3152 (update,
3150 3153 [('b', 'branch', '', _('checkout the head of a specific branch')),
3151 3154 ('m', 'merge', None, _('allow merging of branches (DEPRECATED)')),
3152 3155 ('C', 'clean', None, _('overwrite locally modified files')),
3153 3156 ('f', 'force', None, _('force a merge with outstanding changes'))],
3154 3157 _('hg update [-b TAG] [-m] [-C] [-f] [REV]')),
3155 3158 "verify": (verify, [], _('hg verify')),
3156 3159 "version": (show_version, [], _('hg version')),
3157 3160 }
3158 3161
3159 3162 globalopts = [
3160 3163 ('R', 'repository', '',
3161 3164 _('repository root directory or symbolic path name')),
3162 3165 ('', 'cwd', '', _('change working directory')),
3163 3166 ('y', 'noninteractive', None,
3164 3167 _('do not prompt, assume \'yes\' for any required answers')),
3165 3168 ('q', 'quiet', None, _('suppress output')),
3166 3169 ('v', 'verbose', None, _('enable additional output')),
3167 3170 ('', 'config', [], _('set/override config option')),
3168 3171 ('', 'debug', None, _('enable debugging output')),
3169 3172 ('', 'debugger', None, _('start debugger')),
3170 3173 ('', 'traceback', None, _('print traceback on exception')),
3171 3174 ('', 'time', None, _('time how long the command takes')),
3172 3175 ('', 'profile', None, _('print command execution profile')),
3173 3176 ('', 'version', None, _('output version information and exit')),
3174 3177 ('h', 'help', None, _('display help and exit')),
3175 3178 ]
3176 3179
3177 3180 norepo = ("clone init version help debugancestor debugcomplete debugdata"
3178 3181 " debugindex debugindexdot")
3179 3182 optionalrepo = ("paths serve debugconfig")
3180 3183
3181 3184 def findpossible(cmd):
3182 3185 """
3183 3186 Return cmd -> (aliases, command table entry)
3184 3187 for each matching command.
3185 3188 Return debug commands (or their aliases) only if no normal command matches.
3186 3189 """
3187 3190 choice = {}
3188 3191 debugchoice = {}
3189 3192 for e in table.keys():
3190 3193 aliases = e.lstrip("^").split("|")
3191 3194 found = None
3192 3195 if cmd in aliases:
3193 3196 found = cmd
3194 3197 else:
3195 3198 for a in aliases:
3196 3199 if a.startswith(cmd):
3197 3200 found = a
3198 3201 break
3199 3202 if found is not None:
3200 3203 if aliases[0].startswith("debug"):
3201 3204 debugchoice[found] = (aliases, table[e])
3202 3205 else:
3203 3206 choice[found] = (aliases, table[e])
3204 3207
3205 3208 if not choice and debugchoice:
3206 3209 choice = debugchoice
3207 3210
3208 3211 return choice
3209 3212
3210 3213 def find(cmd):
3211 3214 """Return (aliases, command table entry) for command string."""
3212 3215 choice = findpossible(cmd)
3213 3216
3214 3217 if choice.has_key(cmd):
3215 3218 return choice[cmd]
3216 3219
3217 3220 if len(choice) > 1:
3218 3221 clist = choice.keys()
3219 3222 clist.sort()
3220 3223 raise AmbiguousCommand(cmd, clist)
3221 3224
3222 3225 if choice:
3223 3226 return choice.values()[0]
3224 3227
3225 3228 raise UnknownCommand(cmd)
3226 3229
3227 3230 def catchterm(*args):
3228 3231 raise util.SignalInterrupt
3229 3232
3230 3233 def run():
3231 3234 sys.exit(dispatch(sys.argv[1:]))
3232 3235
3233 3236 class ParseError(Exception):
3234 3237 """Exception raised on errors in parsing the command line."""
3235 3238
3236 3239 def parse(ui, args):
3237 3240 options = {}
3238 3241 cmdoptions = {}
3239 3242
3240 3243 try:
3241 3244 args = fancyopts.fancyopts(args, globalopts, options)
3242 3245 except fancyopts.getopt.GetoptError, inst:
3243 3246 raise ParseError(None, inst)
3244 3247
3245 3248 if args:
3246 3249 cmd, args = args[0], args[1:]
3247 3250 aliases, i = find(cmd)
3248 3251 cmd = aliases[0]
3249 3252 defaults = ui.config("defaults", cmd)
3250 3253 if defaults:
3251 3254 args = defaults.split() + args
3252 3255 c = list(i[1])
3253 3256 else:
3254 3257 cmd = None
3255 3258 c = []
3256 3259
3257 3260 # combine global options into local
3258 3261 for o in globalopts:
3259 3262 c.append((o[0], o[1], options[o[1]], o[3]))
3260 3263
3261 3264 try:
3262 3265 args = fancyopts.fancyopts(args, c, cmdoptions)
3263 3266 except fancyopts.getopt.GetoptError, inst:
3264 3267 raise ParseError(cmd, inst)
3265 3268
3266 3269 # separate global options back out
3267 3270 for o in globalopts:
3268 3271 n = o[1]
3269 3272 options[n] = cmdoptions[n]
3270 3273 del cmdoptions[n]
3271 3274
3272 3275 return (cmd, cmd and i[0] or None, args, options, cmdoptions)
3273 3276
3274 3277 def dispatch(args):
3275 3278 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
3276 3279 num = getattr(signal, name, None)
3277 3280 if num: signal.signal(num, catchterm)
3278 3281
3279 3282 try:
3280 3283 u = ui.ui(traceback='--traceback' in sys.argv[1:])
3281 3284 except util.Abort, inst:
3282 3285 sys.stderr.write(_("abort: %s\n") % inst)
3283 3286 return -1
3284 3287
3285 3288 external = []
3286 3289 for x in u.extensions():
3287 3290 try:
3288 3291 if x[1]:
3289 3292 mod = imp.load_source(x[0], x[1])
3290 3293 else:
3291 3294 def importh(name):
3292 3295 mod = __import__(name)
3293 3296 components = name.split('.')
3294 3297 for comp in components[1:]:
3295 3298 mod = getattr(mod, comp)
3296 3299 return mod
3297 3300 try:
3298 3301 mod = importh("hgext." + x[0])
3299 3302 except ImportError:
3300 3303 mod = importh(x[0])
3301 3304 external.append(mod)
3302 3305 except Exception, inst:
3303 3306 u.warn(_("*** failed to import extension %s: %s\n") % (x[0], inst))
3304 3307 if u.print_exc():
3305 3308 return 1
3306 3309
3307 3310 for x in external:
3308 3311 uisetup = getattr(x, 'uisetup', None)
3309 3312 if uisetup:
3310 3313 uisetup(u)
3311 3314 cmdtable = getattr(x, 'cmdtable', {})
3312 3315 for t in cmdtable:
3313 3316 if t in table:
3314 3317 u.warn(_("module %s overrides %s\n") % (x.__name__, t))
3315 3318 table.update(cmdtable)
3316 3319
3317 3320 try:
3318 3321 cmd, func, args, options, cmdoptions = parse(u, args)
3319 3322 if options["time"]:
3320 3323 def get_times():
3321 3324 t = os.times()
3322 3325 if t[4] == 0.0: # Windows leaves this as zero, so use time.clock()
3323 3326 t = (t[0], t[1], t[2], t[3], time.clock())
3324 3327 return t
3325 3328 s = get_times()
3326 3329 def print_time():
3327 3330 t = get_times()
3328 3331 u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") %
3329 3332 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
3330 3333 atexit.register(print_time)
3331 3334
3332 3335 u.updateopts(options["verbose"], options["debug"], options["quiet"],
3333 3336 not options["noninteractive"], options["traceback"],
3334 3337 options["config"])
3335 3338
3336 3339 # enter the debugger before command execution
3337 3340 if options['debugger']:
3338 3341 pdb.set_trace()
3339 3342
3340 3343 try:
3341 3344 if options['cwd']:
3342 3345 try:
3343 3346 os.chdir(options['cwd'])
3344 3347 except OSError, inst:
3345 3348 raise util.Abort('%s: %s' %
3346 3349 (options['cwd'], inst.strerror))
3347 3350
3348 3351 path = u.expandpath(options["repository"]) or ""
3349 3352 repo = path and hg.repository(u, path=path) or None
3350 3353
3351 3354 if options['help']:
3352 3355 return help_(u, cmd, options['version'])
3353 3356 elif options['version']:
3354 3357 return show_version(u)
3355 3358 elif not cmd:
3356 3359 return help_(u, 'shortlist')
3357 3360
3358 3361 if cmd not in norepo.split():
3359 3362 try:
3360 3363 if not repo:
3361 3364 repo = hg.repository(u, path=path)
3362 3365 u = repo.ui
3363 3366 for x in external:
3364 3367 if hasattr(x, 'reposetup'):
3365 3368 x.reposetup(u, repo)
3366 3369 except hg.RepoError:
3367 3370 if cmd not in optionalrepo.split():
3368 3371 raise
3369 3372 d = lambda: func(u, repo, *args, **cmdoptions)
3370 3373 else:
3371 3374 d = lambda: func(u, *args, **cmdoptions)
3372 3375
3373 3376 try:
3374 3377 if options['profile']:
3375 3378 import hotshot, hotshot.stats
3376 3379 prof = hotshot.Profile("hg.prof")
3377 3380 try:
3378 3381 try:
3379 3382 return prof.runcall(d)
3380 3383 except:
3381 3384 try:
3382 3385 u.warn(_('exception raised - generating '
3383 3386 'profile anyway\n'))
3384 3387 except:
3385 3388 pass
3386 3389 raise
3387 3390 finally:
3388 3391 prof.close()
3389 3392 stats = hotshot.stats.load("hg.prof")
3390 3393 stats.strip_dirs()
3391 3394 stats.sort_stats('time', 'calls')
3392 3395 stats.print_stats(40)
3393 3396 else:
3394 3397 return d()
3395 3398 finally:
3396 3399 u.flush()
3397 3400 except:
3398 3401 # enter the debugger when we hit an exception
3399 3402 if options['debugger']:
3400 3403 pdb.post_mortem(sys.exc_info()[2])
3401 3404 u.print_exc()
3402 3405 raise
3403 3406 except ParseError, inst:
3404 3407 if inst.args[0]:
3405 3408 u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))
3406 3409 help_(u, inst.args[0])
3407 3410 else:
3408 3411 u.warn(_("hg: %s\n") % inst.args[1])
3409 3412 help_(u, 'shortlist')
3410 3413 except AmbiguousCommand, inst:
3411 3414 u.warn(_("hg: command '%s' is ambiguous:\n %s\n") %
3412 3415 (inst.args[0], " ".join(inst.args[1])))
3413 3416 except UnknownCommand, inst:
3414 3417 u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
3415 3418 help_(u, 'shortlist')
3416 3419 except hg.RepoError, inst:
3417 3420 u.warn(_("abort: %s!\n") % inst)
3418 3421 except lock.LockHeld, inst:
3419 3422 if inst.errno == errno.ETIMEDOUT:
3420 3423 reason = _('timed out waiting for lock held by %s') % inst.locker
3421 3424 else:
3422 3425 reason = _('lock held by %s') % inst.locker
3423 3426 u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason))
3424 3427 except lock.LockUnavailable, inst:
3425 3428 u.warn(_("abort: could not lock %s: %s\n") %
3426 3429 (inst.desc or inst.filename, inst.strerror))
3427 3430 except revlog.RevlogError, inst:
3428 3431 u.warn(_("abort: "), inst, "!\n")
3429 3432 except util.SignalInterrupt:
3430 3433 u.warn(_("killed!\n"))
3431 3434 except KeyboardInterrupt:
3432 3435 try:
3433 3436 u.warn(_("interrupted!\n"))
3434 3437 except IOError, inst:
3435 3438 if inst.errno == errno.EPIPE:
3436 3439 if u.debugflag:
3437 3440 u.warn(_("\nbroken pipe\n"))
3438 3441 else:
3439 3442 raise
3440 3443 except IOError, inst:
3441 3444 if hasattr(inst, "code"):
3442 3445 u.warn(_("abort: %s\n") % inst)
3443 3446 elif hasattr(inst, "reason"):
3444 3447 u.warn(_("abort: error: %s\n") % inst.reason[1])
3445 3448 elif hasattr(inst, "args") and inst[0] == errno.EPIPE:
3446 3449 if u.debugflag:
3447 3450 u.warn(_("broken pipe\n"))
3448 3451 elif getattr(inst, "strerror", None):
3449 3452 if getattr(inst, "filename", None):
3450 3453 u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename))
3451 3454 else:
3452 3455 u.warn(_("abort: %s\n") % inst.strerror)
3453 3456 else:
3454 3457 raise
3455 3458 except OSError, inst:
3456 3459 if hasattr(inst, "filename"):
3457 3460 u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
3458 3461 else:
3459 3462 u.warn(_("abort: %s\n") % inst.strerror)
3460 3463 except util.Abort, inst:
3461 3464 u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n')
3462 3465 except TypeError, inst:
3463 3466 # was this an argument error?
3464 3467 tb = traceback.extract_tb(sys.exc_info()[2])
3465 3468 if len(tb) > 2: # no
3466 3469 raise
3467 3470 u.debug(inst, "\n")
3468 3471 u.warn(_("%s: invalid arguments\n") % cmd)
3469 3472 help_(u, cmd)
3470 3473 except SystemExit, inst:
3471 3474 # Commands shouldn't sys.exit directly, but give a return code.
3472 3475 # Just in case catch this and and pass exit code to caller.
3473 3476 return inst.code
3474 3477 except:
3475 3478 u.warn(_("** unknown exception encountered, details follow\n"))
3476 3479 u.warn(_("** report bug details to mercurial@selenic.com\n"))
3477 3480 u.warn(_("** Mercurial Distributed SCM (version %s)\n")
3478 3481 % version.get_version())
3479 3482 raise
3480 3483
3481 3484 return -1
General Comments 0
You need to be logged in to leave comments. Login now