Patchwork addremove: pass command-level similarity value down to scmutil.addremove()

login
register
mail settings
Submitter Yuya Nishihara
Date April 3, 2018, 3:39 p.m.
Message ID <c118bb7c938ae92ffdfb.1522769956@mimosa>
Download mbox | patch
Permalink /patch/30161/
State Accepted
Headers show

Comments

Yuya Nishihara - April 3, 2018, 3:39 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1522761890 -32400
#      Tue Apr 03 22:24:50 2018 +0900
# Node ID c118bb7c938ae92ffdfbab5ea977f1c029c87599
# Parent  6ff8bd691fb8fd25a4e16ead04d13bcf7101e549
addremove: pass command-level similarity value down to scmutil.addremove()

Since we've changed to carry a similarity value by opts dict, it makes sense
to leave a string '0'-'100' value unmodified.
Pulkit Goyal - April 3, 2018, 6:39 p.m.
On Tue, Apr 3, 2018 at 9:09 PM, Yuya Nishihara <yuya@tcha.org> wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1522761890 -32400
> #      Tue Apr 03 22:24:50 2018 +0900
> # Node ID c118bb7c938ae92ffdfbab5ea977f1c029c87599
> # Parent  6ff8bd691fb8fd25a4e16ead04d13bcf7101e549
> addremove: pass command-level similarity value down to scmutil.addremove()
>
> Since we've changed to carry a similarity value by opts dict, it makes sense
> to leave a string '0'-'100' value unmodified.

Queued this. Many thanks!

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -247,13 +247,8 @@  def addremove(ui, repo, *pats, **opts):
     Returns 0 if all files are successfully added.
     """
     opts = pycompat.byteskwargs(opts)
-    try:
-        sim = float(opts.get('similarity') or 100)
-    except ValueError:
-        raise error.Abort(_('similarity must be a number'))
-    if sim < 0 or sim > 100:
-        raise error.Abort(_('similarity must be between 0 and 100'))
-    opts['similarity'] = sim / 100.0
+    if not opts.get('similarity'):
+        opts['similarity'] = '100'
     matcher = scmutil.match(repo[None], pats, opts)
     return scmutil.addremove(repo, matcher, "", opts)
 
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -741,7 +741,13 @@  def addremove(repo, matcher, prefix, opt
         opts = {}
     m = matcher
     dry_run = opts.get('dry_run')
-    similarity = float(opts.get('similarity') or 0)
+    try:
+        similarity = float(opts.get('similarity') or 0)
+    except ValueError:
+        raise error.Abort(_('similarity must be a number'))
+    if similarity < 0 or similarity > 100:
+        raise error.Abort(_('similarity must be between 0 and 100'))
+    similarity /= 100.0
 
     ret = 0
     join = lambda f: os.path.join(prefix, f)