sapling/fastmanifest.py
Laurent Charignon 82f0ca5a93 fastmanifest: introduce revset of what revision to cache
Summary:
For the moment the revset is just the draft revisions, it will evolve
to include likely rebase destination, branching points etc ...

Test Plan:
We add the result of querying the revset to the test to evaluate how
well the prediction match what is actually being accessed

Reviewers: durham, rmcelroy, ttung

Reviewed By: ttung

Subscribers: mjpieters

Differential Revision: https://phabricator.fb.com/D3115578

Tasks: 10604335

Signature: t1:3115578:1459374926:f9df976aae07db05a44f1fb69a4c83c2a11969dc
2016-03-31 16:00:06 -07:00

51 lines
1.4 KiB
Python

# fastmanifest.py
#
# Copyright 2016 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
"""
This extension adds fastmanifest, a treemanifest disk cache for speeding up
manifest comparison. It also contains utilities to investigate manifest access
patterns.
Configuration options:
[fastmanifest]
logfile = "" # Filename, is not empty will log access to any manifest
"""
from mercurial import extensions
from mercurial import manifest
from mercurial import revset
class manifestaccesslogger(object):
def __init__(self, logfile):
self._logfile = logfile
def revwrap(self, orig, *args, **kwargs):
r = orig(*args, **kwargs)
try:
with open(self._logfile, "a") as f:
f.write("%s\n" % r)
except EnvironmentError as e:
pass
return r
def fastmanifesttocache(repo, subset, x):
"""``fastmanifesttocache(])``
Revisions whose fastmanifest should be cached
For the moment just drafts
"""
return repo.revs("not public()")
def extsetup(ui):
logfile = ui.config("fastmanifest", "logfile", "")
if logfile:
logger = manifestaccesslogger(logfile)
extensions.wrapfunction(manifest.manifest, 'rev', logger.revwrap)
revset.symbols['fastmanifesttocache'] = fastmanifesttocache
revset.safesymbols.add('fastmanifesttocache')