Mercurial > hg-stable
comparison mercurial/commands.py @ 946:6d21a3488df9
Merge with MPM.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Thu, 18 Aug 2005 17:49:43 -0800 |
parents | f15901d053e1 e8e5db72ed51 |
children | ffb0665028f0 |
comparison
equal
deleted
inserted
replaced
945:f15901d053e1 | 946:6d21a3488df9 |
---|---|
40 opts.get('exclude'), head) | 40 opts.get('exclude'), head) |
41 | 41 |
42 def makewalk(repo, pats, opts, head = ''): | 42 def makewalk(repo, pats, opts, head = ''): |
43 cwd = repo.getcwd() | 43 cwd = repo.getcwd() |
44 files, matchfn = matchpats(repo, cwd, pats, opts, head) | 44 files, matchfn = matchpats(repo, cwd, pats, opts, head) |
45 exact = dict(zip(files, files)) | |
45 def walk(): | 46 def walk(): |
46 for src, fn in repo.walk(files = files, match = matchfn): | 47 for src, fn in repo.walk(files = files, match = matchfn): |
47 yield src, fn, util.pathto(cwd, fn) | 48 yield src, fn, util.pathto(cwd, fn), fn in exact |
48 return files, matchfn, walk() | 49 return files, matchfn, walk() |
49 | 50 |
50 def walk(repo, pats, opts, head = ''): | 51 def walk(repo, pats, opts, head = ''): |
51 files, matchfn, results = makewalk(repo, pats, opts, head) | 52 files, matchfn, results = makewalk(repo, pats, opts, head) |
52 for r in results: yield r | 53 for r in results: yield r |
373 # Commands start here, listed alphabetically | 374 # Commands start here, listed alphabetically |
374 | 375 |
375 def add(ui, repo, *pats, **opts): | 376 def add(ui, repo, *pats, **opts): |
376 '''add the specified files on the next commit''' | 377 '''add the specified files on the next commit''' |
377 names = [] | 378 names = [] |
378 q = dict(zip(pats, pats)) | 379 for src, abs, rel, exact in walk(repo, pats, opts): |
379 for src, abs, rel in walk(repo, pats, opts): | 380 if exact: |
380 if rel in q or abs in q: | |
381 names.append(abs) | 381 names.append(abs) |
382 elif repo.dirstate.state(abs) == '?': | 382 elif repo.dirstate.state(abs) == '?': |
383 ui.status('adding %s\n' % rel) | 383 ui.status('adding %s\n' % rel) |
384 names.append(abs) | 384 names.append(abs) |
385 repo.add(names) | 385 repo.add(names) |
386 | 386 |
387 def addremove(ui, repo, *pats, **opts): | 387 def addremove(ui, repo, *pats, **opts): |
388 """add all new files, delete all missing files""" | 388 """add all new files, delete all missing files""" |
389 q = dict(zip(pats, pats)) | |
390 add, remove = [], [] | 389 add, remove = [], [] |
391 for src, abs, rel in walk(repo, pats, opts): | 390 for src, abs, rel, exact in walk(repo, pats, opts): |
392 if src == 'f' and repo.dirstate.state(abs) == '?': | 391 if src == 'f' and repo.dirstate.state(abs) == '?': |
393 add.append(abs) | 392 add.append(abs) |
394 if rel not in q: ui.status('adding ', rel, '\n') | 393 if not exact: ui.status('adding ', rel, '\n') |
395 if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): | 394 if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): |
396 remove.append(abs) | 395 remove.append(abs) |
397 if rel not in q: ui.status('removing ', rel, '\n') | 396 if not exact: ui.status('removing ', rel, '\n') |
398 repo.add(add) | 397 repo.add(add) |
399 repo.remove(remove) | 398 repo.remove(remove) |
400 | 399 |
401 def annotate(ui, repo, *pats, **opts): | 400 def annotate(ui, repo, *pats, **opts): |
402 """show changeset information per file line""" | 401 """show changeset information per file line""" |
430 node = repo.changelog.lookup(opts['rev']) | 429 node = repo.changelog.lookup(opts['rev']) |
431 else: | 430 else: |
432 node = repo.dirstate.parents()[0] | 431 node = repo.dirstate.parents()[0] |
433 change = repo.changelog.read(node) | 432 change = repo.changelog.read(node) |
434 mmap = repo.manifest.read(change[0]) | 433 mmap = repo.manifest.read(change[0]) |
435 for src, abs, rel in walk(repo, pats, opts): | 434 for src, abs, rel, exact in walk(repo, pats, opts): |
436 if abs not in mmap: | 435 if abs not in mmap: |
437 ui.warn("warning: %s is not in the repository!\n" % rel) | 436 ui.warn("warning: %s is not in the repository!\n" % rel) |
438 continue | 437 continue |
439 | 438 |
440 lines = repo.file(abs).annotate(mmap[abs]) | 439 lines = repo.file(abs).annotate(mmap[abs]) |
627 ui.write("}\n") | 626 ui.write("}\n") |
628 | 627 |
629 def debugwalk(ui, repo, *pats, **opts): | 628 def debugwalk(ui, repo, *pats, **opts): |
630 items = list(walk(repo, pats, opts)) | 629 items = list(walk(repo, pats, opts)) |
631 if not items: return | 630 if not items: return |
632 fmt = '%%s %%-%ds %%s' % max([len(abs) for (src, abs, rel) in items]) | 631 fmt = '%%s %%-%ds %%-%ds %%s' % ( |
633 for i in items: print fmt % i | 632 max([len(abs) for (src, abs, rel, exact) in items]), |
633 max([len(rel) for (src, abs, rel, exact) in items])) | |
634 exactly = {True: 'exact', False: ''} | |
635 for src, abs, rel, exact in items: | |
636 print fmt % (src, abs, rel, exactly[exact]) | |
634 | 637 |
635 def diff(ui, repo, *pats, **opts): | 638 def diff(ui, repo, *pats, **opts): |
636 """diff working directory (or selected files)""" | 639 """diff working directory (or selected files)""" |
637 revs = [] | 640 revs = [] |
638 if opts['rev']: | 641 if opts['rev']: |
643 | 646 |
644 files = [] | 647 files = [] |
645 match = util.always | 648 match = util.always |
646 if pats: | 649 if pats: |
647 roots, match, results = makewalk(repo, pats, opts) | 650 roots, match, results = makewalk(repo, pats, opts) |
648 for src, abs, rel in results: | 651 for src, abs, rel, exact in results: |
649 files.append(abs) | 652 files.append(abs) |
650 dodiff(sys.stdout, ui, repo, files, *revs, **{'match': match}) | 653 dodiff(sys.stdout, ui, repo, files, *revs, **{'match': match}) |
651 | 654 |
652 def doexport(ui, repo, changeset, seqno, total, revwidth, opts): | 655 def doexport(ui, repo, changeset, seqno, total, revwidth, opts): |
653 node = repo.lookup(changeset) | 656 node = repo.lookup(changeset) |
685 seqno += 1 | 688 seqno += 1 |
686 doexport(ui, repo, cset, seqno, total, revwidth, opts) | 689 doexport(ui, repo, cset, seqno, total, revwidth, opts) |
687 | 690 |
688 def forget(ui, repo, *pats, **opts): | 691 def forget(ui, repo, *pats, **opts): |
689 """don't add the specified files on the next commit""" | 692 """don't add the specified files on the next commit""" |
690 q = dict(zip(pats, pats)) | |
691 forget = [] | 693 forget = [] |
692 for src, abs, rel in walk(repo, pats, opts): | 694 for src, abs, rel, exact in walk(repo, pats, opts): |
693 if repo.dirstate.state(abs) == 'a': | 695 if repo.dirstate.state(abs) == 'a': |
694 forget.append(abs) | 696 forget.append(abs) |
695 if rel not in q: ui.status('forgetting ', rel, '\n') | 697 if not exact: ui.status('forgetting ', rel, '\n') |
696 repo.forget(forget) | 698 repo.forget(forget) |
697 | 699 |
698 def heads(ui, repo, **opts): | 700 def heads(ui, repo, **opts): |
699 """show current repository heads""" | 701 """show current repository heads""" |
700 heads = repo.changelog.heads() | 702 heads = repo.changelog.heads() |
807 def locate(ui, repo, *pats, **opts): | 809 def locate(ui, repo, *pats, **opts): |
808 """locate files matching specific patterns""" | 810 """locate files matching specific patterns""" |
809 end = '\n' | 811 end = '\n' |
810 if opts['print0']: end = '\0' | 812 if opts['print0']: end = '\0' |
811 | 813 |
812 for src, abs, rel in walk(repo, pats, opts, '(?:.*/|)'): | 814 for src, abs, rel, exact in walk(repo, pats, opts, '(?:.*/|)'): |
813 if repo.dirstate.state(abs) == '?': continue | 815 if repo.dirstate.state(abs) == '?': continue |
814 if opts['fullpath']: | 816 if opts['fullpath']: |
815 ui.write(os.path.join(repo.root, abs), end) | 817 ui.write(os.path.join(repo.root, abs), end) |
816 else: | 818 else: |
817 ui.write(rel, end) | 819 ui.write(rel, end) |
1400 | 1402 |
1401 globalopts = [('v', 'verbose', None, 'verbose mode'), | 1403 globalopts = [('v', 'verbose', None, 'verbose mode'), |
1402 ('', 'debug', None, 'debug mode'), | 1404 ('', 'debug', None, 'debug mode'), |
1403 ('q', 'quiet', None, 'quiet mode'), | 1405 ('q', 'quiet', None, 'quiet mode'), |
1404 ('', 'profile', None, 'profile'), | 1406 ('', 'profile', None, 'profile'), |
1407 ('C', 'cwd', '', 'change working directory'), | |
1405 ('R', 'repository', "", 'repository root directory'), | 1408 ('R', 'repository', "", 'repository root directory'), |
1406 ('', 'traceback', None, 'print traceback on exception'), | 1409 ('', 'traceback', None, 'print traceback on exception'), |
1407 ('y', 'noninteractive', None, 'run non-interactively'), | 1410 ('y', 'noninteractive', None, 'run non-interactively'), |
1408 ('', 'version', None, 'output version information and exit'), | 1411 ('', 'version', None, 'output version information and exit'), |
1409 ('', 'time', None, 'time how long the command takes'), | 1412 ('', 'time', None, 'time how long the command takes'), |
1487 except UnknownCommand, inst: | 1490 except UnknownCommand, inst: |
1488 u = ui.ui() | 1491 u = ui.ui() |
1489 u.warn("hg: unknown command '%s'\n" % inst.args[0]) | 1492 u.warn("hg: unknown command '%s'\n" % inst.args[0]) |
1490 help_(u, 'shortlist') | 1493 help_(u, 'shortlist') |
1491 sys.exit(1) | 1494 sys.exit(1) |
1495 | |
1496 if options['cwd']: | |
1497 try: | |
1498 os.chdir(options['cwd']) | |
1499 except OSError, inst: | |
1500 u = ui.ui() | |
1501 u.warn('abort: %s: %s\n' % (options['cwd'], inst.strerror)) | |
1502 sys.exit(1) | |
1492 | 1503 |
1493 if options["time"]: | 1504 if options["time"]: |
1494 def get_times(): | 1505 def get_times(): |
1495 t = os.times() | 1506 t = os.times() |
1496 if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() | 1507 if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() |