Mercurial > hg
comparison hgext/fsmonitor/__init__.py @ 34564:b79f59425964
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
author | Eamonn Kent <ekent@fb.com> |
---|---|
date | Mon, 09 Oct 2017 10:09:36 -0700 |
parents | 718f7acd6d5e |
children | 4aa57627692a |
comparison
equal
deleted
inserted
replaced
34563:1faa34347b24 | 34564:b79f59425964 |
---|---|
658 # Swallow any errors; fire and forget | 658 # Swallow any errors; fire and forget |
659 self.repo.ui.log( | 659 self.repo.ui.log( |
660 'watchman', 'Exception %s while running %s\n', e, cmd) | 660 'watchman', 'Exception %s while running %s\n', e, cmd) |
661 return False | 661 return False |
662 | 662 |
663 # Estimate the distance between two nodes | |
664 def calcdistance(repo, oldnode, newnode): | |
665 anc = repo.changelog.ancestor(oldnode, newnode) | |
666 ancrev = repo[anc].rev() | |
667 distance = (abs(repo[oldnode].rev() - ancrev) | |
668 + abs(repo[newnode].rev() - ancrev)) | |
669 return distance | |
670 | |
663 # Bracket working copy updates with calls to the watchman state-enter | 671 # Bracket working copy updates with calls to the watchman state-enter |
664 # and state-leave commands. This allows clients to perform more intelligent | 672 # and state-leave commands. This allows clients to perform more intelligent |
665 # settling during bulk file change scenarios | 673 # settling during bulk file change scenarios |
666 # https://facebook.github.io/watchman/docs/cmd/subscribe.html#advanced-settling | 674 # https://facebook.github.io/watchman/docs/cmd/subscribe.html#advanced-settling |
667 def wrapupdate(orig, repo, node, branchmerge, force, ancestor=None, | 675 def wrapupdate(orig, repo, node, branchmerge, force, ancestor=None, |
669 | 677 |
670 distance = 0 | 678 distance = 0 |
671 partial = True | 679 partial = True |
672 if matcher is None or matcher.always(): | 680 if matcher is None or matcher.always(): |
673 partial = False | 681 partial = False |
674 wc = repo[None] | 682 distance = calcdistance(repo.unfiltered(), repo['.'].node(), |
675 parents = wc.parents() | 683 repo[node].node()) |
676 if len(parents) == 2: | |
677 anc = repo.changelog.ancestor(parents[0].node(), parents[1].node()) | |
678 ancrev = repo[anc].rev() | |
679 distance = abs(repo[node].rev() - ancrev) | |
680 elif len(parents) == 1: | |
681 distance = abs(repo[node].rev() - parents[0].rev()) | |
682 | 684 |
683 with state_update(repo, node, distance, partial): | 685 with state_update(repo, node, distance, partial): |
684 return orig( | 686 return orig( |
685 repo, node, branchmerge, force, ancestor, mergeancestor, | 687 repo, node, branchmerge, force, ancestor, mergeancestor, |
686 labels, matcher, **kwargs) | 688 labels, matcher, **kwargs) |