730 repo.recover() |
730 repo.recover() |
731 |
731 |
732 def remove(ui, repo, file, *files): |
732 def remove(ui, repo, file, *files): |
733 """remove the specified files on the next commit""" |
733 """remove the specified files on the next commit""" |
734 repo.remove(relpath(repo, (file,) + files)) |
734 repo.remove(relpath(repo, (file,) + files)) |
|
735 |
|
736 def revert(ui, repo, *names, **opts): |
|
737 """revert modified files or dirs back to their unmodified states""" |
|
738 node = opts['rev'] and repo.lookup(opts['rev']) or repo.changelog.tip() |
|
739 root = os.path.realpath(repo.root) |
|
740 def trimpath(p): |
|
741 p = os.path.realpath(p) |
|
742 if p.startswith(root): |
|
743 rest = p[len(root):] |
|
744 if not rest: |
|
745 return rest |
|
746 if p.startswith(os.sep): |
|
747 return rest[1:] |
|
748 return p |
|
749 relnames = map(trimpath, names or [os.getcwd()]) |
|
750 chosen = {} |
|
751 def choose(name): |
|
752 def body(name): |
|
753 for r in relnames: |
|
754 if not name.startswith(r): continue |
|
755 rest = name[len(r):] |
|
756 if not rest: return r, True |
|
757 depth = rest.count(os.sep) |
|
758 if not r: |
|
759 if depth == 0 or not opts['nonrecursive']: return r, True |
|
760 elif rest[0] == os.sep: |
|
761 if depth == 1 or not opts['nonrecursive']: return r, True |
|
762 return None, False |
|
763 relname, ret = body(name) |
|
764 if ret: |
|
765 chosen[relname] = 1 |
|
766 return ret |
|
767 |
|
768 r = repo.update(node, False, True, choose, False) |
|
769 for n in relnames: |
|
770 if n not in chosen: |
|
771 ui.warn('error: no matches for %s\n' % n) |
|
772 r = 1 |
|
773 sys.stdout.flush() |
|
774 return r |
735 |
775 |
736 def root(ui, repo): |
776 def root(ui, repo): |
737 """print the root (top) of the current working dir""" |
777 """print the root (top) of the current working dir""" |
738 ui.write(repo.root + "\n") |
778 ui.write(repo.root + "\n") |
739 |
779 |
887 ('t', 'text', "", 'commit text'), |
927 ('t', 'text', "", 'commit text'), |
888 ('l', 'logfile', "", 'commit text file')], |
928 ('l', 'logfile', "", 'commit text file')], |
889 'hg rawcommit [options] [files]'), |
929 'hg rawcommit [options] [files]'), |
890 "recover": (recover, [], "hg recover"), |
930 "recover": (recover, [], "hg recover"), |
891 "remove|rm": (remove, [], "hg remove [files]"), |
931 "remove|rm": (remove, [], "hg remove [files]"), |
|
932 "revert": (revert, |
|
933 [("n", "nonrecursive", None, "don't recurse into subdirs"), |
|
934 ("r", "rev", "", "revision")], |
|
935 "hg revert [files|dirs]"), |
892 "root": (root, [], "hg root"), |
936 "root": (root, [], "hg root"), |
893 "serve": (serve, [('p', 'port', 8000, 'listen port'), |
937 "serve": (serve, [('p', 'port', 8000, 'listen port'), |
894 ('a', 'address', '', 'interface address'), |
938 ('a', 'address', '', 'interface address'), |
895 ('n', 'name', os.getcwd(), 'repository name'), |
939 ('n', 'name', os.getcwd(), 'repository name'), |
896 ('t', 'templates', "", 'template map')], |
940 ('t', 'templates', "", 'template map')], |