##// END OF EJS Templates
commands: add verbose example to help text for add
Martin Geisler -
r10446:a565a244 default
parent child Browse files
Show More
@@ -1,3813 +1,3826 b''
1 1 # commands.py - command processing for mercurial
2 2 #
3 3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from node import hex, nullid, nullrev, short
9 9 from lock import release
10 10 from i18n import _, gettext
11 11 import os, re, sys, difflib, time, tempfile
12 12 import hg, util, revlog, bundlerepo, extensions, copies, error
13 13 import patch, help, mdiff, url, encoding, templatekw
14 14 import archival, changegroup, cmdutil, sshserver, hbisect
15 15 from hgweb import server
16 16 import merge as merge_
17 17 import minirst
18 18
19 19 # Commands start here, listed alphabetically
20 20
21 21 def add(ui, repo, *pats, **opts):
22 22 """add the specified files on the next commit
23 23
24 24 Schedule files to be version controlled and added to the
25 25 repository.
26 26
27 27 The files will be added to the repository at the next commit. To
28 28 undo an add before that, see hg forget.
29 29
30 30 If no names are given, add all files to the repository.
31
32 .. container:: verbose
33
34 An example showing how new (unknown) files are added
35 automatically by ``hg add``::
36
37 $ ls
38 foo.c
39 $ hg status
40 ? foo.c
41 $ hg add
42 adding foo.c
43 $ hg status
31 44 """
32 45
33 46 bad = []
34 47 names = []
35 48 m = cmdutil.match(repo, pats, opts)
36 49 oldbad = m.bad
37 50 m.bad = lambda x, y: bad.append(x) or oldbad(x, y)
38 51
39 52 for f in repo.walk(m):
40 53 exact = m.exact(f)
41 54 if exact or f not in repo.dirstate:
42 55 names.append(f)
43 56 if ui.verbose or not exact:
44 57 ui.status(_('adding %s\n') % m.rel(f))
45 58 if not opts.get('dry_run'):
46 59 bad += [f for f in repo.add(names) if f in m.files()]
47 60 return bad and 1 or 0
48 61
49 62 def addremove(ui, repo, *pats, **opts):
50 63 """add all new files, delete all missing files
51 64
52 65 Add all new files and remove all missing files from the
53 66 repository.
54 67
55 68 New files are ignored if they match any of the patterns in
56 69 .hgignore. As with add, these changes take effect at the next
57 70 commit.
58 71
59 72 Use the -s/--similarity option to detect renamed files. With a
60 73 parameter greater than 0, this compares every removed file with
61 74 every added file and records those similar enough as renames. This
62 75 option takes a percentage between 0 (disabled) and 100 (files must
63 76 be identical) as its parameter. Detecting renamed files this way
64 77 can be expensive.
65 78 """
66 79 try:
67 80 sim = float(opts.get('similarity') or 0)
68 81 except ValueError:
69 82 raise util.Abort(_('similarity must be a number'))
70 83 if sim < 0 or sim > 100:
71 84 raise util.Abort(_('similarity must be between 0 and 100'))
72 85 return cmdutil.addremove(repo, pats, opts, similarity=sim / 100.0)
73 86
74 87 def annotate(ui, repo, *pats, **opts):
75 88 """show changeset information by line for each file
76 89
77 90 List changes in files, showing the revision id responsible for
78 91 each line
79 92
80 93 This command is useful for discovering when a change was made and
81 94 by whom.
82 95
83 96 Without the -a/--text option, annotate will avoid processing files
84 97 it detects as binary. With -a, annotate will annotate the file
85 98 anyway, although the results will probably be neither useful
86 99 nor desirable.
87 100 """
88 101 datefunc = ui.quiet and util.shortdate or util.datestr
89 102 getdate = util.cachefunc(lambda x: datefunc(x[0].date()))
90 103
91 104 if not pats:
92 105 raise util.Abort(_('at least one filename or pattern is required'))
93 106
94 107 opmap = [('user', lambda x: ui.shortuser(x[0].user())),
95 108 ('number', lambda x: str(x[0].rev())),
96 109 ('changeset', lambda x: short(x[0].node())),
97 110 ('date', getdate),
98 111 ('file', lambda x: x[0].path()),
99 112 ]
100 113
101 114 if (not opts.get('user') and not opts.get('changeset')
102 115 and not opts.get('date') and not opts.get('file')):
103 116 opts['number'] = 1
104 117
105 118 linenumber = opts.get('line_number') is not None
106 119 if linenumber and (not opts.get('changeset')) and (not opts.get('number')):
107 120 raise util.Abort(_('at least one of -n/-c is required for -l'))
108 121
109 122 funcmap = [func for op, func in opmap if opts.get(op)]
110 123 if linenumber:
111 124 lastfunc = funcmap[-1]
112 125 funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1])
113 126
114 127 ctx = repo[opts.get('rev')]
115 128 m = cmdutil.match(repo, pats, opts)
116 129 follow = not opts.get('no_follow')
117 130 for abs in ctx.walk(m):
118 131 fctx = ctx[abs]
119 132 if not opts.get('text') and util.binary(fctx.data()):
120 133 ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
121 134 continue
122 135
123 136 lines = fctx.annotate(follow=follow, linenumber=linenumber)
124 137 pieces = []
125 138
126 139 for f in funcmap:
127 140 l = [f(n) for n, dummy in lines]
128 141 if l:
129 142 ml = max(map(len, l))
130 143 pieces.append(["%*s" % (ml, x) for x in l])
131 144
132 145 if pieces:
133 146 for p, l in zip(zip(*pieces), lines):
134 147 ui.write("%s: %s" % (" ".join(p), l[1]))
135 148
136 149 def archive(ui, repo, dest, **opts):
137 150 '''create an unversioned archive of a repository revision
138 151
139 152 By default, the revision used is the parent of the working
140 153 directory; use -r/--rev to specify a different revision.
141 154
142 155 To specify the type of archive to create, use -t/--type. Valid
143 156 types are:
144 157
145 158 :``files``: a directory full of files (default)
146 159 :``tar``: tar archive, uncompressed
147 160 :``tbz2``: tar archive, compressed using bzip2
148 161 :``tgz``: tar archive, compressed using gzip
149 162 :``uzip``: zip archive, uncompressed
150 163 :``zip``: zip archive, compressed using deflate
151 164
152 165 The exact name of the destination archive or directory is given
153 166 using a format string; see 'hg help export' for details.
154 167
155 168 Each member added to an archive file has a directory prefix
156 169 prepended. Use -p/--prefix to specify a format string for the
157 170 prefix. The default is the basename of the archive, with suffixes
158 171 removed.
159 172 '''
160 173
161 174 ctx = repo[opts.get('rev')]
162 175 if not ctx:
163 176 raise util.Abort(_('no working directory: please specify a revision'))
164 177 node = ctx.node()
165 178 dest = cmdutil.make_filename(repo, dest, node)
166 179 if os.path.realpath(dest) == repo.root:
167 180 raise util.Abort(_('repository root cannot be destination'))
168 181 matchfn = cmdutil.match(repo, [], opts)
169 182 kind = opts.get('type') or 'files'
170 183 prefix = opts.get('prefix')
171 184 if dest == '-':
172 185 if kind == 'files':
173 186 raise util.Abort(_('cannot archive plain files to stdout'))
174 187 dest = sys.stdout
175 188 if not prefix:
176 189 prefix = os.path.basename(repo.root) + '-%h'
177 190 prefix = cmdutil.make_filename(repo, prefix, node)
178 191 archival.archive(repo, dest, node, kind, not opts.get('no_decode'),
179 192 matchfn, prefix)
180 193
181 194 def backout(ui, repo, node=None, rev=None, **opts):
182 195 '''reverse effect of earlier changeset
183 196
184 197 Commit the backed out changes as a new changeset. The new
185 198 changeset is a child of the backed out changeset.
186 199
187 200 If you backout a changeset other than the tip, a new head is
188 201 created. This head will be the new tip and you should merge this
189 202 backout changeset with another head.
190 203
191 204 The --merge option remembers the parent of the working directory
192 205 before starting the backout, then merges the new head with that
193 206 changeset afterwards. This saves you from doing the merge by hand.
194 207 The result of this merge is not committed, as with a normal merge.
195 208
196 209 See 'hg help dates' for a list of formats valid for -d/--date.
197 210 '''
198 211 if rev and node:
199 212 raise util.Abort(_("please specify just one revision"))
200 213
201 214 if not rev:
202 215 rev = node
203 216
204 217 if not rev:
205 218 raise util.Abort(_("please specify a revision to backout"))
206 219
207 220 date = opts.get('date')
208 221 if date:
209 222 opts['date'] = util.parsedate(date)
210 223
211 224 cmdutil.bail_if_changed(repo)
212 225 node = repo.lookup(rev)
213 226
214 227 op1, op2 = repo.dirstate.parents()
215 228 a = repo.changelog.ancestor(op1, node)
216 229 if a != node:
217 230 raise util.Abort(_('cannot backout change on a different branch'))
218 231
219 232 p1, p2 = repo.changelog.parents(node)
220 233 if p1 == nullid:
221 234 raise util.Abort(_('cannot backout a change with no parents'))
222 235 if p2 != nullid:
223 236 if not opts.get('parent'):
224 237 raise util.Abort(_('cannot backout a merge changeset without '
225 238 '--parent'))
226 239 p = repo.lookup(opts['parent'])
227 240 if p not in (p1, p2):
228 241 raise util.Abort(_('%s is not a parent of %s') %
229 242 (short(p), short(node)))
230 243 parent = p
231 244 else:
232 245 if opts.get('parent'):
233 246 raise util.Abort(_('cannot use --parent on non-merge changeset'))
234 247 parent = p1
235 248
236 249 # the backout should appear on the same branch
237 250 branch = repo.dirstate.branch()
238 251 hg.clean(repo, node, show_stats=False)
239 252 repo.dirstate.setbranch(branch)
240 253 revert_opts = opts.copy()
241 254 revert_opts['date'] = None
242 255 revert_opts['all'] = True
243 256 revert_opts['rev'] = hex(parent)
244 257 revert_opts['no_backup'] = None
245 258 revert(ui, repo, **revert_opts)
246 259 commit_opts = opts.copy()
247 260 commit_opts['addremove'] = False
248 261 if not commit_opts['message'] and not commit_opts['logfile']:
249 262 # we don't translate commit messages
250 263 commit_opts['message'] = "Backed out changeset %s" % short(node)
251 264 commit_opts['force_editor'] = True
252 265 commit(ui, repo, **commit_opts)
253 266 def nice(node):
254 267 return '%d:%s' % (repo.changelog.rev(node), short(node))
255 268 ui.status(_('changeset %s backs out changeset %s\n') %
256 269 (nice(repo.changelog.tip()), nice(node)))
257 270 if op1 != node:
258 271 hg.clean(repo, op1, show_stats=False)
259 272 if opts.get('merge'):
260 273 ui.status(_('merging with changeset %s\n')
261 274 % nice(repo.changelog.tip()))
262 275 hg.merge(repo, hex(repo.changelog.tip()))
263 276 else:
264 277 ui.status(_('the backout changeset is a new head - '
265 278 'do not forget to merge\n'))
266 279 ui.status(_('(use "backout --merge" '
267 280 'if you want to auto-merge)\n'))
268 281
269 282 def bisect(ui, repo, rev=None, extra=None, command=None,
270 283 reset=None, good=None, bad=None, skip=None, noupdate=None):
271 284 """subdivision search of changesets
272 285
273 286 This command helps to find changesets which introduce problems. To
274 287 use, mark the earliest changeset you know exhibits the problem as
275 288 bad, then mark the latest changeset which is free from the problem
276 289 as good. Bisect will update your working directory to a revision
277 290 for testing (unless the -U/--noupdate option is specified). Once
278 291 you have performed tests, mark the working directory as good or
279 292 bad, and bisect will either update to another candidate changeset
280 293 or announce that it has found the bad revision.
281 294
282 295 As a shortcut, you can also use the revision argument to mark a
283 296 revision as good or bad without checking it out first.
284 297
285 298 If you supply a command, it will be used for automatic bisection.
286 299 Its exit status will be used to mark revisions as good or bad:
287 300 status 0 means good, 125 means to skip the revision, 127
288 301 (command not found) will abort the bisection, and any other
289 302 non-zero exit status means the revision is bad.
290 303 """
291 304 def print_result(nodes, good):
292 305 displayer = cmdutil.show_changeset(ui, repo, {})
293 306 if len(nodes) == 1:
294 307 # narrowed it down to a single revision
295 308 if good:
296 309 ui.write(_("The first good revision is:\n"))
297 310 else:
298 311 ui.write(_("The first bad revision is:\n"))
299 312 displayer.show(repo[nodes[0]])
300 313 else:
301 314 # multiple possible revisions
302 315 if good:
303 316 ui.write(_("Due to skipped revisions, the first "
304 317 "good revision could be any of:\n"))
305 318 else:
306 319 ui.write(_("Due to skipped revisions, the first "
307 320 "bad revision could be any of:\n"))
308 321 for n in nodes:
309 322 displayer.show(repo[n])
310 323 displayer.close()
311 324
312 325 def check_state(state, interactive=True):
313 326 if not state['good'] or not state['bad']:
314 327 if (good or bad or skip or reset) and interactive:
315 328 return
316 329 if not state['good']:
317 330 raise util.Abort(_('cannot bisect (no known good revisions)'))
318 331 else:
319 332 raise util.Abort(_('cannot bisect (no known bad revisions)'))
320 333 return True
321 334
322 335 # backward compatibility
323 336 if rev in "good bad reset init".split():
324 337 ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n"))
325 338 cmd, rev, extra = rev, extra, None
326 339 if cmd == "good":
327 340 good = True
328 341 elif cmd == "bad":
329 342 bad = True
330 343 else:
331 344 reset = True
332 345 elif extra or good + bad + skip + reset + bool(command) > 1:
333 346 raise util.Abort(_('incompatible arguments'))
334 347
335 348 if reset:
336 349 p = repo.join("bisect.state")
337 350 if os.path.exists(p):
338 351 os.unlink(p)
339 352 return
340 353
341 354 state = hbisect.load_state(repo)
342 355
343 356 if command:
344 357 changesets = 1
345 358 try:
346 359 while changesets:
347 360 # update state
348 361 status = util.system(command)
349 362 if status == 125:
350 363 transition = "skip"
351 364 elif status == 0:
352 365 transition = "good"
353 366 # status < 0 means process was killed
354 367 elif status == 127:
355 368 raise util.Abort(_("failed to execute %s") % command)
356 369 elif status < 0:
357 370 raise util.Abort(_("%s killed") % command)
358 371 else:
359 372 transition = "bad"
360 373 ctx = repo[rev or '.']
361 374 state[transition].append(ctx.node())
362 375 ui.status(_('Changeset %d:%s: %s\n') % (ctx, ctx, transition))
363 376 check_state(state, interactive=False)
364 377 # bisect
365 378 nodes, changesets, good = hbisect.bisect(repo.changelog, state)
366 379 # update to next check
367 380 cmdutil.bail_if_changed(repo)
368 381 hg.clean(repo, nodes[0], show_stats=False)
369 382 finally:
370 383 hbisect.save_state(repo, state)
371 384 return print_result(nodes, good)
372 385
373 386 # update state
374 387 node = repo.lookup(rev or '.')
375 388 if good or bad or skip:
376 389 if good:
377 390 state['good'].append(node)
378 391 elif bad:
379 392 state['bad'].append(node)
380 393 elif skip:
381 394 state['skip'].append(node)
382 395 hbisect.save_state(repo, state)
383 396
384 397 if not check_state(state):
385 398 return
386 399
387 400 # actually bisect
388 401 nodes, changesets, good = hbisect.bisect(repo.changelog, state)
389 402 if changesets == 0:
390 403 print_result(nodes, good)
391 404 else:
392 405 assert len(nodes) == 1 # only a single node can be tested next
393 406 node = nodes[0]
394 407 # compute the approximate number of remaining tests
395 408 tests, size = 0, 2
396 409 while size <= changesets:
397 410 tests, size = tests + 1, size * 2
398 411 rev = repo.changelog.rev(node)
399 412 ui.write(_("Testing changeset %d:%s "
400 413 "(%d changesets remaining, ~%d tests)\n")
401 414 % (rev, short(node), changesets, tests))
402 415 if not noupdate:
403 416 cmdutil.bail_if_changed(repo)
404 417 return hg.clean(repo, node)
405 418
406 419 def branch(ui, repo, label=None, **opts):
407 420 """set or show the current branch name
408 421
409 422 With no argument, show the current branch name. With one argument,
410 423 set the working directory branch name (the branch will not exist
411 424 in the repository until the next commit). Standard practice
412 425 recommends that primary development take place on the 'default'
413 426 branch.
414 427
415 428 Unless -f/--force is specified, branch will not let you set a
416 429 branch name that already exists, even if it's inactive.
417 430
418 431 Use -C/--clean to reset the working directory branch to that of
419 432 the parent of the working directory, negating a previous branch
420 433 change.
421 434
422 435 Use the command 'hg update' to switch to an existing branch. Use
423 436 'hg commit --close-branch' to mark this branch as closed.
424 437 """
425 438
426 439 if opts.get('clean'):
427 440 label = repo[None].parents()[0].branch()
428 441 repo.dirstate.setbranch(label)
429 442 ui.status(_('reset working directory to branch %s\n') % label)
430 443 elif label:
431 444 utflabel = encoding.fromlocal(label)
432 445 if not opts.get('force') and utflabel in repo.branchtags():
433 446 if label not in [p.branch() for p in repo.parents()]:
434 447 raise util.Abort(_('a branch of the same name already exists'
435 448 ' (use --force to override)'))
436 449 repo.dirstate.setbranch(utflabel)
437 450 ui.status(_('marked working directory as branch %s\n') % label)
438 451 else:
439 452 ui.write("%s\n" % encoding.tolocal(repo.dirstate.branch()))
440 453
441 454 def branches(ui, repo, active=False, closed=False):
442 455 """list repository named branches
443 456
444 457 List the repository's named branches, indicating which ones are
445 458 inactive. If -c/--closed is specified, also list branches which have
446 459 been marked closed (see hg commit --close-branch).
447 460
448 461 If -a/--active is specified, only show active branches. A branch
449 462 is considered active if it contains repository heads.
450 463
451 464 Use the command 'hg update' to switch to an existing branch.
452 465 """
453 466
454 467 hexfunc = ui.debugflag and hex or short
455 468 activebranches = [repo[n].branch() for n in repo.heads()]
456 469 def testactive(tag, node):
457 470 realhead = tag in activebranches
458 471 open = node in repo.branchheads(tag, closed=False)
459 472 return realhead and open
460 473 branches = sorted([(testactive(tag, node), repo.changelog.rev(node), tag)
461 474 for tag, node in repo.branchtags().items()],
462 475 reverse=True)
463 476
464 477 for isactive, node, tag in branches:
465 478 if (not active) or isactive:
466 479 encodedtag = encoding.tolocal(tag)
467 480 if ui.quiet:
468 481 ui.write("%s\n" % encodedtag)
469 482 else:
470 483 hn = repo.lookup(node)
471 484 if isactive:
472 485 notice = ''
473 486 elif hn not in repo.branchheads(tag, closed=False):
474 487 if not closed:
475 488 continue
476 489 notice = _(' (closed)')
477 490 else:
478 491 notice = _(' (inactive)')
479 492 rev = str(node).rjust(31 - encoding.colwidth(encodedtag))
480 493 data = encodedtag, rev, hexfunc(hn), notice
481 494 ui.write("%s %s:%s%s\n" % data)
482 495
483 496 def bundle(ui, repo, fname, dest=None, **opts):
484 497 """create a changegroup file
485 498
486 499 Generate a compressed changegroup file collecting changesets not
487 500 known to be in another repository.
488 501
489 502 If you omit the destination repository, then hg assumes the
490 503 destination will have all the nodes you specify with --base
491 504 parameters. To create a bundle containing all changesets, use
492 505 -a/--all (or --base null).
493 506
494 507 You can change compression method with the -t/--type option.
495 508 The available compression methods are: none, bzip2, and
496 509 gzip (by default, bundles are compressed using bzip2).
497 510
498 511 The bundle file can then be transferred using conventional means
499 512 and applied to another repository with the unbundle or pull
500 513 command. This is useful when direct push and pull are not
501 514 available or when exporting an entire repository is undesirable.
502 515
503 516 Applying bundles preserves all changeset contents including
504 517 permissions, copy/rename information, and revision history.
505 518 """
506 519 revs = opts.get('rev') or None
507 520 if revs:
508 521 revs = [repo.lookup(rev) for rev in revs]
509 522 if opts.get('all'):
510 523 base = ['null']
511 524 else:
512 525 base = opts.get('base')
513 526 if base:
514 527 if dest:
515 528 raise util.Abort(_("--base is incompatible with specifying "
516 529 "a destination"))
517 530 base = [repo.lookup(rev) for rev in base]
518 531 # create the right base
519 532 # XXX: nodesbetween / changegroup* should be "fixed" instead
520 533 o = []
521 534 has = set((nullid,))
522 535 for n in base:
523 536 has.update(repo.changelog.reachable(n))
524 537 if revs:
525 538 visit = list(revs)
526 539 else:
527 540 visit = repo.changelog.heads()
528 541 seen = {}
529 542 while visit:
530 543 n = visit.pop(0)
531 544 parents = [p for p in repo.changelog.parents(n) if p not in has]
532 545 if len(parents) == 0:
533 546 o.insert(0, n)
534 547 else:
535 548 for p in parents:
536 549 if p not in seen:
537 550 seen[p] = 1
538 551 visit.append(p)
539 552 else:
540 553 dest = ui.expandpath(dest or 'default-push', dest or 'default')
541 554 dest, branches = hg.parseurl(dest, opts.get('branch'))
542 555 other = hg.repository(cmdutil.remoteui(repo, opts), dest)
543 556 revs, checkout = hg.addbranchrevs(repo, other, branches, revs)
544 557 o = repo.findoutgoing(other, force=opts.get('force'))
545 558
546 559 if revs:
547 560 cg = repo.changegroupsubset(o, revs, 'bundle')
548 561 else:
549 562 cg = repo.changegroup(o, 'bundle')
550 563
551 564 bundletype = opts.get('type', 'bzip2').lower()
552 565 btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'}
553 566 bundletype = btypes.get(bundletype)
554 567 if bundletype not in changegroup.bundletypes:
555 568 raise util.Abort(_('unknown bundle type specified with --type'))
556 569
557 570 changegroup.writebundle(cg, fname, bundletype)
558 571
559 572 def cat(ui, repo, file1, *pats, **opts):
560 573 """output the current or given revision of files
561 574
562 575 Print the specified files as they were at the given revision. If
563 576 no revision is given, the parent of the working directory is used,
564 577 or tip if no revision is checked out.
565 578
566 579 Output may be to a file, in which case the name of the file is
567 580 given using a format string. The formatting rules are the same as
568 581 for the export command, with the following additions:
569 582
570 583 :``%s``: basename of file being printed
571 584 :``%d``: dirname of file being printed, or '.' if in repository root
572 585 :``%p``: root-relative path name of file being printed
573 586 """
574 587 ctx = repo[opts.get('rev')]
575 588 err = 1
576 589 m = cmdutil.match(repo, (file1,) + pats, opts)
577 590 for abs in ctx.walk(m):
578 591 fp = cmdutil.make_file(repo, opts.get('output'), ctx.node(), pathname=abs)
579 592 data = ctx[abs].data()
580 593 if opts.get('decode'):
581 594 data = repo.wwritedata(abs, data)
582 595 fp.write(data)
583 596 err = 0
584 597 return err
585 598
586 599 def clone(ui, source, dest=None, **opts):
587 600 """make a copy of an existing repository
588 601
589 602 Create a copy of an existing repository in a new directory.
590 603
591 604 If no destination directory name is specified, it defaults to the
592 605 basename of the source.
593 606
594 607 The location of the source is added to the new repository's
595 608 .hg/hgrc file, as the default to be used for future pulls.
596 609
597 610 See 'hg help urls' for valid source format details.
598 611
599 612 It is possible to specify an ``ssh://`` URL as the destination, but no
600 613 .hg/hgrc and working directory will be created on the remote side.
601 614 Please see 'hg help urls' for important details about ``ssh://`` URLs.
602 615
603 616 If the -U/--noupdate option is specified, the new clone will contain
604 617 only a repository (.hg) and no working copy (the working copy parent
605 618 will be the null changeset). Otherwise, clone will initially check
606 619 out (in order of precedence):
607 620
608 621 a) the changeset, tag or branch specified with -u/--updaterev
609 622 b) the changeset, tag or branch given with the first -r/--rev
610 623 c) the branch given with the first -b/--branch
611 624 d) the branch given with the url#branch source syntax
612 625 e) the head of the default branch
613 626
614 627 Use 'hg clone -u . src dst' to checkout the source repository's
615 628 parent changeset (applicable for local source repositories only).
616 629
617 630 A set of changesets (tags, or branch names) to pull may be specified
618 631 by listing each changeset (tag, or branch name) with -r/--rev.
619 632 If -r/--rev is used, the cloned repository will contain only a subset
620 633 of the changesets of the source repository. Only the set of changesets
621 634 defined by all -r/--rev options (including all their ancestors)
622 635 will be pulled into the destination repository.
623 636 No subsequent changesets (including subsequent tags) will be present
624 637 in the destination.
625 638
626 639 Using -r/--rev (or 'clone src#rev dest') implies --pull, even for
627 640 local source repositories.
628 641
629 642 For efficiency, hardlinks are used for cloning whenever the source
630 643 and destination are on the same filesystem (note this applies only
631 644 to the repository data, not to the checked out files). Some
632 645 filesystems, such as AFS, implement hardlinking incorrectly, but
633 646 do not report errors. In these cases, use the --pull option to
634 647 avoid hardlinking.
635 648
636 649 In some cases, you can clone repositories and checked out files
637 650 using full hardlinks with ::
638 651
639 652 $ cp -al REPO REPOCLONE
640 653
641 654 This is the fastest way to clone, but it is not always safe. The
642 655 operation is not atomic (making sure REPO is not modified during
643 656 the operation is up to you) and you have to make sure your editor
644 657 breaks hardlinks (Emacs and most Linux Kernel tools do so). Also,
645 658 this is not compatible with certain extensions that place their
646 659 metadata under the .hg directory, such as mq.
647 660 """
648 661 if opts.get('noupdate') and opts.get('updaterev'):
649 662 raise util.Abort(_("cannot specify both --noupdate and --updaterev"))
650 663
651 664 hg.clone(cmdutil.remoteui(ui, opts), source, dest,
652 665 pull=opts.get('pull'),
653 666 stream=opts.get('uncompressed'),
654 667 rev=opts.get('rev'),
655 668 update=opts.get('updaterev') or not opts.get('noupdate'),
656 669 branch=opts.get('branch'))
657 670
658 671 def commit(ui, repo, *pats, **opts):
659 672 """commit the specified files or all outstanding changes
660 673
661 674 Commit changes to the given files into the repository. Unlike a
662 675 centralized RCS, this operation is a local operation. See hg push
663 676 for a way to actively distribute your changes.
664 677
665 678 If a list of files is omitted, all changes reported by "hg status"
666 679 will be committed.
667 680
668 681 If you are committing the result of a merge, do not provide any
669 682 filenames or -I/-X filters.
670 683
671 684 If no commit message is specified, the configured editor is
672 685 started to prompt you for a message.
673 686
674 687 See 'hg help dates' for a list of formats valid for -d/--date.
675 688 """
676 689 extra = {}
677 690 if opts.get('close_branch'):
678 691 extra['close'] = 1
679 692 e = cmdutil.commiteditor
680 693 if opts.get('force_editor'):
681 694 e = cmdutil.commitforceeditor
682 695
683 696 def commitfunc(ui, repo, message, match, opts):
684 697 return repo.commit(message, opts.get('user'), opts.get('date'), match,
685 698 editor=e, extra=extra)
686 699
687 700 node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
688 701 if not node:
689 702 ui.status(_("nothing changed\n"))
690 703 return
691 704 cl = repo.changelog
692 705 rev = cl.rev(node)
693 706 parents = cl.parentrevs(rev)
694 707 if rev - 1 in parents:
695 708 # one of the parents was the old tip
696 709 pass
697 710 elif (parents == (nullrev, nullrev) or
698 711 len(cl.heads(cl.node(parents[0]))) > 1 and
699 712 (parents[1] == nullrev or len(cl.heads(cl.node(parents[1]))) > 1)):
700 713 ui.status(_('created new head\n'))
701 714
702 715 if ui.debugflag:
703 716 ui.write(_('committed changeset %d:%s\n') % (rev, hex(node)))
704 717 elif ui.verbose:
705 718 ui.write(_('committed changeset %d:%s\n') % (rev, short(node)))
706 719
707 720 def copy(ui, repo, *pats, **opts):
708 721 """mark files as copied for the next commit
709 722
710 723 Mark dest as having copies of source files. If dest is a
711 724 directory, copies are put in that directory. If dest is a file,
712 725 the source must be a single file.
713 726
714 727 By default, this command copies the contents of files as they
715 728 exist in the working directory. If invoked with -A/--after, the
716 729 operation is recorded, but no copying is performed.
717 730
718 731 This command takes effect with the next commit. To undo a copy
719 732 before that, see hg revert.
720 733 """
721 734 wlock = repo.wlock(False)
722 735 try:
723 736 return cmdutil.copy(ui, repo, pats, opts)
724 737 finally:
725 738 wlock.release()
726 739
727 740 def debugancestor(ui, repo, *args):
728 741 """find the ancestor revision of two revisions in a given index"""
729 742 if len(args) == 3:
730 743 index, rev1, rev2 = args
731 744 r = revlog.revlog(util.opener(os.getcwd(), audit=False), index)
732 745 lookup = r.lookup
733 746 elif len(args) == 2:
734 747 if not repo:
735 748 raise util.Abort(_("There is no Mercurial repository here "
736 749 "(.hg not found)"))
737 750 rev1, rev2 = args
738 751 r = repo.changelog
739 752 lookup = repo.lookup
740 753 else:
741 754 raise util.Abort(_('either two or three arguments required'))
742 755 a = r.ancestor(lookup(rev1), lookup(rev2))
743 756 ui.write("%d:%s\n" % (r.rev(a), hex(a)))
744 757
745 758 def debugcommands(ui, cmd='', *args):
746 759 for cmd, vals in sorted(table.iteritems()):
747 760 cmd = cmd.split('|')[0].strip('^')
748 761 opts = ', '.join([i[1] for i in vals[1]])
749 762 ui.write('%s: %s\n' % (cmd, opts))
750 763
751 764 def debugcomplete(ui, cmd='', **opts):
752 765 """returns the completion list associated with the given command"""
753 766
754 767 if opts.get('options'):
755 768 options = []
756 769 otables = [globalopts]
757 770 if cmd:
758 771 aliases, entry = cmdutil.findcmd(cmd, table, False)
759 772 otables.append(entry[1])
760 773 for t in otables:
761 774 for o in t:
762 775 if o[0]:
763 776 options.append('-%s' % o[0])
764 777 options.append('--%s' % o[1])
765 778 ui.write("%s\n" % "\n".join(options))
766 779 return
767 780
768 781 cmdlist = cmdutil.findpossible(cmd, table)
769 782 if ui.verbose:
770 783 cmdlist = [' '.join(c[0]) for c in cmdlist.values()]
771 784 ui.write("%s\n" % "\n".join(sorted(cmdlist)))
772 785
773 786 def debugfsinfo(ui, path = "."):
774 787 open('.debugfsinfo', 'w').write('')
775 788 ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no'))
776 789 ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no'))
777 790 ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo')
778 791 and 'yes' or 'no'))
779 792 os.unlink('.debugfsinfo')
780 793
781 794 def debugrebuildstate(ui, repo, rev="tip"):
782 795 """rebuild the dirstate as it would look like for the given revision"""
783 796 ctx = repo[rev]
784 797 wlock = repo.wlock()
785 798 try:
786 799 repo.dirstate.rebuild(ctx.node(), ctx.manifest())
787 800 finally:
788 801 wlock.release()
789 802
790 803 def debugcheckstate(ui, repo):
791 804 """validate the correctness of the current dirstate"""
792 805 parent1, parent2 = repo.dirstate.parents()
793 806 m1 = repo[parent1].manifest()
794 807 m2 = repo[parent2].manifest()
795 808 errors = 0
796 809 for f in repo.dirstate:
797 810 state = repo.dirstate[f]
798 811 if state in "nr" and f not in m1:
799 812 ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
800 813 errors += 1
801 814 if state in "a" and f in m1:
802 815 ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state))
803 816 errors += 1
804 817 if state in "m" and f not in m1 and f not in m2:
805 818 ui.warn(_("%s in state %s, but not in either manifest\n") %
806 819 (f, state))
807 820 errors += 1
808 821 for f in m1:
809 822 state = repo.dirstate[f]
810 823 if state not in "nrm":
811 824 ui.warn(_("%s in manifest1, but listed as state %s") % (f, state))
812 825 errors += 1
813 826 if errors:
814 827 error = _(".hg/dirstate inconsistent with current parent's manifest")
815 828 raise util.Abort(error)
816 829
817 830 def showconfig(ui, repo, *values, **opts):
818 831 """show combined config settings from all hgrc files
819 832
820 833 With no arguments, print names and values of all config items.
821 834
822 835 With one argument of the form section.name, print just the value
823 836 of that config item.
824 837
825 838 With multiple arguments, print names and values of all config
826 839 items with matching section names.
827 840
828 841 With --debug, the source (filename and line number) is printed
829 842 for each config item.
830 843 """
831 844
832 845 untrusted = bool(opts.get('untrusted'))
833 846 if values:
834 847 if len([v for v in values if '.' in v]) > 1:
835 848 raise util.Abort(_('only one config item permitted'))
836 849 for section, name, value in ui.walkconfig(untrusted=untrusted):
837 850 sectname = section + '.' + name
838 851 if values:
839 852 for v in values:
840 853 if v == section:
841 854 ui.debug('%s: ' %
842 855 ui.configsource(section, name, untrusted))
843 856 ui.write('%s=%s\n' % (sectname, value))
844 857 elif v == sectname:
845 858 ui.debug('%s: ' %
846 859 ui.configsource(section, name, untrusted))
847 860 ui.write(value, '\n')
848 861 else:
849 862 ui.debug('%s: ' %
850 863 ui.configsource(section, name, untrusted))
851 864 ui.write('%s=%s\n' % (sectname, value))
852 865
853 866 def debugsetparents(ui, repo, rev1, rev2=None):
854 867 """manually set the parents of the current working directory
855 868
856 869 This is useful for writing repository conversion tools, but should
857 870 be used with care.
858 871 """
859 872
860 873 if not rev2:
861 874 rev2 = hex(nullid)
862 875
863 876 wlock = repo.wlock()
864 877 try:
865 878 repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2))
866 879 finally:
867 880 wlock.release()
868 881
869 882 def debugstate(ui, repo, nodates=None):
870 883 """show the contents of the current dirstate"""
871 884 timestr = ""
872 885 showdate = not nodates
873 886 for file_, ent in sorted(repo.dirstate._map.iteritems()):
874 887 if showdate:
875 888 if ent[3] == -1:
876 889 # Pad or slice to locale representation
877 890 locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ",
878 891 time.localtime(0)))
879 892 timestr = 'unset'
880 893 timestr = (timestr[:locale_len] +
881 894 ' ' * (locale_len - len(timestr)))
882 895 else:
883 896 timestr = time.strftime("%Y-%m-%d %H:%M:%S ",
884 897 time.localtime(ent[3]))
885 898 if ent[1] & 020000:
886 899 mode = 'lnk'
887 900 else:
888 901 mode = '%3o' % (ent[1] & 0777)
889 902 ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_))
890 903 for f in repo.dirstate.copies():
891 904 ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f))
892 905
893 906 def debugsub(ui, repo, rev=None):
894 907 if rev == '':
895 908 rev = None
896 909 for k, v in sorted(repo[rev].substate.items()):
897 910 ui.write('path %s\n' % k)
898 911 ui.write(' source %s\n' % v[0])
899 912 ui.write(' revision %s\n' % v[1])
900 913
901 914 def debugdata(ui, file_, rev):
902 915 """dump the contents of a data file revision"""
903 916 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_[:-2] + ".i")
904 917 try:
905 918 ui.write(r.revision(r.lookup(rev)))
906 919 except KeyError:
907 920 raise util.Abort(_('invalid revision identifier %s') % rev)
908 921
909 922 def debugdate(ui, date, range=None, **opts):
910 923 """parse and display a date"""
911 924 if opts["extended"]:
912 925 d = util.parsedate(date, util.extendeddateformats)
913 926 else:
914 927 d = util.parsedate(date)
915 928 ui.write("internal: %s %s\n" % d)
916 929 ui.write("standard: %s\n" % util.datestr(d))
917 930 if range:
918 931 m = util.matchdate(range)
919 932 ui.write("match: %s\n" % m(d[0]))
920 933
921 934 def debugindex(ui, file_):
922 935 """dump the contents of an index file"""
923 936 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_)
924 937 ui.write(" rev offset length base linkrev"
925 938 " nodeid p1 p2\n")
926 939 for i in r:
927 940 node = r.node(i)
928 941 try:
929 942 pp = r.parents(node)
930 943 except:
931 944 pp = [nullid, nullid]
932 945 ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % (
933 946 i, r.start(i), r.length(i), r.base(i), r.linkrev(i),
934 947 short(node), short(pp[0]), short(pp[1])))
935 948
936 949 def debugindexdot(ui, file_):
937 950 """dump an index DAG as a graphviz dot file"""
938 951 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_)
939 952 ui.write("digraph G {\n")
940 953 for i in r:
941 954 node = r.node(i)
942 955 pp = r.parents(node)
943 956 ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
944 957 if pp[1] != nullid:
945 958 ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
946 959 ui.write("}\n")
947 960
948 961 def debuginstall(ui):
949 962 '''test Mercurial installation'''
950 963
951 964 def writetemp(contents):
952 965 (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-")
953 966 f = os.fdopen(fd, "wb")
954 967 f.write(contents)
955 968 f.close()
956 969 return name
957 970
958 971 problems = 0
959 972
960 973 # encoding
961 974 ui.status(_("Checking encoding (%s)...\n") % encoding.encoding)
962 975 try:
963 976 encoding.fromlocal("test")
964 977 except util.Abort, inst:
965 978 ui.write(" %s\n" % inst)
966 979 ui.write(_(" (check that your locale is properly set)\n"))
967 980 problems += 1
968 981
969 982 # compiled modules
970 983 ui.status(_("Checking extensions...\n"))
971 984 try:
972 985 import bdiff, mpatch, base85
973 986 except Exception, inst:
974 987 ui.write(" %s\n" % inst)
975 988 ui.write(_(" One or more extensions could not be found"))
976 989 ui.write(_(" (check that you compiled the extensions)\n"))
977 990 problems += 1
978 991
979 992 # templates
980 993 ui.status(_("Checking templates...\n"))
981 994 try:
982 995 import templater
983 996 templater.templater(templater.templatepath("map-cmdline.default"))
984 997 except Exception, inst:
985 998 ui.write(" %s\n" % inst)
986 999 ui.write(_(" (templates seem to have been installed incorrectly)\n"))
987 1000 problems += 1
988 1001
989 1002 # patch
990 1003 ui.status(_("Checking patch...\n"))
991 1004 patchproblems = 0
992 1005 a = "1\n2\n3\n4\n"
993 1006 b = "1\n2\n3\ninsert\n4\n"
994 1007 fa = writetemp(a)
995 1008 d = mdiff.unidiff(a, None, b, None, os.path.basename(fa),
996 1009 os.path.basename(fa))
997 1010 fd = writetemp(d)
998 1011
999 1012 files = {}
1000 1013 try:
1001 1014 patch.patch(fd, ui, cwd=os.path.dirname(fa), files=files)
1002 1015 except util.Abort, e:
1003 1016 ui.write(_(" patch call failed:\n"))
1004 1017 ui.write(" " + str(e) + "\n")
1005 1018 patchproblems += 1
1006 1019 else:
1007 1020 if list(files) != [os.path.basename(fa)]:
1008 1021 ui.write(_(" unexpected patch output!\n"))
1009 1022 patchproblems += 1
1010 1023 a = open(fa).read()
1011 1024 if a != b:
1012 1025 ui.write(_(" patch test failed!\n"))
1013 1026 patchproblems += 1
1014 1027
1015 1028 if patchproblems:
1016 1029 if ui.config('ui', 'patch'):
1017 1030 ui.write(_(" (Current patch tool may be incompatible with patch,"
1018 1031 " or misconfigured. Please check your .hgrc file)\n"))
1019 1032 else:
1020 1033 ui.write(_(" Internal patcher failure, please report this error"
1021 1034 " to http://mercurial.selenic.com/bts/\n"))
1022 1035 problems += patchproblems
1023 1036
1024 1037 os.unlink(fa)
1025 1038 os.unlink(fd)
1026 1039
1027 1040 # editor
1028 1041 ui.status(_("Checking commit editor...\n"))
1029 1042 editor = ui.geteditor()
1030 1043 cmdpath = util.find_exe(editor) or util.find_exe(editor.split()[0])
1031 1044 if not cmdpath:
1032 1045 if editor == 'vi':
1033 1046 ui.write(_(" No commit editor set and can't find vi in PATH\n"))
1034 1047 ui.write(_(" (specify a commit editor in your .hgrc file)\n"))
1035 1048 else:
1036 1049 ui.write(_(" Can't find editor '%s' in PATH\n") % editor)
1037 1050 ui.write(_(" (specify a commit editor in your .hgrc file)\n"))
1038 1051 problems += 1
1039 1052
1040 1053 # check username
1041 1054 ui.status(_("Checking username...\n"))
1042 1055 try:
1043 1056 user = ui.username()
1044 1057 except util.Abort, e:
1045 1058 ui.write(" %s\n" % e)
1046 1059 ui.write(_(" (specify a username in your .hgrc file)\n"))
1047 1060 problems += 1
1048 1061
1049 1062 if not problems:
1050 1063 ui.status(_("No problems detected\n"))
1051 1064 else:
1052 1065 ui.write(_("%s problems detected,"
1053 1066 " please check your install!\n") % problems)
1054 1067
1055 1068 return problems
1056 1069
1057 1070 def debugrename(ui, repo, file1, *pats, **opts):
1058 1071 """dump rename information"""
1059 1072
1060 1073 ctx = repo[opts.get('rev')]
1061 1074 m = cmdutil.match(repo, (file1,) + pats, opts)
1062 1075 for abs in ctx.walk(m):
1063 1076 fctx = ctx[abs]
1064 1077 o = fctx.filelog().renamed(fctx.filenode())
1065 1078 rel = m.rel(abs)
1066 1079 if o:
1067 1080 ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1])))
1068 1081 else:
1069 1082 ui.write(_("%s not renamed\n") % rel)
1070 1083
1071 1084 def debugwalk(ui, repo, *pats, **opts):
1072 1085 """show how files match on given patterns"""
1073 1086 m = cmdutil.match(repo, pats, opts)
1074 1087 items = list(repo.walk(m))
1075 1088 if not items:
1076 1089 return
1077 1090 fmt = 'f %%-%ds %%-%ds %%s' % (
1078 1091 max([len(abs) for abs in items]),
1079 1092 max([len(m.rel(abs)) for abs in items]))
1080 1093 for abs in items:
1081 1094 line = fmt % (abs, m.rel(abs), m.exact(abs) and 'exact' or '')
1082 1095 ui.write("%s\n" % line.rstrip())
1083 1096
1084 1097 def diff(ui, repo, *pats, **opts):
1085 1098 """diff repository (or selected files)
1086 1099
1087 1100 Show differences between revisions for the specified files.
1088 1101
1089 1102 Differences between files are shown using the unified diff format.
1090 1103
1091 1104 NOTE: diff may generate unexpected results for merges, as it will
1092 1105 default to comparing against the working directory's first parent
1093 1106 changeset if no revisions are specified.
1094 1107
1095 1108 When two revision arguments are given, then changes are shown
1096 1109 between those revisions. If only one revision is specified then
1097 1110 that revision is compared to the working directory, and, when no
1098 1111 revisions are specified, the working directory files are compared
1099 1112 to its parent.
1100 1113
1101 1114 Without the -a/--text option, diff will avoid generating diffs of
1102 1115 files it detects as binary. With -a, diff will generate a diff
1103 1116 anyway, probably with undesirable results.
1104 1117
1105 1118 Use the -g/--git option to generate diffs in the git extended diff
1106 1119 format. For more information, read 'hg help diffs'.
1107 1120 """
1108 1121
1109 1122 revs = opts.get('rev')
1110 1123 change = opts.get('change')
1111 1124 stat = opts.get('stat')
1112 1125 reverse = opts.get('reverse')
1113 1126
1114 1127 if revs and change:
1115 1128 msg = _('cannot specify --rev and --change at the same time')
1116 1129 raise util.Abort(msg)
1117 1130 elif change:
1118 1131 node2 = repo.lookup(change)
1119 1132 node1 = repo[node2].parents()[0].node()
1120 1133 else:
1121 1134 node1, node2 = cmdutil.revpair(repo, revs)
1122 1135
1123 1136 if reverse:
1124 1137 node1, node2 = node2, node1
1125 1138
1126 1139 if stat:
1127 1140 opts['unified'] = '0'
1128 1141 diffopts = patch.diffopts(ui, opts)
1129 1142
1130 1143 m = cmdutil.match(repo, pats, opts)
1131 1144 it = patch.diff(repo, node1, node2, match=m, opts=diffopts)
1132 1145 if stat:
1133 1146 width = ui.interactive() and util.termwidth() or 80
1134 1147 ui.write(patch.diffstat(util.iterlines(it), width=width,
1135 1148 git=diffopts.git))
1136 1149 else:
1137 1150 for chunk in it:
1138 1151 ui.write(chunk)
1139 1152
1140 1153 def export(ui, repo, *changesets, **opts):
1141 1154 """dump the header and diffs for one or more changesets
1142 1155
1143 1156 Print the changeset header and diffs for one or more revisions.
1144 1157
1145 1158 The information shown in the changeset header is: author, date,
1146 1159 branch name (if non-default), changeset hash, parent(s) and commit
1147 1160 comment.
1148 1161
1149 1162 NOTE: export may generate unexpected diff output for merge
1150 1163 changesets, as it will compare the merge changeset against its
1151 1164 first parent only.
1152 1165
1153 1166 Output may be to a file, in which case the name of the file is
1154 1167 given using a format string. The formatting rules are as follows:
1155 1168
1156 1169 :``%%``: literal "%" character
1157 1170 :``%H``: changeset hash (40 bytes of hexadecimal)
1158 1171 :``%N``: number of patches being generated
1159 1172 :``%R``: changeset revision number
1160 1173 :``%b``: basename of the exporting repository
1161 1174 :``%h``: short-form changeset hash (12 bytes of hexadecimal)
1162 1175 :``%n``: zero-padded sequence number, starting at 1
1163 1176 :``%r``: zero-padded changeset revision number
1164 1177
1165 1178 Without the -a/--text option, export will avoid generating diffs
1166 1179 of files it detects as binary. With -a, export will generate a
1167 1180 diff anyway, probably with undesirable results.
1168 1181
1169 1182 Use the -g/--git option to generate diffs in the git extended diff
1170 1183 format. See 'hg help diffs' for more information.
1171 1184
1172 1185 With the --switch-parent option, the diff will be against the
1173 1186 second parent. It can be useful to review a merge.
1174 1187 """
1175 1188 changesets += tuple(opts.get('rev', []))
1176 1189 if not changesets:
1177 1190 raise util.Abort(_("export requires at least one changeset"))
1178 1191 revs = cmdutil.revrange(repo, changesets)
1179 1192 if len(revs) > 1:
1180 1193 ui.note(_('exporting patches:\n'))
1181 1194 else:
1182 1195 ui.note(_('exporting patch:\n'))
1183 1196 patch.export(repo, revs, template=opts.get('output'),
1184 1197 switch_parent=opts.get('switch_parent'),
1185 1198 opts=patch.diffopts(ui, opts))
1186 1199
1187 1200 def forget(ui, repo, *pats, **opts):
1188 1201 """forget the specified files on the next commit
1189 1202
1190 1203 Mark the specified files so they will no longer be tracked
1191 1204 after the next commit.
1192 1205
1193 1206 This only removes files from the current branch, not from the
1194 1207 entire project history, and it does not delete them from the
1195 1208 working directory.
1196 1209
1197 1210 To undo a forget before the next commit, see hg add.
1198 1211 """
1199 1212
1200 1213 if not pats:
1201 1214 raise util.Abort(_('no files specified'))
1202 1215
1203 1216 m = cmdutil.match(repo, pats, opts)
1204 1217 s = repo.status(match=m, clean=True)
1205 1218 forget = sorted(s[0] + s[1] + s[3] + s[6])
1206 1219
1207 1220 for f in m.files():
1208 1221 if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
1209 1222 ui.warn(_('not removing %s: file is already untracked\n')
1210 1223 % m.rel(f))
1211 1224
1212 1225 for f in forget:
1213 1226 if ui.verbose or not m.exact(f):
1214 1227 ui.status(_('removing %s\n') % m.rel(f))
1215 1228
1216 1229 repo.remove(forget, unlink=False)
1217 1230
1218 1231 def grep(ui, repo, pattern, *pats, **opts):
1219 1232 """search for a pattern in specified files and revisions
1220 1233
1221 1234 Search revisions of files for a regular expression.
1222 1235
1223 1236 This command behaves differently than Unix grep. It only accepts
1224 1237 Python/Perl regexps. It searches repository history, not the
1225 1238 working directory. It always prints the revision number in which a
1226 1239 match appears.
1227 1240
1228 1241 By default, grep only prints output for the first revision of a
1229 1242 file in which it finds a match. To get it to print every revision
1230 1243 that contains a change in match status ("-" for a match that
1231 1244 becomes a non-match, or "+" for a non-match that becomes a match),
1232 1245 use the --all flag.
1233 1246 """
1234 1247 reflags = 0
1235 1248 if opts.get('ignore_case'):
1236 1249 reflags |= re.I
1237 1250 try:
1238 1251 regexp = re.compile(pattern, reflags)
1239 1252 except Exception, inst:
1240 1253 ui.warn(_("grep: invalid match pattern: %s\n") % inst)
1241 1254 return None
1242 1255 sep, eol = ':', '\n'
1243 1256 if opts.get('print0'):
1244 1257 sep = eol = '\0'
1245 1258
1246 1259 getfile = util.lrucachefunc(repo.file)
1247 1260
1248 1261 def matchlines(body):
1249 1262 begin = 0
1250 1263 linenum = 0
1251 1264 while True:
1252 1265 match = regexp.search(body, begin)
1253 1266 if not match:
1254 1267 break
1255 1268 mstart, mend = match.span()
1256 1269 linenum += body.count('\n', begin, mstart) + 1
1257 1270 lstart = body.rfind('\n', begin, mstart) + 1 or begin
1258 1271 begin = body.find('\n', mend) + 1 or len(body)
1259 1272 lend = begin - 1
1260 1273 yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
1261 1274
1262 1275 class linestate(object):
1263 1276 def __init__(self, line, linenum, colstart, colend):
1264 1277 self.line = line
1265 1278 self.linenum = linenum
1266 1279 self.colstart = colstart
1267 1280 self.colend = colend
1268 1281
1269 1282 def __hash__(self):
1270 1283 return hash((self.linenum, self.line))
1271 1284
1272 1285 def __eq__(self, other):
1273 1286 return self.line == other.line
1274 1287
1275 1288 matches = {}
1276 1289 copies = {}
1277 1290 def grepbody(fn, rev, body):
1278 1291 matches[rev].setdefault(fn, [])
1279 1292 m = matches[rev][fn]
1280 1293 for lnum, cstart, cend, line in matchlines(body):
1281 1294 s = linestate(line, lnum, cstart, cend)
1282 1295 m.append(s)
1283 1296
1284 1297 def difflinestates(a, b):
1285 1298 sm = difflib.SequenceMatcher(None, a, b)
1286 1299 for tag, alo, ahi, blo, bhi in sm.get_opcodes():
1287 1300 if tag == 'insert':
1288 1301 for i in xrange(blo, bhi):
1289 1302 yield ('+', b[i])
1290 1303 elif tag == 'delete':
1291 1304 for i in xrange(alo, ahi):
1292 1305 yield ('-', a[i])
1293 1306 elif tag == 'replace':
1294 1307 for i in xrange(alo, ahi):
1295 1308 yield ('-', a[i])
1296 1309 for i in xrange(blo, bhi):
1297 1310 yield ('+', b[i])
1298 1311
1299 1312 def display(fn, ctx, pstates, states):
1300 1313 rev = ctx.rev()
1301 1314 datefunc = ui.quiet and util.shortdate or util.datestr
1302 1315 found = False
1303 1316 filerevmatches = {}
1304 1317 if opts.get('all'):
1305 1318 iter = difflinestates(pstates, states)
1306 1319 else:
1307 1320 iter = [('', l) for l in states]
1308 1321 for change, l in iter:
1309 1322 cols = [fn, str(rev)]
1310 1323 if opts.get('line_number'):
1311 1324 cols.append(str(l.linenum))
1312 1325 if opts.get('all'):
1313 1326 cols.append(change)
1314 1327 if opts.get('user'):
1315 1328 cols.append(ui.shortuser(ctx.user()))
1316 1329 if opts.get('date'):
1317 1330 cols.append(datefunc(ctx.date()))
1318 1331 if opts.get('files_with_matches'):
1319 1332 c = (fn, rev)
1320 1333 if c in filerevmatches:
1321 1334 continue
1322 1335 filerevmatches[c] = 1
1323 1336 else:
1324 1337 cols.append(l.line)
1325 1338 ui.write(sep.join(cols), eol)
1326 1339 found = True
1327 1340 return found
1328 1341
1329 1342 skip = {}
1330 1343 revfiles = {}
1331 1344 matchfn = cmdutil.match(repo, pats, opts)
1332 1345 found = False
1333 1346 follow = opts.get('follow')
1334 1347
1335 1348 def prep(ctx, fns):
1336 1349 rev = ctx.rev()
1337 1350 pctx = ctx.parents()[0]
1338 1351 parent = pctx.rev()
1339 1352 matches.setdefault(rev, {})
1340 1353 matches.setdefault(parent, {})
1341 1354 files = revfiles.setdefault(rev, [])
1342 1355 for fn in fns:
1343 1356 flog = getfile(fn)
1344 1357 try:
1345 1358 fnode = ctx.filenode(fn)
1346 1359 except error.LookupError:
1347 1360 continue
1348 1361
1349 1362 copied = flog.renamed(fnode)
1350 1363 copy = follow and copied and copied[0]
1351 1364 if copy:
1352 1365 copies.setdefault(rev, {})[fn] = copy
1353 1366 if fn in skip:
1354 1367 if copy:
1355 1368 skip[copy] = True
1356 1369 continue
1357 1370 files.append(fn)
1358 1371
1359 1372 if fn not in matches[rev]:
1360 1373 grepbody(fn, rev, flog.read(fnode))
1361 1374
1362 1375 pfn = copy or fn
1363 1376 if pfn not in matches[parent]:
1364 1377 try:
1365 1378 fnode = pctx.filenode(pfn)
1366 1379 grepbody(pfn, parent, flog.read(fnode))
1367 1380 except error.LookupError:
1368 1381 pass
1369 1382
1370 1383 for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep):
1371 1384 rev = ctx.rev()
1372 1385 parent = ctx.parents()[0].rev()
1373 1386 for fn in sorted(revfiles.get(rev, [])):
1374 1387 states = matches[rev][fn]
1375 1388 copy = copies.get(rev, {}).get(fn)
1376 1389 if fn in skip:
1377 1390 if copy:
1378 1391 skip[copy] = True
1379 1392 continue
1380 1393 pstates = matches.get(parent, {}).get(copy or fn, [])
1381 1394 if pstates or states:
1382 1395 r = display(fn, ctx, pstates, states)
1383 1396 found = found or r
1384 1397 if r and not opts.get('all'):
1385 1398 skip[fn] = True
1386 1399 if copy:
1387 1400 skip[copy] = True
1388 1401 del matches[rev]
1389 1402 del revfiles[rev]
1390 1403
1391 1404 def heads(ui, repo, *branchrevs, **opts):
1392 1405 """show current repository heads or show branch heads
1393 1406
1394 1407 With no arguments, show all repository branch heads.
1395 1408
1396 1409 Repository "heads" are changesets with no child changesets. They are
1397 1410 where development generally takes place and are the usual targets
1398 1411 for update and merge operations. Branch heads are changesets that have
1399 1412 no child changeset on the same branch.
1400 1413
1401 1414 If one or more REVs are given, only branch heads on the branches
1402 1415 associated with the specified changesets are shown.
1403 1416
1404 1417 If -c/--closed is specified, also show branch heads marked closed
1405 1418 (see hg commit --close-branch).
1406 1419
1407 1420 If STARTREV is specified, only those heads that are descendants of
1408 1421 STARTREV will be displayed.
1409 1422
1410 1423 If -t/--topo is specified, named branch mechanics will be ignored and only
1411 1424 changesets without children will be shown.
1412 1425 """
1413 1426
1414 1427 if opts.get('rev'):
1415 1428 start = repo.lookup(opts['rev'])
1416 1429 else:
1417 1430 start = None
1418 1431
1419 1432 if opts.get('topo'):
1420 1433 heads = [repo[h] for h in repo.heads(start)]
1421 1434 else:
1422 1435 heads = []
1423 1436 for b, ls in repo.branchmap().iteritems():
1424 1437 if start is None:
1425 1438 heads += [repo[h] for h in ls]
1426 1439 continue
1427 1440 startrev = repo.changelog.rev(start)
1428 1441 descendants = set(repo.changelog.descendants(startrev))
1429 1442 descendants.add(startrev)
1430 1443 rev = repo.changelog.rev
1431 1444 heads += [repo[h] for h in ls if rev(h) in descendants]
1432 1445
1433 1446 if branchrevs:
1434 1447 decode, encode = encoding.fromlocal, encoding.tolocal
1435 1448 branches = set(repo[decode(br)].branch() for br in branchrevs)
1436 1449 heads = [h for h in heads if h.branch() in branches]
1437 1450
1438 1451 if not opts.get('closed'):
1439 1452 heads = [h for h in heads if not h.extra().get('close')]
1440 1453
1441 1454 if opts.get('active') and branchrevs:
1442 1455 dagheads = repo.heads(start)
1443 1456 heads = [h for h in heads if h.node() in dagheads]
1444 1457
1445 1458 if branchrevs:
1446 1459 haveheads = set(h.branch() for h in heads)
1447 1460 if branches - haveheads:
1448 1461 headless = ', '.join(encode(b) for b in branches - haveheads)
1449 1462 msg = _('no open branch heads found on branches %s')
1450 1463 if opts.get('rev'):
1451 1464 msg += _(' (started at %s)' % opts['rev'])
1452 1465 ui.warn((msg + '\n') % headless)
1453 1466
1454 1467 if not heads:
1455 1468 return 1
1456 1469
1457 1470 heads = sorted(heads, key=lambda x: -x.rev())
1458 1471 displayer = cmdutil.show_changeset(ui, repo, opts)
1459 1472 for ctx in heads:
1460 1473 displayer.show(ctx)
1461 1474 displayer.close()
1462 1475
1463 1476 def help_(ui, name=None, with_version=False, unknowncmd=False):
1464 1477 """show help for a given topic or a help overview
1465 1478
1466 1479 With no arguments, print a list of commands with short help messages.
1467 1480
1468 1481 Given a topic, extension, or command name, print help for that
1469 1482 topic."""
1470 1483 option_lists = []
1471 1484 textwidth = util.termwidth() - 2
1472 1485
1473 1486 def addglobalopts(aliases):
1474 1487 if ui.verbose:
1475 1488 option_lists.append((_("global options:"), globalopts))
1476 1489 if name == 'shortlist':
1477 1490 option_lists.append((_('use "hg help" for the full list '
1478 1491 'of commands'), ()))
1479 1492 else:
1480 1493 if name == 'shortlist':
1481 1494 msg = _('use "hg help" for the full list of commands '
1482 1495 'or "hg -v" for details')
1483 1496 elif aliases:
1484 1497 msg = _('use "hg -v help%s" to show aliases and '
1485 1498 'global options') % (name and " " + name or "")
1486 1499 else:
1487 1500 msg = _('use "hg -v help %s" to show global options') % name
1488 1501 option_lists.append((msg, ()))
1489 1502
1490 1503 def helpcmd(name):
1491 1504 if with_version:
1492 1505 version_(ui)
1493 1506 ui.write('\n')
1494 1507
1495 1508 try:
1496 1509 aliases, entry = cmdutil.findcmd(name, table, strict=unknowncmd)
1497 1510 except error.AmbiguousCommand, inst:
1498 1511 # py3k fix: except vars can't be used outside the scope of the
1499 1512 # except block, nor can be used inside a lambda. python issue4617
1500 1513 prefix = inst.args[0]
1501 1514 select = lambda c: c.lstrip('^').startswith(prefix)
1502 1515 helplist(_('list of commands:\n\n'), select)
1503 1516 return
1504 1517
1505 1518 # check if it's an invalid alias and display its error if it is
1506 1519 if getattr(entry[0], 'badalias', False):
1507 1520 if not unknowncmd:
1508 1521 entry[0](ui)
1509 1522 return
1510 1523
1511 1524 # synopsis
1512 1525 if len(entry) > 2:
1513 1526 if entry[2].startswith('hg'):
1514 1527 ui.write("%s\n" % entry[2])
1515 1528 else:
1516 1529 ui.write('hg %s %s\n' % (aliases[0], entry[2]))
1517 1530 else:
1518 1531 ui.write('hg %s\n' % aliases[0])
1519 1532
1520 1533 # aliases
1521 1534 if not ui.quiet and len(aliases) > 1:
1522 1535 ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
1523 1536
1524 1537 # description
1525 1538 doc = gettext(entry[0].__doc__)
1526 1539 if not doc:
1527 1540 doc = _("(no help text available)")
1528 1541 if ui.quiet:
1529 1542 doc = doc.splitlines()[0]
1530 1543 keep = ui.verbose and ['verbose'] or []
1531 1544 formatted, pruned = minirst.format(doc, textwidth, keep=keep)
1532 1545 ui.write("\n%s\n" % formatted)
1533 1546 if pruned:
1534 1547 ui.write(_('\nuse "hg -v help %s" to show verbose help\n') % name)
1535 1548
1536 1549 if not ui.quiet:
1537 1550 # options
1538 1551 if entry[1]:
1539 1552 option_lists.append((_("options:\n"), entry[1]))
1540 1553
1541 1554 addglobalopts(False)
1542 1555
1543 1556 def helplist(header, select=None):
1544 1557 h = {}
1545 1558 cmds = {}
1546 1559 for c, e in table.iteritems():
1547 1560 f = c.split("|", 1)[0]
1548 1561 if select and not select(f):
1549 1562 continue
1550 1563 if (not select and name != 'shortlist' and
1551 1564 e[0].__module__ != __name__):
1552 1565 continue
1553 1566 if name == "shortlist" and not f.startswith("^"):
1554 1567 continue
1555 1568 f = f.lstrip("^")
1556 1569 if not ui.debugflag and f.startswith("debug"):
1557 1570 continue
1558 1571 doc = e[0].__doc__
1559 1572 if doc and 'DEPRECATED' in doc and not ui.verbose:
1560 1573 continue
1561 1574 doc = gettext(doc)
1562 1575 if not doc:
1563 1576 doc = _("(no help text available)")
1564 1577 h[f] = doc.splitlines()[0].rstrip()
1565 1578 cmds[f] = c.lstrip("^")
1566 1579
1567 1580 if not h:
1568 1581 ui.status(_('no commands defined\n'))
1569 1582 return
1570 1583
1571 1584 ui.status(header)
1572 1585 fns = sorted(h)
1573 1586 m = max(map(len, fns))
1574 1587 for f in fns:
1575 1588 if ui.verbose:
1576 1589 commands = cmds[f].replace("|",", ")
1577 1590 ui.write(" %s:\n %s\n"%(commands, h[f]))
1578 1591 else:
1579 1592 ui.write(' %-*s %s\n' % (m, f, util.wrap(h[f], m + 4)))
1580 1593
1581 1594 if not ui.quiet:
1582 1595 addglobalopts(True)
1583 1596
1584 1597 def helptopic(name):
1585 1598 for names, header, doc in help.helptable:
1586 1599 if name in names:
1587 1600 break
1588 1601 else:
1589 1602 raise error.UnknownCommand(name)
1590 1603
1591 1604 # description
1592 1605 if not doc:
1593 1606 doc = _("(no help text available)")
1594 1607 if hasattr(doc, '__call__'):
1595 1608 doc = doc()
1596 1609
1597 1610 ui.write("%s\n\n" % header)
1598 1611 ui.write("%s\n" % minirst.format(doc, textwidth, indent=4))
1599 1612
1600 1613 def helpext(name):
1601 1614 try:
1602 1615 mod = extensions.find(name)
1603 1616 doc = gettext(mod.__doc__) or _('no help text available')
1604 1617 except KeyError:
1605 1618 mod = None
1606 1619 doc = extensions.disabledext(name)
1607 1620 if not doc:
1608 1621 raise error.UnknownCommand(name)
1609 1622
1610 1623 if '\n' not in doc:
1611 1624 head, tail = doc, ""
1612 1625 else:
1613 1626 head, tail = doc.split('\n', 1)
1614 1627 ui.write(_('%s extension - %s\n\n') % (name.split('.')[-1], head))
1615 1628 if tail:
1616 1629 ui.write(minirst.format(tail, textwidth))
1617 1630 ui.status('\n\n')
1618 1631
1619 1632 if mod:
1620 1633 try:
1621 1634 ct = mod.cmdtable
1622 1635 except AttributeError:
1623 1636 ct = {}
1624 1637 modcmds = set([c.split('|', 1)[0] for c in ct])
1625 1638 helplist(_('list of commands:\n\n'), modcmds.__contains__)
1626 1639 else:
1627 1640 ui.write(_('use "hg help extensions" for information on enabling '
1628 1641 'extensions\n'))
1629 1642
1630 1643 def helpextcmd(name):
1631 1644 cmd, ext, mod = extensions.disabledcmd(name, ui.config('ui', 'strict'))
1632 1645 doc = gettext(mod.__doc__).splitlines()[0]
1633 1646
1634 1647 msg = help.listexts(_("'%s' is provided by the following "
1635 1648 "extension:") % cmd, {ext: doc}, len(ext),
1636 1649 indent=4)
1637 1650 ui.write(minirst.format(msg, textwidth))
1638 1651 ui.write('\n\n')
1639 1652 ui.write(_('use "hg help extensions" for information on enabling '
1640 1653 'extensions\n'))
1641 1654
1642 1655 if name and name != 'shortlist':
1643 1656 i = None
1644 1657 if unknowncmd:
1645 1658 queries = (helpextcmd,)
1646 1659 else:
1647 1660 queries = (helptopic, helpcmd, helpext, helpextcmd)
1648 1661 for f in queries:
1649 1662 try:
1650 1663 f(name)
1651 1664 i = None
1652 1665 break
1653 1666 except error.UnknownCommand, inst:
1654 1667 i = inst
1655 1668 if i:
1656 1669 raise i
1657 1670
1658 1671 else:
1659 1672 # program name
1660 1673 if ui.verbose or with_version:
1661 1674 version_(ui)
1662 1675 else:
1663 1676 ui.status(_("Mercurial Distributed SCM\n"))
1664 1677 ui.status('\n')
1665 1678
1666 1679 # list of commands
1667 1680 if name == "shortlist":
1668 1681 header = _('basic commands:\n\n')
1669 1682 else:
1670 1683 header = _('list of commands:\n\n')
1671 1684
1672 1685 helplist(header)
1673 1686 if name != 'shortlist':
1674 1687 exts, maxlength = extensions.enabled()
1675 1688 text = help.listexts(_('enabled extensions:'), exts, maxlength)
1676 1689 if text:
1677 1690 ui.write("\n%s\n" % minirst.format(text, textwidth))
1678 1691
1679 1692 # list all option lists
1680 1693 opt_output = []
1681 1694 for title, options in option_lists:
1682 1695 opt_output.append(("\n%s" % title, None))
1683 1696 for shortopt, longopt, default, desc in options:
1684 1697 if _("DEPRECATED") in desc and not ui.verbose:
1685 1698 continue
1686 1699 opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt,
1687 1700 longopt and " --%s" % longopt),
1688 1701 "%s%s" % (desc,
1689 1702 default
1690 1703 and _(" (default: %s)") % default
1691 1704 or "")))
1692 1705
1693 1706 if not name:
1694 1707 ui.write(_("\nadditional help topics:\n\n"))
1695 1708 topics = []
1696 1709 for names, header, doc in help.helptable:
1697 1710 topics.append((sorted(names, key=len, reverse=True)[0], header))
1698 1711 topics_len = max([len(s[0]) for s in topics])
1699 1712 for t, desc in topics:
1700 1713 ui.write(" %-*s %s\n" % (topics_len, t, desc))
1701 1714
1702 1715 if opt_output:
1703 1716 opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0])
1704 1717 for first, second in opt_output:
1705 1718 if second:
1706 1719 second = util.wrap(second, opts_len + 3)
1707 1720 ui.write(" %-*s %s\n" % (opts_len, first, second))
1708 1721 else:
1709 1722 ui.write("%s\n" % first)
1710 1723
1711 1724 def identify(ui, repo, source=None,
1712 1725 rev=None, num=None, id=None, branch=None, tags=None):
1713 1726 """identify the working copy or specified revision
1714 1727
1715 1728 With no revision, print a summary of the current state of the
1716 1729 repository.
1717 1730
1718 1731 Specifying a path to a repository root or Mercurial bundle will
1719 1732 cause lookup to operate on that repository/bundle.
1720 1733
1721 1734 This summary identifies the repository state using one or two
1722 1735 parent hash identifiers, followed by a "+" if there are
1723 1736 uncommitted changes in the working directory, a list of tags for
1724 1737 this revision and a branch name for non-default branches.
1725 1738 """
1726 1739
1727 1740 if not repo and not source:
1728 1741 raise util.Abort(_("There is no Mercurial repository here "
1729 1742 "(.hg not found)"))
1730 1743
1731 1744 hexfunc = ui.debugflag and hex or short
1732 1745 default = not (num or id or branch or tags)
1733 1746 output = []
1734 1747
1735 1748 revs = []
1736 1749 if source:
1737 1750 source, branches = hg.parseurl(ui.expandpath(source))
1738 1751 repo = hg.repository(ui, source)
1739 1752 revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
1740 1753
1741 1754 if not repo.local():
1742 1755 if not rev and revs:
1743 1756 rev = revs[0]
1744 1757 if not rev:
1745 1758 rev = "tip"
1746 1759 if num or branch or tags:
1747 1760 raise util.Abort(
1748 1761 "can't query remote revision number, branch, or tags")
1749 1762 output = [hexfunc(repo.lookup(rev))]
1750 1763 elif not rev:
1751 1764 ctx = repo[None]
1752 1765 parents = ctx.parents()
1753 1766 changed = False
1754 1767 if default or id or num:
1755 1768 changed = ctx.files() + ctx.deleted()
1756 1769 if default or id:
1757 1770 output = ["%s%s" % ('+'.join([hexfunc(p.node()) for p in parents]),
1758 1771 (changed) and "+" or "")]
1759 1772 if num:
1760 1773 output.append("%s%s" % ('+'.join([str(p.rev()) for p in parents]),
1761 1774 (changed) and "+" or ""))
1762 1775 else:
1763 1776 ctx = repo[rev]
1764 1777 if default or id:
1765 1778 output = [hexfunc(ctx.node())]
1766 1779 if num:
1767 1780 output.append(str(ctx.rev()))
1768 1781
1769 1782 if repo.local() and default and not ui.quiet:
1770 1783 b = encoding.tolocal(ctx.branch())
1771 1784 if b != 'default':
1772 1785 output.append("(%s)" % b)
1773 1786
1774 1787 # multiple tags for a single parent separated by '/'
1775 1788 t = "/".join(ctx.tags())
1776 1789 if t:
1777 1790 output.append(t)
1778 1791
1779 1792 if branch:
1780 1793 output.append(encoding.tolocal(ctx.branch()))
1781 1794
1782 1795 if tags:
1783 1796 output.extend(ctx.tags())
1784 1797
1785 1798 ui.write("%s\n" % ' '.join(output))
1786 1799
1787 1800 def import_(ui, repo, patch1, *patches, **opts):
1788 1801 """import an ordered set of patches
1789 1802
1790 1803 Import a list of patches and commit them individually (unless
1791 1804 --no-commit is specified).
1792 1805
1793 1806 If there are outstanding changes in the working directory, import
1794 1807 will abort unless given the -f/--force flag.
1795 1808
1796 1809 You can import a patch straight from a mail message. Even patches
1797 1810 as attachments work (to use the body part, it must have type
1798 1811 text/plain or text/x-patch). From and Subject headers of email
1799 1812 message are used as default committer and commit message. All
1800 1813 text/plain body parts before first diff are added to commit
1801 1814 message.
1802 1815
1803 1816 If the imported patch was generated by hg export, user and
1804 1817 description from patch override values from message headers and
1805 1818 body. Values given on command line with -m/--message and -u/--user
1806 1819 override these.
1807 1820
1808 1821 If --exact is specified, import will set the working directory to
1809 1822 the parent of each patch before applying it, and will abort if the
1810 1823 resulting changeset has a different ID than the one recorded in
1811 1824 the patch. This may happen due to character set problems or other
1812 1825 deficiencies in the text patch format.
1813 1826
1814 1827 With -s/--similarity, hg will attempt to discover renames and
1815 1828 copies in the patch in the same way as 'addremove'.
1816 1829
1817 1830 To read a patch from standard input, use "-" as the patch name. If
1818 1831 a URL is specified, the patch will be downloaded from it.
1819 1832 See 'hg help dates' for a list of formats valid for -d/--date.
1820 1833 """
1821 1834 patches = (patch1,) + patches
1822 1835
1823 1836 date = opts.get('date')
1824 1837 if date:
1825 1838 opts['date'] = util.parsedate(date)
1826 1839
1827 1840 try:
1828 1841 sim = float(opts.get('similarity') or 0)
1829 1842 except ValueError:
1830 1843 raise util.Abort(_('similarity must be a number'))
1831 1844 if sim < 0 or sim > 100:
1832 1845 raise util.Abort(_('similarity must be between 0 and 100'))
1833 1846
1834 1847 if opts.get('exact') or not opts.get('force'):
1835 1848 cmdutil.bail_if_changed(repo)
1836 1849
1837 1850 d = opts["base"]
1838 1851 strip = opts["strip"]
1839 1852 wlock = lock = None
1840 1853
1841 1854 def tryone(ui, hunk):
1842 1855 tmpname, message, user, date, branch, nodeid, p1, p2 = \
1843 1856 patch.extract(ui, hunk)
1844 1857
1845 1858 if not tmpname:
1846 1859 return None
1847 1860 commitid = _('to working directory')
1848 1861
1849 1862 try:
1850 1863 cmdline_message = cmdutil.logmessage(opts)
1851 1864 if cmdline_message:
1852 1865 # pickup the cmdline msg
1853 1866 message = cmdline_message
1854 1867 elif message:
1855 1868 # pickup the patch msg
1856 1869 message = message.strip()
1857 1870 else:
1858 1871 # launch the editor
1859 1872 message = None
1860 1873 ui.debug('message:\n%s\n' % message)
1861 1874
1862 1875 wp = repo.parents()
1863 1876 if opts.get('exact'):
1864 1877 if not nodeid or not p1:
1865 1878 raise util.Abort(_('not a Mercurial patch'))
1866 1879 p1 = repo.lookup(p1)
1867 1880 p2 = repo.lookup(p2 or hex(nullid))
1868 1881
1869 1882 if p1 != wp[0].node():
1870 1883 hg.clean(repo, p1)
1871 1884 repo.dirstate.setparents(p1, p2)
1872 1885 elif p2:
1873 1886 try:
1874 1887 p1 = repo.lookup(p1)
1875 1888 p2 = repo.lookup(p2)
1876 1889 if p1 == wp[0].node():
1877 1890 repo.dirstate.setparents(p1, p2)
1878 1891 except error.RepoError:
1879 1892 pass
1880 1893 if opts.get('exact') or opts.get('import_branch'):
1881 1894 repo.dirstate.setbranch(branch or 'default')
1882 1895
1883 1896 files = {}
1884 1897 try:
1885 1898 patch.patch(tmpname, ui, strip=strip, cwd=repo.root,
1886 1899 files=files, eolmode=None)
1887 1900 finally:
1888 1901 files = patch.updatedir(ui, repo, files,
1889 1902 similarity=sim / 100.0)
1890 1903 if not opts.get('no_commit'):
1891 1904 if opts.get('exact'):
1892 1905 m = None
1893 1906 else:
1894 1907 m = cmdutil.matchfiles(repo, files or [])
1895 1908 n = repo.commit(message, opts.get('user') or user,
1896 1909 opts.get('date') or date, match=m,
1897 1910 editor=cmdutil.commiteditor)
1898 1911 if opts.get('exact'):
1899 1912 if hex(n) != nodeid:
1900 1913 repo.rollback()
1901 1914 raise util.Abort(_('patch is damaged'
1902 1915 ' or loses information'))
1903 1916 # Force a dirstate write so that the next transaction
1904 1917 # backups an up-do-date file.
1905 1918 repo.dirstate.write()
1906 1919 if n:
1907 1920 commitid = short(n)
1908 1921
1909 1922 return commitid
1910 1923 finally:
1911 1924 os.unlink(tmpname)
1912 1925
1913 1926 try:
1914 1927 wlock = repo.wlock()
1915 1928 lock = repo.lock()
1916 1929 lastcommit = None
1917 1930 for p in patches:
1918 1931 pf = os.path.join(d, p)
1919 1932
1920 1933 if pf == '-':
1921 1934 ui.status(_("applying patch from stdin\n"))
1922 1935 pf = sys.stdin
1923 1936 else:
1924 1937 ui.status(_("applying %s\n") % p)
1925 1938 pf = url.open(ui, pf)
1926 1939
1927 1940 haspatch = False
1928 1941 for hunk in patch.split(pf):
1929 1942 commitid = tryone(ui, hunk)
1930 1943 if commitid:
1931 1944 haspatch = True
1932 1945 if lastcommit:
1933 1946 ui.status(_('applied %s\n') % lastcommit)
1934 1947 lastcommit = commitid
1935 1948
1936 1949 if not haspatch:
1937 1950 raise util.Abort(_('no diffs found'))
1938 1951
1939 1952 finally:
1940 1953 release(lock, wlock)
1941 1954
1942 1955 def incoming(ui, repo, source="default", **opts):
1943 1956 """show new changesets found in source
1944 1957
1945 1958 Show new changesets found in the specified path/URL or the default
1946 1959 pull location. These are the changesets that would have been pulled
1947 1960 if a pull at the time you issued this command.
1948 1961
1949 1962 For remote repository, using --bundle avoids downloading the
1950 1963 changesets twice if the incoming is followed by a pull.
1951 1964
1952 1965 See pull for valid source format details.
1953 1966 """
1954 1967 limit = cmdutil.loglimit(opts)
1955 1968 source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch'))
1956 1969 other = hg.repository(cmdutil.remoteui(repo, opts), source)
1957 1970 ui.status(_('comparing with %s\n') % url.hidepassword(source))
1958 1971 revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev'))
1959 1972 if revs:
1960 1973 revs = [other.lookup(rev) for rev in revs]
1961 1974 common, incoming, rheads = repo.findcommonincoming(other, heads=revs,
1962 1975 force=opts["force"])
1963 1976 if not incoming:
1964 1977 try:
1965 1978 os.unlink(opts["bundle"])
1966 1979 except:
1967 1980 pass
1968 1981 ui.status(_("no changes found\n"))
1969 1982 return 1
1970 1983
1971 1984 cleanup = None
1972 1985 try:
1973 1986 fname = opts["bundle"]
1974 1987 if fname or not other.local():
1975 1988 # create a bundle (uncompressed if other repo is not local)
1976 1989
1977 1990 if revs is None and other.capable('changegroupsubset'):
1978 1991 revs = rheads
1979 1992
1980 1993 if revs is None:
1981 1994 cg = other.changegroup(incoming, "incoming")
1982 1995 else:
1983 1996 cg = other.changegroupsubset(incoming, revs, 'incoming')
1984 1997 bundletype = other.local() and "HG10BZ" or "HG10UN"
1985 1998 fname = cleanup = changegroup.writebundle(cg, fname, bundletype)
1986 1999 # keep written bundle?
1987 2000 if opts["bundle"]:
1988 2001 cleanup = None
1989 2002 if not other.local():
1990 2003 # use the created uncompressed bundlerepo
1991 2004 other = bundlerepo.bundlerepository(ui, repo.root, fname)
1992 2005
1993 2006 o = other.changelog.nodesbetween(incoming, revs)[0]
1994 2007 if opts.get('newest_first'):
1995 2008 o.reverse()
1996 2009 displayer = cmdutil.show_changeset(ui, other, opts)
1997 2010 count = 0
1998 2011 for n in o:
1999 2012 if limit is not None and count >= limit:
2000 2013 break
2001 2014 parents = [p for p in other.changelog.parents(n) if p != nullid]
2002 2015 if opts.get('no_merges') and len(parents) == 2:
2003 2016 continue
2004 2017 count += 1
2005 2018 displayer.show(other[n])
2006 2019 displayer.close()
2007 2020 finally:
2008 2021 if hasattr(other, 'close'):
2009 2022 other.close()
2010 2023 if cleanup:
2011 2024 os.unlink(cleanup)
2012 2025
2013 2026 def init(ui, dest=".", **opts):
2014 2027 """create a new repository in the given directory
2015 2028
2016 2029 Initialize a new repository in the given directory. If the given
2017 2030 directory does not exist, it will be created.
2018 2031
2019 2032 If no directory is given, the current directory is used.
2020 2033
2021 2034 It is possible to specify an ``ssh://`` URL as the destination.
2022 2035 See 'hg help urls' for more information.
2023 2036 """
2024 2037 hg.repository(cmdutil.remoteui(ui, opts), dest, create=1)
2025 2038
2026 2039 def locate(ui, repo, *pats, **opts):
2027 2040 """locate files matching specific patterns
2028 2041
2029 2042 Print files under Mercurial control in the working directory whose
2030 2043 names match the given patterns.
2031 2044
2032 2045 By default, this command searches all directories in the working
2033 2046 directory. To search just the current directory and its
2034 2047 subdirectories, use "--include .".
2035 2048
2036 2049 If no patterns are given to match, this command prints the names
2037 2050 of all files under Mercurial control in the working directory.
2038 2051
2039 2052 If you want to feed the output of this command into the "xargs"
2040 2053 command, use the -0 option to both this command and "xargs". This
2041 2054 will avoid the problem of "xargs" treating single filenames that
2042 2055 contain whitespace as multiple filenames.
2043 2056 """
2044 2057 end = opts.get('print0') and '\0' or '\n'
2045 2058 rev = opts.get('rev') or None
2046 2059
2047 2060 ret = 1
2048 2061 m = cmdutil.match(repo, pats, opts, default='relglob')
2049 2062 m.bad = lambda x, y: False
2050 2063 for abs in repo[rev].walk(m):
2051 2064 if not rev and abs not in repo.dirstate:
2052 2065 continue
2053 2066 if opts.get('fullpath'):
2054 2067 ui.write(repo.wjoin(abs), end)
2055 2068 else:
2056 2069 ui.write(((pats and m.rel(abs)) or abs), end)
2057 2070 ret = 0
2058 2071
2059 2072 return ret
2060 2073
2061 2074 def log(ui, repo, *pats, **opts):
2062 2075 """show revision history of entire repository or files
2063 2076
2064 2077 Print the revision history of the specified files or the entire
2065 2078 project.
2066 2079
2067 2080 File history is shown without following rename or copy history of
2068 2081 files. Use -f/--follow with a filename to follow history across
2069 2082 renames and copies. --follow without a filename will only show
2070 2083 ancestors or descendants of the starting revision. --follow-first
2071 2084 only follows the first parent of merge revisions.
2072 2085
2073 2086 If no revision range is specified, the default is tip:0 unless
2074 2087 --follow is set, in which case the working directory parent is
2075 2088 used as the starting revision.
2076 2089
2077 2090 See 'hg help dates' for a list of formats valid for -d/--date.
2078 2091
2079 2092 By default this command prints revision number and changeset id,
2080 2093 tags, non-trivial parents, user, date and time, and a summary for
2081 2094 each commit. When the -v/--verbose switch is used, the list of
2082 2095 changed files and full commit message are shown.
2083 2096
2084 2097 NOTE: log -p/--patch may generate unexpected diff output for merge
2085 2098 changesets, as it will only compare the merge changeset against
2086 2099 its first parent. Also, only files different from BOTH parents
2087 2100 will appear in files:.
2088 2101 """
2089 2102
2090 2103 matchfn = cmdutil.match(repo, pats, opts)
2091 2104 limit = cmdutil.loglimit(opts)
2092 2105 count = 0
2093 2106
2094 2107 endrev = None
2095 2108 if opts.get('copies') and opts.get('rev'):
2096 2109 endrev = max(cmdutil.revrange(repo, opts.get('rev'))) + 1
2097 2110
2098 2111 df = False
2099 2112 if opts["date"]:
2100 2113 df = util.matchdate(opts["date"])
2101 2114
2102 2115 displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn)
2103 2116 def prep(ctx, fns):
2104 2117 rev = ctx.rev()
2105 2118 parents = [p for p in repo.changelog.parentrevs(rev)
2106 2119 if p != nullrev]
2107 2120 if opts.get('no_merges') and len(parents) == 2:
2108 2121 return
2109 2122 if opts.get('only_merges') and len(parents) != 2:
2110 2123 return
2111 2124 if opts.get('only_branch') and ctx.branch() not in opts['only_branch']:
2112 2125 return
2113 2126 if df and not df(ctx.date()[0]):
2114 2127 return
2115 2128 if opts['user'] and not [k for k in opts['user'] if k in ctx.user()]:
2116 2129 return
2117 2130 if opts.get('keyword'):
2118 2131 for k in [kw.lower() for kw in opts['keyword']]:
2119 2132 if (k in ctx.user().lower() or
2120 2133 k in ctx.description().lower() or
2121 2134 k in " ".join(ctx.files()).lower()):
2122 2135 break
2123 2136 else:
2124 2137 return
2125 2138
2126 2139 copies = None
2127 2140 if opts.get('copies') and rev:
2128 2141 copies = []
2129 2142 getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
2130 2143 for fn in ctx.files():
2131 2144 rename = getrenamed(fn, rev)
2132 2145 if rename:
2133 2146 copies.append((fn, rename[0]))
2134 2147
2135 2148 displayer.show(ctx, copies=copies)
2136 2149
2137 2150 for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep):
2138 2151 if count == limit:
2139 2152 break
2140 2153 if displayer.flush(ctx.rev()):
2141 2154 count += 1
2142 2155 displayer.close()
2143 2156
2144 2157 def manifest(ui, repo, node=None, rev=None):
2145 2158 """output the current or given revision of the project manifest
2146 2159
2147 2160 Print a list of version controlled files for the given revision.
2148 2161 If no revision is given, the first parent of the working directory
2149 2162 is used, or the null revision if no revision is checked out.
2150 2163
2151 2164 With -v, print file permissions, symlink and executable bits.
2152 2165 With --debug, print file revision hashes.
2153 2166 """
2154 2167
2155 2168 if rev and node:
2156 2169 raise util.Abort(_("please specify just one revision"))
2157 2170
2158 2171 if not node:
2159 2172 node = rev
2160 2173
2161 2174 decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '}
2162 2175 ctx = repo[node]
2163 2176 for f in ctx:
2164 2177 if ui.debugflag:
2165 2178 ui.write("%40s " % hex(ctx.manifest()[f]))
2166 2179 if ui.verbose:
2167 2180 ui.write(decor[ctx.flags(f)])
2168 2181 ui.write("%s\n" % f)
2169 2182
2170 2183 def merge(ui, repo, node=None, **opts):
2171 2184 """merge working directory with another revision
2172 2185
2173 2186 The current working directory is updated with all changes made in
2174 2187 the requested revision since the last common predecessor revision.
2175 2188
2176 2189 Files that changed between either parent are marked as changed for
2177 2190 the next commit and a commit must be performed before any further
2178 2191 updates to the repository are allowed. The next commit will have
2179 2192 two parents.
2180 2193
2181 2194 If no revision is specified, the working directory's parent is a
2182 2195 head revision, and the current branch contains exactly one other
2183 2196 head, the other head is merged with by default. Otherwise, an
2184 2197 explicit revision with which to merge with must be provided.
2185 2198 """
2186 2199
2187 2200 if opts.get('rev') and node:
2188 2201 raise util.Abort(_("please specify just one revision"))
2189 2202 if not node:
2190 2203 node = opts.get('rev')
2191 2204
2192 2205 if not node:
2193 2206 branch = repo.changectx(None).branch()
2194 2207 bheads = repo.branchheads(branch)
2195 2208 if len(bheads) > 2:
2196 2209 ui.warn(_("abort: branch '%s' has %d heads - "
2197 2210 "please merge with an explicit rev\n")
2198 2211 % (branch, len(bheads)))
2199 2212 ui.status(_("(run 'hg heads .' to see heads)\n"))
2200 2213 return False
2201 2214
2202 2215 parent = repo.dirstate.parents()[0]
2203 2216 if len(bheads) == 1:
2204 2217 if len(repo.heads()) > 1:
2205 2218 ui.warn(_("abort: branch '%s' has one head - "
2206 2219 "please merge with an explicit rev\n" % branch))
2207 2220 ui.status(_("(run 'hg heads' to see all heads)\n"))
2208 2221 return False
2209 2222 msg = _('there is nothing to merge')
2210 2223 if parent != repo.lookup(repo[None].branch()):
2211 2224 msg = _('%s - use "hg update" instead') % msg
2212 2225 raise util.Abort(msg)
2213 2226
2214 2227 if parent not in bheads:
2215 2228 raise util.Abort(_('working dir not at a head rev - '
2216 2229 'use "hg update" or merge with an explicit rev'))
2217 2230 node = parent == bheads[0] and bheads[-1] or bheads[0]
2218 2231
2219 2232 if opts.get('preview'):
2220 2233 p1 = repo['.']
2221 2234 p2 = repo[node]
2222 2235 common = p1.ancestor(p2)
2223 2236 roots, heads = [common.node()], [p2.node()]
2224 2237 displayer = cmdutil.show_changeset(ui, repo, opts)
2225 2238 for node in repo.changelog.nodesbetween(roots=roots, heads=heads)[0]:
2226 2239 if node not in roots:
2227 2240 displayer.show(repo[node])
2228 2241 displayer.close()
2229 2242 return 0
2230 2243
2231 2244 return hg.merge(repo, node, force=opts.get('force'))
2232 2245
2233 2246 def outgoing(ui, repo, dest=None, **opts):
2234 2247 """show changesets not found in the destination
2235 2248
2236 2249 Show changesets not found in the specified destination repository
2237 2250 or the default push location. These are the changesets that would
2238 2251 be pushed if a push was requested.
2239 2252
2240 2253 See pull for details of valid destination formats.
2241 2254 """
2242 2255 limit = cmdutil.loglimit(opts)
2243 2256 dest = ui.expandpath(dest or 'default-push', dest or 'default')
2244 2257 dest, branches = hg.parseurl(dest, opts.get('branch'))
2245 2258 revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
2246 2259 if revs:
2247 2260 revs = [repo.lookup(rev) for rev in revs]
2248 2261
2249 2262 other = hg.repository(cmdutil.remoteui(repo, opts), dest)
2250 2263 ui.status(_('comparing with %s\n') % url.hidepassword(dest))
2251 2264 o = repo.findoutgoing(other, force=opts.get('force'))
2252 2265 if not o:
2253 2266 ui.status(_("no changes found\n"))
2254 2267 return 1
2255 2268 o = repo.changelog.nodesbetween(o, revs)[0]
2256 2269 if opts.get('newest_first'):
2257 2270 o.reverse()
2258 2271 displayer = cmdutil.show_changeset(ui, repo, opts)
2259 2272 count = 0
2260 2273 for n in o:
2261 2274 if limit is not None and count >= limit:
2262 2275 break
2263 2276 parents = [p for p in repo.changelog.parents(n) if p != nullid]
2264 2277 if opts.get('no_merges') and len(parents) == 2:
2265 2278 continue
2266 2279 count += 1
2267 2280 displayer.show(repo[n])
2268 2281 displayer.close()
2269 2282
2270 2283 def parents(ui, repo, file_=None, **opts):
2271 2284 """show the parents of the working directory or revision
2272 2285
2273 2286 Print the working directory's parent revisions. If a revision is
2274 2287 given via -r/--rev, the parent of that revision will be printed.
2275 2288 If a file argument is given, the revision in which the file was
2276 2289 last changed (before the working directory revision or the
2277 2290 argument to --rev if given) is printed.
2278 2291 """
2279 2292 rev = opts.get('rev')
2280 2293 if rev:
2281 2294 ctx = repo[rev]
2282 2295 else:
2283 2296 ctx = repo[None]
2284 2297
2285 2298 if file_:
2286 2299 m = cmdutil.match(repo, (file_,), opts)
2287 2300 if m.anypats() or len(m.files()) != 1:
2288 2301 raise util.Abort(_('can only specify an explicit filename'))
2289 2302 file_ = m.files()[0]
2290 2303 filenodes = []
2291 2304 for cp in ctx.parents():
2292 2305 if not cp:
2293 2306 continue
2294 2307 try:
2295 2308 filenodes.append(cp.filenode(file_))
2296 2309 except error.LookupError:
2297 2310 pass
2298 2311 if not filenodes:
2299 2312 raise util.Abort(_("'%s' not found in manifest!") % file_)
2300 2313 fl = repo.file(file_)
2301 2314 p = [repo.lookup(fl.linkrev(fl.rev(fn))) for fn in filenodes]
2302 2315 else:
2303 2316 p = [cp.node() for cp in ctx.parents()]
2304 2317
2305 2318 displayer = cmdutil.show_changeset(ui, repo, opts)
2306 2319 for n in p:
2307 2320 if n != nullid:
2308 2321 displayer.show(repo[n])
2309 2322 displayer.close()
2310 2323
2311 2324 def paths(ui, repo, search=None):
2312 2325 """show aliases for remote repositories
2313 2326
2314 2327 Show definition of symbolic path name NAME. If no name is given,
2315 2328 show definition of all available names.
2316 2329
2317 2330 Path names are defined in the [paths] section of /etc/mercurial/hgrc
2318 2331 and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too.
2319 2332
2320 2333 See 'hg help urls' for more information.
2321 2334 """
2322 2335 if search:
2323 2336 for name, path in ui.configitems("paths"):
2324 2337 if name == search:
2325 2338 ui.write("%s\n" % url.hidepassword(path))
2326 2339 return
2327 2340 ui.warn(_("not found!\n"))
2328 2341 return 1
2329 2342 else:
2330 2343 for name, path in ui.configitems("paths"):
2331 2344 ui.write("%s = %s\n" % (name, url.hidepassword(path)))
2332 2345
2333 2346 def postincoming(ui, repo, modheads, optupdate, checkout):
2334 2347 if modheads == 0:
2335 2348 return
2336 2349 if optupdate:
2337 2350 if (modheads <= 1 or len(repo.branchheads()) == 1) or checkout:
2338 2351 return hg.update(repo, checkout)
2339 2352 else:
2340 2353 ui.status(_("not updating, since new heads added\n"))
2341 2354 if modheads > 1:
2342 2355 ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n"))
2343 2356 else:
2344 2357 ui.status(_("(run 'hg update' to get a working copy)\n"))
2345 2358
2346 2359 def pull(ui, repo, source="default", **opts):
2347 2360 """pull changes from the specified source
2348 2361
2349 2362 Pull changes from a remote repository to a local one.
2350 2363
2351 2364 This finds all changes from the repository at the specified path
2352 2365 or URL and adds them to a local repository (the current one unless
2353 2366 -R is specified). By default, this does not update the copy of the
2354 2367 project in the working directory.
2355 2368
2356 2369 Use hg incoming if you want to see what would have been added by a
2357 2370 pull at the time you issued this command. If you then decide to
2358 2371 added those changes to the repository, you should use pull -r X
2359 2372 where X is the last changeset listed by hg incoming.
2360 2373
2361 2374 If SOURCE is omitted, the 'default' path will be used.
2362 2375 See 'hg help urls' for more information.
2363 2376 """
2364 2377 source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch'))
2365 2378 other = hg.repository(cmdutil.remoteui(repo, opts), source)
2366 2379 ui.status(_('pulling from %s\n') % url.hidepassword(source))
2367 2380 revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev'))
2368 2381 if revs:
2369 2382 try:
2370 2383 revs = [other.lookup(rev) for rev in revs]
2371 2384 except error.CapabilityError:
2372 2385 err = _("Other repository doesn't support revision lookup, "
2373 2386 "so a rev cannot be specified.")
2374 2387 raise util.Abort(err)
2375 2388
2376 2389 modheads = repo.pull(other, heads=revs, force=opts.get('force'))
2377 2390 if checkout:
2378 2391 checkout = str(repo.changelog.rev(other.lookup(checkout)))
2379 2392 return postincoming(ui, repo, modheads, opts.get('update'), checkout)
2380 2393
2381 2394 def push(ui, repo, dest=None, **opts):
2382 2395 """push changes to the specified destination
2383 2396
2384 2397 Push changes from the local repository to the specified destination.
2385 2398
2386 2399 This is the symmetrical operation for pull. It moves changes from
2387 2400 the current repository to a different one. If the destination is
2388 2401 local this is identical to a pull in that directory from the
2389 2402 current one.
2390 2403
2391 2404 By default, push will refuse to run if it detects the result would
2392 2405 increase the number of remote heads. This generally indicates the
2393 2406 user forgot to pull and merge before pushing.
2394 2407
2395 2408 If -r/--rev is used, the named revision and all its ancestors will
2396 2409 be pushed to the remote repository.
2397 2410
2398 2411 Please see 'hg help urls' for important details about ``ssh://``
2399 2412 URLs. If DESTINATION is omitted, a default path will be used.
2400 2413 """
2401 2414 dest = ui.expandpath(dest or 'default-push', dest or 'default')
2402 2415 dest, branches = hg.parseurl(dest, opts.get('branch'))
2403 2416 revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
2404 2417 other = hg.repository(cmdutil.remoteui(repo, opts), dest)
2405 2418 ui.status(_('pushing to %s\n') % url.hidepassword(dest))
2406 2419 if revs:
2407 2420 revs = [repo.lookup(rev) for rev in revs]
2408 2421
2409 2422 # push subrepos depth-first for coherent ordering
2410 2423 c = repo['']
2411 2424 subs = c.substate # only repos that are committed
2412 2425 for s in sorted(subs):
2413 2426 c.sub(s).push(opts.get('force'))
2414 2427
2415 2428 r = repo.push(other, opts.get('force'), revs=revs)
2416 2429 return r == 0
2417 2430
2418 2431 def recover(ui, repo):
2419 2432 """roll back an interrupted transaction
2420 2433
2421 2434 Recover from an interrupted commit or pull.
2422 2435
2423 2436 This command tries to fix the repository status after an
2424 2437 interrupted operation. It should only be necessary when Mercurial
2425 2438 suggests it.
2426 2439 """
2427 2440 if repo.recover():
2428 2441 return hg.verify(repo)
2429 2442 return 1
2430 2443
2431 2444 def remove(ui, repo, *pats, **opts):
2432 2445 """remove the specified files on the next commit
2433 2446
2434 2447 Schedule the indicated files for removal from the repository.
2435 2448
2436 2449 This only removes files from the current branch, not from the
2437 2450 entire project history. -A/--after can be used to remove only
2438 2451 files that have already been deleted, -f/--force can be used to
2439 2452 force deletion, and -Af can be used to remove files from the next
2440 2453 revision without deleting them from the working directory.
2441 2454
2442 2455 The following table details the behavior of remove for different
2443 2456 file states (columns) and option combinations (rows). The file
2444 2457 states are Added [A], Clean [C], Modified [M] and Missing [!] (as
2445 2458 reported by hg status). The actions are Warn, Remove (from branch)
2446 2459 and Delete (from disk)::
2447 2460
2448 2461 A C M !
2449 2462 none W RD W R
2450 2463 -f R RD RD R
2451 2464 -A W W W R
2452 2465 -Af R R R R
2453 2466
2454 2467 This command schedules the files to be removed at the next commit.
2455 2468 To undo a remove before that, see hg revert.
2456 2469 """
2457 2470
2458 2471 after, force = opts.get('after'), opts.get('force')
2459 2472 if not pats and not after:
2460 2473 raise util.Abort(_('no files specified'))
2461 2474
2462 2475 m = cmdutil.match(repo, pats, opts)
2463 2476 s = repo.status(match=m, clean=True)
2464 2477 modified, added, deleted, clean = s[0], s[1], s[3], s[6]
2465 2478
2466 2479 for f in m.files():
2467 2480 if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
2468 2481 ui.warn(_('not removing %s: file is untracked\n') % m.rel(f))
2469 2482
2470 2483 def warn(files, reason):
2471 2484 for f in files:
2472 2485 ui.warn(_('not removing %s: file %s (use -f to force removal)\n')
2473 2486 % (m.rel(f), reason))
2474 2487
2475 2488 if force:
2476 2489 remove, forget = modified + deleted + clean, added
2477 2490 elif after:
2478 2491 remove, forget = deleted, []
2479 2492 warn(modified + added + clean, _('still exists'))
2480 2493 else:
2481 2494 remove, forget = deleted + clean, []
2482 2495 warn(modified, _('is modified'))
2483 2496 warn(added, _('has been marked for add'))
2484 2497
2485 2498 for f in sorted(remove + forget):
2486 2499 if ui.verbose or not m.exact(f):
2487 2500 ui.status(_('removing %s\n') % m.rel(f))
2488 2501
2489 2502 repo.forget(forget)
2490 2503 repo.remove(remove, unlink=not after)
2491 2504
2492 2505 def rename(ui, repo, *pats, **opts):
2493 2506 """rename files; equivalent of copy + remove
2494 2507
2495 2508 Mark dest as copies of sources; mark sources for deletion. If dest
2496 2509 is a directory, copies are put in that directory. If dest is a
2497 2510 file, there can only be one source.
2498 2511
2499 2512 By default, this command copies the contents of files as they
2500 2513 exist in the working directory. If invoked with -A/--after, the
2501 2514 operation is recorded, but no copying is performed.
2502 2515
2503 2516 This command takes effect at the next commit. To undo a rename
2504 2517 before that, see hg revert.
2505 2518 """
2506 2519 wlock = repo.wlock(False)
2507 2520 try:
2508 2521 return cmdutil.copy(ui, repo, pats, opts, rename=True)
2509 2522 finally:
2510 2523 wlock.release()
2511 2524
2512 2525 def resolve(ui, repo, *pats, **opts):
2513 2526 """retry file merges from a merge or update
2514 2527
2515 2528 This command can cleanly retry unresolved file merges using file
2516 2529 revisions preserved from the last update or merge.
2517 2530
2518 2531 If a conflict is resolved manually, please note that the changes
2519 2532 will be overwritten if the merge is retried with resolve. The
2520 2533 -m/--mark switch should be used to mark the file as resolved.
2521 2534
2522 2535 You can specify a set of files to operate on, or use the -a/--all
2523 2536 switch to select all unresolved files.
2524 2537
2525 2538 This command also allows listing resolved files and manually
2526 2539 indicating whether or not files are resolved. All files must be
2527 2540 marked as resolved before a commit is permitted.
2528 2541
2529 2542 The codes used to show the status of files are::
2530 2543
2531 2544 U = unresolved
2532 2545 R = resolved
2533 2546 """
2534 2547
2535 2548 all, mark, unmark, show, nostatus = \
2536 2549 [opts.get(o) for o in 'all mark unmark list no_status'.split()]
2537 2550
2538 2551 if (show and (mark or unmark)) or (mark and unmark):
2539 2552 raise util.Abort(_("too many options specified"))
2540 2553 if pats and all:
2541 2554 raise util.Abort(_("can't specify --all and patterns"))
2542 2555 if not (all or pats or show or mark or unmark):
2543 2556 raise util.Abort(_('no files or directories specified; '
2544 2557 'use --all to remerge all files'))
2545 2558
2546 2559 ms = merge_.mergestate(repo)
2547 2560 m = cmdutil.match(repo, pats, opts)
2548 2561
2549 2562 for f in ms:
2550 2563 if m(f):
2551 2564 if show:
2552 2565 if nostatus:
2553 2566 ui.write("%s\n" % f)
2554 2567 else:
2555 2568 ui.write("%s %s\n" % (ms[f].upper(), f))
2556 2569 elif mark:
2557 2570 ms.mark(f, "r")
2558 2571 elif unmark:
2559 2572 ms.mark(f, "u")
2560 2573 else:
2561 2574 wctx = repo[None]
2562 2575 mctx = wctx.parents()[-1]
2563 2576
2564 2577 # backup pre-resolve (merge uses .orig for its own purposes)
2565 2578 a = repo.wjoin(f)
2566 2579 util.copyfile(a, a + ".resolve")
2567 2580
2568 2581 # resolve file
2569 2582 ms.resolve(f, wctx, mctx)
2570 2583
2571 2584 # replace filemerge's .orig file with our resolve file
2572 2585 util.rename(a + ".resolve", a + ".orig")
2573 2586
2574 2587 def revert(ui, repo, *pats, **opts):
2575 2588 """restore individual files or directories to an earlier state
2576 2589
2577 2590 (Use update -r to check out earlier revisions, revert does not
2578 2591 change the working directory parents.)
2579 2592
2580 2593 With no revision specified, revert the named files or directories
2581 2594 to the contents they had in the parent of the working directory.
2582 2595 This restores the contents of the affected files to an unmodified
2583 2596 state and unschedules adds, removes, copies, and renames. If the
2584 2597 working directory has two parents, you must explicitly specify a
2585 2598 revision.
2586 2599
2587 2600 Using the -r/--rev option, revert the given files or directories
2588 2601 to their contents as of a specific revision. This can be helpful
2589 2602 to "roll back" some or all of an earlier change. See 'hg help
2590 2603 dates' for a list of formats valid for -d/--date.
2591 2604
2592 2605 Revert modifies the working directory. It does not commit any
2593 2606 changes, or change the parent of the working directory. If you
2594 2607 revert to a revision other than the parent of the working
2595 2608 directory, the reverted files will thus appear modified
2596 2609 afterwards.
2597 2610
2598 2611 If a file has been deleted, it is restored. If the executable mode
2599 2612 of a file was changed, it is reset.
2600 2613
2601 2614 If names are given, all files matching the names are reverted.
2602 2615 If no arguments are given, no files are reverted.
2603 2616
2604 2617 Modified files are saved with a .orig suffix before reverting.
2605 2618 To disable these backups, use --no-backup.
2606 2619 """
2607 2620
2608 2621 if opts["date"]:
2609 2622 if opts["rev"]:
2610 2623 raise util.Abort(_("you can't specify a revision and a date"))
2611 2624 opts["rev"] = cmdutil.finddate(ui, repo, opts["date"])
2612 2625
2613 2626 if not pats and not opts.get('all'):
2614 2627 raise util.Abort(_('no files or directories specified; '
2615 2628 'use --all to revert the whole repo'))
2616 2629
2617 2630 parent, p2 = repo.dirstate.parents()
2618 2631 if not opts.get('rev') and p2 != nullid:
2619 2632 raise util.Abort(_('uncommitted merge - please provide a '
2620 2633 'specific revision'))
2621 2634 ctx = repo[opts.get('rev')]
2622 2635 node = ctx.node()
2623 2636 mf = ctx.manifest()
2624 2637 if node == parent:
2625 2638 pmf = mf
2626 2639 else:
2627 2640 pmf = None
2628 2641
2629 2642 # need all matching names in dirstate and manifest of target rev,
2630 2643 # so have to walk both. do not print errors if files exist in one
2631 2644 # but not other.
2632 2645
2633 2646 names = {}
2634 2647
2635 2648 wlock = repo.wlock()
2636 2649 try:
2637 2650 # walk dirstate.
2638 2651
2639 2652 m = cmdutil.match(repo, pats, opts)
2640 2653 m.bad = lambda x, y: False
2641 2654 for abs in repo.walk(m):
2642 2655 names[abs] = m.rel(abs), m.exact(abs)
2643 2656
2644 2657 # walk target manifest.
2645 2658
2646 2659 def badfn(path, msg):
2647 2660 if path in names:
2648 2661 return
2649 2662 path_ = path + '/'
2650 2663 for f in names:
2651 2664 if f.startswith(path_):
2652 2665 return
2653 2666 ui.warn("%s: %s\n" % (m.rel(path), msg))
2654 2667
2655 2668 m = cmdutil.match(repo, pats, opts)
2656 2669 m.bad = badfn
2657 2670 for abs in repo[node].walk(m):
2658 2671 if abs not in names:
2659 2672 names[abs] = m.rel(abs), m.exact(abs)
2660 2673
2661 2674 m = cmdutil.matchfiles(repo, names)
2662 2675 changes = repo.status(match=m)[:4]
2663 2676 modified, added, removed, deleted = map(set, changes)
2664 2677
2665 2678 # if f is a rename, also revert the source
2666 2679 cwd = repo.getcwd()
2667 2680 for f in added:
2668 2681 src = repo.dirstate.copied(f)
2669 2682 if src and src not in names and repo.dirstate[src] == 'r':
2670 2683 removed.add(src)
2671 2684 names[src] = (repo.pathto(src, cwd), True)
2672 2685
2673 2686 def removeforget(abs):
2674 2687 if repo.dirstate[abs] == 'a':
2675 2688 return _('forgetting %s\n')
2676 2689 return _('removing %s\n')
2677 2690
2678 2691 revert = ([], _('reverting %s\n'))
2679 2692 add = ([], _('adding %s\n'))
2680 2693 remove = ([], removeforget)
2681 2694 undelete = ([], _('undeleting %s\n'))
2682 2695
2683 2696 disptable = (
2684 2697 # dispatch table:
2685 2698 # file state
2686 2699 # action if in target manifest
2687 2700 # action if not in target manifest
2688 2701 # make backup if in target manifest
2689 2702 # make backup if not in target manifest
2690 2703 (modified, revert, remove, True, True),
2691 2704 (added, revert, remove, True, False),
2692 2705 (removed, undelete, None, False, False),
2693 2706 (deleted, revert, remove, False, False),
2694 2707 )
2695 2708
2696 2709 for abs, (rel, exact) in sorted(names.items()):
2697 2710 mfentry = mf.get(abs)
2698 2711 target = repo.wjoin(abs)
2699 2712 def handle(xlist, dobackup):
2700 2713 xlist[0].append(abs)
2701 2714 if dobackup and not opts.get('no_backup') and util.lexists(target):
2702 2715 bakname = "%s.orig" % rel
2703 2716 ui.note(_('saving current version of %s as %s\n') %
2704 2717 (rel, bakname))
2705 2718 if not opts.get('dry_run'):
2706 2719 util.copyfile(target, bakname)
2707 2720 if ui.verbose or not exact:
2708 2721 msg = xlist[1]
2709 2722 if not isinstance(msg, basestring):
2710 2723 msg = msg(abs)
2711 2724 ui.status(msg % rel)
2712 2725 for table, hitlist, misslist, backuphit, backupmiss in disptable:
2713 2726 if abs not in table:
2714 2727 continue
2715 2728 # file has changed in dirstate
2716 2729 if mfentry:
2717 2730 handle(hitlist, backuphit)
2718 2731 elif misslist is not None:
2719 2732 handle(misslist, backupmiss)
2720 2733 break
2721 2734 else:
2722 2735 if abs not in repo.dirstate:
2723 2736 if mfentry:
2724 2737 handle(add, True)
2725 2738 elif exact:
2726 2739 ui.warn(_('file not managed: %s\n') % rel)
2727 2740 continue
2728 2741 # file has not changed in dirstate
2729 2742 if node == parent:
2730 2743 if exact:
2731 2744 ui.warn(_('no changes needed to %s\n') % rel)
2732 2745 continue
2733 2746 if pmf is None:
2734 2747 # only need parent manifest in this unlikely case,
2735 2748 # so do not read by default
2736 2749 pmf = repo[parent].manifest()
2737 2750 if abs in pmf:
2738 2751 if mfentry:
2739 2752 # if version of file is same in parent and target
2740 2753 # manifests, do nothing
2741 2754 if (pmf[abs] != mfentry or
2742 2755 pmf.flags(abs) != mf.flags(abs)):
2743 2756 handle(revert, False)
2744 2757 else:
2745 2758 handle(remove, False)
2746 2759
2747 2760 if not opts.get('dry_run'):
2748 2761 def checkout(f):
2749 2762 fc = ctx[f]
2750 2763 repo.wwrite(f, fc.data(), fc.flags())
2751 2764
2752 2765 audit_path = util.path_auditor(repo.root)
2753 2766 for f in remove[0]:
2754 2767 if repo.dirstate[f] == 'a':
2755 2768 repo.dirstate.forget(f)
2756 2769 continue
2757 2770 audit_path(f)
2758 2771 try:
2759 2772 util.unlink(repo.wjoin(f))
2760 2773 except OSError:
2761 2774 pass
2762 2775 repo.dirstate.remove(f)
2763 2776
2764 2777 normal = None
2765 2778 if node == parent:
2766 2779 # We're reverting to our parent. If possible, we'd like status
2767 2780 # to report the file as clean. We have to use normallookup for
2768 2781 # merges to avoid losing information about merged/dirty files.
2769 2782 if p2 != nullid:
2770 2783 normal = repo.dirstate.normallookup
2771 2784 else:
2772 2785 normal = repo.dirstate.normal
2773 2786 for f in revert[0]:
2774 2787 checkout(f)
2775 2788 if normal:
2776 2789 normal(f)
2777 2790
2778 2791 for f in add[0]:
2779 2792 checkout(f)
2780 2793 repo.dirstate.add(f)
2781 2794
2782 2795 normal = repo.dirstate.normallookup
2783 2796 if node == parent and p2 == nullid:
2784 2797 normal = repo.dirstate.normal
2785 2798 for f in undelete[0]:
2786 2799 checkout(f)
2787 2800 normal(f)
2788 2801
2789 2802 finally:
2790 2803 wlock.release()
2791 2804
2792 2805 def rollback(ui, repo):
2793 2806 """roll back the last transaction
2794 2807
2795 2808 This command should be used with care. There is only one level of
2796 2809 rollback, and there is no way to undo a rollback. It will also
2797 2810 restore the dirstate at the time of the last transaction, losing
2798 2811 any dirstate changes since that time. This command does not alter
2799 2812 the working directory.
2800 2813
2801 2814 Transactions are used to encapsulate the effects of all commands
2802 2815 that create new changesets or propagate existing changesets into a
2803 2816 repository. For example, the following commands are transactional,
2804 2817 and their effects can be rolled back:
2805 2818
2806 2819 - commit
2807 2820 - import
2808 2821 - pull
2809 2822 - push (with this repository as the destination)
2810 2823 - unbundle
2811 2824
2812 2825 This command is not intended for use on public repositories. Once
2813 2826 changes are visible for pull by other users, rolling a transaction
2814 2827 back locally is ineffective (someone else may already have pulled
2815 2828 the changes). Furthermore, a race is possible with readers of the
2816 2829 repository; for example an in-progress pull from the repository
2817 2830 may fail if a rollback is performed.
2818 2831 """
2819 2832 repo.rollback()
2820 2833
2821 2834 def root(ui, repo):
2822 2835 """print the root (top) of the current working directory
2823 2836
2824 2837 Print the root directory of the current repository.
2825 2838 """
2826 2839 ui.write(repo.root + "\n")
2827 2840
2828 2841 def serve(ui, repo, **opts):
2829 2842 """export the repository via HTTP
2830 2843
2831 2844 Start a local HTTP repository browser and pull server.
2832 2845
2833 2846 By default, the server logs accesses to stdout and errors to
2834 2847 stderr. Use the -A/--accesslog and -E/--errorlog options to log to
2835 2848 files.
2836 2849 """
2837 2850
2838 2851 if opts["stdio"]:
2839 2852 if repo is None:
2840 2853 raise error.RepoError(_("There is no Mercurial repository here"
2841 2854 " (.hg not found)"))
2842 2855 s = sshserver.sshserver(ui, repo)
2843 2856 s.serve_forever()
2844 2857
2845 2858 baseui = repo and repo.baseui or ui
2846 2859 optlist = ("name templates style address port prefix ipv6"
2847 2860 " accesslog errorlog webdir_conf certificate encoding")
2848 2861 for o in optlist.split():
2849 2862 if opts.get(o, None):
2850 2863 baseui.setconfig("web", o, str(opts[o]))
2851 2864 if (repo is not None) and (repo.ui != baseui):
2852 2865 repo.ui.setconfig("web", o, str(opts[o]))
2853 2866
2854 2867 if repo is None and not ui.config("web", "webdir_conf"):
2855 2868 raise error.RepoError(_("There is no Mercurial repository here"
2856 2869 " (.hg not found)"))
2857 2870
2858 2871 class service(object):
2859 2872 def init(self):
2860 2873 util.set_signal_handler()
2861 2874 self.httpd = server.create_server(baseui, repo)
2862 2875
2863 2876 if not ui.verbose:
2864 2877 return
2865 2878
2866 2879 if self.httpd.prefix:
2867 2880 prefix = self.httpd.prefix.strip('/') + '/'
2868 2881 else:
2869 2882 prefix = ''
2870 2883
2871 2884 port = ':%d' % self.httpd.port
2872 2885 if port == ':80':
2873 2886 port = ''
2874 2887
2875 2888 bindaddr = self.httpd.addr
2876 2889 if bindaddr == '0.0.0.0':
2877 2890 bindaddr = '*'
2878 2891 elif ':' in bindaddr: # IPv6
2879 2892 bindaddr = '[%s]' % bindaddr
2880 2893
2881 2894 fqaddr = self.httpd.fqaddr
2882 2895 if ':' in fqaddr:
2883 2896 fqaddr = '[%s]' % fqaddr
2884 2897 ui.status(_('listening at http://%s%s/%s (bound to %s:%d)\n') %
2885 2898 (fqaddr, port, prefix, bindaddr, self.httpd.port))
2886 2899
2887 2900 def run(self):
2888 2901 self.httpd.serve_forever()
2889 2902
2890 2903 service = service()
2891 2904
2892 2905 cmdutil.service(opts, initfn=service.init, runfn=service.run)
2893 2906
2894 2907 def status(ui, repo, *pats, **opts):
2895 2908 """show changed files in the working directory
2896 2909
2897 2910 Show status of files in the repository. If names are given, only
2898 2911 files that match are shown. Files that are clean or ignored or
2899 2912 the source of a copy/move operation, are not listed unless
2900 2913 -c/--clean, -i/--ignored, -C/--copies or -A/--all are given.
2901 2914 Unless options described with "show only ..." are given, the
2902 2915 options -mardu are used.
2903 2916
2904 2917 Option -q/--quiet hides untracked (unknown and ignored) files
2905 2918 unless explicitly requested with -u/--unknown or -i/--ignored.
2906 2919
2907 2920 NOTE: status may appear to disagree with diff if permissions have
2908 2921 changed or a merge has occurred. The standard diff format does not
2909 2922 report permission changes and diff only reports changes relative
2910 2923 to one merge parent.
2911 2924
2912 2925 If one revision is given, it is used as the base revision.
2913 2926 If two revisions are given, the differences between them are
2914 2927 shown. The --change option can also be used as a shortcut to list
2915 2928 the changed files of a revision from its first parent.
2916 2929
2917 2930 The codes used to show the status of files are::
2918 2931
2919 2932 M = modified
2920 2933 A = added
2921 2934 R = removed
2922 2935 C = clean
2923 2936 ! = missing (deleted by non-hg command, but still tracked)
2924 2937 ? = not tracked
2925 2938 I = ignored
2926 2939 = origin of the previous file listed as A (added)
2927 2940 """
2928 2941
2929 2942 revs = opts.get('rev')
2930 2943 change = opts.get('change')
2931 2944
2932 2945 if revs and change:
2933 2946 msg = _('cannot specify --rev and --change at the same time')
2934 2947 raise util.Abort(msg)
2935 2948 elif change:
2936 2949 node2 = repo.lookup(change)
2937 2950 node1 = repo[node2].parents()[0].node()
2938 2951 else:
2939 2952 node1, node2 = cmdutil.revpair(repo, revs)
2940 2953
2941 2954 cwd = (pats and repo.getcwd()) or ''
2942 2955 end = opts.get('print0') and '\0' or '\n'
2943 2956 copy = {}
2944 2957 states = 'modified added removed deleted unknown ignored clean'.split()
2945 2958 show = [k for k in states if opts.get(k)]
2946 2959 if opts.get('all'):
2947 2960 show += ui.quiet and (states[:4] + ['clean']) or states
2948 2961 if not show:
2949 2962 show = ui.quiet and states[:4] or states[:5]
2950 2963
2951 2964 stat = repo.status(node1, node2, cmdutil.match(repo, pats, opts),
2952 2965 'ignored' in show, 'clean' in show, 'unknown' in show)
2953 2966 changestates = zip(states, 'MAR!?IC', stat)
2954 2967
2955 2968 if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'):
2956 2969 ctxn = repo[nullid]
2957 2970 ctx1 = repo[node1]
2958 2971 ctx2 = repo[node2]
2959 2972 added = stat[1]
2960 2973 if node2 is None:
2961 2974 added = stat[0] + stat[1] # merged?
2962 2975
2963 2976 for k, v in copies.copies(repo, ctx1, ctx2, ctxn)[0].iteritems():
2964 2977 if k in added:
2965 2978 copy[k] = v
2966 2979 elif v in added:
2967 2980 copy[v] = k
2968 2981
2969 2982 for state, char, files in changestates:
2970 2983 if state in show:
2971 2984 format = "%s %%s%s" % (char, end)
2972 2985 if opts.get('no_status'):
2973 2986 format = "%%s%s" % end
2974 2987
2975 2988 for f in files:
2976 2989 ui.write(format % repo.pathto(f, cwd))
2977 2990 if f in copy:
2978 2991 ui.write(' %s%s' % (repo.pathto(copy[f], cwd), end))
2979 2992
2980 2993 def summary(ui, repo, **opts):
2981 2994 """summarize working directory state
2982 2995
2983 2996 This generates a brief summary of the working directory state,
2984 2997 including parents, branch, commit status, and available updates.
2985 2998
2986 2999 With the --remote option, this will check the default paths for
2987 3000 incoming and outgoing changes. This can be time-consuming.
2988 3001 """
2989 3002
2990 3003 ctx = repo[None]
2991 3004 parents = ctx.parents()
2992 3005 pnode = parents[0].node()
2993 3006 tags = repo.tags()
2994 3007
2995 3008 for p in parents:
2996 3009 t = ' '.join([t for t in tags if tags[t] == p.node()])
2997 3010 if p.rev() == -1:
2998 3011 if not len(repo):
2999 3012 t += _(' (empty repository)')
3000 3013 else:
3001 3014 t += _(' (no revision checked out)')
3002 3015 ui.write(_('parent: %d:%s %s\n') % (p.rev(), str(p), t))
3003 3016 if p.description():
3004 3017 ui.status(' ' + p.description().splitlines()[0].strip() + '\n')
3005 3018
3006 3019 branch = ctx.branch()
3007 3020 bheads = repo.branchheads(branch)
3008 3021 m = _('branch: %s\n') % branch
3009 3022 if branch != 'default':
3010 3023 ui.write(m)
3011 3024 else:
3012 3025 ui.status(m)
3013 3026
3014 3027 st = list(repo.status(unknown=True))[:6]
3015 3028 ms = merge_.mergestate(repo)
3016 3029 st.append([f for f in ms if ms[f] == 'u'])
3017 3030 labels = [_('%d modified'), _('%d added'), _('%d removed'),
3018 3031 _('%d deleted'), _('%d unknown'), _('%d ignored'),
3019 3032 _('%d unresolved')]
3020 3033 t = []
3021 3034 for s, l in zip(st, labels):
3022 3035 if s:
3023 3036 t.append(l % len(s))
3024 3037
3025 3038 t = ', '.join(t)
3026 3039 cleanworkdir = False
3027 3040
3028 3041 if len(parents) > 1:
3029 3042 t += _(' (merge)')
3030 3043 elif branch != parents[0].branch():
3031 3044 t += _(' (new branch)')
3032 3045 elif (not st[0] and not st[1] and not st[2]):
3033 3046 t += _(' (clean)')
3034 3047 cleanworkdir = True
3035 3048 elif pnode not in bheads:
3036 3049 t += _(' (new branch head)')
3037 3050
3038 3051 if cleanworkdir:
3039 3052 ui.status(_('commit: %s\n') % t.strip())
3040 3053 else:
3041 3054 ui.write(_('commit: %s\n') % t.strip())
3042 3055
3043 3056 # all ancestors of branch heads - all ancestors of parent = new csets
3044 3057 new = [0] * len(repo)
3045 3058 cl = repo.changelog
3046 3059 for a in [cl.rev(n) for n in bheads]:
3047 3060 new[a] = 1
3048 3061 for a in cl.ancestors(*[cl.rev(n) for n in bheads]):
3049 3062 new[a] = 1
3050 3063 for a in [p.rev() for p in parents]:
3051 3064 if a >= 0:
3052 3065 new[a] = 0
3053 3066 for a in cl.ancestors(*[p.rev() for p in parents]):
3054 3067 new[a] = 0
3055 3068 new = sum(new)
3056 3069
3057 3070 if new == 0:
3058 3071 ui.status(_('update: (current)\n'))
3059 3072 elif pnode not in bheads:
3060 3073 ui.write(_('update: %d new changesets (update)\n') % new)
3061 3074 else:
3062 3075 ui.write(_('update: %d new changesets, %d branch heads (merge)\n') %
3063 3076 (new, len(bheads)))
3064 3077
3065 3078 if opts.get('remote'):
3066 3079 t = []
3067 3080 source, branches = hg.parseurl(ui.expandpath('default'))
3068 3081 other = hg.repository(cmdutil.remoteui(repo, {}), source)
3069 3082 revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev'))
3070 3083 ui.debug('comparing with %s\n' % url.hidepassword(source))
3071 3084 repo.ui.pushbuffer()
3072 3085 common, incoming, rheads = repo.findcommonincoming(other)
3073 3086 repo.ui.popbuffer()
3074 3087 if incoming:
3075 3088 t.append(_('1 or more incoming'))
3076 3089
3077 3090 dest, branches = hg.parseurl(ui.expandpath('default-push', 'default'))
3078 3091 revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
3079 3092 other = hg.repository(cmdutil.remoteui(repo, {}), dest)
3080 3093 ui.debug('comparing with %s\n' % url.hidepassword(dest))
3081 3094 repo.ui.pushbuffer()
3082 3095 o = repo.findoutgoing(other)
3083 3096 repo.ui.popbuffer()
3084 3097 o = repo.changelog.nodesbetween(o, None)[0]
3085 3098 if o:
3086 3099 t.append(_('%d outgoing') % len(o))
3087 3100
3088 3101 if t:
3089 3102 ui.write(_('remote: %s\n') % (', '.join(t)))
3090 3103 else:
3091 3104 ui.status(_('remote: (synced)\n'))
3092 3105
3093 3106 def tag(ui, repo, name1, *names, **opts):
3094 3107 """add one or more tags for the current or given revision
3095 3108
3096 3109 Name a particular revision using <name>.
3097 3110
3098 3111 Tags are used to name particular revisions of the repository and are
3099 3112 very useful to compare different revisions, to go back to significant
3100 3113 earlier versions or to mark branch points as releases, etc.
3101 3114
3102 3115 If no revision is given, the parent of the working directory is
3103 3116 used, or tip if no revision is checked out.
3104 3117
3105 3118 To facilitate version control, distribution, and merging of tags,
3106 3119 they are stored as a file named ".hgtags" which is managed
3107 3120 similarly to other project files and can be hand-edited if
3108 3121 necessary. The file '.hg/localtags' is used for local tags (not
3109 3122 shared among repositories).
3110 3123
3111 3124 See 'hg help dates' for a list of formats valid for -d/--date.
3112 3125 """
3113 3126
3114 3127 rev_ = "."
3115 3128 names = (name1,) + names
3116 3129 if len(names) != len(set(names)):
3117 3130 raise util.Abort(_('tag names must be unique'))
3118 3131 for n in names:
3119 3132 if n in ['tip', '.', 'null']:
3120 3133 raise util.Abort(_('the name \'%s\' is reserved') % n)
3121 3134 if opts.get('rev') and opts.get('remove'):
3122 3135 raise util.Abort(_("--rev and --remove are incompatible"))
3123 3136 if opts.get('rev'):
3124 3137 rev_ = opts['rev']
3125 3138 message = opts.get('message')
3126 3139 if opts.get('remove'):
3127 3140 expectedtype = opts.get('local') and 'local' or 'global'
3128 3141 for n in names:
3129 3142 if not repo.tagtype(n):
3130 3143 raise util.Abort(_('tag \'%s\' does not exist') % n)
3131 3144 if repo.tagtype(n) != expectedtype:
3132 3145 if expectedtype == 'global':
3133 3146 raise util.Abort(_('tag \'%s\' is not a global tag') % n)
3134 3147 else:
3135 3148 raise util.Abort(_('tag \'%s\' is not a local tag') % n)
3136 3149 rev_ = nullid
3137 3150 if not message:
3138 3151 # we don't translate commit messages
3139 3152 message = 'Removed tag %s' % ', '.join(names)
3140 3153 elif not opts.get('force'):
3141 3154 for n in names:
3142 3155 if n in repo.tags():
3143 3156 raise util.Abort(_('tag \'%s\' already exists '
3144 3157 '(use -f to force)') % n)
3145 3158 if not rev_ and repo.dirstate.parents()[1] != nullid:
3146 3159 raise util.Abort(_('uncommitted merge - please provide a '
3147 3160 'specific revision'))
3148 3161 r = repo[rev_].node()
3149 3162
3150 3163 if not message:
3151 3164 # we don't translate commit messages
3152 3165 message = ('Added tag %s for changeset %s' %
3153 3166 (', '.join(names), short(r)))
3154 3167
3155 3168 date = opts.get('date')
3156 3169 if date:
3157 3170 date = util.parsedate(date)
3158 3171
3159 3172 repo.tag(names, r, message, opts.get('local'), opts.get('user'), date)
3160 3173
3161 3174 def tags(ui, repo):
3162 3175 """list repository tags
3163 3176
3164 3177 This lists both regular and local tags. When the -v/--verbose
3165 3178 switch is used, a third column "local" is printed for local tags.
3166 3179 """
3167 3180
3168 3181 hexfunc = ui.debugflag and hex or short
3169 3182 tagtype = ""
3170 3183
3171 3184 for t, n in reversed(repo.tagslist()):
3172 3185 if ui.quiet:
3173 3186 ui.write("%s\n" % t)
3174 3187 continue
3175 3188
3176 3189 try:
3177 3190 hn = hexfunc(n)
3178 3191 r = "%5d:%s" % (repo.changelog.rev(n), hn)
3179 3192 except error.LookupError:
3180 3193 r = " ?:%s" % hn
3181 3194 else:
3182 3195 spaces = " " * (30 - encoding.colwidth(t))
3183 3196 if ui.verbose:
3184 3197 if repo.tagtype(t) == 'local':
3185 3198 tagtype = " local"
3186 3199 else:
3187 3200 tagtype = ""
3188 3201 ui.write("%s%s %s%s\n" % (t, spaces, r, tagtype))
3189 3202
3190 3203 def tip(ui, repo, **opts):
3191 3204 """show the tip revision
3192 3205
3193 3206 The tip revision (usually just called the tip) is the changeset
3194 3207 most recently added to the repository (and therefore the most
3195 3208 recently changed head).
3196 3209
3197 3210 If you have just made a commit, that commit will be the tip. If
3198 3211 you have just pulled changes from another repository, the tip of
3199 3212 that repository becomes the current tip. The "tip" tag is special
3200 3213 and cannot be renamed or assigned to a different changeset.
3201 3214 """
3202 3215 displayer = cmdutil.show_changeset(ui, repo, opts)
3203 3216 displayer.show(repo[len(repo) - 1])
3204 3217 displayer.close()
3205 3218
3206 3219 def unbundle(ui, repo, fname1, *fnames, **opts):
3207 3220 """apply one or more changegroup files
3208 3221
3209 3222 Apply one or more compressed changegroup files generated by the
3210 3223 bundle command.
3211 3224 """
3212 3225 fnames = (fname1,) + fnames
3213 3226
3214 3227 lock = repo.lock()
3215 3228 try:
3216 3229 for fname in fnames:
3217 3230 f = url.open(ui, fname)
3218 3231 gen = changegroup.readbundle(f, fname)
3219 3232 modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname)
3220 3233 finally:
3221 3234 lock.release()
3222 3235
3223 3236 return postincoming(ui, repo, modheads, opts.get('update'), None)
3224 3237
3225 3238 def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False):
3226 3239 """update working directory
3227 3240
3228 3241 Update the repository's working directory to the specified
3229 3242 changeset.
3230 3243
3231 3244 If no changeset is specified, attempt to update to the head of the
3232 3245 current branch. If this head is a descendant of the working
3233 3246 directory's parent, update to it, otherwise abort.
3234 3247
3235 3248 The following rules apply when the working directory contains
3236 3249 uncommitted changes:
3237 3250
3238 3251 1. If neither -c/--check nor -C/--clean is specified, and if
3239 3252 the requested changeset is an ancestor or descendant of
3240 3253 the working directory's parent, the uncommitted changes
3241 3254 are merged into the requested changeset and the merged
3242 3255 result is left uncommitted. If the requested changeset is
3243 3256 not an ancestor or descendant (that is, it is on another
3244 3257 branch), the update is aborted and the uncommitted changes
3245 3258 are preserved.
3246 3259
3247 3260 2. With the -c/--check option, the update is aborted and the
3248 3261 uncommitted changes are preserved.
3249 3262
3250 3263 3. With the -C/--clean option, uncommitted changes are discarded and
3251 3264 the working directory is updated to the requested changeset.
3252 3265
3253 3266 Use null as the changeset to remove the working directory (like 'hg
3254 3267 clone -U').
3255 3268
3256 3269 If you want to update just one file to an older changeset, use 'hg revert'.
3257 3270
3258 3271 See 'hg help dates' for a list of formats valid for -d/--date.
3259 3272 """
3260 3273 if rev and node:
3261 3274 raise util.Abort(_("please specify just one revision"))
3262 3275
3263 3276 if not rev:
3264 3277 rev = node
3265 3278
3266 3279 if check and clean:
3267 3280 raise util.Abort(_("cannot specify both -c/--check and -C/--clean"))
3268 3281
3269 3282 if check:
3270 3283 # we could use dirty() but we can ignore merge and branch trivia
3271 3284 c = repo[None]
3272 3285 if c.modified() or c.added() or c.removed():
3273 3286 raise util.Abort(_("uncommitted local changes"))
3274 3287
3275 3288 if date:
3276 3289 if rev:
3277 3290 raise util.Abort(_("you can't specify a revision and a date"))
3278 3291 rev = cmdutil.finddate(ui, repo, date)
3279 3292
3280 3293 if clean or check:
3281 3294 return hg.clean(repo, rev)
3282 3295 else:
3283 3296 return hg.update(repo, rev)
3284 3297
3285 3298 def verify(ui, repo):
3286 3299 """verify the integrity of the repository
3287 3300
3288 3301 Verify the integrity of the current repository.
3289 3302
3290 3303 This will perform an extensive check of the repository's
3291 3304 integrity, validating the hashes and checksums of each entry in
3292 3305 the changelog, manifest, and tracked files, as well as the
3293 3306 integrity of their crosslinks and indices.
3294 3307 """
3295 3308 return hg.verify(repo)
3296 3309
3297 3310 def version_(ui):
3298 3311 """output version and copyright information"""
3299 3312 ui.write(_("Mercurial Distributed SCM (version %s)\n")
3300 3313 % util.version())
3301 3314 ui.status(_(
3302 3315 "\nCopyright (C) 2005-2010 Matt Mackall <mpm@selenic.com> and others\n"
3303 3316 "This is free software; see the source for copying conditions. "
3304 3317 "There is NO\nwarranty; "
3305 3318 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
3306 3319 ))
3307 3320
3308 3321 # Command options and aliases are listed here, alphabetically
3309 3322
3310 3323 globalopts = [
3311 3324 ('R', 'repository', '',
3312 3325 _('repository root directory or name of overlay bundle file')),
3313 3326 ('', 'cwd', '', _('change working directory')),
3314 3327 ('y', 'noninteractive', None,
3315 3328 _('do not prompt, assume \'yes\' for any required answers')),
3316 3329 ('q', 'quiet', None, _('suppress output')),
3317 3330 ('v', 'verbose', None, _('enable additional output')),
3318 3331 ('', 'config', [], _('set/override config option')),
3319 3332 ('', 'debug', None, _('enable debugging output')),
3320 3333 ('', 'debugger', None, _('start debugger')),
3321 3334 ('', 'encoding', encoding.encoding, _('set the charset encoding')),
3322 3335 ('', 'encodingmode', encoding.encodingmode,
3323 3336 _('set the charset encoding mode')),
3324 3337 ('', 'traceback', None, _('always print a traceback on exception')),
3325 3338 ('', 'time', None, _('time how long the command takes')),
3326 3339 ('', 'profile', None, _('print command execution profile')),
3327 3340 ('', 'version', None, _('output version information and exit')),
3328 3341 ('h', 'help', None, _('display help and exit')),
3329 3342 ]
3330 3343
3331 3344 dryrunopts = [('n', 'dry-run', None,
3332 3345 _('do not perform actions, just print output'))]
3333 3346
3334 3347 remoteopts = [
3335 3348 ('e', 'ssh', '', _('specify ssh command to use')),
3336 3349 ('', 'remotecmd', '', _('specify hg command to run on the remote side')),
3337 3350 ]
3338 3351
3339 3352 walkopts = [
3340 3353 ('I', 'include', [], _('include names matching the given patterns')),
3341 3354 ('X', 'exclude', [], _('exclude names matching the given patterns')),
3342 3355 ]
3343 3356
3344 3357 commitopts = [
3345 3358 ('m', 'message', '', _('use <text> as commit message')),
3346 3359 ('l', 'logfile', '', _('read commit message from <file>')),
3347 3360 ]
3348 3361
3349 3362 commitopts2 = [
3350 3363 ('d', 'date', '', _('record datecode as commit date')),
3351 3364 ('u', 'user', '', _('record the specified user as committer')),
3352 3365 ]
3353 3366
3354 3367 templateopts = [
3355 3368 ('', 'style', '', _('display using template map file')),
3356 3369 ('', 'template', '', _('display with template')),
3357 3370 ]
3358 3371
3359 3372 logopts = [
3360 3373 ('p', 'patch', None, _('show patch')),
3361 3374 ('g', 'git', None, _('use git extended diff format')),
3362 3375 ('l', 'limit', '', _('limit number of changes displayed')),
3363 3376 ('M', 'no-merges', None, _('do not show merges')),
3364 3377 ] + templateopts
3365 3378
3366 3379 diffopts = [
3367 3380 ('a', 'text', None, _('treat all files as text')),
3368 3381 ('g', 'git', None, _('use git extended diff format')),
3369 3382 ('', 'nodates', None, _('omit dates from diff headers'))
3370 3383 ]
3371 3384
3372 3385 diffopts2 = [
3373 3386 ('p', 'show-function', None, _('show which function each change is in')),
3374 3387 ('', 'reverse', None, _('produce a diff that undoes the changes')),
3375 3388 ('w', 'ignore-all-space', None,
3376 3389 _('ignore white space when comparing lines')),
3377 3390 ('b', 'ignore-space-change', None,
3378 3391 _('ignore changes in the amount of white space')),
3379 3392 ('B', 'ignore-blank-lines', None,
3380 3393 _('ignore changes whose lines are all blank')),
3381 3394 ('U', 'unified', '', _('number of lines of context to show')),
3382 3395 ('', 'stat', None, _('output diffstat-style summary of changes')),
3383 3396 ]
3384 3397
3385 3398 similarityopts = [
3386 3399 ('s', 'similarity', '',
3387 3400 _('guess renamed files by similarity (0<=s<=100)'))
3388 3401 ]
3389 3402
3390 3403 table = {
3391 3404 "^add": (add, walkopts + dryrunopts, _('[OPTION]... [FILE]...')),
3392 3405 "addremove":
3393 3406 (addremove, similarityopts + walkopts + dryrunopts,
3394 3407 _('[OPTION]... [FILE]...')),
3395 3408 "^annotate|blame":
3396 3409 (annotate,
3397 3410 [('r', 'rev', '', _('annotate the specified revision')),
3398 3411 ('', 'follow', None, _('follow copies and renames (DEPRECATED)')),
3399 3412 ('', 'no-follow', None, _("don't follow copies and renames")),
3400 3413 ('a', 'text', None, _('treat all files as text')),
3401 3414 ('u', 'user', None, _('list the author (long with -v)')),
3402 3415 ('f', 'file', None, _('list the filename')),
3403 3416 ('d', 'date', None, _('list the date (short with -q)')),
3404 3417 ('n', 'number', None, _('list the revision number (default)')),
3405 3418 ('c', 'changeset', None, _('list the changeset')),
3406 3419 ('l', 'line-number', None,
3407 3420 _('show line number at the first appearance'))
3408 3421 ] + walkopts,
3409 3422 _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...')),
3410 3423 "archive":
3411 3424 (archive,
3412 3425 [('', 'no-decode', None, _('do not pass files through decoders')),
3413 3426 ('p', 'prefix', '', _('directory prefix for files in archive')),
3414 3427 ('r', 'rev', '', _('revision to distribute')),
3415 3428 ('t', 'type', '', _('type of distribution to create')),
3416 3429 ] + walkopts,
3417 3430 _('[OPTION]... DEST')),
3418 3431 "backout":
3419 3432 (backout,
3420 3433 [('', 'merge', None,
3421 3434 _('merge with old dirstate parent after backout')),
3422 3435 ('', 'parent', '', _('parent to choose when backing out merge')),
3423 3436 ('r', 'rev', '', _('revision to backout')),
3424 3437 ] + walkopts + commitopts + commitopts2,
3425 3438 _('[OPTION]... [-r] REV')),
3426 3439 "bisect":
3427 3440 (bisect,
3428 3441 [('r', 'reset', False, _('reset bisect state')),
3429 3442 ('g', 'good', False, _('mark changeset good')),
3430 3443 ('b', 'bad', False, _('mark changeset bad')),
3431 3444 ('s', 'skip', False, _('skip testing changeset')),
3432 3445 ('c', 'command', '', _('use command to check changeset state')),
3433 3446 ('U', 'noupdate', False, _('do not update to target'))],
3434 3447 _("[-gbsr] [-U] [-c CMD] [REV]")),
3435 3448 "branch":
3436 3449 (branch,
3437 3450 [('f', 'force', None,
3438 3451 _('set branch name even if it shadows an existing branch')),
3439 3452 ('C', 'clean', None, _('reset branch name to parent branch name'))],
3440 3453 _('[-fC] [NAME]')),
3441 3454 "branches":
3442 3455 (branches,
3443 3456 [('a', 'active', False,
3444 3457 _('show only branches that have unmerged heads')),
3445 3458 ('c', 'closed', False,
3446 3459 _('show normal and closed branches'))],
3447 3460 _('[-ac]')),
3448 3461 "bundle":
3449 3462 (bundle,
3450 3463 [('f', 'force', None,
3451 3464 _('run even when the destination is unrelated')),
3452 3465 ('r', 'rev', [],
3453 3466 _('a changeset intended to be added to the destination')),
3454 3467 ('b', 'branch', [],
3455 3468 _('a specific branch you would like to bundle')),
3456 3469 ('', 'base', [],
3457 3470 _('a base changeset assumed to be available at the destination')),
3458 3471 ('a', 'all', None, _('bundle all changesets in the repository')),
3459 3472 ('t', 'type', 'bzip2', _('bundle compression type to use')),
3460 3473 ] + remoteopts,
3461 3474 _('[-f] [-t TYPE] [-a] [-r REV]... [--base REV]... FILE [DEST]')),
3462 3475 "cat":
3463 3476 (cat,
3464 3477 [('o', 'output', '', _('print output to file with formatted name')),
3465 3478 ('r', 'rev', '', _('print the given revision')),
3466 3479 ('', 'decode', None, _('apply any matching decode filter')),
3467 3480 ] + walkopts,
3468 3481 _('[OPTION]... FILE...')),
3469 3482 "^clone":
3470 3483 (clone,
3471 3484 [('U', 'noupdate', None,
3472 3485 _('the clone will include an empty working copy (only a repository)')),
3473 3486 ('u', 'updaterev', '',
3474 3487 _('revision, tag or branch to check out')),
3475 3488 ('r', 'rev', [],
3476 3489 _('include the specified changeset')),
3477 3490 ('b', 'branch', [],
3478 3491 _('clone only the specified branch')),
3479 3492 ('', 'pull', None, _('use pull protocol to copy metadata')),
3480 3493 ('', 'uncompressed', None,
3481 3494 _('use uncompressed transfer (fast over LAN)')),
3482 3495 ] + remoteopts,
3483 3496 _('[OPTION]... SOURCE [DEST]')),
3484 3497 "^commit|ci":
3485 3498 (commit,
3486 3499 [('A', 'addremove', None,
3487 3500 _('mark new/missing files as added/removed before committing')),
3488 3501 ('', 'close-branch', None,
3489 3502 _('mark a branch as closed, hiding it from the branch list')),
3490 3503 ] + walkopts + commitopts + commitopts2,
3491 3504 _('[OPTION]... [FILE]...')),
3492 3505 "copy|cp":
3493 3506 (copy,
3494 3507 [('A', 'after', None, _('record a copy that has already occurred')),
3495 3508 ('f', 'force', None,
3496 3509 _('forcibly copy over an existing managed file')),
3497 3510 ] + walkopts + dryrunopts,
3498 3511 _('[OPTION]... [SOURCE]... DEST')),
3499 3512 "debugancestor": (debugancestor, [], _('[INDEX] REV1 REV2')),
3500 3513 "debugcheckstate": (debugcheckstate, [], ''),
3501 3514 "debugcommands": (debugcommands, [], _('[COMMAND]')),
3502 3515 "debugcomplete":
3503 3516 (debugcomplete,
3504 3517 [('o', 'options', None, _('show the command options'))],
3505 3518 _('[-o] CMD')),
3506 3519 "debugdate":
3507 3520 (debugdate,
3508 3521 [('e', 'extended', None, _('try extended date formats'))],
3509 3522 _('[-e] DATE [RANGE]')),
3510 3523 "debugdata": (debugdata, [], _('FILE REV')),
3511 3524 "debugfsinfo": (debugfsinfo, [], _('[PATH]')),
3512 3525 "debugindex": (debugindex, [], _('FILE')),
3513 3526 "debugindexdot": (debugindexdot, [], _('FILE')),
3514 3527 "debuginstall": (debuginstall, [], ''),
3515 3528 "debugrebuildstate":
3516 3529 (debugrebuildstate,
3517 3530 [('r', 'rev', '', _('revision to rebuild to'))],
3518 3531 _('[-r REV] [REV]')),
3519 3532 "debugrename":
3520 3533 (debugrename,
3521 3534 [('r', 'rev', '', _('revision to debug'))],
3522 3535 _('[-r REV] FILE')),
3523 3536 "debugsetparents":
3524 3537 (debugsetparents, [], _('REV1 [REV2]')),
3525 3538 "debugstate":
3526 3539 (debugstate,
3527 3540 [('', 'nodates', None, _('do not display the saved mtime'))],
3528 3541 _('[OPTION]...')),
3529 3542 "debugsub":
3530 3543 (debugsub,
3531 3544 [('r', 'rev', '', _('revision to check'))],
3532 3545 _('[-r REV] [REV]')),
3533 3546 "debugwalk": (debugwalk, walkopts, _('[OPTION]... [FILE]...')),
3534 3547 "^diff":
3535 3548 (diff,
3536 3549 [('r', 'rev', [], _('revision')),
3537 3550 ('c', 'change', '', _('change made by revision'))
3538 3551 ] + diffopts + diffopts2 + walkopts,
3539 3552 _('[OPTION]... [-r REV1 [-r REV2]] [FILE]...')),
3540 3553 "^export":
3541 3554 (export,
3542 3555 [('o', 'output', '', _('print output to file with formatted name')),
3543 3556 ('', 'switch-parent', None, _('diff against the second parent')),
3544 3557 ('r', 'rev', [], _('revisions to export')),
3545 3558 ] + diffopts,
3546 3559 _('[OPTION]... [-o OUTFILESPEC] REV...')),
3547 3560 "^forget":
3548 3561 (forget,
3549 3562 [] + walkopts,
3550 3563 _('[OPTION]... FILE...')),
3551 3564 "grep":
3552 3565 (grep,
3553 3566 [('0', 'print0', None, _('end fields with NUL')),
3554 3567 ('', 'all', None, _('print all revisions that match')),
3555 3568 ('f', 'follow', None,
3556 3569 _('follow changeset history,'
3557 3570 ' or file history across copies and renames')),
3558 3571 ('i', 'ignore-case', None, _('ignore case when matching')),
3559 3572 ('l', 'files-with-matches', None,
3560 3573 _('print only filenames and revisions that match')),
3561 3574 ('n', 'line-number', None, _('print matching line numbers')),
3562 3575 ('r', 'rev', [], _('search in given revision range')),
3563 3576 ('u', 'user', None, _('list the author (long with -v)')),
3564 3577 ('d', 'date', None, _('list the date (short with -q)')),
3565 3578 ] + walkopts,
3566 3579 _('[OPTION]... PATTERN [FILE]...')),
3567 3580 "heads":
3568 3581 (heads,
3569 3582 [('r', 'rev', '', _('show only heads which are descendants of REV')),
3570 3583 ('t', 'topo', False, _('show topological heads only')),
3571 3584 ('a', 'active', False,
3572 3585 _('show active branchheads only [DEPRECATED]')),
3573 3586 ('c', 'closed', False,
3574 3587 _('show normal and closed branch heads')),
3575 3588 ] + templateopts,
3576 3589 _('[-ac] [-r STARTREV] [REV]...')),
3577 3590 "help": (help_, [], _('[TOPIC]')),
3578 3591 "identify|id":
3579 3592 (identify,
3580 3593 [('r', 'rev', '', _('identify the specified revision')),
3581 3594 ('n', 'num', None, _('show local revision number')),
3582 3595 ('i', 'id', None, _('show global revision id')),
3583 3596 ('b', 'branch', None, _('show branch')),
3584 3597 ('t', 'tags', None, _('show tags'))],
3585 3598 _('[-nibt] [-r REV] [SOURCE]')),
3586 3599 "import|patch":
3587 3600 (import_,
3588 3601 [('p', 'strip', 1,
3589 3602 _('directory strip option for patch. This has the same '
3590 3603 'meaning as the corresponding patch option')),
3591 3604 ('b', 'base', '', _('base path')),
3592 3605 ('f', 'force', None,
3593 3606 _('skip check for outstanding uncommitted changes')),
3594 3607 ('', 'no-commit', None,
3595 3608 _("don't commit, just update the working directory")),
3596 3609 ('', 'exact', None,
3597 3610 _('apply patch to the nodes from which it was generated')),
3598 3611 ('', 'import-branch', None,
3599 3612 _('use any branch information in patch (implied by --exact)'))] +
3600 3613 commitopts + commitopts2 + similarityopts,
3601 3614 _('[OPTION]... PATCH...')),
3602 3615 "incoming|in":
3603 3616 (incoming,
3604 3617 [('f', 'force', None,
3605 3618 _('run even if remote repository is unrelated')),
3606 3619 ('n', 'newest-first', None, _('show newest record first')),
3607 3620 ('', 'bundle', '', _('file to store the bundles into')),
3608 3621 ('r', 'rev', [],
3609 3622 _('a remote changeset intended to be added')),
3610 3623 ('b', 'branch', [],
3611 3624 _('a specific branch you would like to pull')),
3612 3625 ] + logopts + remoteopts,
3613 3626 _('[-p] [-n] [-M] [-f] [-r REV]...'
3614 3627 ' [--bundle FILENAME] [SOURCE]')),
3615 3628 "^init":
3616 3629 (init,
3617 3630 remoteopts,
3618 3631 _('[-e CMD] [--remotecmd CMD] [DEST]')),
3619 3632 "locate":
3620 3633 (locate,
3621 3634 [('r', 'rev', '', _('search the repository as it is in REV')),
3622 3635 ('0', 'print0', None,
3623 3636 _('end filenames with NUL, for use with xargs')),
3624 3637 ('f', 'fullpath', None,
3625 3638 _('print complete paths from the filesystem root')),
3626 3639 ] + walkopts,
3627 3640 _('[OPTION]... [PATTERN]...')),
3628 3641 "^log|history":
3629 3642 (log,
3630 3643 [('f', 'follow', None,
3631 3644 _('follow changeset history,'
3632 3645 ' or file history across copies and renames')),
3633 3646 ('', 'follow-first', None,
3634 3647 _('only follow the first parent of merge changesets')),
3635 3648 ('d', 'date', '', _('show revisions matching date spec')),
3636 3649 ('C', 'copies', None, _('show copied files')),
3637 3650 ('k', 'keyword', [], _('do case-insensitive search for a keyword')),
3638 3651 ('r', 'rev', [], _('show the specified revision or range')),
3639 3652 ('', 'removed', None, _('include revisions where files were removed')),
3640 3653 ('m', 'only-merges', None, _('show only merges')),
3641 3654 ('u', 'user', [], _('revisions committed by user')),
3642 3655 ('b', 'only-branch', [],
3643 3656 _('show only changesets within the given named branch')),
3644 3657 ('P', 'prune', [],
3645 3658 _('do not display revision or any of its ancestors')),
3646 3659 ] + logopts + walkopts,
3647 3660 _('[OPTION]... [FILE]')),
3648 3661 "manifest":
3649 3662 (manifest,
3650 3663 [('r', 'rev', '', _('revision to display'))],
3651 3664 _('[-r REV]')),
3652 3665 "^merge":
3653 3666 (merge,
3654 3667 [('f', 'force', None, _('force a merge with outstanding changes')),
3655 3668 ('r', 'rev', '', _('revision to merge')),
3656 3669 ('P', 'preview', None,
3657 3670 _('review revisions to merge (no merge is performed)'))],
3658 3671 _('[-P] [-f] [[-r] REV]')),
3659 3672 "outgoing|out":
3660 3673 (outgoing,
3661 3674 [('f', 'force', None,
3662 3675 _('run even when the destination is unrelated')),
3663 3676 ('r', 'rev', [],
3664 3677 _('a changeset intended to be included in the destination')),
3665 3678 ('n', 'newest-first', None, _('show newest record first')),
3666 3679 ('b', 'branch', [],
3667 3680 _('a specific branch you would like to push')),
3668 3681 ] + logopts + remoteopts,
3669 3682 _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')),
3670 3683 "parents":
3671 3684 (parents,
3672 3685 [('r', 'rev', '', _('show parents of the specified revision')),
3673 3686 ] + templateopts,
3674 3687 _('[-r REV] [FILE]')),
3675 3688 "paths": (paths, [], _('[NAME]')),
3676 3689 "^pull":
3677 3690 (pull,
3678 3691 [('u', 'update', None,
3679 3692 _('update to new branch head if changesets were pulled')),
3680 3693 ('f', 'force', None,
3681 3694 _('run even when remote repository is unrelated')),
3682 3695 ('r', 'rev', [],
3683 3696 _('a remote changeset intended to be added')),
3684 3697 ('b', 'branch', [],
3685 3698 _('a specific branch you would like to pull')),
3686 3699 ] + remoteopts,
3687 3700 _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')),
3688 3701 "^push":
3689 3702 (push,
3690 3703 [('f', 'force', None, _('force push')),
3691 3704 ('r', 'rev', [],
3692 3705 _('a changeset intended to be included in the destination')),
3693 3706 ('b', 'branch', [],
3694 3707 _('a specific branch you would like to push')),
3695 3708 ] + remoteopts,
3696 3709 _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')),
3697 3710 "recover": (recover, []),
3698 3711 "^remove|rm":
3699 3712 (remove,
3700 3713 [('A', 'after', None, _('record delete for missing files')),
3701 3714 ('f', 'force', None,
3702 3715 _('remove (and delete) file even if added or modified')),
3703 3716 ] + walkopts,
3704 3717 _('[OPTION]... FILE...')),
3705 3718 "rename|mv":
3706 3719 (rename,
3707 3720 [('A', 'after', None, _('record a rename that has already occurred')),
3708 3721 ('f', 'force', None,
3709 3722 _('forcibly copy over an existing managed file')),
3710 3723 ] + walkopts + dryrunopts,
3711 3724 _('[OPTION]... SOURCE... DEST')),
3712 3725 "resolve":
3713 3726 (resolve,
3714 3727 [('a', 'all', None, _('select all unresolved files')),
3715 3728 ('l', 'list', None, _('list state of files needing merge')),
3716 3729 ('m', 'mark', None, _('mark files as resolved')),
3717 3730 ('u', 'unmark', None, _('unmark files as resolved')),
3718 3731 ('n', 'no-status', None, _('hide status prefix'))]
3719 3732 + walkopts,
3720 3733 _('[OPTION]... [FILE]...')),
3721 3734 "revert":
3722 3735 (revert,
3723 3736 [('a', 'all', None, _('revert all changes when no arguments given')),
3724 3737 ('d', 'date', '', _('tipmost revision matching date')),
3725 3738 ('r', 'rev', '', _('revert to the specified revision')),
3726 3739 ('', 'no-backup', None, _('do not save backup copies of files')),
3727 3740 ] + walkopts + dryrunopts,
3728 3741 _('[OPTION]... [-r REV] [NAME]...')),
3729 3742 "rollback": (rollback, []),
3730 3743 "root": (root, []),
3731 3744 "^serve":
3732 3745 (serve,
3733 3746 [('A', 'accesslog', '', _('name of access log file to write to')),
3734 3747 ('d', 'daemon', None, _('run server in background')),
3735 3748 ('', 'daemon-pipefds', '', _('used internally by daemon mode')),
3736 3749 ('E', 'errorlog', '', _('name of error log file to write to')),
3737 3750 ('p', 'port', 0, _('port to listen on (default: 8000)')),
3738 3751 ('a', 'address', '',
3739 3752 _('address to listen on (default: all interfaces)')),
3740 3753 ('', 'prefix', '',
3741 3754 _('prefix path to serve from (default: server root)')),
3742 3755 ('n', 'name', '',
3743 3756 _('name to show in web pages (default: working directory)')),
3744 3757 ('', 'webdir-conf', '', _('name of the webdir config file'
3745 3758 ' (serve more than one repository)')),
3746 3759 ('', 'pid-file', '', _('name of file to write process ID to')),
3747 3760 ('', 'stdio', None, _('for remote clients')),
3748 3761 ('t', 'templates', '', _('web templates to use')),
3749 3762 ('', 'style', '', _('template style to use')),
3750 3763 ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')),
3751 3764 ('', 'certificate', '', _('SSL certificate file'))],
3752 3765 _('[OPTION]...')),
3753 3766 "showconfig|debugconfig":
3754 3767 (showconfig,
3755 3768 [('u', 'untrusted', None, _('show untrusted configuration options'))],
3756 3769 _('[-u] [NAME]...')),
3757 3770 "^summary|sum":
3758 3771 (summary,
3759 3772 [('', 'remote', None, _('check for push and pull'))], '[--remote]'),
3760 3773 "^status|st":
3761 3774 (status,
3762 3775 [('A', 'all', None, _('show status of all files')),
3763 3776 ('m', 'modified', None, _('show only modified files')),
3764 3777 ('a', 'added', None, _('show only added files')),
3765 3778 ('r', 'removed', None, _('show only removed files')),
3766 3779 ('d', 'deleted', None, _('show only deleted (but tracked) files')),
3767 3780 ('c', 'clean', None, _('show only files without changes')),
3768 3781 ('u', 'unknown', None, _('show only unknown (not tracked) files')),
3769 3782 ('i', 'ignored', None, _('show only ignored files')),
3770 3783 ('n', 'no-status', None, _('hide status prefix')),
3771 3784 ('C', 'copies', None, _('show source of copied files')),
3772 3785 ('0', 'print0', None,
3773 3786 _('end filenames with NUL, for use with xargs')),
3774 3787 ('', 'rev', [], _('show difference from revision')),
3775 3788 ('', 'change', '', _('list the changed files of a revision')),
3776 3789 ] + walkopts,
3777 3790 _('[OPTION]... [FILE]...')),
3778 3791 "tag":
3779 3792 (tag,
3780 3793 [('f', 'force', None, _('replace existing tag')),
3781 3794 ('l', 'local', None, _('make the tag local')),
3782 3795 ('r', 'rev', '', _('revision to tag')),
3783 3796 ('', 'remove', None, _('remove a tag')),
3784 3797 # -l/--local is already there, commitopts cannot be used
3785 3798 ('m', 'message', '', _('use <text> as commit message')),
3786 3799 ] + commitopts2,
3787 3800 _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')),
3788 3801 "tags": (tags, [], ''),
3789 3802 "tip":
3790 3803 (tip,
3791 3804 [('p', 'patch', None, _('show patch')),
3792 3805 ('g', 'git', None, _('use git extended diff format')),
3793 3806 ] + templateopts,
3794 3807 _('[-p] [-g]')),
3795 3808 "unbundle":
3796 3809 (unbundle,
3797 3810 [('u', 'update', None,
3798 3811 _('update to new branch head if changesets were unbundled'))],
3799 3812 _('[-u] FILE...')),
3800 3813 "^update|up|checkout|co":
3801 3814 (update,
3802 3815 [('C', 'clean', None, _('discard uncommitted changes (no backup)')),
3803 3816 ('c', 'check', None, _('check for uncommitted changes')),
3804 3817 ('d', 'date', '', _('tipmost revision matching date')),
3805 3818 ('r', 'rev', '', _('revision'))],
3806 3819 _('[-c] [-C] [-d DATE] [[-r] REV]')),
3807 3820 "verify": (verify, []),
3808 3821 "version": (version_, []),
3809 3822 }
3810 3823
3811 3824 norepo = ("clone init version help debugcommands debugcomplete debugdata"
3812 3825 " debugindex debugindexdot debugdate debuginstall debugfsinfo")
3813 3826 optionalrepo = ("identify paths serve showconfig debugancestor")
@@ -1,60 +1,63 b''
1 1 #!/bin/sh
2 2
3 3 hg
4 4 hg -q
5 5 hg help
6 6 hg -q help
7 7
8 8 echo %% test short command list with verbose option
9 9 hg -v help shortlist | sed 's/[(]version [^)]*[)]/(version xxx)/'
10 10
11 11 hg add -h
12 12
13 echo %% verbose help for add
14 hg add -hv
15
13 16 echo %% test help option with version option
14 17 hg add -h --version | sed 's/[(]version [^)]*[)]/(version xxx)/'
15 18
16 19 hg add --skjdfks
17 20
18 21 echo %% test ambiguous command help
19 22 hg help ad
20 23
21 24 echo %% test command without options
22 25 hg help verify
23 26
24 27 hg help diff
25 28 hg help status
26 29 hg -q help status
27 30 hg help foo
28 31 hg skjdfks
29 32
30 33 cat > helpext.py <<EOF
31 34 import os
32 35 from mercurial import commands
33 36
34 37 def nohelp(ui, *args, **kwargs):
35 38 pass
36 39
37 40 cmdtable = {
38 41 "nohelp": (nohelp, [], "hg nohelp"),
39 42 }
40 43
41 44 commands.norepo += ' nohelp'
42 45 EOF
43 46 abspath=`pwd`/helpext.py
44 47
45 48 echo '[extensions]' >> $HGRCPATH
46 49 echo "helpext = $abspath" >> $HGRCPATH
47 50
48 51 echo %% test command with no help text
49 52 hg help nohelp
50 53
51 54 echo %% test that default list of commands omits extension commands
52 55 hg help
53 56
54 57 echo %% test list of commands with command with no help text
55 58 hg help helpext
56 59
57 60 echo %% test a help topic
58 61 hg help revs
59 62
60 63 exit 0
@@ -1,582 +1,633 b''
1 1 Mercurial Distributed SCM
2 2
3 3 basic commands:
4 4
5 5 add add the specified files on the next commit
6 6 annotate show changeset information by line for each file
7 7 clone make a copy of an existing repository
8 8 commit commit the specified files or all outstanding changes
9 9 diff diff repository (or selected files)
10 10 export dump the header and diffs for one or more changesets
11 11 forget forget the specified files on the next commit
12 12 init create a new repository in the given directory
13 13 log show revision history of entire repository or files
14 14 merge merge working directory with another revision
15 15 pull pull changes from the specified source
16 16 push push changes to the specified destination
17 17 remove remove the specified files on the next commit
18 18 serve export the repository via HTTP
19 19 status show changed files in the working directory
20 20 summary summarize working directory state
21 21 update update working directory
22 22
23 23 use "hg help" for the full list of commands or "hg -v" for details
24 24 add add the specified files on the next commit
25 25 annotate show changeset information by line for each file
26 26 clone make a copy of an existing repository
27 27 commit commit the specified files or all outstanding changes
28 28 diff diff repository (or selected files)
29 29 export dump the header and diffs for one or more changesets
30 30 forget forget the specified files on the next commit
31 31 init create a new repository in the given directory
32 32 log show revision history of entire repository or files
33 33 merge merge working directory with another revision
34 34 pull pull changes from the specified source
35 35 push push changes to the specified destination
36 36 remove remove the specified files on the next commit
37 37 serve export the repository via HTTP
38 38 status show changed files in the working directory
39 39 summary summarize working directory state
40 40 update update working directory
41 41 Mercurial Distributed SCM
42 42
43 43 list of commands:
44 44
45 45 add add the specified files on the next commit
46 46 addremove add all new files, delete all missing files
47 47 annotate show changeset information by line for each file
48 48 archive create an unversioned archive of a repository revision
49 49 backout reverse effect of earlier changeset
50 50 bisect subdivision search of changesets
51 51 branch set or show the current branch name
52 52 branches list repository named branches
53 53 bundle create a changegroup file
54 54 cat output the current or given revision of files
55 55 clone make a copy of an existing repository
56 56 commit commit the specified files or all outstanding changes
57 57 copy mark files as copied for the next commit
58 58 diff diff repository (or selected files)
59 59 export dump the header and diffs for one or more changesets
60 60 forget forget the specified files on the next commit
61 61 grep search for a pattern in specified files and revisions
62 62 heads show current repository heads or show branch heads
63 63 help show help for a given topic or a help overview
64 64 identify identify the working copy or specified revision
65 65 import import an ordered set of patches
66 66 incoming show new changesets found in source
67 67 init create a new repository in the given directory
68 68 locate locate files matching specific patterns
69 69 log show revision history of entire repository or files
70 70 manifest output the current or given revision of the project manifest
71 71 merge merge working directory with another revision
72 72 outgoing show changesets not found in the destination
73 73 parents show the parents of the working directory or revision
74 74 paths show aliases for remote repositories
75 75 pull pull changes from the specified source
76 76 push push changes to the specified destination
77 77 recover roll back an interrupted transaction
78 78 remove remove the specified files on the next commit
79 79 rename rename files; equivalent of copy + remove
80 80 resolve retry file merges from a merge or update
81 81 revert restore individual files or directories to an earlier state
82 82 rollback roll back the last transaction
83 83 root print the root (top) of the current working directory
84 84 serve export the repository via HTTP
85 85 showconfig show combined config settings from all hgrc files
86 86 status show changed files in the working directory
87 87 summary summarize working directory state
88 88 tag add one or more tags for the current or given revision
89 89 tags list repository tags
90 90 tip show the tip revision
91 91 unbundle apply one or more changegroup files
92 92 update update working directory
93 93 verify verify the integrity of the repository
94 94 version output version and copyright information
95 95
96 96 additional help topics:
97 97
98 98 config Configuration Files
99 99 dates Date Formats
100 100 patterns File Name Patterns
101 101 environment Environment Variables
102 102 revisions Specifying Single Revisions
103 103 multirevs Specifying Multiple Revisions
104 104 diffs Diff Formats
105 105 templating Template Usage
106 106 urls URL Paths
107 107 extensions Using additional features
108 108
109 109 use "hg -v help" to show aliases and global options
110 110 add add the specified files on the next commit
111 111 addremove add all new files, delete all missing files
112 112 annotate show changeset information by line for each file
113 113 archive create an unversioned archive of a repository revision
114 114 backout reverse effect of earlier changeset
115 115 bisect subdivision search of changesets
116 116 branch set or show the current branch name
117 117 branches list repository named branches
118 118 bundle create a changegroup file
119 119 cat output the current or given revision of files
120 120 clone make a copy of an existing repository
121 121 commit commit the specified files or all outstanding changes
122 122 copy mark files as copied for the next commit
123 123 diff diff repository (or selected files)
124 124 export dump the header and diffs for one or more changesets
125 125 forget forget the specified files on the next commit
126 126 grep search for a pattern in specified files and revisions
127 127 heads show current repository heads or show branch heads
128 128 help show help for a given topic or a help overview
129 129 identify identify the working copy or specified revision
130 130 import import an ordered set of patches
131 131 incoming show new changesets found in source
132 132 init create a new repository in the given directory
133 133 locate locate files matching specific patterns
134 134 log show revision history of entire repository or files
135 135 manifest output the current or given revision of the project manifest
136 136 merge merge working directory with another revision
137 137 outgoing show changesets not found in the destination
138 138 parents show the parents of the working directory or revision
139 139 paths show aliases for remote repositories
140 140 pull pull changes from the specified source
141 141 push push changes to the specified destination
142 142 recover roll back an interrupted transaction
143 143 remove remove the specified files on the next commit
144 144 rename rename files; equivalent of copy + remove
145 145 resolve retry file merges from a merge or update
146 146 revert restore individual files or directories to an earlier state
147 147 rollback roll back the last transaction
148 148 root print the root (top) of the current working directory
149 149 serve export the repository via HTTP
150 150 showconfig show combined config settings from all hgrc files
151 151 status show changed files in the working directory
152 152 summary summarize working directory state
153 153 tag add one or more tags for the current or given revision
154 154 tags list repository tags
155 155 tip show the tip revision
156 156 unbundle apply one or more changegroup files
157 157 update update working directory
158 158 verify verify the integrity of the repository
159 159 version output version and copyright information
160 160
161 161 additional help topics:
162 162
163 163 config Configuration Files
164 164 dates Date Formats
165 165 patterns File Name Patterns
166 166 environment Environment Variables
167 167 revisions Specifying Single Revisions
168 168 multirevs Specifying Multiple Revisions
169 169 diffs Diff Formats
170 170 templating Template Usage
171 171 urls URL Paths
172 172 extensions Using additional features
173 173 %% test short command list with verbose option
174 174 Mercurial Distributed SCM (version xxx)
175 175
176 176 Copyright (C) 2005-2010 Matt Mackall <mpm@selenic.com> and others
177 177 This is free software; see the source for copying conditions. There is NO
178 178 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
179 179
180 180 basic commands:
181 181
182 182 add:
183 183 add the specified files on the next commit
184 184 annotate, blame:
185 185 show changeset information by line for each file
186 186 clone:
187 187 make a copy of an existing repository
188 188 commit, ci:
189 189 commit the specified files or all outstanding changes
190 190 diff:
191 191 diff repository (or selected files)
192 192 export:
193 193 dump the header and diffs for one or more changesets
194 194 forget:
195 195 forget the specified files on the next commit
196 196 init:
197 197 create a new repository in the given directory
198 198 log, history:
199 199 show revision history of entire repository or files
200 200 merge:
201 201 merge working directory with another revision
202 202 pull:
203 203 pull changes from the specified source
204 204 push:
205 205 push changes to the specified destination
206 206 remove, rm:
207 207 remove the specified files on the next commit
208 208 serve:
209 209 export the repository via HTTP
210 210 status, st:
211 211 show changed files in the working directory
212 212 summary, sum:
213 213 summarize working directory state
214 214 update, up, checkout, co:
215 215 update working directory
216 216
217 217 global options:
218 218 -R --repository repository root directory or name of overlay bundle file
219 219 --cwd change working directory
220 220 -y --noninteractive do not prompt, assume 'yes' for any required answers
221 221 -q --quiet suppress output
222 222 -v --verbose enable additional output
223 223 --config set/override config option
224 224 --debug enable debugging output
225 225 --debugger start debugger
226 226 --encoding set the charset encoding (default: ascii)
227 227 --encodingmode set the charset encoding mode (default: strict)
228 228 --traceback always print a traceback on exception
229 229 --time time how long the command takes
230 230 --profile print command execution profile
231 231 --version output version information and exit
232 232 -h --help display help and exit
233 233
234 234 use "hg help" for the full list of commands
235 235 hg add [OPTION]... [FILE]...
236 236
237 237 add the specified files on the next commit
238 238
239 239 Schedule files to be version controlled and added to the repository.
240 240
241 241 The files will be added to the repository at the next commit. To undo an
242 242 add before that, see hg forget.
243 243
244 244 If no names are given, add all files to the repository.
245 245
246 use "hg -v help add" to show verbose help
247
246 248 options:
247 249
248 250 -I --include include names matching the given patterns
249 251 -X --exclude exclude names matching the given patterns
250 252 -n --dry-run do not perform actions, just print output
251 253
252 254 use "hg -v help add" to show global options
255 %% verbose help for add
256 hg add [OPTION]... [FILE]...
257
258 add the specified files on the next commit
259
260 Schedule files to be version controlled and added to the repository.
261
262 The files will be added to the repository at the next commit. To undo an
263 add before that, see hg forget.
264
265 If no names are given, add all files to the repository.
266
267 An example showing how new (unknown) files are added automatically by "hg
268 add":
269
270 $ ls
271 foo.c
272 $ hg status
273 ? foo.c
274 $ hg add
275 adding foo.c
276 $ hg status
277
278 options:
279
280 -I --include include names matching the given patterns
281 -X --exclude exclude names matching the given patterns
282 -n --dry-run do not perform actions, just print output
283
284 global options:
285 -R --repository repository root directory or name of overlay bundle file
286 --cwd change working directory
287 -y --noninteractive do not prompt, assume 'yes' for any required answers
288 -q --quiet suppress output
289 -v --verbose enable additional output
290 --config set/override config option
291 --debug enable debugging output
292 --debugger start debugger
293 --encoding set the charset encoding (default: ascii)
294 --encodingmode set the charset encoding mode (default: strict)
295 --traceback always print a traceback on exception
296 --time time how long the command takes
297 --profile print command execution profile
298 --version output version information and exit
299 -h --help display help and exit
253 300 %% test help option with version option
254 301 Mercurial Distributed SCM (version xxx)
255 302
256 303 Copyright (C) 2005-2010 Matt Mackall <mpm@selenic.com> and others
257 304 This is free software; see the source for copying conditions. There is NO
258 305 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
259 306
260 307 hg add [OPTION]... [FILE]...
261 308
262 309 add the specified files on the next commit
263 310
264 311 Schedule files to be version controlled and added to the repository.
265 312
266 313 The files will be added to the repository at the next commit. To undo an
267 314 add before that, see hg forget.
268 315
269 316 If no names are given, add all files to the repository.
270 317
318 use "hg -v help add" to show verbose help
319
271 320 options:
272 321
273 322 -I --include include names matching the given patterns
274 323 -X --exclude exclude names matching the given patterns
275 324 -n --dry-run do not perform actions, just print output
276 325
277 326 use "hg -v help add" to show global options
278 327 hg add: option --skjdfks not recognized
279 328 hg add [OPTION]... [FILE]...
280 329
281 330 add the specified files on the next commit
282 331
283 332 Schedule files to be version controlled and added to the repository.
284 333
285 334 The files will be added to the repository at the next commit. To undo an
286 335 add before that, see hg forget.
287 336
288 337 If no names are given, add all files to the repository.
289 338
339 use "hg -v help add" to show verbose help
340
290 341 options:
291 342
292 343 -I --include include names matching the given patterns
293 344 -X --exclude exclude names matching the given patterns
294 345 -n --dry-run do not perform actions, just print output
295 346
296 347 use "hg -v help add" to show global options
297 348 %% test ambiguous command help
298 349 list of commands:
299 350
300 351 add add the specified files on the next commit
301 352 addremove add all new files, delete all missing files
302 353
303 354 use "hg -v help ad" to show aliases and global options
304 355 %% test command without options
305 356 hg verify
306 357
307 358 verify the integrity of the repository
308 359
309 360 Verify the integrity of the current repository.
310 361
311 362 This will perform an extensive check of the repository's integrity,
312 363 validating the hashes and checksums of each entry in the changelog,
313 364 manifest, and tracked files, as well as the integrity of their crosslinks
314 365 and indices.
315 366
316 367 use "hg -v help verify" to show global options
317 368 hg diff [OPTION]... [-r REV1 [-r REV2]] [FILE]...
318 369
319 370 diff repository (or selected files)
320 371
321 372 Show differences between revisions for the specified files.
322 373
323 374 Differences between files are shown using the unified diff format.
324 375
325 376 NOTE: diff may generate unexpected results for merges, as it will default
326 377 to comparing against the working directory's first parent changeset if no
327 378 revisions are specified.
328 379
329 380 When two revision arguments are given, then changes are shown between
330 381 those revisions. If only one revision is specified then that revision is
331 382 compared to the working directory, and, when no revisions are specified,
332 383 the working directory files are compared to its parent.
333 384
334 385 Without the -a/--text option, diff will avoid generating diffs of files it
335 386 detects as binary. With -a, diff will generate a diff anyway, probably
336 387 with undesirable results.
337 388
338 389 Use the -g/--git option to generate diffs in the git extended diff format.
339 390 For more information, read 'hg help diffs'.
340 391
341 392 options:
342 393
343 394 -r --rev revision
344 395 -c --change change made by revision
345 396 -a --text treat all files as text
346 397 -g --git use git extended diff format
347 398 --nodates omit dates from diff headers
348 399 -p --show-function show which function each change is in
349 400 --reverse produce a diff that undoes the changes
350 401 -w --ignore-all-space ignore white space when comparing lines
351 402 -b --ignore-space-change ignore changes in the amount of white space
352 403 -B --ignore-blank-lines ignore changes whose lines are all blank
353 404 -U --unified number of lines of context to show
354 405 --stat output diffstat-style summary of changes
355 406 -I --include include names matching the given patterns
356 407 -X --exclude exclude names matching the given patterns
357 408
358 409 use "hg -v help diff" to show global options
359 410 hg status [OPTION]... [FILE]...
360 411
361 412 aliases: st
362 413
363 414 show changed files in the working directory
364 415
365 416 Show status of files in the repository. If names are given, only files
366 417 that match are shown. Files that are clean or ignored or the source of a
367 418 copy/move operation, are not listed unless -c/--clean, -i/--ignored,
368 419 -C/--copies or -A/--all are given. Unless options described with "show
369 420 only ..." are given, the options -mardu are used.
370 421
371 422 Option -q/--quiet hides untracked (unknown and ignored) files unless
372 423 explicitly requested with -u/--unknown or -i/--ignored.
373 424
374 425 NOTE: status may appear to disagree with diff if permissions have changed
375 426 or a merge has occurred. The standard diff format does not report
376 427 permission changes and diff only reports changes relative to one merge
377 428 parent.
378 429
379 430 If one revision is given, it is used as the base revision. If two
380 431 revisions are given, the differences between them are shown. The --change
381 432 option can also be used as a shortcut to list the changed files of a
382 433 revision from its first parent.
383 434
384 435 The codes used to show the status of files are:
385 436
386 437 M = modified
387 438 A = added
388 439 R = removed
389 440 C = clean
390 441 ! = missing (deleted by non-hg command, but still tracked)
391 442 ? = not tracked
392 443 I = ignored
393 444 = origin of the previous file listed as A (added)
394 445
395 446 options:
396 447
397 448 -A --all show status of all files
398 449 -m --modified show only modified files
399 450 -a --added show only added files
400 451 -r --removed show only removed files
401 452 -d --deleted show only deleted (but tracked) files
402 453 -c --clean show only files without changes
403 454 -u --unknown show only unknown (not tracked) files
404 455 -i --ignored show only ignored files
405 456 -n --no-status hide status prefix
406 457 -C --copies show source of copied files
407 458 -0 --print0 end filenames with NUL, for use with xargs
408 459 --rev show difference from revision
409 460 --change list the changed files of a revision
410 461 -I --include include names matching the given patterns
411 462 -X --exclude exclude names matching the given patterns
412 463
413 464 use "hg -v help status" to show global options
414 465 hg status [OPTION]... [FILE]...
415 466
416 467 show changed files in the working directory
417 468 hg: unknown command 'foo'
418 469 Mercurial Distributed SCM
419 470
420 471 basic commands:
421 472
422 473 add add the specified files on the next commit
423 474 annotate show changeset information by line for each file
424 475 clone make a copy of an existing repository
425 476 commit commit the specified files or all outstanding changes
426 477 diff diff repository (or selected files)
427 478 export dump the header and diffs for one or more changesets
428 479 forget forget the specified files on the next commit
429 480 init create a new repository in the given directory
430 481 log show revision history of entire repository or files
431 482 merge merge working directory with another revision
432 483 pull pull changes from the specified source
433 484 push push changes to the specified destination
434 485 remove remove the specified files on the next commit
435 486 serve export the repository via HTTP
436 487 status show changed files in the working directory
437 488 summary summarize working directory state
438 489 update update working directory
439 490
440 491 use "hg help" for the full list of commands or "hg -v" for details
441 492 hg: unknown command 'skjdfks'
442 493 Mercurial Distributed SCM
443 494
444 495 basic commands:
445 496
446 497 add add the specified files on the next commit
447 498 annotate show changeset information by line for each file
448 499 clone make a copy of an existing repository
449 500 commit commit the specified files or all outstanding changes
450 501 diff diff repository (or selected files)
451 502 export dump the header and diffs for one or more changesets
452 503 forget forget the specified files on the next commit
453 504 init create a new repository in the given directory
454 505 log show revision history of entire repository or files
455 506 merge merge working directory with another revision
456 507 pull pull changes from the specified source
457 508 push push changes to the specified destination
458 509 remove remove the specified files on the next commit
459 510 serve export the repository via HTTP
460 511 status show changed files in the working directory
461 512 summary summarize working directory state
462 513 update update working directory
463 514
464 515 use "hg help" for the full list of commands or "hg -v" for details
465 516 %% test command with no help text
466 517 hg nohelp
467 518
468 519 (no help text available)
469 520
470 521 use "hg -v help nohelp" to show global options
471 522 %% test that default list of commands omits extension commands
472 523 Mercurial Distributed SCM
473 524
474 525 list of commands:
475 526
476 527 add add the specified files on the next commit
477 528 addremove add all new files, delete all missing files
478 529 annotate show changeset information by line for each file
479 530 archive create an unversioned archive of a repository revision
480 531 backout reverse effect of earlier changeset
481 532 bisect subdivision search of changesets
482 533 branch set or show the current branch name
483 534 branches list repository named branches
484 535 bundle create a changegroup file
485 536 cat output the current or given revision of files
486 537 clone make a copy of an existing repository
487 538 commit commit the specified files or all outstanding changes
488 539 copy mark files as copied for the next commit
489 540 diff diff repository (or selected files)
490 541 export dump the header and diffs for one or more changesets
491 542 forget forget the specified files on the next commit
492 543 grep search for a pattern in specified files and revisions
493 544 heads show current repository heads or show branch heads
494 545 help show help for a given topic or a help overview
495 546 identify identify the working copy or specified revision
496 547 import import an ordered set of patches
497 548 incoming show new changesets found in source
498 549 init create a new repository in the given directory
499 550 locate locate files matching specific patterns
500 551 log show revision history of entire repository or files
501 552 manifest output the current or given revision of the project manifest
502 553 merge merge working directory with another revision
503 554 outgoing show changesets not found in the destination
504 555 parents show the parents of the working directory or revision
505 556 paths show aliases for remote repositories
506 557 pull pull changes from the specified source
507 558 push push changes to the specified destination
508 559 recover roll back an interrupted transaction
509 560 remove remove the specified files on the next commit
510 561 rename rename files; equivalent of copy + remove
511 562 resolve retry file merges from a merge or update
512 563 revert restore individual files or directories to an earlier state
513 564 rollback roll back the last transaction
514 565 root print the root (top) of the current working directory
515 566 serve export the repository via HTTP
516 567 showconfig show combined config settings from all hgrc files
517 568 status show changed files in the working directory
518 569 summary summarize working directory state
519 570 tag add one or more tags for the current or given revision
520 571 tags list repository tags
521 572 tip show the tip revision
522 573 unbundle apply one or more changegroup files
523 574 update update working directory
524 575 verify verify the integrity of the repository
525 576 version output version and copyright information
526 577
527 578 enabled extensions:
528 579
529 580 helpext (no help text available)
530 581
531 582 additional help topics:
532 583
533 584 config Configuration Files
534 585 dates Date Formats
535 586 patterns File Name Patterns
536 587 environment Environment Variables
537 588 revisions Specifying Single Revisions
538 589 multirevs Specifying Multiple Revisions
539 590 diffs Diff Formats
540 591 templating Template Usage
541 592 urls URL Paths
542 593 extensions Using additional features
543 594
544 595 use "hg -v help" to show aliases and global options
545 596 %% test list of commands with command with no help text
546 597 helpext extension - no help text available
547 598
548 599 list of commands:
549 600
550 601 nohelp (no help text available)
551 602
552 603 use "hg -v help helpext" to show aliases and global options
553 604 %% test a help topic
554 605 Specifying Single Revisions
555 606
556 607 Mercurial supports several ways to specify individual revisions.
557 608
558 609 A plain integer is treated as a revision number. Negative integers are
559 610 treated as sequential offsets from the tip, with -1 denoting the tip, -2
560 611 denoting the revision prior to the tip, and so forth.
561 612
562 613 A 40-digit hexadecimal string is treated as a unique revision identifier.
563 614
564 615 A hexadecimal string less than 40 characters long is treated as a unique
565 616 revision identifier and is referred to as a short-form identifier. A
566 617 short-form identifier is only valid if it is the prefix of exactly one
567 618 full-length identifier.
568 619
569 620 Any other string is treated as a tag or branch name. A tag name is a
570 621 symbolic name associated with a revision identifier. A branch name denotes
571 622 the tipmost revision of that branch. Tag and branch names must not contain
572 623 the ":" character.
573 624
574 625 The reserved name "tip" is a special tag that always identifies the most
575 626 recent revision.
576 627
577 628 The reserved name "null" indicates the null revision. This is the revision
578 629 of an empty repository, and the parent of revision 0.
579 630
580 631 The reserved name "." indicates the working directory parent. If no
581 632 working directory is checked out, it is equivalent to null. If an
582 633 uncommitted merge is in progress, "." is the revision of the first parent.
General Comments 0
You need to be logged in to leave comments. Login now