diff --git a/remotefilelog/__init__.py b/remotefilelog/__init__.py --- a/remotefilelog/__init__.py +++ b/remotefilelog/__init__.py @@ -18,6 +18,8 @@ ``remotefilelog.nodettl`` specifies maximum TTL of a node in seconds before it is garbage collected ``remotefilelog.repackonhggc`` runs repack on hg gc when True + ``remotefilelog.prefetchdays`` specifies the maximum age of a commit in + days after which it is no longer prefetched. """ from . import fileserverclient, remotefilelog, remotefilectx, shallowstore @@ -789,6 +791,11 @@ if shallow and bgprefetchrevs: bgrepack = repo.ui.configbool('remotefilelog', 'backgroundrepack', False) + # only prefetch changesets no older than 'prefetchdays' days + # default value is set to 14 days + days = ui.configint('remotefilelog', 'prefetchdays', 14) + bgprefetchrevs = '(%s) & date(-%s)' % (bgprefetchrevs, days) + def anon(): if util.safehasattr(repo, 'ranprefetch') and repo.ranprefetch: return @@ -929,8 +936,12 @@ bgprefetchrevs = ui.config('remotefilelog', 'bgprefetchrevs', None) if bgprefetchrevs: revset.append('(%s)' % bgprefetchrevs) + revset = '+'.join(revset) - opts['rev'] = ['+'.join(revset)] + # only prefetch changesets no older than 'prefetchdays' days + # default value is set to 14 days + days = ui.configint('remotefilelog', 'prefetchdays', 14) + opts['rev'] = ['(%s) & date(-%s)' % (revset, days)] revs = scmutil.revrange(repo, opts.get('rev')) diff --git a/tests/test-remotefilelog-bgprefetch.t b/tests/test-remotefilelog-bgprefetch.t --- a/tests/test-remotefilelog-bgprefetch.t +++ b/tests/test-remotefilelog-bgprefetch.t @@ -22,7 +22,7 @@ $ cd .. -# prefetch a revision +# clone the repo $ hgcloneshallow ssh://user@dummy/master shallow --noupdate streaming all changes @@ -30,6 +30,17 @@ transferred 776 bytes in * seconds (*/sec) (glob) searching for changes no changes found + +# For the purposes of the test prefetchdays is set to current days since epoch + 100 days. i.e. all commits in tests have +# a date of 1970 and therefore to prefetch all revisions we have to set prefetchdays to be farther from 1970 than we are now. + $ cd shallow + $ cat >> .hg/hgrc < [remotefilelog] + > prefetchdays=$(($(date +%s) + 100)) + > EOF + $ cd .. + +# prefetch a revision $ cd shallow $ hg prefetch -r 0 diff --git a/tests/test-remotefilelog-gc.t b/tests/test-remotefilelog-gc.t --- a/tests/test-remotefilelog-gc.t +++ b/tests/test-remotefilelog-gc.t @@ -17,6 +17,15 @@ $ hgcloneshallow ssh://user@dummy/master shallow -q 1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob) +# For the purposes of the test prefetchdays is set to current days since epoch + 100 days. i.e. all commits in tests have +# a date of 1970 and therefore to prefetch all revisions we have to set prefetchdays to be farther from 1970 than we are now. + $ cd shallow + $ cat >> .hg/hgrc < [remotefilelog] + > prefetchdays=$(($(date +%s) + 100)) + > EOF + $ cd .. + # commit a new version of x so we can gc the old one $ cd master diff --git a/tests/test-remotefilelog-gcrepack.t b/tests/test-remotefilelog-gcrepack.t --- a/tests/test-remotefilelog-gcrepack.t +++ b/tests/test-remotefilelog-gcrepack.t @@ -21,6 +21,15 @@ $ hgcloneshallow ssh://user@dummy/master shallow -q 1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob) +# For the purposes of the test prefetchdays is set to current days since epoch + 100 days. i.e. all commits in tests have +# a date of 1970 and therefore to prefetch all revisions we have to set prefetchdays to be farther from 1970 than we are now. + $ cd shallow + $ cat >> .hg/hgrc < [remotefilelog] + > prefetchdays=$(($(date +%s) + 100)) + > EOF + $ cd .. + # Prefetch all data and repack $ cd shallow diff --git a/tests/test-remotefilelog-repack-fast.t b/tests/test-remotefilelog-repack-fast.t --- a/tests/test-remotefilelog-repack-fast.t +++ b/tests/test-remotefilelog-repack-fast.t @@ -24,6 +24,15 @@ $ hgcloneshallow ssh://user@dummy/master shallow -q 1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob) +# For the purposes of the test prefetchdays is set to current days since epoch + 100 days. i.e. all commits in tests have +# a date of 1970 and therefore to prefetch all revisions we have to set prefetchdays to be farther from 1970 than we are now. + $ cd shallow + $ cat >> .hg/hgrc < [remotefilelog] + > prefetchdays=$(($(date +%s) + 100)) + > EOF + $ cd .. + # Test that repack cleans up the old files and creates new packs $ cd shallow diff --git a/tests/test-remotefilelog-repack.t b/tests/test-remotefilelog-repack.t --- a/tests/test-remotefilelog-repack.t +++ b/tests/test-remotefilelog-repack.t @@ -19,6 +19,15 @@ $ hgcloneshallow ssh://user@dummy/master shallow -q 1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over *s (glob) +# For the purposes of the test prefetchdays is set to current days since epoch + 100 days. i.e. all commits in tests have +# a date of 1970 and therefore to prefetch all revisions we have to set prefetchdays to be farther from 1970 than we are now. + $ cd shallow + $ cat >> .hg/hgrc < [remotefilelog] + > prefetchdays=$(($(date +%s) + 100)) + > EOF + $ cd .. + # Test that repack cleans up the old files and creates new packs $ cd shallow