D987: copies: add a config to limit the number of candidates to check in heuristics
pulkit (Pulkit Goyal)
phabricator at mercurial-scm.org
Mon Oct 9 17:09:40 EDT 2017
pulkit updated this revision to Diff 2539.
pulkit edited the summary of this revision.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D987?vs=2522&id=2539
REVISION DETAIL
https://phab.mercurial-scm.org/D987
AFFECTED FILES
mercurial/configitems.py
mercurial/copies.py
tests/test-copytrace-heuristics.t
CHANGE DETAILS
diff --git a/tests/test-copytrace-heuristics.t b/tests/test-copytrace-heuristics.t
--- a/tests/test-copytrace-heuristics.t
+++ b/tests/test-copytrace-heuristics.t
@@ -201,6 +201,64 @@
$ cd ..
$ rm -rf repo
+Test the copytrace.movecandidateslimit with many move candidates
+----------------------------------------------------------------
+
+ $ hg init repo
+ $ initclient repo
+ $ cd repo
+ $ echo a > a
+ $ hg add a
+ $ hg ci -m initial
+ $ hg mv a foo
+ $ echo a > b
+ $ echo a > c
+ $ echo a > d
+ $ echo a > e
+ $ echo a > f
+ $ echo a > g
+ $ hg add b
+ $ hg add c
+ $ hg add d
+ $ hg add e
+ $ hg add f
+ $ hg add g
+ $ hg ci -m 'mv a foo, add many files'
+ $ hg up -q ".^"
+ $ echo b > a
+ $ hg ci -m 'mod a'
+ created new head
+
+ $ hg log -G -T 'changeset: {node}\n desc: {desc}\n'
+ @ changeset: ef716627c70bf4ca0bdb623cfb0d6fe5b9acc51e
+ | desc: mod a
+ | o changeset: 8329d5c6bf479ec5ca59b9864f3f45d07213f5a4
+ |/ desc: mv a foo, add many files
+ o changeset: 1451231c87572a7d3f92fc210b4b35711c949a98
+ desc: initial
+
+With small limit
+
+ $ hg rebase -s 2 -d 1 --config experimental.copytrace.movecandidateslimit=0
+ rebasing 2:ef716627c70b "mod a" (tip)
+ other [source] changed a which local [dest] deleted
+ use (c)hanged version, leave (d)eleted, or leave (u)nresolved? u
+ unresolved conflicts (see hg resolve, then hg rebase --continue)
+ [1]
+
+ $ hg rebase --abort
+ rebase aborted
+
+With default limit which is 100
+
+ $ hg rebase -s 2 -d 1
+ rebasing 2:ef716627c70b "mod a" (tip)
+ merging foo and a to foo
+ saved backup bundle to $TESTTMP/repo/.hg/strip-backup/ef716627c70b-24681561-rebase.hg (glob)
+
+ $ cd ..
+ $ rm -rf repo
+
Move file in one branch and delete it in another
-----------------------------------------------
diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -644,6 +644,11 @@
[experimental]
copytrace = heuristics
+
+ In some cases the copy/move candidates found by heuristics can be very large
+ in number and that will make the algorithm slow. The number of possible
+ candidates to check can be limited by using the config
+ `experimental.copytrace.movecandidateslimit` which defaults to 100.
"""
if c1.rev() is None:
@@ -704,14 +709,23 @@
# f is guaranteed to be present in c2, that's why
# c2.filectx(f) won't fail
f2 = c2.filectx(f)
- for candidate in movecandidates:
+ # we can have a lot of candidates which can slow down the heuristics
+ # config value to limit the number of candidates moves to check
+ maxcandidates = repo.ui.configint('experimental',
+ 'copytrace.movecandidateslimit')
+
+ for candidate in movecandidates[:maxcandidates]:
f1 = c1.filectx(candidate)
if _related(f1, f2, anc.rev()):
# if there are a few related copies then we'll merge
# changes into all of them. This matches the behaviour
# of upstream copytracing
copies[candidate] = f
+ if len(movecandidates) > maxcandidates:
+ repo.ui.debug("more candidates than the limit: %d\n" %
+ len(movecandidates))
+
return copies, {}, {}, {}, {}
def _related(f1, f2, limit):
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -185,6 +185,9 @@
coreconfigitem('experimental', 'copytrace',
default='on',
)
+coreconfigitem('experimental', 'copytrace.movecandidateslimit',
+ default=100,
+)
coreconfigitem('experimental', 'copytrace.sourcecommitlimit',
default=100,
)
To: pulkit, #hg-reviewers, yuja
Cc: yuja, mercurial-devel
More information about the Mercurial-devel
mailing list