##// END OF EJS Templates
[PATCH] hg revert...
mpm@selenic.com -
r588:0c3bae18 default
parent child Browse files
Show More
@@ -253,6 +253,24 b' remove [files ...]::'
253 253
254 254 aliases: rm
255 255
256 revert [names ...]::
257 Revert any uncommitted modifications made to the named files or
258 directories. This restores the contents of the affected files to
259 an unmodified state.
260
261 If a file has been deleted, it is recreated. If the executable
262 mode of a file was changed, it is reset.
263
264 If a directory is given, all files in that directory and its
265 subdirectories are reverted.
266
267 If no arguments are given, all files in the current directory and
268 its subdirectories are reverted.
269
270 options:
271 -r, --rev <rev> revision to revert to
272 -n, --nonrecursive do not recurse into subdirectories
273
256 274 root::
257 275 Print the root directory of the current repository.
258 276
@@ -733,6 +733,46 b' def remove(ui, repo, file, *files):'
733 733 """remove the specified files on the next commit"""
734 734 repo.remove(relpath(repo, (file,) + files))
735 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
775
736 776 def root(ui, repo):
737 777 """print the root (top) of the current working dir"""
738 778 ui.write(repo.root + "\n")
@@ -889,6 +929,10 b' table = {'
889 929 'hg rawcommit [options] [files]'),
890 930 "recover": (recover, [], "hg recover"),
891 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 936 "root": (root, [], "hg root"),
893 937 "serve": (serve, [('p', 'port', 8000, 'listen port'),
894 938 ('a', 'address', '', 'interface address'),
@@ -1065,7 +1065,8 b' class localrepository:'
1065 1065 tr.close()
1066 1066 return
1067 1067
1068 def update(self, node, allow=False, force=False):
1068 def update(self, node, allow=False, force=False, choose=None,
1069 moddirstate=True):
1069 1070 pl = self.dirstate.parents()
1070 1071 if not force and pl[1] != nullid:
1071 1072 self.ui.warn("aborting: outstanding uncommitted merges\n")
@@ -1117,11 +1118,12 b' class localrepository:'
1117 1118 # the file, then we need to remove it from the dirstate, to
1118 1119 # prevent the dirstate from listing the file when it is no
1119 1120 # longer in the manifest.
1120 if linear_path and f not in m2:
1121 if moddirstate and linear_path and f not in m2:
1121 1122 self.dirstate.forget((f,))
1122 1123
1123 1124 # Compare manifests
1124 1125 for f, n in mw.iteritems():
1126 if choose and not choose(f): continue
1125 1127 if f in m2:
1126 1128 s = 0
1127 1129
@@ -1194,6 +1196,7 b' class localrepository:'
1194 1196 self.ui.debug("working dir created %s, keeping\n" % f)
1195 1197
1196 1198 for f, n in m2.iteritems():
1199 if choose and not choose(f): continue
1197 1200 if f[0] == "/": continue
1198 1201 if not force and f in ma and n != ma[f]:
1199 1202 r = ""
@@ -1234,9 +1237,11 b' class localrepository:'
1234 1237 # because any file that's different from either one of its
1235 1238 # parents must be in the changeset
1236 1239 mode = 'm'
1237 self.dirstate.update(mark.keys(), "m")
1240 if moddirstate:
1241 self.dirstate.update(mark.keys(), "m")
1238 1242
1239 self.dirstate.setparents(p1, p2)
1243 if moddirstate:
1244 self.dirstate.setparents(p1, p2)
1240 1245
1241 1246 # get the files we don't need to change
1242 1247 files = get.keys()
@@ -1251,7 +1256,8 b' class localrepository:'
1251 1256 os.makedirs(os.path.dirname(self.wjoin(f)))
1252 1257 self.wfile(f, "w").write(t)
1253 1258 util.set_exec(self.wjoin(f), mf2[f])
1254 self.dirstate.update([f], mode)
1259 if moddirstate:
1260 self.dirstate.update([f], mode)
1255 1261
1256 1262 # merge the tricky bits
1257 1263 files = merge.keys()
@@ -1261,7 +1267,8 b' class localrepository:'
1261 1267 m, o, flag = merge[f]
1262 1268 self.merge3(f, m, o)
1263 1269 util.set_exec(self.wjoin(f), flag)
1264 self.dirstate.update([f], 'm')
1270 if moddirstate:
1271 self.dirstate.update([f], 'm')
1265 1272
1266 1273 for f in remove:
1267 1274 self.ui.note("removing %s\n" % f)
@@ -1269,10 +1276,11 b' class localrepository:'
1269 1276 # try removing directories that might now be empty
1270 1277 try: os.removedirs(os.path.dirname(f))
1271 1278 except: pass
1272 if mode == 'n':
1273 self.dirstate.forget(remove)
1274 else:
1275 self.dirstate.update(remove, 'r')
1279 if moddirstate:
1280 if mode == 'n':
1281 self.dirstate.forget(remove)
1282 else:
1283 self.dirstate.update(remove, 'r')
1276 1284
1277 1285 def merge3(self, fn, my, other):
1278 1286 """perform a 3-way merge in the working directory"""
@@ -24,6 +24,7 b' hg commands:'
24 24 rawcommit raw commit interface
25 25 recover roll back an interrupted transaction
26 26 remove remove the specified files on the next commit
27 revert revert modified files or dirs back to their unmodified states
27 28 root print the root (top) of the current working dir
28 29 serve export the repository via HTTP
29 30 status show changed files in the working directory
@@ -75,6 +76,7 b' hg commands:'
75 76 rawcommit raw commit interface
76 77 recover roll back an interrupted transaction
77 78 remove remove the specified files on the next commit
79 revert revert modified files or dirs back to their unmodified states
78 80 root print the root (top) of the current working dir
79 81 serve export the repository via HTTP
80 82 status show changed files in the working directory
General Comments 0
You need to be logged in to leave comments. Login now