Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 22208:d3659b3795e9
revert: simplify handling of `added` files
There are multiple possible cases for added files. But it's all handled by magic
much lower in the stack. We document them, simplify the codes and move on.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Sat, 02 Aug 2014 11:32:24 -0700 |
parents | 9fa429723f26 |
children | 06fbd9518bc5 |
comparison
equal
deleted
inserted
replaced
22207:8dda6f6ff564 | 22208:d3659b3795e9 |
---|---|
2405 else: | 2405 else: |
2406 changes = repo.status(node1=parent, match=m) | 2406 changes = repo.status(node1=parent, match=m) |
2407 dsmodified = set(changes[0]) | 2407 dsmodified = set(changes[0]) |
2408 dsadded = set(changes[1]) | 2408 dsadded = set(changes[1]) |
2409 dsremoved = set(changes[2]) | 2409 dsremoved = set(changes[2]) |
2410 dsadded |= _deletedadded | |
2411 | 2410 |
2412 # only take into account for removes between wc and target | 2411 # only take into account for removes between wc and target |
2413 clean |= dsremoved - removed | 2412 clean |= dsremoved - removed |
2414 dsremoved &= removed | 2413 dsremoved &= removed |
2415 # distinct between dirstate remove and other | 2414 # distinct between dirstate remove and other |
2417 | 2416 |
2418 # tell newly modified apart. | 2417 # tell newly modified apart. |
2419 dsmodified &= modified | 2418 dsmodified &= modified |
2420 dsmodified |= modified & dsadded # dirstate added may needs backup | 2419 dsmodified |= modified & dsadded # dirstate added may needs backup |
2421 modified -= dsmodified | 2420 modified -= dsmodified |
2421 | |
2422 # There are three categories of added files | |
2423 # | |
2424 # 1. addition that just happened in the dirstate | |
2425 # (should be forgotten) | |
2426 # 2. file is added since target revision and has local changes | |
2427 # (should be backed up and removed) | |
2428 # 3. file is added since target revision and is clean | |
2429 # (should be removed) | |
2430 # | |
2431 # However we do not need to split them yet. The current revert code | |
2432 # will automatically recognize (1) when performing operation. And | |
2433 # the backup system is currently unabled to handle (2). | |
2434 # | |
2435 # So we just put them all in the same group. | |
2436 dsadded = added | |
2422 | 2437 |
2423 # if f is a rename, update `names` to also revert the source | 2438 # if f is a rename, update `names` to also revert the source |
2424 cwd = repo.getcwd() | 2439 cwd = repo.getcwd() |
2425 for f in dsadded: | 2440 for f in dsadded: |
2426 src = repo.dirstate.copied(f) | 2441 src = repo.dirstate.copied(f) |
2435 return _('forgetting %s\n') | 2450 return _('forgetting %s\n') |
2436 return _('removing %s\n') | 2451 return _('removing %s\n') |
2437 | 2452 |
2438 missingmodified = dsmodified - smf | 2453 missingmodified = dsmodified - smf |
2439 dsmodified -= missingmodified | 2454 dsmodified -= missingmodified |
2440 missingadded = dsadded - smf | |
2441 dsadded -= missingadded | |
2442 | 2455 |
2443 # action to be actually performed by revert | 2456 # action to be actually performed by revert |
2444 # (<list of file>, message>) tuple | 2457 # (<list of file>, message>) tuple |
2445 actions = {'revert': ([], _('reverting %s\n')), | 2458 actions = {'revert': ([], _('reverting %s\n')), |
2446 'add': ([], _('adding %s\n')), | 2459 'add': ([], _('adding %s\n')), |
2453 # action | 2466 # action |
2454 # make backup | 2467 # make backup |
2455 (modified, (actions['revert'], False)), | 2468 (modified, (actions['revert'], False)), |
2456 (dsmodified, (actions['revert'], True)), | 2469 (dsmodified, (actions['revert'], True)), |
2457 (missingmodified, (actions['remove'], True)), | 2470 (missingmodified, (actions['remove'], True)), |
2458 (dsadded, (actions['revert'], True)), | 2471 (dsadded, (actions['remove'], True)), |
2459 (missingadded, (actions['remove'], False)), | |
2460 (removed, (actions['add'], True)), | 2472 (removed, (actions['add'], True)), |
2461 (dsremoved, (actions['undelete'], True)), | 2473 (dsremoved, (actions['undelete'], True)), |
2462 (clean, (None, False)), | 2474 (clean, (None, False)), |
2463 ) | 2475 ) |
2464 | 2476 |