comparison mercurial/merge.py @ 32151:4d504e541d3d

rebase: use matcher to optimize manifestmerge The old merge code would call manifestmerge and calculate the complete diff between the source to the destination. In many cases, like rebase, the vast majority of differences between the source and destination are irrelevant because they are differences between the destination and the common ancestor only, and therefore don't affect the merge. Since most actions are 'keep', all the effort to compute them is wasted. Instead, let's compute the difference between the source and the common ancestor and only perform the diff of those files against the merge destination. When using treemanifest, this lets us avoid loading almost the entire tree when rebasing from a very old ancestor. This speeds up rebase of an old stack of 27 commits by 20x. In mozilla-central, without treemanifest, when rebasing a commit from default~100000 to default, this speeds up the manifestmerge step from 2.6s to 1.2s. However, the additional diff adds an overhead to all manifestmerge calls, especially for flat manifests. When rebasing a commit from default~1 to default it appears to add 100ms in mozilla-central. While we could put this optimization behind a flag, I think the fact that it makes merge O(number of changes being applied) instead of O(number of changes between X and Y) justifies it.
author Durham Goode <durham@fb.com>
date Wed, 03 May 2017 10:43:59 -0700
parents e960eba3581c
children 7e79373263ab
comparison
equal deleted inserted replaced
32150:282b288aa20c 32151:4d504e541d3d
784 784
785 This is currently not implemented -- it's an extension point.""" 785 This is currently not implemented -- it's an extension point."""
786 return True 786 return True
787 787
788 def manifestmerge(repo, wctx, p2, pa, branchmerge, force, matcher, 788 def manifestmerge(repo, wctx, p2, pa, branchmerge, force, matcher,
789 acceptremote, followcopies): 789 acceptremote, followcopies, forcefulldiff=False):
790 """ 790 """
791 Merge wctx and p2 with ancestor pa and generate merge action list 791 Merge wctx and p2 with ancestor pa and generate merge action list
792 792
793 branchmerge and force are as passed in to update 793 branchmerge and force are as passed in to update
794 matcher = matcher to filter file lists 794 matcher = matcher to filter file lists
818 818
819 if '.hgsubstate' in m1: 819 if '.hgsubstate' in m1:
820 # check whether sub state is modified 820 # check whether sub state is modified
821 if any(wctx.sub(s).dirty() for s in wctx.substate): 821 if any(wctx.sub(s).dirty() for s in wctx.substate):
822 m1['.hgsubstate'] = modifiednodeid 822 m1['.hgsubstate'] = modifiednodeid
823
824 # Don't use m2-vs-ma optimization if:
825 # - ma is the same as m1 or m2, which we're just going to diff again later
826 # - The matcher is set already, so we can't override it
827 # - The caller specifically asks for a full diff, which is useful during bid
828 # merge.
829 if (pa not in ([wctx, p2] + wctx.parents()) and
830 matcher is None and not forcefulldiff):
831 # Identify which files are relevant to the merge, so we can limit the
832 # total m1-vs-m2 diff to just those files. This has significant
833 # performance benefits in large repositories.
834 relevantfiles = set(ma.diff(m2).keys())
835
836 # For copied and moved files, we need to add the source file too.
837 for copykey, copyvalue in copy.iteritems():
838 if copyvalue in relevantfiles:
839 relevantfiles.add(copykey)
840 for movedirkey in movewithdir.iterkeys():
841 relevantfiles.add(movedirkey)
842 matcher = scmutil.matchfiles(repo, relevantfiles)
823 843
824 diff = m1.diff(m2, match=matcher) 844 diff = m1.diff(m2, match=matcher)
825 845
826 if matcher is None: 846 if matcher is None:
827 matcher = matchmod.always('', '') 847 matcher = matchmod.always('', '')
972 diverge, renamedelete = None, None 992 diverge, renamedelete = None, None
973 for ancestor in ancestors: 993 for ancestor in ancestors:
974 repo.ui.note(_('\ncalculating bids for ancestor %s\n') % ancestor) 994 repo.ui.note(_('\ncalculating bids for ancestor %s\n') % ancestor)
975 actions, diverge1, renamedelete1 = manifestmerge( 995 actions, diverge1, renamedelete1 = manifestmerge(
976 repo, wctx, mctx, ancestor, branchmerge, force, matcher, 996 repo, wctx, mctx, ancestor, branchmerge, force, matcher,
977 acceptremote, followcopies) 997 acceptremote, followcopies, forcefulldiff=True)
978 _checkunknownfiles(repo, wctx, mctx, force, actions, mergeforce) 998 _checkunknownfiles(repo, wctx, mctx, force, actions, mergeforce)
979 999
980 # Track the shortest set of warning on the theory that bid 1000 # Track the shortest set of warning on the theory that bid
981 # merge will correctly incorporate more information 1001 # merge will correctly incorporate more information
982 if diverge is None or len(diverge1) < len(diverge): 1002 if diverge is None or len(diverge1) < len(diverge):