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