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