# HG changeset patch # User FUJIWARA Katsunori # Date 1475942598 -32400 # Node ID 148ccd1d9f2f1e676b52c48777052e968e2a4f7b # Parent 113aa61450205ea4ab731bc4cb052f33a8565c07 perf: add functions to get vfs-like object for Mercurial earlier than 2.3 Before this patch, using svfs prevents perf.py from measuring performance of Mercurial earlier than 2.3 (or 7034365089bf), because svfs isn't available in such Mercurial, even though there are some code paths for Mercurial earlier than 2.3 in perf.py. For example, setting "_prereadsize" attribute in perfindex() and perfnodelookup() is effective only with hg earlier than 1.8 (or 61c9bc3da402). To get appropriate vfs-like object to access files under .hg/store, this patch adds getsvfs() (and also getvfs(), for future use). To avoid examining existence of attribute at each repetition while measuring performance, getsvfs() is invoked outside the function to be called repeatedly. This patch also adds check-perf-code.py an extra check entry to detect direct usage of repo.(vfs|svfs|opener|sopener) in perf.py. diff -r 113aa6145020 -r 148ccd1d9f2f contrib/perf.py --- a/contrib/perf.py Sun Oct 09 01:03:17 2016 +0900 +++ b/contrib/perf.py Sun Oct 09 01:03:18 2016 +0900 @@ -232,6 +232,28 @@ raise error.Abort(("perfbranchmap not available with this Mercurial"), hint="use 2.5 or later") +def getsvfs(repo): + """Return appropriate object to access files under .hg/store + """ + # for "historical portability": + # repo.svfs has been available since 2.3 (or 7034365089bf) + svfs = getattr(repo, 'svfs', None) + if svfs: + return svfs + else: + return getattr(repo, 'sopener') + +def getvfs(repo): + """Return appropriate object to access files under .hg + """ + # for "historical portability": + # repo.vfs has been available since 2.3 (or 7034365089bf) + vfs = getattr(repo, 'vfs', None) + if vfs: + return vfs + else: + return getattr(repo, 'opener') + # perf commands @command('perfwalk', formatteropts) @@ -302,9 +324,10 @@ import mercurial.changelog import mercurial.manifest timer, fm = gettimer(ui, opts) + svfs = getsvfs(repo) def t(): - repo.changelog = mercurial.changelog.changelog(repo.svfs) - repo.manifest = mercurial.manifest.manifest(repo.svfs) + repo.changelog = mercurial.changelog.changelog(svfs) + repo.manifest = mercurial.manifest.manifest(svfs) repo._tags = None return len(repo.tags()) timer(t) @@ -483,8 +506,9 @@ timer, fm = gettimer(ui, opts) mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg n = repo["tip"].node() + svfs = getsvfs(repo) def d(): - cl = mercurial.revlog.revlog(repo.svfs, "00changelog.i") + cl = mercurial.revlog.revlog(svfs, "00changelog.i") cl.rev(n) timer(d) fm.end() @@ -556,7 +580,7 @@ import mercurial.revlog mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg n = repo[rev].node() - cl = mercurial.revlog.revlog(repo.svfs, "00changelog.i") + cl = mercurial.revlog.revlog(getsvfs(repo), "00changelog.i") def d(): cl.rev(n) clearcaches(cl) @@ -903,7 +927,8 @@ Result is the number of markers in the repo.""" timer, fm = gettimer(ui) - timer(lambda: len(obsolete.obsstore(repo.svfs))) + svfs = getsvfs(repo) + timer(lambda: len(obsolete.obsstore(svfs))) fm.end() @command('perflrucachedict', formatteropts + diff -r 113aa6145020 -r 148ccd1d9f2f tests/check-perf-code.py --- a/tests/check-perf-code.py Sun Oct 09 01:03:17 2016 +0900 +++ b/tests/check-perf-code.py Sun Oct 09 01:03:18 2016 +0900 @@ -12,6 +12,8 @@ [ (r'(branchmap|repoview)\.subsettable', "use getbranchmapsubsettable() for early Mercurial"), + (r'\.(vfs|svfs|opener|sopener)', + "use getvfs()/getsvfs() for early Mercurial"), ], # warnings [