changeset 22230:316ba2ddc034

revset: factorize backup decision The conditional controlling the creation of backup is fairly big. We move config related decisions outside of the loop.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 24 Jun 2014 17:54:33 +0100
parents 3a7b45a0bd20
children 10d9e7908a3c
files mercurial/cmdutil.py
diffstat 1 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Tue Jun 24 17:44:31 2014 +0100
+++ b/mercurial/cmdutil.py	Tue Jun 24 17:54:33 2014 +0100
@@ -2471,17 +2471,22 @@
                    'remove': ([], removeforget),
                    'undelete': ([], _('undeleting %s\n'))}
 
+
+        # should we do a backup?
+        backup = not opts.get('no_backup')
+        discard = False
+
         disptable = (
             # dispatch table:
             #   file state
             #   action
             #   make backup
-            (modified,   actions['revert'],   False),
-            (dsmodified, actions['revert'],   True),
-            (dsadded,    actions['remove'],   True),
-            (removed,    actions['add'],      True),
-            (dsremoved,  actions['undelete'], True),
-            (clean,      None,                False),
+            (modified,   actions['revert'],   discard),
+            (dsmodified, actions['revert'],   backup),
+            (dsadded,    actions['remove'],   backup),
+            (removed,    actions['add'],      backup),
+            (dsremoved,  actions['undelete'], backup),
+            (clean,      None,                discard),
             )
 
         for abs, (rel, exact) in sorted(names.items()):
@@ -2498,8 +2503,7 @@
                         ui.warn(_('no changes needed to %s\n') % rel)
                     break
                 xlist[0].append(abs)
-                if (dobackup and not opts.get('no_backup') and
-                    os.path.lexists(target) and
+                if (dobackup and os.path.lexists(target) and
                     abs in ctx and repo[None][abs].cmp(ctx[abs])):
                     bakname = "%s.orig" % rel
                     ui.note(_('saving current version of %s as %s\n') %