Patchwork [2,of,5] revset: factorize backup decision

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 18, 2014, 10:30 p.m.
Message ID <df01b592e5060253f5d8.1408401052@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5479/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 18, 2014, 10:30 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1403628873 -3600
#      Tue Jun 24 17:54:33 2014 +0100
# Node ID df01b592e5060253f5d85c44b267b643c3ef396b
# Parent  06da9bf044178ea90877006dc6f6ced7dc6fad18
revset: factorize backup decision

The conditional controlling the creation of backup is fairly big. We move config
related decision outside of the loop.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2466,21 +2466,26 @@  def revert(ui, repo, ctx, parents, *pats
         actions = {'revert': ([], _('reverting %s\n')),
                    'add': ([], _('adding %s\n')),
                    '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()):
             # target file to be touch on disk (relative to cwd)
             target = repo.wjoin(abs)
@@ -2493,12 +2498,11 @@  def revert(ui, repo, ctx, parents, *pats
                 if xlist is None:
                     if exact:
                         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') %
                             (rel, bakname))
                     if not opts.get('dry_run'):