Patchwork D988: fsmonitor: change the distance calculation

login
register
mail settings
Submitter phabricator
Date Oct. 10, 2017, 6:16 p.m.
Message ID <5d75299eeb8741cfb9f685621c2fbb23@localhost.localdomain>
Download mbox | patch
Permalink /patch/24711/
State Not Applicable
Headers show

Comments

phabricator - Oct. 10, 2017, 6:16 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGb79f59425964: fsmonitor: change the distance calculation (authored by ekent, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D988?vs=2533&id=2568

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

AFFECTED FILES
  hgext/fsmonitor/__init__.py

CHANGE DETAILS




To: ekent, #hg-reviewers, quark
Cc: mercurial-devel

Patch

diff --git a/hgext/fsmonitor/__init__.py b/hgext/fsmonitor/__init__.py
--- a/hgext/fsmonitor/__init__.py
+++ b/hgext/fsmonitor/__init__.py
@@ -660,6 +660,14 @@ 
                 'watchman', 'Exception %s while running %s\n', e, cmd)
             return False
 
+# Estimate the distance between two nodes
+def calcdistance(repo, oldnode, newnode):
+    anc = repo.changelog.ancestor(oldnode, newnode)
+    ancrev = repo[anc].rev()
+    distance = (abs(repo[oldnode].rev() - ancrev)
+        + abs(repo[newnode].rev() - ancrev))
+    return distance
+
 # Bracket working copy updates with calls to the watchman state-enter
 # and state-leave commands.  This allows clients to perform more intelligent
 # settling during bulk file change scenarios
@@ -671,14 +679,8 @@ 
     partial = True
     if matcher is None or matcher.always():
         partial = False
-        wc = repo[None]
-        parents = wc.parents()
-        if len(parents) == 2:
-            anc = repo.changelog.ancestor(parents[0].node(), parents[1].node())
-            ancrev = repo[anc].rev()
-            distance = abs(repo[node].rev() - ancrev)
-        elif len(parents) == 1:
-            distance = abs(repo[node].rev() - parents[0].rev())
+        distance = calcdistance(repo.unfiltered(), repo['.'].node(),
+                                repo[node].node())
 
     with state_update(repo, node, distance, partial):
         return orig(