diff --git a/tests/test-treemanifest-repack.t b/tests/test-treemanifest-repack.t --- a/tests/test-treemanifest-repack.t +++ b/tests/test-treemanifest-repack.t @@ -276,3 +276,9 @@ $ hg repack --incremental --config remotefilelog.data.generations=300,20 $ ls_l .hg/cache/packs/manifests/ | grep datapack -r--r--r-- 496 bc6c2ebb080844d7a227dacbc847a5b375ec620c.datapack + +- Test pruning the manifest cache using packs.maxpackfilecount + $ hg repack --incremental --config packs.maxpackfilecount=0 + $ hg repack --incremental --config packs.maxpackfilecount=1 + purging shared treemanifest pack cache (4 entries) -- too many files + $ ls_l .hg/cache/packs/manifests/ diff --git a/treemanifest/__init__.py b/treemanifest/__init__.py --- a/treemanifest/__init__.py +++ b/treemanifest/__init__.py @@ -128,6 +128,7 @@ import cstore import os +import shutil import struct import time @@ -263,6 +264,19 @@ if not util.safehasattr(repo, 'connectionpool'): repo.connectionpool = connectionpool.connectionpool(repo) +def _prunesharedpacks(repo, packpath): + """Wipe the packpath if it has too many packs in it""" + try: + numentries = len(os.listdir(packpath)) + # Note this is based on file count, not pack count. + config = repo.ui.configint("packs", "maxpackfilecount") + if config and numentries > config: + repo.ui.warn("purging shared treemanifest pack cache (%d entries) " + "-- too many files\n" % numentries) + shutil.rmtree(packpath, True) + except OSError: + pass + def setuptreestores(repo, mfl): if repo.ui.configbool("treemanifest", "server"): packpath = repo.vfs.join('cache/packs/%s' % PACK_CATEGORY) @@ -278,7 +292,7 @@ historystore, revlogstore, ) - + _prunesharedpacks(repo, packpath) return usecdatapack = repo.ui.configbool('remotefilelog', 'fastdatapack') @@ -286,6 +300,7 @@ if not util.safehasattr(repo, 'name'): repo.name = repo.ui.config('remotefilelog', 'reponame') packpath = shallowutil.getcachepackpath(repo, PACK_CATEGORY) + _prunesharedpacks(repo, packpath) localpackpath = shallowutil.getlocalpackpath(repo.svfs.vfs.base, PACK_CATEGORY)