46 def makewalk(repo, pats, opts, node=None, head='', badmatch=None): |
46 def makewalk(repo, pats, opts, node=None, head='', badmatch=None): |
47 files, matchfn, anypats = matchpats(repo, pats, opts, head) |
47 files, matchfn, anypats = matchpats(repo, pats, opts, head) |
48 exact = dict(zip(files, files)) |
48 exact = dict(zip(files, files)) |
49 def walk(): |
49 def walk(): |
50 for src, fn in repo.walk(node=node, files=files, match=matchfn, |
50 for src, fn in repo.walk(node=node, files=files, match=matchfn, |
51 badmatch=None): |
51 badmatch=badmatch): |
52 yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact |
52 yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact |
53 return files, matchfn, walk() |
53 return files, matchfn, walk() |
54 |
54 |
55 def walk(repo, pats, opts, node=None, head='', badmatch=None): |
55 def walk(repo, pats, opts, node=None, head='', badmatch=None): |
56 files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch) |
56 files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch) |
2347 node = opts['rev'] and repo.lookup(opts['rev']) or parent |
2347 node = opts['rev'] and repo.lookup(opts['rev']) or parent |
2348 mf = repo.manifest.read(repo.changelog.read(node)[0]) |
2348 mf = repo.manifest.read(repo.changelog.read(node)[0]) |
2349 |
2349 |
2350 wlock = repo.wlock() |
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 names = {} |
2356 names = {} |
|
2357 target_only = {} |
|
2358 |
|
2359 # walk dirstate. |
|
2360 |
2354 for src, abs, rel, exact in walk(repo, pats, opts, badmatch=mf.has_key): |
2361 for src, abs, rel, exact in walk(repo, pats, opts, badmatch=mf.has_key): |
2355 names[abs] = True |
2362 names[abs] = (rel, exact) |
2356 entries.append((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 changes = repo.changes(match=names.has_key, wlock=wlock) |
2374 changes = repo.changes(match=names.has_key, wlock=wlock) |
2359 modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) |
2375 modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) |
2360 |
2376 |
2361 revert = ([], _('reverting %s\n')) |
2377 revert = ([], _('reverting %s\n')) |
2375 (modified, revert, remove, True, True), |
2391 (modified, revert, remove, True, True), |
2376 (added, revert, forget, True, True), |
2392 (added, revert, forget, True, True), |
2377 (removed, undelete, None, False, False), |
2393 (removed, undelete, None, False, False), |
2378 (deleted, revert, remove, False, False), |
2394 (deleted, revert, remove, False, False), |
2379 (unknown, add, None, True, False), |
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 def handle(xlist, dobackup): |
2404 def handle(xlist, dobackup): |
2384 xlist[0].append(abs) |
2405 xlist[0].append(abs) |
2385 if dobackup and not opts['no_backup'] and os.path.exists(rel): |
2406 if dobackup and not opts['no_backup'] and os.path.exists(rel): |
2386 bakname = "%s.orig" % rel |
2407 bakname = "%s.orig" % rel |
2387 ui.note(_('saving current version of %s as %s\n') % |
2408 ui.note(_('saving current version of %s as %s\n') % |
2391 if ui.verbose or not exact: |
2412 if ui.verbose or not exact: |
2392 ui.status(xlist[1] % rel) |
2413 ui.status(xlist[1] % rel) |
2393 for table, hitlist, misslist, backuphit, backupmiss in disptable: |
2414 for table, hitlist, misslist, backuphit, backupmiss in disptable: |
2394 if abs not in table: continue |
2415 if abs not in table: continue |
2395 # file has changed in dirstate |
2416 # file has changed in dirstate |
2396 if abs in mf: |
2417 if in_mf: |
2397 handle(hitlist, backuphit) |
2418 handle(hitlist, backuphit) |
2398 elif misslist is not None: |
2419 elif misslist is not None: |
2399 handle(misslist, backupmiss) |
2420 handle(misslist, backupmiss) |
2400 else: |
2421 else: |
2401 if exact: ui.warn(_('file not managed: %s\n' % rel)) |
2422 if exact: ui.warn(_('file not managed: %s\n' % rel)) |
2403 else: |
2424 else: |
2404 # file has not changed in dirstate |
2425 # file has not changed in dirstate |
2405 if node == parent: |
2426 if node == parent: |
2406 if exact: ui.warn(_('no changes needed to %s\n' % rel)) |
2427 if exact: ui.warn(_('no changes needed to %s\n' % rel)) |
2407 continue |
2428 continue |
2408 if abs not in mf: |
2429 if not in_mf: |
2409 remove[0].append(abs) |
2430 handle(remove, False) |
2410 update[abs] = True |
2431 update[abs] = True |
2411 |
2432 |
2412 repo.dirstate.forget(forget[0]) |
2433 repo.dirstate.forget(forget[0]) |
2413 r = repo.update(node, False, True, update.has_key, False, wlock=wlock) |
2434 r = repo.update(node, False, True, update.has_key, False, wlock=wlock) |
2414 repo.dirstate.update(add[0], 'a') |
2435 repo.dirstate.update(add[0], 'a') |