diff --git a/remotefilelog/repack.py b/remotefilelog/repack.py --- a/remotefilelog/repack.py +++ b/remotefilelog/repack.py @@ -229,36 +229,35 @@ packing small things when possible, and rolling the packs up to the big ones over time). """ - generations = ui.configlist("remotefilelog", "data.generations", - ['1GB', '100MB', '1MB']) - generations = list(sorted((util.sizetoint(s) for s in generations), - reverse=True)) - generations.append(0) - gencountlimit = ui.configint('remotefilelog', 'data.gencountlimit', 2) - repacksizelimit = ui.configbytes('remotefilelog', 'data.repacksizelimit', - '100MB') - maxrepackpacks = ui.configint('remotefilelog', 'data.maxrepackpacks', 50) + opts = { + 'generations' : ui.configlist( + 'remotefilelog', 'data.generations', ['1GB', '100MB', '1MB']), + 'gencountlimit' : ui.configint( + 'remotefilelog', 'data.gencountlimit', 2), + 'repacksizelimit' : ui.configbytes( + 'remotefilelog', 'data.repacksizelimit', '100MB'), + 'maxrepackpacks' : ui.configint( + 'remotefilelog', 'data.maxrepackpacks', 50), + } - return _computeincrementalpack(ui, files, generations, datapack.PACKSUFFIX, - datapack.INDEXSUFFIX, gencountlimit, - repacksizelimit, maxrepackpacks) + return _computeincrementalpack( + files, datapack.PACKSUFFIX, datapack.INDEXSUFFIX, opts) def _computeincrementalhistorypack(ui, files): - generations = ui.configlist("remotefilelog", "history.generations", - ['100MB']) - generations = list(sorted((util.sizetoint(s) for s in generations), - reverse=True)) - generations.append(0) + opts = { + 'generations' : ui.configlist( + 'remotefilelog', 'history.generations', ['100MB']), + 'gencountlimit' : ui.configint( + 'remotefilelog', 'history.gencountlimit', 2), + 'repacksizelimit' : ui.configbytes( + 'remotefilelog', 'history.repacksizelimit', '100MB'), + 'maxrepackpacks' : ui.configint( + 'remotefilelog', 'history.maxrepackpacks', 50), + } - gencountlimit = ui.configint('remotefilelog', 'history.gencountlimit', 2) - repacksizelimit = ui.configbytes('remotefilelog', 'history.repacksizelimit', - '100MB') - maxrepackpacks = ui.configint('remotefilelog', 'history.maxrepackpacks', 50) - - return _computeincrementalpack(ui, files, generations, - historypack.PACKSUFFIX, historypack.INDEXSUFFIX, gencountlimit, - repacksizelimit, maxrepackpacks) + return _computeincrementalpack( + files, historypack.PACKSUFFIX, historypack.INDEXSUFFIX, opts) def _allpackfileswithsuffix(files, packsuffix, indexsuffix): result = [] @@ -276,8 +275,11 @@ return result -def _computeincrementalpack(ui, files, limits, packsuffix, indexsuffix, - gencountlimit, repacksizelimit, maxrepackpacks): +def _computeincrementalpack(files, packsuffix, indexsuffix, opts): + limits = list(sorted((util.sizetoint(s) for s in opts['generations']), + reverse=True)) + limits.append(0) + # Group the packs by generation (i.e. by size) generations = [] for i in xrange(len(limits)): @@ -301,7 +303,7 @@ # Find the largest generation with more than gencountlimit packs genpacks = [] for i, limit in enumerate(limits): - if len(generations[i]) > gencountlimit: + if len(generations[i]) > opts['gencountlimit']: # Sort to be smallest last, for easy popping later genpacks.extend(sorted(generations[i], reverse=True, key=lambda x: sizes[x])) @@ -311,8 +313,8 @@ chosenpacks = genpacks[-3:] genpacks = genpacks[:-3] repacksize = sum(sizes[n] for n in chosenpacks) - while (repacksize < repacksizelimit and genpacks and - len(chosenpacks) < maxrepackpacks): + while (repacksize < opts['repacksizelimit'] and genpacks and + len(chosenpacks) < opts['maxrepackpacks']): chosenpacks.append(genpacks.pop()) repacksize += sizes[chosenpacks[-1]]