Patchwork [1,of,4,V2] revert: small refactoring in the way backup value are handled

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 30, 2014, 6:05 p.m.
Message ID <5ddd515bd5209e36ccc0.1412100337@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6047/
State Accepted
Headers show

Comments

Pierre-Yves David - Sept. 30, 2014, 6:05 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1409358507 -7200
#      Sat Aug 30 02:28:27 2014 +0200
# Node ID 5ddd515bd5209e36ccc0cc40d9e8436253bc611b
# Parent  4109cc16279ef0e04dc70e7f4c9ab7415e6a22d3
revert: small refactoring in the way backup value are handled

The current backup value may have two different values:

  1. Do not try to do backup
  2. Do backup if applicable

We are about to move to:

  1. Do not try to do backup
  2. Do backup if applicable
  3. Do backup in all cases

So we change the current values to make room for the new one.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2615,14 +2615,17 @@  def revert(ui, repo, ctx, parents, *pats
                    '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')
-        discard = False
+        # "constant" that convey the backup strategy.
+        # All set to `discard` if `no-backup` is set do avoid checking
+        # no_backup lower in the code.
+        backup = 2  # unconditionnally do backup
+        discard = 0 # never do backup
+        if opts.get('no_backup'):
+            backup = discard
 
         disptable = (
             # dispatch table:
             #   file state
             #   action