comparison mercurial/commands.py @ 1472:3c909a747d7f

make revert use standard matcher
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Thu, 27 Oct 2005 13:31:12 -0700
parents fb9b84c91222
children d791c335fb7b
comparison
equal deleted inserted replaced
1471:f56f38a1a85f 1472:3c909a747d7f
1788 if ui.verbose or not exact: ui.status(_('removing %s\n') % rel) 1788 if ui.verbose or not exact: ui.status(_('removing %s\n') % rel)
1789 names.append(abs) 1789 names.append(abs)
1790 repo.remove(names, unlink=True) 1790 repo.remove(names, unlink=True)
1791 return errs 1791 return errs
1792 1792
1793 def revert(ui, repo, *names, **opts): 1793 def revert(ui, repo, *pats, **opts):
1794 """revert modified files or dirs back to their unmodified states 1794 """revert modified files or dirs back to their unmodified states
1795 1795
1796 Revert any uncommitted modifications made to the named files or 1796 Revert any uncommitted modifications made to the named files or
1797 directories. This restores the contents of the affected files to 1797 directories. This restores the contents of the affected files to
1798 an unmodified state. 1798 an unmodified state.
1799 1799
1800 If a file has been deleted, it is recreated. If the executable 1800 If a file has been deleted, it is recreated. If the executable
1801 mode of a file was changed, it is reset. 1801 mode of a file was changed, it is reset.
1802 1802
1803 If a directory is given, all files in that directory and its 1803 If names are given, all files matching the names are reverted.
1804 subdirectories are reverted. 1804
1805 1805 If no names are given, all files in the current directory and
1806 If no arguments are given, all files in the current directory and
1807 its subdirectories are reverted. 1806 its subdirectories are reverted.
1808 """ 1807 """
1809 node = opts['rev'] and repo.lookup(opts['rev']) or \ 1808 node = opts['rev'] and repo.lookup(opts['rev']) or \
1810 repo.dirstate.parents()[0] 1809 repo.dirstate.parents()[0]
1811 root = os.path.realpath(repo.root) 1810
1812 1811 files, choose, anypats = matchpats(repo, repo.getcwd(), pats, opts)
1813 def trimpath(p): 1812 (c, a, d, u) = repo.changes(match=choose)
1814 p = os.path.realpath(p) 1813 repo.forget(a)
1815 if p.startswith(root): 1814 repo.undelete(d)
1816 rest = p[len(root):] 1815
1817 if not rest: 1816 return repo.update(node, False, True, choose, False)
1818 return rest
1819 if p.startswith(os.sep):
1820 return rest[1:]
1821 return p
1822
1823 relnames = map(trimpath, names or [os.getcwd()])
1824 chosen = {}
1825
1826 def choose(name):
1827 def body(name):
1828 for r in relnames:
1829 if not name.startswith(r):
1830 continue
1831 rest = name[len(r):]
1832 if not rest:
1833 return r, True
1834 depth = rest.count(os.sep)
1835 if not r:
1836 if depth == 0 or not opts['nonrecursive']:
1837 return r, True
1838 elif rest[0] == os.sep:
1839 if depth == 1 or not opts['nonrecursive']:
1840 return r, True
1841 return None, False
1842 relname, ret = body(name)
1843 if ret:
1844 chosen[relname] = 1
1845 return ret
1846
1847 (c, a, d, u) = repo.changes()
1848 repo.forget(filter(choose, a))
1849 repo.undelete(filter(choose, d))
1850
1851 r = repo.update(node, False, True, choose, False)
1852 for n in relnames:
1853 if n not in chosen:
1854 ui.warn(_('error: no matches for %s\n') % n)
1855 r = 1
1856 sys.stdout.flush()
1857 return r
1858 1817
1859 def root(ui, repo): 1818 def root(ui, repo):
1860 """print the root (top) of the current working dir 1819 """print the root (top) of the current working dir
1861 1820
1862 Print the root directory of the current repository. 1821 Print the root directory of the current repository.
2346 ('A', 'after', None, _('record a rename that has already occurred')), 2305 ('A', 'after', None, _('record a rename that has already occurred')),
2347 ('f', 'force', None, _('forcibly copy over an existing managed file'))], 2306 ('f', 'force', None, _('forcibly copy over an existing managed file'))],
2348 _('hg rename [OPTION]... [SOURCE]... DEST')), 2307 _('hg rename [OPTION]... [SOURCE]... DEST')),
2349 "^revert": 2308 "^revert":
2350 (revert, 2309 (revert,
2351 [("n", "nonrecursive", None, _("do not recurse into subdirectories")), 2310 [('I', 'include', [], _('include names matching the given patterns')),
2311 ('X', 'exclude', [], _('exclude names matching the given patterns')),
2352 ("r", "rev", "", _("revision to revert to"))], 2312 ("r", "rev", "", _("revision to revert to"))],
2353 _("hg revert [-n] [-r REV] [NAME]...")), 2313 _("hg revert [-n] [-r REV] [NAME]...")),
2354 "root": (root, [], _("hg root")), 2314 "root": (root, [], _("hg root")),
2355 "^serve": 2315 "^serve":
2356 (serve, 2316 (serve,