Patchwork D6123: similar: add condition to avoid Zerodivisonerror in function _score() (issue6099)

login
register
mail settings
Submitter phabricator
Date March 15, 2019, 2:19 p.m.
Message ID <6dec769ccc6253cb38a128cae402742c@localhost.localdomain>
Download mbox | patch
Permalink /patch/39270/
State Not Applicable
Headers show

Comments

phabricator - March 15, 2019, 2:19 p.m.
akshjain.jain74 updated this revision to Diff 14508.
akshjain.jain74 marked 2 inline comments as done.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6123?vs=14487&id=14508

REVISION DETAIL
  https://phab.mercurial-scm.org/D6123

AFFECTED FILES
  mercurial/similar.py

CHANGE DETAILS




To: akshjain.jain74, durin42, #hg-reviewers
Cc: av6, pulkit, mercurial-devel

Patch

diff --git a/mercurial/similar.py b/mercurial/similar.py
--- a/mercurial/similar.py
+++ b/mercurial/similar.py
@@ -63,7 +63,9 @@ 
             equal += len(line)
 
     lengths = len(text) + len(orig)
-    return equal * 2.0 / lengths
+    if lengths:
+        return equal * 2.0 / lengths
+    return 0
 
 def score(fctx1, fctx2):
     return _score(fctx1, _ctxdata(fctx2))