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