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.
This commit is contained in:
Pierre-Yves David 2014-08-02 11:32:24 -07:00
parent 92e0debc2b
commit 9f80242186
2 changed files with 18 additions and 18 deletions

View File

@ -2407,7 +2407,6 @@ def revert(ui, repo, ctx, parents, *pats, **opts):
dsmodified = set(changes[0])
dsadded = set(changes[1])
dsremoved = set(changes[2])
dsadded |= _deletedadded
# only take into account for removes between wc and target
clean |= dsremoved - removed
@ -2420,6 +2419,22 @@ def revert(ui, repo, ctx, parents, *pats, **opts):
dsmodified |= modified & dsadded # dirstate added may needs backup
modified -= dsmodified
# There are three categories of added files
#
# 1. addition that just happened in the dirstate
# (should be forgotten)
# 2. file is added since target revision and has local changes
# (should be backed up and removed)
# 3. file is added since target revision and is clean
# (should be removed)
#
# However we do not need to split them yet. The current revert code
# will automatically recognize (1) when performing operation. And
# the backup system is currently unabled to handle (2).
#
# So we just put them all in the same group.
dsadded = added
# if f is a rename, update `names` to also revert the source
cwd = repo.getcwd()
for f in dsadded:
@ -2437,8 +2452,6 @@ def revert(ui, repo, ctx, parents, *pats, **opts):
missingmodified = dsmodified - smf
dsmodified -= missingmodified
missingadded = dsadded - smf
dsadded -= missingadded
# action to be actually performed by revert
# (<list of file>, message>) tuple
@ -2455,8 +2468,7 @@ def revert(ui, repo, ctx, parents, *pats, **opts):
(modified, (actions['revert'], False)),
(dsmodified, (actions['revert'], True)),
(missingmodified, (actions['remove'], True)),
(dsadded, (actions['revert'], True)),
(missingadded, (actions['remove'], False)),
(dsadded, (actions['remove'], True)),
(removed, (actions['add'], True)),
(dsremoved, (actions['undelete'], True)),
(clean, (None, False)),

View File

@ -908,12 +908,6 @@ Test revert --all to "base" content
check revert output
Misbehavior:
- report "reverting" when file needs no changes
|
| - reverting removed_revert
$ hg revert --all --rev 'desc(base)'
removing added_clean
removing added_deleted
@ -936,7 +930,6 @@ Misbehavior:
adding removed_clean
reverting removed_deleted
adding removed_removed
reverting removed_revert
adding removed_untracked-clean
adding removed_untracked-revert
adding removed_untracked-wc
@ -1098,12 +1091,6 @@ Test revert to "base" content with explicit file name
revert all files individually and check the output
(output is expected to be different than in the --all case)
Misbehavior:
- fails to report no change to revert for
|
| - removed_revert
$ for file in `python ../gen-revert-cases.py filelist`; do
> echo '### revert for:' $file;
> hg revert $file --rev 'desc(base)';
@ -1194,6 +1181,7 @@ Misbehavior:
### revert for: removed_removed
### revert for: removed_revert
no changes needed to removed_revert
### revert for: removed_untracked-clean