##// 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 aliases: rm
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 root::
274 root::
257 Print the root directory of the current repository.
275 Print the root directory of the current repository.
258
276
@@ -733,6 +733,46 b' 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
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 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")
@@ -889,6 +929,10 b' table = {'
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'),
@@ -1065,7 +1065,8 b' class localrepository:'
1065 tr.close()
1065 tr.close()
1066 return
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 pl = self.dirstate.parents()
1070 pl = self.dirstate.parents()
1070 if not force and pl[1] != nullid:
1071 if not force and pl[1] != nullid:
1071 self.ui.warn("aborting: outstanding uncommitted merges\n")
1072 self.ui.warn("aborting: outstanding uncommitted merges\n")
@@ -1117,11 +1118,12 b' class localrepository:'
1117 # the file, then we need to remove it from the dirstate, to
1118 # the file, then we need to remove it from the dirstate, to
1118 # prevent the dirstate from listing the file when it is no
1119 # prevent the dirstate from listing the file when it is no
1119 # longer in the manifest.
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 self.dirstate.forget((f,))
1122 self.dirstate.forget((f,))
1122
1123
1123 # Compare manifests
1124 # Compare manifests
1124 for f, n in mw.iteritems():
1125 for f, n in mw.iteritems():
1126 if choose and not choose(f): continue
1125 if f in m2:
1127 if f in m2:
1126 s = 0
1128 s = 0
1127
1129
@@ -1194,6 +1196,7 b' class localrepository:'
1194 self.ui.debug("working dir created %s, keeping\n" % f)
1196 self.ui.debug("working dir created %s, keeping\n" % f)
1195
1197
1196 for f, n in m2.iteritems():
1198 for f, n in m2.iteritems():
1199 if choose and not choose(f): continue
1197 if f[0] == "/": continue
1200 if f[0] == "/": continue
1198 if not force and f in ma and n != ma[f]:
1201 if not force and f in ma and n != ma[f]:
1199 r = ""
1202 r = ""
@@ -1234,9 +1237,11 b' class localrepository:'
1234 # because any file that's different from either one of its
1237 # because any file that's different from either one of its
1235 # parents must be in the changeset
1238 # parents must be in the changeset
1236 mode = 'm'
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 # get the files we don't need to change
1246 # get the files we don't need to change
1242 files = get.keys()
1247 files = get.keys()
@@ -1251,7 +1256,8 b' class localrepository:'
1251 os.makedirs(os.path.dirname(self.wjoin(f)))
1256 os.makedirs(os.path.dirname(self.wjoin(f)))
1252 self.wfile(f, "w").write(t)
1257 self.wfile(f, "w").write(t)
1253 util.set_exec(self.wjoin(f), mf2[f])
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 # merge the tricky bits
1262 # merge the tricky bits
1257 files = merge.keys()
1263 files = merge.keys()
@@ -1261,7 +1267,8 b' class localrepository:'
1261 m, o, flag = merge[f]
1267 m, o, flag = merge[f]
1262 self.merge3(f, m, o)
1268 self.merge3(f, m, o)
1263 util.set_exec(self.wjoin(f), flag)
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 for f in remove:
1273 for f in remove:
1267 self.ui.note("removing %s\n" % f)
1274 self.ui.note("removing %s\n" % f)
@@ -1269,10 +1276,11 b' class localrepository:'
1269 # try removing directories that might now be empty
1276 # try removing directories that might now be empty
1270 try: os.removedirs(os.path.dirname(f))
1277 try: os.removedirs(os.path.dirname(f))
1271 except: pass
1278 except: pass
1272 if mode == 'n':
1279 if moddirstate:
1273 self.dirstate.forget(remove)
1280 if mode == 'n':
1274 else:
1281 self.dirstate.forget(remove)
1275 self.dirstate.update(remove, 'r')
1282 else:
1283 self.dirstate.update(remove, 'r')
1276
1284
1277 def merge3(self, fn, my, other):
1285 def merge3(self, fn, my, other):
1278 """perform a 3-way merge in the working directory"""
1286 """perform a 3-way merge in the working directory"""
@@ -24,6 +24,7 b' hg commands:'
24 rawcommit raw commit interface
24 rawcommit raw commit interface
25 recover roll back an interrupted transaction
25 recover roll back an interrupted transaction
26 remove remove the specified files on the next commit
26 remove remove the specified files on the next commit
27 revert revert modified files or dirs back to their unmodified states
27 root print the root (top) of the current working dir
28 root print the root (top) of the current working dir
28 serve export the repository via HTTP
29 serve export the repository via HTTP
29 status show changed files in the working directory
30 status show changed files in the working directory
@@ -75,6 +76,7 b' hg commands:'
75 rawcommit raw commit interface
76 rawcommit raw commit interface
76 recover roll back an interrupted transaction
77 recover roll back an interrupted transaction
77 remove remove the specified files on the next commit
78 remove remove the specified files on the next commit
79 revert revert modified files or dirs back to their unmodified states
78 root print the root (top) of the current working dir
80 root print the root (top) of the current working dir
79 serve export the repository via HTTP
81 serve export the repository via HTTP
80 status show changed files in the working directory
82 status show changed files in the working directory
General Comments 0
You need to be logged in to leave comments. Login now