# HG changeset patch # User Eamonn Kent # Date 1507568976 25200 # Node ID b79f59425964aa67c382f20557cef9ddc176e394 # Parent 1faa34347b247d710b4207ad8a95d744c5c9b3ea fsmonitor: change the distance calculation Change the distance calculation in the fsmonitor extension. It is done in a method since anticipated changes will need to use this logic as well. Test Plan: Tested on development server. Differential Revision: https://phab.mercurial-scm.org/D988 diff -r 1faa34347b24 -r b79f59425964 hgext/fsmonitor/__init__.py --- a/hgext/fsmonitor/__init__.py Mon Oct 09 16:31:43 2017 +0200 +++ b/hgext/fsmonitor/__init__.py Mon Oct 09 10:09:36 2017 -0700 @@ -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(