##// END OF EJS Templates
small changes to revert command....
Vadim Gelfer -
r2042:a514c750 default
parent child Browse files
Show More
@@ -48,7 +48,7 b' def makewalk(repo, pats, opts, node=None'
48 48 exact = dict(zip(files, files))
49 49 def walk():
50 50 for src, fn in repo.walk(node=node, files=files, match=matchfn,
51 badmatch=None):
51 badmatch=badmatch):
52 52 yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact
53 53 return files, matchfn, walk()
54 54
@@ -2349,11 +2349,27 b' def revert(ui, repo, *pats, **opts):'
2349 2349
2350 2350 wlock = repo.wlock()
2351 2351
2352 entries = []
2352 # need all matching names in dirstate and manifest of target rev,
2353 # so have to walk both. do not print errors if files exist in one
2354 # but not other.
2355
2353 2356 names = {}
2357 target_only = {}
2358
2359 # walk dirstate.
2360
2354 2361 for src, abs, rel, exact in walk(repo, pats, opts, badmatch=mf.has_key):
2355 names[abs] = True
2356 entries.append((abs, rel, exact))
2362 names[abs] = (rel, exact)
2363 if src == 'b':
2364 target_only[abs] = True
2365
2366 # walk target manifest.
2367
2368 for src, abs, rel, exact in walk(repo, pats, opts, node=node,
2369 badmatch=names.has_key):
2370 if abs in names: continue
2371 names[abs] = (rel, exact)
2372 target_only[abs] = True
2357 2373
2358 2374 changes = repo.changes(match=names.has_key, wlock=wlock)
2359 2375 modified, added, removed, deleted, unknown = map(dict.fromkeys, changes)
@@ -2377,9 +2393,14 b' def revert(ui, repo, *pats, **opts):'
2377 2393 (removed, undelete, None, False, False),
2378 2394 (deleted, revert, remove, False, False),
2379 2395 (unknown, add, None, True, False),
2396 (target_only, add, None, False, False),
2380 2397 )
2381 2398
2382 for abs, rel, exact in entries:
2399 entries = names.items()
2400 entries.sort()
2401
2402 for abs, (rel, exact) in entries:
2403 in_mf = abs in mf
2383 2404 def handle(xlist, dobackup):
2384 2405 xlist[0].append(abs)
2385 2406 if dobackup and not opts['no_backup'] and os.path.exists(rel):
@@ -2393,7 +2414,7 b' def revert(ui, repo, *pats, **opts):'
2393 2414 for table, hitlist, misslist, backuphit, backupmiss in disptable:
2394 2415 if abs not in table: continue
2395 2416 # file has changed in dirstate
2396 if abs in mf:
2417 if in_mf:
2397 2418 handle(hitlist, backuphit)
2398 2419 elif misslist is not None:
2399 2420 handle(misslist, backupmiss)
@@ -2405,8 +2426,8 b' def revert(ui, repo, *pats, **opts):'
2405 2426 if node == parent:
2406 2427 if exact: ui.warn(_('no changes needed to %s\n' % rel))
2407 2428 continue
2408 if abs not in mf:
2409 remove[0].append(abs)
2429 if not in_mf:
2430 handle(remove, False)
2410 2431 update[abs] = True
2411 2432
2412 2433 repo.dirstate.forget(forget[0])
@@ -294,7 +294,8 b' class dirstate(object):'
294 294 kind))
295 295 return False
296 296
297 def statwalk(self, files=None, match=util.always, dc=None, ignored=False):
297 def statwalk(self, files=None, match=util.always, dc=None, ignored=False,
298 badmatch=None):
298 299 self.lazyread()
299 300
300 301 # walk all files by default
@@ -311,11 +312,12 b' class dirstate(object):'
311 312 return False
312 313 return match(file_)
313 314
314 return self.walkhelper(files=files, statmatch=statmatch, dc=dc)
315 return self.walkhelper(files=files, statmatch=statmatch, dc=dc,
316 badmatch=badmatch)
315 317
316 def walk(self, files=None, match=util.always, dc=None):
318 def walk(self, files=None, match=util.always, dc=None, badmatch=None):
317 319 # filter out the stat
318 for src, f, st in self.statwalk(files, match, dc):
320 for src, f, st in self.statwalk(files, match, dc, badmatch=badmatch):
319 321 yield src, f
320 322
321 323 # walk recursively through the directory tree, finding all files
@@ -330,7 +332,7 b' class dirstate(object):'
330 332 # dc is an optional arg for the current dirstate. dc is not modified
331 333 # directly by this function, but might be modified by your statmatch call.
332 334 #
333 def walkhelper(self, files, statmatch, dc):
335 def walkhelper(self, files, statmatch, dc, badmatch=None):
334 336 # recursion free walker, faster than os.walk.
335 337 def findfiles(s):
336 338 work = [s]
@@ -379,9 +381,12 b' class dirstate(object):'
379 381 found = True
380 382 break
381 383 if not found:
382 self.ui.warn('%s: %s\n' % (
383 util.pathto(self.getcwd(), ff),
384 inst.strerror))
384 if inst.errno != errno.ENOENT or not badmatch:
385 self.ui.warn('%s: %s\n' % (
386 util.pathto(self.getcwd(), ff),
387 inst.strerror))
388 elif badmatch and badmatch(ff) and statmatch(ff, None):
389 yield 'b', ff, None
385 390 continue
386 391 if stat.S_ISDIR(st.st_mode):
387 392 cmp1 = (lambda x, y: cmp(x[1], y[1]))
@@ -498,7 +498,7 b' class localrepository(object):'
498 498 self.ui.warn(_('%s: No such file in rev %s\n') % (
499 499 util.pathto(self.getcwd(), fn), short(node)))
500 500 else:
501 for src, fn in self.dirstate.walk(files, match):
501 for src, fn in self.dirstate.walk(files, match, badmatch=badmatch):
502 502 yield src, fn
503 503
504 504 def changes(self, node1=None, node2=None, files=[], match=util.always,
@@ -2,8 +2,8 b''
2 2 A b
3 3 R a
4 4 reverting...
5 undeleting a
5 6 forgetting b
6 undeleting a
7 7 %%% should show b unknown and a back to normal
8 8 ? b
9 9 ? b.orig
@@ -15,8 +15,8 b' A b'
15 15 R a
16 16 ? b.orig
17 17 reverting...
18 undeleting a
18 19 forgetting b
19 undeleting a
20 20 %%% should show b unknown and a marked modified (merged)
21 21 ? b
22 22 ? b.orig
@@ -37,7 +37,21 b' hg revert a'
37 37 echo %% should say file not managed
38 38 echo q > q
39 39 hg revert q
40 rm q
40 41 echo %% should say file not found
41 42 hg revert notfound
43 hg rm a
44 hg commit -m "second" -d "1000000 0"
45 echo z > z
46 hg add z
47 hg st
48 echo %% should add a, forget z
49 hg revert -r0
50 echo %% should forget a
51 hg revert -rtip
52 rm -f a *.orig
53 echo %% should silently add a
54 hg revert -r0 a
55 hg st a
42 56
43 57 true
@@ -1,5 +1,6 b''
1 1 %% Should show unknown
2 2 ? unknown
3 removing b
3 4 %% Should show unknown and b removed
4 5 R b
5 6 ? unknown
@@ -37,4 +37,15 b' no changes needed to a'
37 37 %% should say file not managed
38 38 file not managed: q
39 39 %% should say file not found
40 notfound: No such file or directory
40 notfound: No such file in rev 095eacd0c0d7
41 A z
42 ? b
43 ? b.orig
44 ? e.orig
45 %% should add a, forget z
46 adding a
47 forgetting z
48 %% should forget a
49 forgetting a
50 %% should silently add a
51 A a
General Comments 0
You need to be logged in to leave comments. Login now