[PATCH 3 of 4] revert: handle unknown file through status

Pierre-Yves David pierre-yves.david at ens-lyon.org
Mon Aug 18 18:36:52 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1403650890 -3600
#      Wed Jun 25 00:01:30 2014 +0100
# Node ID cbdd2b77da8097c37c5a93733b4870e15294c93d
# Parent  dc71811ffcd0443fbec9bdd21d8be6ce7c30659e
revert: handle unknown file through status

This will allow to drop the code dedicated to this special case.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2376,15 +2376,18 @@ def revert(ui, repo, ctx, parents, *pats
         targetsubs = sorted(s for s in ctx.substate if m(s))
 
         # Find status of all file in `names`.
         m = scmutil.matchfiles(repo, names)
 
-        changes = repo.status(node1=node, match=m, clean=True)
+        changes = repo.status(node1=node, match=m,
+                              unknown=True, ignored=True, clean=True)
         modified = set(changes[0])
         added    = set(changes[1])
         removed  = set(changes[2])
-        _deleted  = set(changes[3])
+        _deleted = set(changes[3])
+        unknown  = set(changes[4])
+        unknown.update(changes[5])
         clean    = set(changes[6])
 
         # split between files known in target manifest and the others
         smf = set(mf)
 
@@ -2469,10 +2472,11 @@ def revert(ui, repo, ctx, parents, *pats
         actions = {'revert': ([], _('reverting %s\n')),
                    'add': ([], _('adding %s\n')),
                    'remove': ([], removeforget),
                    'undelete': ([], _('undeleting %s\n')),
                    'noop': (None, _('no changes needed to %s\n')),
+                   'unknown': (None, _('file not managed: %s\n')),
                   }
 
 
         # should we do a backup ?
         backup = not opts.get('no_backup')
@@ -2487,10 +2491,11 @@ def revert(ui, repo, ctx, parents, *pats
             (dsmodified, actions['revert'],   backup),
             (dsadded,    actions['remove'],   backup),
             (removed,    actions['add'],      backup),
             (dsremoved,  actions['undelete'], backup),
             (clean,      actions['noop'],     discard),
+            (unknown,    actions['unknown'],  discard),
             )
 
         for abs, (rel, exact) in sorted(names.items()):
             # target file to be touch on disk (relative to cwd)
             target = repo.wjoin(abs)


More information about the Mercurial-devel mailing list