revert: only pre-fetch files that needs to be touched

Summary:
With recent version of mercurial (>= 3.2, 4dfcf21a6aa7), revert uses status
information to determine the files that needs to be touched. It then offer a
simple handle for extensions that needs prefetch.

Test Plan:
Ran the tests. Certain tests depended on the old revert behavior (of
prefetching everything), so they required slight changes.

Reviewers: pyd, sid0, davidsp

Differential Revision: https://phabricator.fb.com/D1551059
This commit is contained in:
Pierre-Yves David 2014-09-08 15:20:59 +02:00
parent 580f3eaeb3
commit 2c956d95e2
3 changed files with 21 additions and 3 deletions

View File

@ -309,7 +309,10 @@ def onetimeclientsetup(ui):
pass
wrapfunction(verify, '_verify', _verify)
wrapfunction(cmdutil, 'revert', revert)
if util.safehasattr(cmdutil, '_revertprefetch'):
wrapfunction(cmdutil, '_revertprefetch', _revertprefetch)
else:
wrapfunction(cmdutil, 'revert', revert)
def getrenamedfn(repo, endrev=None):
rcache = {}
@ -535,6 +538,7 @@ def pull(orig, ui, repo, *pats, **opts):
def revert(orig, ui, repo, ctx, parents, *pats, **opts):
# prefetch prior to reverting
# used for old mercurial version
if shallowrepo.requirement in repo.requirements:
files = []
m = scmutil.match(ctx, pats, opts)
@ -546,6 +550,18 @@ def revert(orig, ui, repo, ctx, parents, *pats, **opts):
return orig(ui, repo, ctx, parents, *pats, **opts)
def _revertprefetch(orig, repo, ctx, *files):
# prefetch data that needs to be reverted
# used for new mercurial version
if shallowrepo.requirement in repo.requirements:
allfiles = []
mf = ctx.manifest()
for f in files:
for path in f:
allfiles.append((path, hex(mf[path])))
repo.fileservice.prefetch(allfiles)
return orig(repo, ctx, *files)
commands.norepo += " debugremotefilelog"
@command('debugremotefilelog', [

View File

@ -120,7 +120,8 @@
$ clearcache
$ hg revert -r .~2 y z
3 files fetched over 2 fetches - (3 misses, 0.00% hit ratio) over *s (glob)
no changes needed to z
2 files fetched over 2 fetches - (2 misses, 0.00% hit ratio) over *s (glob)
$ hg checkout -C -r . -q
# explicit bundle should produce full bundle file
@ -131,6 +132,7 @@
$ cd ..
$ hgcloneshallow ssh://user@dummy/master shallow2 -q
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob)
$ cd shallow2
$ hg unbundle ../local.bundle
adding changesets

View File

@ -71,7 +71,7 @@
updating bookmark foo
(run 'hg update' to get a working copy)
prefetching file contents
3 files fetched over 1 fetches - (3 misses, 0.00% hit ratio) over 0.09s
3 files fetched over 1 fetches - (3 misses, 0.00% hit ratio) over *s (glob)
$ hg up tip
3 files updated, 0 files merged, 0 files removed, 0 files unresolved