Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 30066:5f93737d0ba8
bisect: move the 'extendrange' to the 'hbisect' module
We have a module ready to host any bisect logic. That logic was already isolated
in a function so we just migrate it as is.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Wed, 24 Aug 2016 04:16:07 +0200 |
parents | ee21ed7fc7a2 |
children | 6e88cd060ba2 |
comparison
equal
deleted
inserted
replaced
30065:ee21ed7fc7a2 | 30066:5f93737d0ba8 |
---|---|
833 | 833 |
834 See :hg:`help revsets` for more about the `bisect()` keyword. | 834 See :hg:`help revsets` for more about the `bisect()` keyword. |
835 | 835 |
836 Returns 0 on success. | 836 Returns 0 on success. |
837 """ | 837 """ |
838 def extendbisectrange(nodes, good): | |
839 # bisect is incomplete when it ends on a merge node and | |
840 # one of the parent was not checked. | |
841 parents = repo[nodes[0]].parents() | |
842 if len(parents) > 1: | |
843 if good: | |
844 side = state['bad'] | |
845 else: | |
846 side = state['good'] | |
847 num = len(set(i.node() for i in parents) & set(side)) | |
848 if num == 1: | |
849 return parents[0].ancestor(parents[1]) | |
850 return None | |
851 | |
852 def print_result(nodes, good): | 838 def print_result(nodes, good): |
853 displayer = cmdutil.show_changeset(ui, repo, {}) | 839 displayer = cmdutil.show_changeset(ui, repo, {}) |
854 if len(nodes) == 1: | 840 if len(nodes) == 1: |
855 # narrowed it down to a single revision | 841 # narrowed it down to a single revision |
856 if good: | 842 if good: |
857 ui.write(_("The first good revision is:\n")) | 843 ui.write(_("The first good revision is:\n")) |
858 else: | 844 else: |
859 ui.write(_("The first bad revision is:\n")) | 845 ui.write(_("The first bad revision is:\n")) |
860 displayer.show(repo[nodes[0]]) | 846 displayer.show(repo[nodes[0]]) |
861 extendnode = extendbisectrange(nodes, good) | 847 extendnode = hbisect.extendrange(repo, state, nodes, good) |
862 if extendnode is not None: | 848 if extendnode is not None: |
863 ui.write(_('Not all ancestors of this changeset have been' | 849 ui.write(_('Not all ancestors of this changeset have been' |
864 ' checked.\nUse bisect --extend to continue the ' | 850 ' checked.\nUse bisect --extend to continue the ' |
865 'bisection from\nthe common ancestor, %s.\n') | 851 'bisection from\nthe common ancestor, %s.\n') |
866 % extendnode) | 852 % extendnode) |
975 | 961 |
976 # actually bisect | 962 # actually bisect |
977 nodes, changesets, good = hbisect.bisect(repo.changelog, state) | 963 nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
978 if extend: | 964 if extend: |
979 if not changesets: | 965 if not changesets: |
980 extendnode = extendbisectrange(nodes, good) | 966 extendnode = hbisect.extendrange(repo, state, nodes, good) |
981 if extendnode is not None: | 967 if extendnode is not None: |
982 ui.write(_("Extending search to changeset %d:%s\n") | 968 ui.write(_("Extending search to changeset %d:%s\n") |
983 % (extendnode.rev(), extendnode)) | 969 % (extendnode.rev(), extendnode)) |
984 state['current'] = [extendnode.node()] | 970 state['current'] = [extendnode.node()] |
985 hbisect.save_state(repo, state) | 971 hbisect.save_state(repo, state) |