2016-05-26 22:34:38 +03:00
|
|
|
# implementation.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.
|
2018-01-10 02:23:52 +03:00
|
|
|
from __future__ import absolute_import
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2016-07-12 03:34:01 +03:00
|
|
|
import collections
|
2016-05-26 22:34:38 +03:00
|
|
|
import os
|
|
|
|
import time
|
2016-06-09 00:33:02 +03:00
|
|
|
import heapq
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
from mercurial import error, manifest, mdiff, revlog, util
|
2018-01-24 23:30:25 +03:00
|
|
|
from ..extlib import cfastmanifest
|
2018-01-10 02:23:52 +03:00
|
|
|
from .metrics import metricscollector
|
2018-05-30 12:16:33 +03:00
|
|
|
from .constants import CACHE_SUBDIR, DEFAULT_MAX_MEMORY_ENTRIES
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2016-08-24 21:31:06 +03:00
|
|
|
try:
|
2018-01-24 23:30:25 +03:00
|
|
|
from ..extlib import cstore
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2016-08-24 21:31:06 +03:00
|
|
|
supportsctree = True
|
|
|
|
except ImportError:
|
|
|
|
supportsctree = False
|
|
|
|
|
2016-12-14 20:41:15 +03:00
|
|
|
propertycache = util.propertycache
|
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2016-05-26 22:34:38 +03:00
|
|
|
class hybridmanifest(object):
|
|
|
|
"""
|
|
|
|
Hybrid manifest that behaves like a lazy manifest.
|
|
|
|
|
|
|
|
Initialized with one of the three:
|
|
|
|
- flat an existing flat manifest
|
|
|
|
- fast an existing fast manifest
|
|
|
|
- loadflat a function to load a flat manifest from disk
|
|
|
|
"""
|
2018-05-30 12:16:33 +03:00
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
ui,
|
|
|
|
opener,
|
|
|
|
manifestlog,
|
|
|
|
flat=None,
|
|
|
|
fast=None,
|
|
|
|
loadflat=None,
|
|
|
|
tree=None,
|
|
|
|
node=None,
|
|
|
|
):
|
2016-05-26 22:34:38 +03:00
|
|
|
self.__flatmanifest = flat
|
|
|
|
self.loadflat = loadflat
|
|
|
|
|
2017-10-24 06:13:13 +03:00
|
|
|
if supportsctree and ui.configbool("fastmanifest", "usetree"):
|
2016-08-24 21:31:06 +03:00
|
|
|
self.__treemanifest = tree
|
|
|
|
else:
|
|
|
|
self.__treemanifest = False
|
|
|
|
|
2017-10-24 06:02:57 +03:00
|
|
|
if ui.configbool("fastmanifest", "usecache"):
|
2017-01-11 01:43:32 +03:00
|
|
|
self.__cachedmanifest = fast
|
|
|
|
else:
|
|
|
|
self.__cachedmanifest = False
|
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
assert (
|
|
|
|
self.__flatmanifest is not None
|
|
|
|
or self.__cachedmanifest not in (None, False)
|
|
|
|
or self.__treemanifest not in (None, False)
|
|
|
|
or self.loadflat is not None
|
|
|
|
)
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
self.ui = ui
|
|
|
|
self.opener = opener
|
2017-08-08 05:27:18 +03:00
|
|
|
self.manifestlog = manifestlog
|
2016-05-26 22:34:38 +03:00
|
|
|
self.node = node
|
treemanifest: improve integration with fastmanifest
Summary:
Previously treemanifest and fastmanifest were largely unaware of each other. If
the fastmanifest was available, we'd use that. If not, we'd try tree. Then we'd
fall back to flat. When comparing two manifests, this could cause problems since
if one manifest was fast and one was tree, we'd have to fall all the way back to
flat manifests to compare them.
This patch adds the ability to build a treemanifest from a fastmanifest for
inmemory manifests that were copied from a commit that has both a fastmanifest
and a treemanifest. We do it by diff'ing the inmemory fastmanifest with the
commit fastmanifest, then applying that diff to the commit's treemanifest. Then
we can compare that tree with the other tree.
This is particularly useful when doing things like 'hg up master' after a pull.
The new master commit probably has a treemanifest, but doesn't yet have a
fastmanifest, while the commit the user is on probably has both. Now we can do
that hg up without having to parse a full manifest.
Once treemanifest has been enabled, every commit (both pulled and user created)
should have treemanifests. Therefore this case should never happen when
comparing two normal commits. So in theory, the only way to hit this case is
when Mercurial does a manifest.copy() on a manifest that has a fastmanifest
(like when reading a workingctx which must copy the commit manifest and apply
working copy changes), since the copy will choose to copy the fastmanifest and
leave the treemanifest behind. This patch addresses that case, so I think there
shouldn't be other cases.
Test Plan: Adds a test that covers this case.
Reviewers: #mercurial, rmcelroy
Reviewed By: rmcelroy
Subscribers: rmcelroy, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D4402604
Signature: t1:4402604:1484216866:1c075f314026aaf608095b4aca37c9a4277ababa
2017-01-12 23:26:21 +03:00
|
|
|
self.basemanifest = None
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
self.cachekey = revlog.hex(self.node) if self.node is not None else None
|
|
|
|
|
|
|
|
self.fastcache = fastmanifestcache.getinstance(opener, self.ui)
|
2016-10-21 21:02:24 +03:00
|
|
|
self.treecache = treemanifestcache.getinstance(opener, self.ui)
|
2018-05-30 12:16:33 +03:00
|
|
|
self.debugfastmanifest = self.ui.configbool(
|
|
|
|
"fastmanifest", "debugfastmanifest", False
|
|
|
|
)
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
self.incache = True if self.__cachedmanifest not in (None, False) else None
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2016-06-01 23:46:38 +03:00
|
|
|
if self.ui.configbool("fastmanifest", "silent"):
|
2016-05-26 22:34:38 +03:00
|
|
|
self.debug = _silent_debug
|
|
|
|
else:
|
|
|
|
self.debug = self.ui.debug
|
|
|
|
|
|
|
|
def _flatmanifest(self):
|
|
|
|
if self.__flatmanifest is None:
|
|
|
|
if self.loadflat is not None:
|
|
|
|
# Load the manifest and cache it.
|
|
|
|
self.__flatmanifest = self.loadflat()
|
|
|
|
|
|
|
|
if isinstance(self.__flatmanifest, hybridmanifest):
|
|
|
|
# See comment in extsetup to see why we have to do that
|
|
|
|
self.__flatmanifest = self.__flatmanifest._flatmanifest()
|
2017-01-11 01:43:32 +03:00
|
|
|
elif self.__cachedmanifest not in (None, False):
|
2016-05-26 22:34:38 +03:00
|
|
|
# build a flat manifest from the text of the fastmanifest.
|
|
|
|
self.__flatmanifest = manifest.manifestdict(
|
2018-05-30 12:16:33 +03:00
|
|
|
self.__cachedmanifest.text()
|
|
|
|
)
|
2017-01-11 01:43:32 +03:00
|
|
|
elif self.__treemanifest not in (None, False):
|
2016-10-21 21:02:13 +03:00
|
|
|
# build a flat manifest from the text of the fastmanifest.
|
2018-05-30 12:16:33 +03:00
|
|
|
self.__flatmanifest = manifest.manifestdict(self.__treemanifest.text())
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
assert isinstance(self.__flatmanifest, manifest.manifestdict)
|
|
|
|
return self.__flatmanifest
|
|
|
|
|
|
|
|
def _cachedmanifest(self):
|
2017-01-11 01:43:32 +03:00
|
|
|
if self.__cachedmanifest is False:
|
|
|
|
return None
|
|
|
|
|
2016-05-26 22:34:38 +03:00
|
|
|
if self.incache is None:
|
|
|
|
# Cache lookup
|
2018-05-30 12:16:33 +03:00
|
|
|
if self.cachekey is not None and self.cachekey in self.fastcache:
|
2016-06-17 19:35:39 +03:00
|
|
|
self.__cachedmanifest = self.fastcache[self.cachekey]
|
2016-05-26 22:34:38 +03:00
|
|
|
elif self.node == revlog.nullid:
|
|
|
|
fm = cfastmanifest.fastmanifest()
|
|
|
|
self.__cachedmanifest = fastmanifestdict(fm)
|
|
|
|
elif self.debugfastmanifest:
|
|
|
|
# in debug mode, we always convert into a fastmanifest.
|
|
|
|
r = self._flatmanifest()
|
|
|
|
fm = cfastmanifest.fastmanifest(r.text())
|
|
|
|
self.__cachedmanifest = fastmanifestdict(fm)
|
|
|
|
|
|
|
|
self.incache = self.__cachedmanifest is not None
|
2018-05-30 12:16:33 +03:00
|
|
|
metricscollector.get().recordsample(
|
|
|
|
"cachehit", hit=self.incache, node=self.cachekey
|
|
|
|
)
|
|
|
|
self.debug(
|
|
|
|
"[FM] cache %s for fastmanifest %s\n"
|
|
|
|
% ("hit" if self.incache else "miss", self.cachekey)
|
|
|
|
)
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
return self.__cachedmanifest
|
|
|
|
|
2016-08-24 21:31:06 +03:00
|
|
|
def _treemanifest(self):
|
2017-01-11 01:43:32 +03:00
|
|
|
if self.__treemanifest is False:
|
2016-08-24 21:31:06 +03:00
|
|
|
return None
|
|
|
|
assert supportsctree
|
|
|
|
if self.__treemanifest is None:
|
2017-01-11 01:43:32 +03:00
|
|
|
if self.node is None:
|
|
|
|
return None
|
2016-10-21 21:02:24 +03:00
|
|
|
if self.node in self.treecache:
|
|
|
|
self.__treemanifest = self.treecache[self.node]
|
2016-12-03 01:38:02 +03:00
|
|
|
elif self.node == revlog.nullid:
|
2017-08-08 05:27:18 +03:00
|
|
|
store = self.manifestlog.datastore
|
2017-02-24 01:03:03 +03:00
|
|
|
self.__treemanifest = cstore.treemanifest(store)
|
2016-08-24 21:31:06 +03:00
|
|
|
else:
|
2017-08-08 05:27:18 +03:00
|
|
|
store = self.manifestlog.datastore
|
2017-09-22 07:23:40 +03:00
|
|
|
self.ui.pushbuffer()
|
2017-04-20 07:14:03 +03:00
|
|
|
try:
|
2018-05-30 12:16:33 +03:00
|
|
|
store.get("", self.node)
|
|
|
|
self.__treemanifest = cstore.treemanifest(store, self.node)
|
2017-09-22 07:23:40 +03:00
|
|
|
# The buffer is only to eat certain errors, so show
|
|
|
|
# non-error messages.
|
|
|
|
output = self.ui.popbuffer()
|
|
|
|
if output:
|
|
|
|
self.ui.status(output)
|
|
|
|
except (KeyError, error.Abort):
|
2016-10-21 21:02:24 +03:00
|
|
|
# Record that it doesn't exist, so we don't keep checking
|
|
|
|
# the store.
|
2017-09-22 07:23:40 +03:00
|
|
|
self.ui.popbuffer()
|
|
|
|
# Eat the buffer so we don't print a remote: warning
|
2016-10-21 21:02:24 +03:00
|
|
|
self.__treemanifest = False
|
|
|
|
return None
|
2017-09-22 09:21:18 +03:00
|
|
|
except Exception:
|
2017-09-22 07:23:40 +03:00
|
|
|
# Other errors should be printed
|
|
|
|
output = self.ui.popbuffer()
|
|
|
|
if output:
|
|
|
|
self.ui.status(output)
|
|
|
|
raise
|
2016-08-24 21:31:06 +03:00
|
|
|
|
|
|
|
return self.__treemanifest
|
|
|
|
|
2016-05-26 22:34:38 +03:00
|
|
|
def _incache(self):
|
|
|
|
if self.incache or self.debugfastmanifest:
|
|
|
|
return True
|
|
|
|
elif self.cachekey:
|
2016-06-17 19:35:39 +03:00
|
|
|
return self.cachekey in self.fastcache
|
2016-05-26 22:34:38 +03:00
|
|
|
return False
|
|
|
|
|
|
|
|
def _manifest(self, operation):
|
|
|
|
# Get the manifest most suited for the operations (flat or cached)
|
|
|
|
# TODO: return fastmanifest when suitable
|
|
|
|
c = self._cachedmanifest()
|
|
|
|
if c is not None:
|
|
|
|
return c
|
|
|
|
|
2016-08-24 21:31:06 +03:00
|
|
|
t = self._treemanifest()
|
|
|
|
if t is not None:
|
|
|
|
return t
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2016-08-24 21:31:06 +03:00
|
|
|
r = self._flatmanifest()
|
2016-05-26 22:34:38 +03:00
|
|
|
return r
|
|
|
|
|
|
|
|
# Proxy all the manifest methods to the flatmanifest except magic methods
|
|
|
|
def __getattr__(self, name):
|
|
|
|
return getattr(self._manifest(name), name)
|
|
|
|
|
|
|
|
# Magic methods should be proxied differently than __getattr__
|
|
|
|
# For the moment all methods they all use the _flatmanifest
|
|
|
|
def __iter__(self):
|
2018-05-30 12:16:33 +03:00
|
|
|
return self._manifest("__iter__").__iter__()
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
def __contains__(self, key):
|
2018-05-30 12:16:33 +03:00
|
|
|
return self._manifest("__contains__").__contains__(key)
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
def __getitem__(self, key):
|
2018-05-30 12:16:33 +03:00
|
|
|
return self._manifest("__getitem__").__getitem__(key)
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
def __setitem__(self, key, val):
|
2018-05-30 12:16:33 +03:00
|
|
|
return self._manifest("__setitem__").__setitem__(key, val)
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
def __delitem__(self, key):
|
2018-05-30 12:16:33 +03:00
|
|
|
return self._manifest("__delitem__").__delitem__(key)
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2016-10-15 02:01:12 +03:00
|
|
|
def __nonzero__(self):
|
2018-05-30 12:16:33 +03:00
|
|
|
return bool(self._manifest("__nonzero__"))
|
2016-10-15 02:01:12 +03:00
|
|
|
|
2017-03-21 04:58:10 +03:00
|
|
|
__bool__ = __nonzero__
|
|
|
|
|
2016-05-26 22:34:38 +03:00
|
|
|
def __len__(self):
|
2018-05-30 12:16:33 +03:00
|
|
|
return len(self._manifest("__len__"))
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2016-12-03 01:37:33 +03:00
|
|
|
def text(self, *args, **kwargs):
|
|
|
|
# Normally we would prefer treemanifest instead of flat, but for text()
|
|
|
|
# flat is actually faster for now.
|
|
|
|
m = self._cachedmanifest()
|
|
|
|
if m is None:
|
|
|
|
m = self._flatmanifest()
|
|
|
|
if m is None:
|
|
|
|
m = self._treemanifest()
|
|
|
|
return m.text(*args, **kwargs)
|
|
|
|
|
2016-12-03 01:37:40 +03:00
|
|
|
def fastdelta(self, base, changes):
|
2018-05-30 12:16:33 +03:00
|
|
|
m = self._manifest("fastdelta")
|
2017-02-24 01:03:03 +03:00
|
|
|
if isinstance(m, cstore.treemanifest):
|
2017-01-11 01:43:32 +03:00
|
|
|
return fastdelta(m, m.find, base, changes)
|
|
|
|
return m.fastdelta(base, changes)
|
2016-12-03 01:37:40 +03:00
|
|
|
|
2017-01-11 01:43:32 +03:00
|
|
|
def _converttohybridmanifest(self, m):
|
2016-06-01 21:00:53 +03:00
|
|
|
if isinstance(m, hybridmanifest):
|
|
|
|
return m
|
|
|
|
elif isinstance(m, fastmanifestdict):
|
2018-05-30 12:16:33 +03:00
|
|
|
return hybridmanifest(self.ui, self.opener, self.manifestlog, fast=m)
|
2016-06-01 21:00:53 +03:00
|
|
|
elif isinstance(m, manifest.manifestdict):
|
2018-05-30 12:16:33 +03:00
|
|
|
return hybridmanifest(self.ui, self.opener, self.manifestlog, flat=m)
|
2017-02-24 01:03:03 +03:00
|
|
|
elif supportsctree and isinstance(m, cstore.treemanifest):
|
2018-05-30 12:16:33 +03:00
|
|
|
return hybridmanifest(self.ui, self.opener, self.manifestlog, tree=m)
|
2016-05-26 22:34:38 +03:00
|
|
|
else:
|
2016-06-01 21:00:53 +03:00
|
|
|
raise ValueError("unknown manifest type {0}".format(type(m)))
|
|
|
|
|
|
|
|
def copy(self):
|
2018-05-30 12:16:33 +03:00
|
|
|
copy = self._manifest("copy").copy()
|
treemanifest: improve integration with fastmanifest
Summary:
Previously treemanifest and fastmanifest were largely unaware of each other. If
the fastmanifest was available, we'd use that. If not, we'd try tree. Then we'd
fall back to flat. When comparing two manifests, this could cause problems since
if one manifest was fast and one was tree, we'd have to fall all the way back to
flat manifests to compare them.
This patch adds the ability to build a treemanifest from a fastmanifest for
inmemory manifests that were copied from a commit that has both a fastmanifest
and a treemanifest. We do it by diff'ing the inmemory fastmanifest with the
commit fastmanifest, then applying that diff to the commit's treemanifest. Then
we can compare that tree with the other tree.
This is particularly useful when doing things like 'hg up master' after a pull.
The new master commit probably has a treemanifest, but doesn't yet have a
fastmanifest, while the commit the user is on probably has both. Now we can do
that hg up without having to parse a full manifest.
Once treemanifest has been enabled, every commit (both pulled and user created)
should have treemanifests. Therefore this case should never happen when
comparing two normal commits. So in theory, the only way to hit this case is
when Mercurial does a manifest.copy() on a manifest that has a fastmanifest
(like when reading a workingctx which must copy the commit manifest and apply
working copy changes), since the copy will choose to copy the fastmanifest and
leave the treemanifest behind. This patch addresses that case, so I think there
shouldn't be other cases.
Test Plan: Adds a test that covers this case.
Reviewers: #mercurial, rmcelroy
Reviewed By: rmcelroy
Subscribers: rmcelroy, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D4402604
Signature: t1:4402604:1484216866:1c075f314026aaf608095b4aca37c9a4277ababa
2017-01-12 23:26:21 +03:00
|
|
|
hybridmf = self._converttohybridmanifest(copy)
|
|
|
|
hybridmf.basemanifest = self.basemanifest or self
|
|
|
|
return hybridmf
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
def matches(self, *args, **kwargs):
|
2018-05-30 12:16:33 +03:00
|
|
|
matches = self._manifest("matches").matches(*args, **kwargs)
|
treemanifest: improve integration with fastmanifest
Summary:
Previously treemanifest and fastmanifest were largely unaware of each other. If
the fastmanifest was available, we'd use that. If not, we'd try tree. Then we'd
fall back to flat. When comparing two manifests, this could cause problems since
if one manifest was fast and one was tree, we'd have to fall all the way back to
flat manifests to compare them.
This patch adds the ability to build a treemanifest from a fastmanifest for
inmemory manifests that were copied from a commit that has both a fastmanifest
and a treemanifest. We do it by diff'ing the inmemory fastmanifest with the
commit fastmanifest, then applying that diff to the commit's treemanifest. Then
we can compare that tree with the other tree.
This is particularly useful when doing things like 'hg up master' after a pull.
The new master commit probably has a treemanifest, but doesn't yet have a
fastmanifest, while the commit the user is on probably has both. Now we can do
that hg up without having to parse a full manifest.
Once treemanifest has been enabled, every commit (both pulled and user created)
should have treemanifests. Therefore this case should never happen when
comparing two normal commits. So in theory, the only way to hit this case is
when Mercurial does a manifest.copy() on a manifest that has a fastmanifest
(like when reading a workingctx which must copy the commit manifest and apply
working copy changes), since the copy will choose to copy the fastmanifest and
leave the treemanifest behind. This patch addresses that case, so I think there
shouldn't be other cases.
Test Plan: Adds a test that covers this case.
Reviewers: #mercurial, rmcelroy
Reviewed By: rmcelroy
Subscribers: rmcelroy, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D4402604
Signature: t1:4402604:1484216866:1c075f314026aaf608095b4aca37c9a4277ababa
2017-01-12 23:26:21 +03:00
|
|
|
hybridmf = self._converttohybridmanifest(matches)
|
|
|
|
hybridmf.basemanifest = self.basemanifest or self
|
|
|
|
return hybridmf
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2016-07-06 23:39:42 +03:00
|
|
|
def _getmatchingtypemanifest(self, m2, operation):
|
2016-05-26 22:34:38 +03:00
|
|
|
# Find _m1 and _m2 of the same type, to provide the fastest computation
|
|
|
|
if isinstance(m2, hybridmanifest):
|
2016-07-06 23:39:42 +03:00
|
|
|
self.debug("[FM] %s: other side is hybrid manifest\n" % operation)
|
treemanifest: improve integration with fastmanifest
Summary:
Previously treemanifest and fastmanifest were largely unaware of each other. If
the fastmanifest was available, we'd use that. If not, we'd try tree. Then we'd
fall back to flat. When comparing two manifests, this could cause problems since
if one manifest was fast and one was tree, we'd have to fall all the way back to
flat manifests to compare them.
This patch adds the ability to build a treemanifest from a fastmanifest for
inmemory manifests that were copied from a commit that has both a fastmanifest
and a treemanifest. We do it by diff'ing the inmemory fastmanifest with the
commit fastmanifest, then applying that diff to the commit's treemanifest. Then
we can compare that tree with the other tree.
This is particularly useful when doing things like 'hg up master' after a pull.
The new master commit probably has a treemanifest, but doesn't yet have a
fastmanifest, while the commit the user is on probably has both. Now we can do
that hg up without having to parse a full manifest.
Once treemanifest has been enabled, every commit (both pulled and user created)
should have treemanifests. Therefore this case should never happen when
comparing two normal commits. So in theory, the only way to hit this case is
when Mercurial does a manifest.copy() on a manifest that has a fastmanifest
(like when reading a workingctx which must copy the commit manifest and apply
working copy changes), since the copy will choose to copy the fastmanifest and
leave the treemanifest behind. This patch addresses that case, so I think there
shouldn't be other cases.
Test Plan: Adds a test that covers this case.
Reviewers: #mercurial, rmcelroy
Reviewed By: rmcelroy
Subscribers: rmcelroy, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D4402604
Signature: t1:4402604:1484216866:1c075f314026aaf608095b4aca37c9a4277ababa
2017-01-12 23:26:21 +03:00
|
|
|
|
|
|
|
# Best case: both are in the cache
|
2016-05-26 22:34:38 +03:00
|
|
|
if self._incache() and m2._incache():
|
treemanifest: improve integration with fastmanifest
Summary:
Previously treemanifest and fastmanifest were largely unaware of each other. If
the fastmanifest was available, we'd use that. If not, we'd try tree. Then we'd
fall back to flat. When comparing two manifests, this could cause problems since
if one manifest was fast and one was tree, we'd have to fall all the way back to
flat manifests to compare them.
This patch adds the ability to build a treemanifest from a fastmanifest for
inmemory manifests that were copied from a commit that has both a fastmanifest
and a treemanifest. We do it by diff'ing the inmemory fastmanifest with the
commit fastmanifest, then applying that diff to the commit's treemanifest. Then
we can compare that tree with the other tree.
This is particularly useful when doing things like 'hg up master' after a pull.
The new master commit probably has a treemanifest, but doesn't yet have a
fastmanifest, while the commit the user is on probably has both. Now we can do
that hg up without having to parse a full manifest.
Once treemanifest has been enabled, every commit (both pulled and user created)
should have treemanifests. Therefore this case should never happen when
comparing two normal commits. So in theory, the only way to hit this case is
when Mercurial does a manifest.copy() on a manifest that has a fastmanifest
(like when reading a workingctx which must copy the commit manifest and apply
working copy changes), since the copy will choose to copy the fastmanifest and
leave the treemanifest behind. This patch addresses that case, so I think there
shouldn't be other cases.
Test Plan: Adds a test that covers this case.
Reviewers: #mercurial, rmcelroy
Reviewed By: rmcelroy
Subscribers: rmcelroy, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D4402604
Signature: t1:4402604:1484216866:1c075f314026aaf608095b4aca37c9a4277ababa
2017-01-12 23:26:21 +03:00
|
|
|
cachedmf1 = self._cachedmanifest()
|
|
|
|
cachedmf2 = m2._cachedmanifest()
|
|
|
|
if cachedmf1 is not None and cachedmf2 is not None:
|
|
|
|
return cachedmf1, cachedmf2, True
|
|
|
|
|
|
|
|
# Second best: both are trees
|
|
|
|
treemf1 = self._treemanifest()
|
|
|
|
treemf2 = m2._treemanifest()
|
|
|
|
if treemf1 is not None and treemf2 is not None:
|
2018-05-30 12:16:33 +03:00
|
|
|
self.debug(("[FM] %s: loaded matching tree " "manifests\n") % operation)
|
treemanifest: improve integration with fastmanifest
Summary:
Previously treemanifest and fastmanifest were largely unaware of each other. If
the fastmanifest was available, we'd use that. If not, we'd try tree. Then we'd
fall back to flat. When comparing two manifests, this could cause problems since
if one manifest was fast and one was tree, we'd have to fall all the way back to
flat manifests to compare them.
This patch adds the ability to build a treemanifest from a fastmanifest for
inmemory manifests that were copied from a commit that has both a fastmanifest
and a treemanifest. We do it by diff'ing the inmemory fastmanifest with the
commit fastmanifest, then applying that diff to the commit's treemanifest. Then
we can compare that tree with the other tree.
This is particularly useful when doing things like 'hg up master' after a pull.
The new master commit probably has a treemanifest, but doesn't yet have a
fastmanifest, while the commit the user is on probably has both. Now we can do
that hg up without having to parse a full manifest.
Once treemanifest has been enabled, every commit (both pulled and user created)
should have treemanifests. Therefore this case should never happen when
comparing two normal commits. So in theory, the only way to hit this case is
when Mercurial does a manifest.copy() on a manifest that has a fastmanifest
(like when reading a workingctx which must copy the commit manifest and apply
working copy changes), since the copy will choose to copy the fastmanifest and
leave the treemanifest behind. This patch addresses that case, so I think there
shouldn't be other cases.
Test Plan: Adds a test that covers this case.
Reviewers: #mercurial, rmcelroy
Reviewed By: rmcelroy
Subscribers: rmcelroy, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D4402604
Signature: t1:4402604:1484216866:1c075f314026aaf608095b4aca37c9a4277ababa
2017-01-12 23:26:21 +03:00
|
|
|
return treemf1, treemf2, False
|
|
|
|
|
|
|
|
# Third best: one tree, one computed tree
|
|
|
|
def canbuildtree(m):
|
2018-05-30 12:16:33 +03:00
|
|
|
return (
|
|
|
|
m._cachedmanifest() is not None
|
|
|
|
and m.basemanifest is not None
|
|
|
|
and m.basemanifest._cachedmanifest() is not None
|
|
|
|
and m.basemanifest._treemanifest() is not None
|
|
|
|
)
|
treemanifest: improve integration with fastmanifest
Summary:
Previously treemanifest and fastmanifest were largely unaware of each other. If
the fastmanifest was available, we'd use that. If not, we'd try tree. Then we'd
fall back to flat. When comparing two manifests, this could cause problems since
if one manifest was fast and one was tree, we'd have to fall all the way back to
flat manifests to compare them.
This patch adds the ability to build a treemanifest from a fastmanifest for
inmemory manifests that were copied from a commit that has both a fastmanifest
and a treemanifest. We do it by diff'ing the inmemory fastmanifest with the
commit fastmanifest, then applying that diff to the commit's treemanifest. Then
we can compare that tree with the other tree.
This is particularly useful when doing things like 'hg up master' after a pull.
The new master commit probably has a treemanifest, but doesn't yet have a
fastmanifest, while the commit the user is on probably has both. Now we can do
that hg up without having to parse a full manifest.
Once treemanifest has been enabled, every commit (both pulled and user created)
should have treemanifests. Therefore this case should never happen when
comparing two normal commits. So in theory, the only way to hit this case is
when Mercurial does a manifest.copy() on a manifest that has a fastmanifest
(like when reading a workingctx which must copy the commit manifest and apply
working copy changes), since the copy will choose to copy the fastmanifest and
leave the treemanifest behind. This patch addresses that case, so I think there
shouldn't be other cases.
Test Plan: Adds a test that covers this case.
Reviewers: #mercurial, rmcelroy
Reviewed By: rmcelroy
Subscribers: rmcelroy, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D4402604
Signature: t1:4402604:1484216866:1c075f314026aaf608095b4aca37c9a4277ababa
2017-01-12 23:26:21 +03:00
|
|
|
|
|
|
|
def buildtree(m):
|
2018-05-30 12:16:33 +03:00
|
|
|
diff = m.basemanifest._cachedmanifest().diff(m._cachedmanifest())
|
treemanifest: improve integration with fastmanifest
Summary:
Previously treemanifest and fastmanifest were largely unaware of each other. If
the fastmanifest was available, we'd use that. If not, we'd try tree. Then we'd
fall back to flat. When comparing two manifests, this could cause problems since
if one manifest was fast and one was tree, we'd have to fall all the way back to
flat manifests to compare them.
This patch adds the ability to build a treemanifest from a fastmanifest for
inmemory manifests that were copied from a commit that has both a fastmanifest
and a treemanifest. We do it by diff'ing the inmemory fastmanifest with the
commit fastmanifest, then applying that diff to the commit's treemanifest. Then
we can compare that tree with the other tree.
This is particularly useful when doing things like 'hg up master' after a pull.
The new master commit probably has a treemanifest, but doesn't yet have a
fastmanifest, while the commit the user is on probably has both. Now we can do
that hg up without having to parse a full manifest.
Once treemanifest has been enabled, every commit (both pulled and user created)
should have treemanifests. Therefore this case should never happen when
comparing two normal commits. So in theory, the only way to hit this case is
when Mercurial does a manifest.copy() on a manifest that has a fastmanifest
(like when reading a workingctx which must copy the commit manifest and apply
working copy changes), since the copy will choose to copy the fastmanifest and
leave the treemanifest behind. This patch addresses that case, so I think there
shouldn't be other cases.
Test Plan: Adds a test that covers this case.
Reviewers: #mercurial, rmcelroy
Reviewed By: rmcelroy
Subscribers: rmcelroy, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D4402604
Signature: t1:4402604:1484216866:1c075f314026aaf608095b4aca37c9a4277ababa
2017-01-12 23:26:21 +03:00
|
|
|
temptreemf = m.basemanifest._treemanifest().copy()
|
|
|
|
for f, ((an, af), (bn, bf)) in diff.iteritems():
|
|
|
|
temptreemf.set(f, bn, bf)
|
|
|
|
return temptreemf
|
|
|
|
|
|
|
|
if treemf1 is not None and canbuildtree(m2):
|
2018-05-30 12:16:33 +03:00
|
|
|
self.debug(
|
|
|
|
("[FM] %s: computed matching tree " "manifests\n") % operation
|
|
|
|
)
|
treemanifest: improve integration with fastmanifest
Summary:
Previously treemanifest and fastmanifest were largely unaware of each other. If
the fastmanifest was available, we'd use that. If not, we'd try tree. Then we'd
fall back to flat. When comparing two manifests, this could cause problems since
if one manifest was fast and one was tree, we'd have to fall all the way back to
flat manifests to compare them.
This patch adds the ability to build a treemanifest from a fastmanifest for
inmemory manifests that were copied from a commit that has both a fastmanifest
and a treemanifest. We do it by diff'ing the inmemory fastmanifest with the
commit fastmanifest, then applying that diff to the commit's treemanifest. Then
we can compare that tree with the other tree.
This is particularly useful when doing things like 'hg up master' after a pull.
The new master commit probably has a treemanifest, but doesn't yet have a
fastmanifest, while the commit the user is on probably has both. Now we can do
that hg up without having to parse a full manifest.
Once treemanifest has been enabled, every commit (both pulled and user created)
should have treemanifests. Therefore this case should never happen when
comparing two normal commits. So in theory, the only way to hit this case is
when Mercurial does a manifest.copy() on a manifest that has a fastmanifest
(like when reading a workingctx which must copy the commit manifest and apply
working copy changes), since the copy will choose to copy the fastmanifest and
leave the treemanifest behind. This patch addresses that case, so I think there
shouldn't be other cases.
Test Plan: Adds a test that covers this case.
Reviewers: #mercurial, rmcelroy
Reviewed By: rmcelroy
Subscribers: rmcelroy, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D4402604
Signature: t1:4402604:1484216866:1c075f314026aaf608095b4aca37c9a4277ababa
2017-01-12 23:26:21 +03:00
|
|
|
return treemf1, buildtree(m2), False
|
|
|
|
elif treemf2 is not None and canbuildtree(self):
|
2018-05-30 12:16:33 +03:00
|
|
|
self.debug(
|
|
|
|
("[FM] %s: computed matching tree " "manifests\n") % operation
|
|
|
|
)
|
treemanifest: improve integration with fastmanifest
Summary:
Previously treemanifest and fastmanifest were largely unaware of each other. If
the fastmanifest was available, we'd use that. If not, we'd try tree. Then we'd
fall back to flat. When comparing two manifests, this could cause problems since
if one manifest was fast and one was tree, we'd have to fall all the way back to
flat manifests to compare them.
This patch adds the ability to build a treemanifest from a fastmanifest for
inmemory manifests that were copied from a commit that has both a fastmanifest
and a treemanifest. We do it by diff'ing the inmemory fastmanifest with the
commit fastmanifest, then applying that diff to the commit's treemanifest. Then
we can compare that tree with the other tree.
This is particularly useful when doing things like 'hg up master' after a pull.
The new master commit probably has a treemanifest, but doesn't yet have a
fastmanifest, while the commit the user is on probably has both. Now we can do
that hg up without having to parse a full manifest.
Once treemanifest has been enabled, every commit (both pulled and user created)
should have treemanifests. Therefore this case should never happen when
comparing two normal commits. So in theory, the only way to hit this case is
when Mercurial does a manifest.copy() on a manifest that has a fastmanifest
(like when reading a workingctx which must copy the commit manifest and apply
working copy changes), since the copy will choose to copy the fastmanifest and
leave the treemanifest behind. This patch addresses that case, so I think there
shouldn't be other cases.
Test Plan: Adds a test that covers this case.
Reviewers: #mercurial, rmcelroy
Reviewed By: rmcelroy
Subscribers: rmcelroy, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D4402604
Signature: t1:4402604:1484216866:1c075f314026aaf608095b4aca37c9a4277ababa
2017-01-12 23:26:21 +03:00
|
|
|
return buildtree(self), treemf2, False
|
|
|
|
|
|
|
|
# Worst: both flat
|
|
|
|
self.debug("[FM] %s: cache and tree miss\n" % operation)
|
|
|
|
return self._flatmanifest(), m2._flatmanifest(), False
|
2016-05-26 22:34:38 +03:00
|
|
|
else:
|
|
|
|
# This happens when diffing against a new manifest (like rev -1)
|
2016-07-06 23:39:42 +03:00
|
|
|
self.debug("[FM] %s: other side not hybrid manifest\n" % operation)
|
treemanifest: improve integration with fastmanifest
Summary:
Previously treemanifest and fastmanifest were largely unaware of each other. If
the fastmanifest was available, we'd use that. If not, we'd try tree. Then we'd
fall back to flat. When comparing two manifests, this could cause problems since
if one manifest was fast and one was tree, we'd have to fall all the way back to
flat manifests to compare them.
This patch adds the ability to build a treemanifest from a fastmanifest for
inmemory manifests that were copied from a commit that has both a fastmanifest
and a treemanifest. We do it by diff'ing the inmemory fastmanifest with the
commit fastmanifest, then applying that diff to the commit's treemanifest. Then
we can compare that tree with the other tree.
This is particularly useful when doing things like 'hg up master' after a pull.
The new master commit probably has a treemanifest, but doesn't yet have a
fastmanifest, while the commit the user is on probably has both. Now we can do
that hg up without having to parse a full manifest.
Once treemanifest has been enabled, every commit (both pulled and user created)
should have treemanifests. Therefore this case should never happen when
comparing two normal commits. So in theory, the only way to hit this case is
when Mercurial does a manifest.copy() on a manifest that has a fastmanifest
(like when reading a workingctx which must copy the commit manifest and apply
working copy changes), since the copy will choose to copy the fastmanifest and
leave the treemanifest behind. This patch addresses that case, so I think there
shouldn't be other cases.
Test Plan: Adds a test that covers this case.
Reviewers: #mercurial, rmcelroy
Reviewed By: rmcelroy
Subscribers: rmcelroy, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D4402604
Signature: t1:4402604:1484216866:1c075f314026aaf608095b4aca37c9a4277ababa
2017-01-12 23:26:21 +03:00
|
|
|
return self._flatmanifest(), m2, False
|
2016-06-09 00:34:26 +03:00
|
|
|
|
|
|
|
def diff(self, m2, *args, **kwargs):
|
|
|
|
self.debug("[FM] performing diff\n")
|
2016-07-06 23:39:42 +03:00
|
|
|
_m1, _m2, hit = self._getmatchingtypemanifest(m2, "diff")
|
2016-06-30 21:51:06 +03:00
|
|
|
metricscollector.get().recordsample("diffcachehit", hit=hit)
|
2016-05-26 22:34:38 +03:00
|
|
|
return _m1.diff(_m2, *args, **kwargs)
|
|
|
|
|
2016-05-27 03:03:56 +03:00
|
|
|
def filesnotin(self, m2, *args, **kwargs):
|
2016-05-27 22:41:56 +03:00
|
|
|
self.debug("[FM] performing filesnotin\n")
|
2016-07-06 23:39:42 +03:00
|
|
|
_m1, _m2, hit = self._getmatchingtypemanifest(m2, "filesnotin")
|
2016-06-30 21:51:06 +03:00
|
|
|
metricscollector.get().recordsample("filesnotincachehit", hit=hit)
|
2016-05-27 03:03:56 +03:00
|
|
|
return _m1.filesnotin(_m2, *args, **kwargs)
|
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2016-05-26 22:34:38 +03:00
|
|
|
class fastmanifestdict(object):
|
|
|
|
def __init__(self, fm):
|
|
|
|
self._fm = fm
|
|
|
|
|
|
|
|
def __getitem__(self, key):
|
|
|
|
return self._fm[key][0]
|
|
|
|
|
|
|
|
def find(self, key):
|
|
|
|
return self._fm[key]
|
|
|
|
|
2016-10-15 02:01:12 +03:00
|
|
|
def __nonzero__(self):
|
|
|
|
for x in self:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2017-03-21 04:58:10 +03:00
|
|
|
__bool__ = __nonzero__
|
|
|
|
|
2016-05-26 22:34:38 +03:00
|
|
|
def __len__(self):
|
|
|
|
return len(self._fm)
|
|
|
|
|
|
|
|
def __setitem__(self, key, node):
|
|
|
|
if len(node) == 22:
|
|
|
|
# sometimes we set the 22nd byte. this is not preserved by
|
|
|
|
# lazymanifest or manifest::_lazymanifest.
|
|
|
|
node = node[:21]
|
2018-05-30 12:16:33 +03:00
|
|
|
self._fm[key] = node, self.flags(key, "")
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
def __contains__(self, key):
|
|
|
|
return key in self._fm
|
|
|
|
|
|
|
|
def __delitem__(self, key):
|
|
|
|
del self._fm[key]
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return self._fm.__iter__()
|
|
|
|
|
|
|
|
def iterkeys(self):
|
|
|
|
return self._fm.iterkeys()
|
|
|
|
|
|
|
|
def iterentries(self):
|
|
|
|
return self._fm.iterentries()
|
|
|
|
|
|
|
|
def iteritems(self):
|
2016-06-07 20:25:49 +03:00
|
|
|
# TODO: we can improve the speed of this by making it return the
|
|
|
|
# right thing from the native code
|
2016-05-26 22:34:38 +03:00
|
|
|
return (x[:2] for x in self._fm.iterentries())
|
|
|
|
|
|
|
|
def keys(self):
|
|
|
|
return list(self.iterkeys())
|
|
|
|
|
2017-03-12 21:14:35 +03:00
|
|
|
def filesnotin(self, m2, match=None):
|
2018-05-30 12:16:33 +03:00
|
|
|
"""Set of files in this manifest that are not in the other"""
|
2017-03-12 21:14:35 +03:00
|
|
|
diff = self.diff(m2, match=match)
|
2018-05-30 12:16:33 +03:00
|
|
|
files = set(
|
|
|
|
filepath
|
|
|
|
for filepath, hashflags in diff.iteritems()
|
|
|
|
if hashflags[1][0] is None
|
|
|
|
)
|
2016-05-26 22:34:38 +03:00
|
|
|
return files
|
|
|
|
|
|
|
|
@util.propertycache
|
|
|
|
def _dirs(self):
|
|
|
|
return util.dirs(self)
|
|
|
|
|
|
|
|
def dirs(self):
|
|
|
|
return self._dirs
|
|
|
|
|
|
|
|
def hasdir(self, dir):
|
|
|
|
return dir in self._dirs
|
|
|
|
|
|
|
|
def _filesfastpath(self, match):
|
2018-05-30 12:16:33 +03:00
|
|
|
"""Checks whether we can correctly and quickly iterate over matcher
|
|
|
|
files instead of over manifest files."""
|
2016-05-26 22:34:38 +03:00
|
|
|
files = match.files()
|
2018-05-30 12:16:33 +03:00
|
|
|
return len(files) < 100 and (
|
|
|
|
match.isexact() or (match.prefix() and all(fn in self for fn in files))
|
|
|
|
)
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
def walk(self, match):
|
2018-05-30 12:16:33 +03:00
|
|
|
"""Generates matching file names.
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
Equivalent to manifest.matches(match).iterkeys(), but without creating
|
|
|
|
an entirely new manifest.
|
|
|
|
|
|
|
|
It also reports nonexistent files by marking them bad with match.bad().
|
2018-05-30 12:16:33 +03:00
|
|
|
"""
|
2016-05-26 22:34:38 +03:00
|
|
|
if match.always():
|
|
|
|
for f in iter(self):
|
|
|
|
yield f
|
|
|
|
return
|
|
|
|
|
|
|
|
fset = set(match.files())
|
|
|
|
|
|
|
|
# avoid the entire walk if we're only looking for specific files
|
|
|
|
if self._filesfastpath(match):
|
|
|
|
for fn in sorted(fset):
|
|
|
|
yield fn
|
|
|
|
return
|
|
|
|
|
|
|
|
for fn in self:
|
|
|
|
if fn in fset:
|
|
|
|
# specified pattern is the exact name
|
|
|
|
fset.remove(fn)
|
|
|
|
if match(fn):
|
|
|
|
yield fn
|
|
|
|
|
|
|
|
# for dirstate.walk, files=['.'] means "walk the whole tree".
|
|
|
|
# follow that here, too
|
2018-05-30 12:16:33 +03:00
|
|
|
fset.discard(".")
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
for fn in sorted(fset):
|
|
|
|
if not self.hasdir(fn):
|
|
|
|
match.bad(fn, None)
|
|
|
|
|
|
|
|
def matches(self, match):
|
2018-05-30 12:16:33 +03:00
|
|
|
"""generate a new manifest filtered by the match argument"""
|
2016-05-26 22:34:38 +03:00
|
|
|
if match.always():
|
|
|
|
return self.copy()
|
|
|
|
|
|
|
|
if self._filesfastpath(match):
|
|
|
|
nfm = cfastmanifest.fastmanifest()
|
|
|
|
for fn in match.files():
|
|
|
|
if fn in self._fm:
|
|
|
|
nfm[fn] = self._fm[fn]
|
|
|
|
m = fastmanifestdict(nfm)
|
|
|
|
return m
|
|
|
|
|
|
|
|
nfm = self._fm.filtercopy(match)
|
|
|
|
m = fastmanifestdict(nfm)
|
|
|
|
return m
|
|
|
|
|
2017-03-12 21:14:35 +03:00
|
|
|
def diff(self, m2, match=None, clean=False):
|
2018-05-30 12:16:33 +03:00
|
|
|
"""Finds changes between the current manifest and m2.
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
Args:
|
|
|
|
m2: the manifest to which this manifest should be compared.
|
|
|
|
clean: if true, include files unchanged between these manifests
|
|
|
|
with a None value in the returned dictionary.
|
|
|
|
|
|
|
|
The result is returned as a dict with filename as key and
|
|
|
|
values of the form ((n1,fl1),(n2,fl2)), where n1/n2 is the
|
|
|
|
nodeid in the current/other manifest and fl1/fl2 is the flag
|
|
|
|
in the current/other manifest. Where the file does not exist,
|
|
|
|
the nodeid will be None and the flags will be the empty
|
|
|
|
string.
|
2018-05-30 12:16:33 +03:00
|
|
|
"""
|
2017-03-12 21:14:35 +03:00
|
|
|
if match:
|
|
|
|
mf1 = self.matches(match)
|
|
|
|
mf2 = m2.matches(match)
|
|
|
|
return mf1.diff(mf2, clean=clean)
|
|
|
|
return self._fm.diff(m2._fm, clean=clean)
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
def setflag(self, key, flag):
|
|
|
|
self._fm[key] = self[key], flag
|
|
|
|
|
|
|
|
def get(self, key, default=None):
|
|
|
|
try:
|
|
|
|
return self._fm[key][0]
|
|
|
|
except KeyError:
|
|
|
|
return default
|
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
def flags(self, key, default=""):
|
2016-05-26 22:34:38 +03:00
|
|
|
try:
|
|
|
|
return self._fm[key][1]
|
|
|
|
except KeyError:
|
|
|
|
return default
|
|
|
|
|
|
|
|
def copy(self):
|
|
|
|
c = fastmanifestdict(self._fm.copy())
|
|
|
|
return c
|
|
|
|
|
|
|
|
def text(self, usemanifestv2=False):
|
|
|
|
if usemanifestv2:
|
2016-06-23 23:42:30 +03:00
|
|
|
raise NotImplementedError("v2 not supported")
|
2016-05-26 22:34:38 +03:00
|
|
|
else:
|
|
|
|
# use (probably) native version for v1
|
|
|
|
return self._fm.text()
|
|
|
|
|
|
|
|
def fastdelta(self, base, changes):
|
|
|
|
"""Given a base manifest text as an array.array and a list of changes
|
|
|
|
relative to that text, compute a delta that can be used by revlog.
|
|
|
|
"""
|
2016-12-03 01:37:35 +03:00
|
|
|
return fastdelta(self, self._fm.__getitem__, base, changes)
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2016-12-03 01:37:35 +03:00
|
|
|
def fastdelta(mf, mfgetter, base, changes):
|
|
|
|
"""Given a base manifest text as an array.array and a list of changes
|
|
|
|
relative to that text, compute a delta that can be used by revlog.
|
|
|
|
"""
|
|
|
|
delta = []
|
|
|
|
dstart = None
|
|
|
|
dend = None
|
|
|
|
dline = [""]
|
|
|
|
start = 0
|
|
|
|
# zero copy representation of base as a buffer
|
|
|
|
addbuf = util.buffer(base)
|
|
|
|
|
|
|
|
changes = list(changes)
|
|
|
|
if len(changes) < 1000:
|
|
|
|
# start with a readonly loop that finds the offset of
|
|
|
|
# each line and creates the deltas
|
|
|
|
for f, todelete in changes:
|
|
|
|
# bs will either be the index of the item or the insert point
|
|
|
|
start, end = manifest._msearch(addbuf, f, start)
|
|
|
|
if not todelete:
|
|
|
|
h, fl = mfgetter(f)
|
|
|
|
l = "%s\0%s%s\n" % (f, revlog.hex(h), fl)
|
|
|
|
else:
|
|
|
|
if start == end:
|
|
|
|
# item we want to delete was not found, error out
|
2018-05-30 12:16:33 +03:00
|
|
|
raise AssertionError((("failed to remove %s from manifest") % f))
|
2016-12-03 01:37:35 +03:00
|
|
|
l = ""
|
|
|
|
if dstart is not None and dstart <= start and dend >= start:
|
|
|
|
if dend < end:
|
|
|
|
dend = end
|
|
|
|
if l:
|
|
|
|
dline.append(l)
|
|
|
|
else:
|
|
|
|
if dstart is not None:
|
|
|
|
delta.append([dstart, dend, "".join(dline)])
|
|
|
|
dstart = start
|
|
|
|
dend = end
|
|
|
|
dline = [l]
|
|
|
|
|
|
|
|
if dstart is not None:
|
|
|
|
delta.append([dstart, dend, "".join(dline)])
|
|
|
|
# apply the delta to the base, and get a delta for addrevision
|
|
|
|
deltatext, arraytext = manifest._addlistdelta(base, delta)
|
|
|
|
else:
|
|
|
|
# For large changes, it's much cheaper to just build the text and
|
|
|
|
# diff it.
|
2017-03-13 21:22:18 +03:00
|
|
|
arraytext = bytearray(mf.text())
|
2017-03-16 23:48:48 +03:00
|
|
|
deltatext = mdiff.textdiff(util.buffer(base), util.buffer(arraytext))
|
2016-12-03 01:37:35 +03:00
|
|
|
|
|
|
|
return arraytext, deltatext
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2016-06-17 19:35:39 +03:00
|
|
|
class ondiskcache(object):
|
|
|
|
def __init__(self, debugf, opener, ui):
|
|
|
|
self.debugf = debugf
|
2016-05-26 22:34:38 +03:00
|
|
|
self.opener = opener
|
|
|
|
self.ui = ui
|
2016-06-17 19:35:39 +03:00
|
|
|
self.pathprefix = "fast"
|
2016-05-26 22:34:38 +03:00
|
|
|
base = opener.join(None)
|
|
|
|
self.cachepath = os.path.join(base, CACHE_SUBDIR)
|
|
|
|
if not os.path.exists(self.cachepath):
|
2016-06-14 01:26:55 +03:00
|
|
|
try:
|
|
|
|
os.makedirs(self.cachepath)
|
|
|
|
except EnvironmentError:
|
|
|
|
# Likely permission issues, in that case, we won't be able to
|
|
|
|
# access the cache afterwards
|
|
|
|
pass
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2016-06-17 19:35:39 +03:00
|
|
|
def _pathfromnode(self, hexnode):
|
|
|
|
return os.path.join(self.cachepath, self.pathprefix + hexnode)
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2016-06-17 19:35:39 +03:00
|
|
|
def touch(self, hexnode, delay=0):
|
2016-05-26 22:34:38 +03:00
|
|
|
filetime = time.time() - delay
|
2016-06-17 19:35:39 +03:00
|
|
|
path = self._pathfromnode(hexnode)
|
2016-05-26 22:34:38 +03:00
|
|
|
try:
|
2018-05-30 12:16:33 +03:00
|
|
|
self.debugf("[FM] refreshing %s with delay %d\n" % (hexnode, delay))
|
2016-05-26 22:34:38 +03:00
|
|
|
os.utime(path, (filetime, filetime))
|
|
|
|
except EnvironmentError:
|
|
|
|
pass
|
|
|
|
|
2016-06-17 19:35:39 +03:00
|
|
|
def __contains__(self, hexnode):
|
|
|
|
path = self._pathfromnode(hexnode)
|
|
|
|
return os.path.exists(path)
|
2016-06-08 20:46:11 +03:00
|
|
|
|
2016-06-17 19:35:39 +03:00
|
|
|
def items(self):
|
2016-06-25 02:13:39 +03:00
|
|
|
"""Return the entries in the cache, sorted from most relevant to least
|
|
|
|
relevant"""
|
2016-06-17 19:35:39 +03:00
|
|
|
entries = []
|
|
|
|
for entry in os.listdir(self.cachepath):
|
|
|
|
try:
|
2016-06-17 19:35:39 +03:00
|
|
|
if entry.startswith(self.pathprefix):
|
2016-06-17 19:35:39 +03:00
|
|
|
path = os.path.join(self.cachepath, entry)
|
2018-05-30 12:16:33 +03:00
|
|
|
entries.append(
|
|
|
|
(entry, os.path.getmtime(path), os.path.getsize(path))
|
|
|
|
)
|
2016-06-17 19:35:39 +03:00
|
|
|
except EnvironmentError:
|
|
|
|
pass
|
2018-05-30 12:16:33 +03:00
|
|
|
entries.sort(key=lambda x: (-x[1], x[0]))
|
2016-06-17 19:35:39 +03:00
|
|
|
return [x[0].replace(self.pathprefix, "") for x in entries]
|
2016-06-17 19:35:39 +03:00
|
|
|
|
2016-05-26 22:34:38 +03:00
|
|
|
def __iter__(self):
|
2016-06-17 19:35:39 +03:00
|
|
|
return iter(self.items())
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2016-06-17 19:35:39 +03:00
|
|
|
def setwithlimit(self, hexnode, manifest, limit=-1):
|
2016-07-12 07:58:04 +03:00
|
|
|
"""Writes a manifest to the cache. Returns True if the cache already
|
|
|
|
contains the item or if the write is successful. Returns False if the
|
|
|
|
write fails. Raises CacheFullException if writing the cache entry would
|
|
|
|
cause us to pass the limit.
|
|
|
|
"""
|
2016-06-22 03:07:46 +03:00
|
|
|
if hexnode in self:
|
2016-07-12 07:58:04 +03:00
|
|
|
return True
|
2016-06-17 19:35:39 +03:00
|
|
|
path = self._pathfromnode(hexnode)
|
2018-05-30 12:16:33 +03:00
|
|
|
if isinstance(manifest, cfastmanifest.fastmanifest) or isinstance(
|
|
|
|
manifest, fastmanifestdict
|
|
|
|
):
|
2016-07-12 00:08:45 +03:00
|
|
|
fm = manifest
|
|
|
|
else:
|
|
|
|
fm = cfastmanifest.fastmanifest(manifest.text())
|
2016-06-17 19:35:39 +03:00
|
|
|
tmpfpath = util.mktempcopy(path, True)
|
2016-07-12 07:58:19 +03:00
|
|
|
entrysize = fm.bytes()
|
|
|
|
if limit != -1 and self.totalsize()[0] + entrysize > limit:
|
|
|
|
raise CacheFullException()
|
2016-05-26 22:34:38 +03:00
|
|
|
try:
|
2016-06-23 23:42:24 +03:00
|
|
|
fm._save(tmpfpath)
|
2016-06-17 19:35:39 +03:00
|
|
|
util.rename(tmpfpath, path)
|
|
|
|
return True
|
|
|
|
except EnvironmentError:
|
|
|
|
return False
|
|
|
|
finally:
|
|
|
|
try:
|
|
|
|
os.unlink(tmpfpath)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __setitem__(self, hexnode, manifest):
|
|
|
|
self.setwithlimit(hexnode, manifest)
|
|
|
|
|
|
|
|
def __delitem__(self, hexnode):
|
|
|
|
path = self._pathfromnode(hexnode)
|
|
|
|
try:
|
|
|
|
os.unlink(path)
|
|
|
|
except EnvironmentError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __getitem__(self, hexnode):
|
|
|
|
path = self._pathfromnode(hexnode)
|
|
|
|
try:
|
|
|
|
fm = cfastmanifest.fastmanifest.load(path)
|
|
|
|
# touch on access to make this cache a LRU cache
|
|
|
|
os.utime(path, None)
|
|
|
|
except EnvironmentError:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return fastmanifestdict(fm)
|
|
|
|
|
|
|
|
def entrysize(self, hexnode):
|
|
|
|
try:
|
|
|
|
return os.path.getsize(self._pathfromnode(hexnode))
|
2016-05-26 22:34:38 +03:00
|
|
|
except EnvironmentError:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def totalsize(self, silent=True):
|
|
|
|
totalsize = 0
|
|
|
|
numentries = 0
|
|
|
|
for entry in self:
|
|
|
|
entrysize = self.entrysize(entry)
|
|
|
|
if entrysize == -1:
|
|
|
|
# Entry was deleted by another process
|
|
|
|
continue
|
|
|
|
totalsize += entrysize
|
|
|
|
numentries += 1
|
|
|
|
if not silent:
|
2018-05-30 12:16:33 +03:00
|
|
|
msg = "%s (size %s)\n" % (
|
|
|
|
self.pathprefix + entry,
|
|
|
|
util.bytecount(entrysize),
|
|
|
|
)
|
2016-06-17 19:35:39 +03:00
|
|
|
self.ui.status(msg)
|
2016-05-26 22:34:38 +03:00
|
|
|
return totalsize, numentries
|
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2016-06-17 19:35:39 +03:00
|
|
|
class CacheFullException(Exception):
|
|
|
|
pass
|
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2016-10-21 21:02:24 +03:00
|
|
|
class treemanifestcache(object):
|
|
|
|
@staticmethod
|
|
|
|
def getinstance(opener, ui):
|
2018-05-30 12:16:33 +03:00
|
|
|
if not util.safehasattr(opener, "treemanifestcache"):
|
2016-10-21 21:02:24 +03:00
|
|
|
opener.treemanifestcache = treemanifestcache(opener, ui)
|
|
|
|
return opener.treemanifestcache
|
|
|
|
|
|
|
|
def __init__(self, opener, ui):
|
|
|
|
self.ui = ui
|
|
|
|
self._cache = {}
|
|
|
|
|
|
|
|
def clear(self):
|
|
|
|
self._cache.clear()
|
|
|
|
|
|
|
|
def __contains__(self, node):
|
|
|
|
return node in self._cache
|
|
|
|
|
|
|
|
def get(self, node, default=None):
|
|
|
|
return self._cache.get(node, default=default)
|
|
|
|
|
|
|
|
def __getitem__(self, node):
|
|
|
|
return self._cache[node]
|
|
|
|
|
|
|
|
def __setitem__(self, node, value):
|
|
|
|
self._cache[node] = value
|
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2016-06-17 19:35:39 +03:00
|
|
|
class fastmanifestcache(object):
|
2016-07-13 10:02:48 +03:00
|
|
|
@staticmethod
|
|
|
|
def getinstance(opener, ui):
|
2018-05-30 12:16:33 +03:00
|
|
|
if not util.safehasattr(opener, "fastmanifestcache"):
|
2018-01-10 02:23:52 +03:00
|
|
|
# Avoid circular imports
|
|
|
|
from . import cachemanager
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2016-06-17 19:35:39 +03:00
|
|
|
limit = cachemanager._systemawarecachelimit(opener=opener, ui=ui)
|
2016-07-13 10:02:48 +03:00
|
|
|
opener.fastmanifestcache = fastmanifestcache(opener, ui, limit)
|
|
|
|
return opener.fastmanifestcache
|
2016-06-17 19:35:39 +03:00
|
|
|
|
|
|
|
def __init__(self, opener, ui, limit):
|
|
|
|
self.ui = ui
|
|
|
|
if self.ui.configbool("fastmanifest", "silent"):
|
|
|
|
self.debug = _silent_debug
|
|
|
|
else:
|
|
|
|
self.debug = self.ui.debug
|
|
|
|
self.ondiskcache = ondiskcache(self.debug, opener, ui)
|
2018-05-30 12:16:33 +03:00
|
|
|
maxinmemoryentries = self.ui.config(
|
|
|
|
"fastmanifest", "maxinmemoryentries", DEFAULT_MAX_MEMORY_ENTRIES
|
|
|
|
)
|
2016-06-17 19:35:39 +03:00
|
|
|
self.inmemorycache = util.lrucachedict(maxinmemoryentries)
|
|
|
|
self.limit = limit
|
|
|
|
|
[fastmanifest] refactor limit code
Summary:
Previously, depending on the code path, the limit specified would not actually take effect. For instance, if we came in from debugmanifestcache, and attempted to populated the cache, we would use `systemawarecachelimit` when filling the cache, and the fixedsize limit specified by the user when pruning.
With this change, we unify the all the cache limit decisions to `fastmanifestcache`. If the user actually overrides the limit, we set the limit in `fastmanifestcache` and let that make the decisions.
We also change the definitions of limit in `hg debugcachemanifest` to:
1) >0 => it's the limit.
2) =0 => use systemawarecachelimit
3) <0 => no limit!
Test Plan: pass existing unit tests. there's a small change in the test output, because we always evaluate the limit now, plus we remove the test for limit=0, since it means something different now.
Reviewers: lcharignon, durham
Reviewed By: durham
Subscribers: trunkagent, mitrandir, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D3544997
Signature: t1:3544997:1468281604:8f78f00ebf2afd8f3f1fbefbd82316b97cc4b193
2016-07-12 03:33:37 +03:00
|
|
|
def overridelimit(self, limiter):
|
|
|
|
self.limit = limiter
|
|
|
|
|
2016-06-17 19:35:39 +03:00
|
|
|
def touch(self, hexnode, delay=0):
|
|
|
|
self.ondiskcache.touch(hexnode, delay)
|
|
|
|
|
|
|
|
def __getitem__(self, hexnode):
|
|
|
|
if hexnode in self.inmemorycache:
|
|
|
|
return self.inmemorycache[hexnode]
|
|
|
|
|
|
|
|
r = self.ondiskcache[hexnode]
|
|
|
|
if r:
|
|
|
|
self.inmemorycache[hexnode] = r
|
|
|
|
return r
|
|
|
|
|
|
|
|
def __contains__(self, hexnode):
|
|
|
|
return hexnode in self.inmemorycache or hexnode in self.ondiskcache
|
|
|
|
|
|
|
|
def __setitem__(self, hexnode, manifest):
|
2016-06-22 03:07:46 +03:00
|
|
|
if hexnode in self.ondiskcache and hexnode in self.inmemorycache:
|
2016-06-17 19:35:39 +03:00
|
|
|
self.debug("[FM] skipped %s, already cached\n" % hexnode)
|
2016-05-26 22:34:38 +03:00
|
|
|
return
|
|
|
|
|
2016-06-17 19:35:39 +03:00
|
|
|
if self.limit:
|
|
|
|
if self.ondiskcache.totalsize()[0] > self.limit.bytes():
|
|
|
|
self.debug("[FM] skipped %s, cache full\n" % hexnode)
|
|
|
|
else:
|
|
|
|
self.debug("[FM] caching revision %s\n" % hexnode)
|
2018-05-30 12:16:33 +03:00
|
|
|
self.ondiskcache.setwithlimit(hexnode, manifest, self.limit.bytes())
|
2016-06-17 19:35:39 +03:00
|
|
|
else:
|
|
|
|
self.debug("[FM] caching revision %s\n" % hexnode)
|
|
|
|
self.ondiskcache[hexnode] = manifest
|
2016-06-22 03:07:46 +03:00
|
|
|
self.put_inmemory(hexnode, manifest)
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2016-06-17 19:35:39 +03:00
|
|
|
def put_inmemory(self, hexnode, fmdict):
|
|
|
|
if hexnode not in self.inmemorycache:
|
|
|
|
self.inmemorycache[hexnode] = fmdict.copy()
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2016-06-17 19:35:39 +03:00
|
|
|
def __iter__(self):
|
|
|
|
return self.ondiskcache.__iter__()
|
|
|
|
|
[fastmanifest] refactor limit code
Summary:
Previously, depending on the code path, the limit specified would not actually take effect. For instance, if we came in from debugmanifestcache, and attempted to populated the cache, we would use `systemawarecachelimit` when filling the cache, and the fixedsize limit specified by the user when pruning.
With this change, we unify the all the cache limit decisions to `fastmanifestcache`. If the user actually overrides the limit, we set the limit in `fastmanifestcache` and let that make the decisions.
We also change the definitions of limit in `hg debugcachemanifest` to:
1) >0 => it's the limit.
2) =0 => use systemawarecachelimit
3) <0 => no limit!
Test Plan: pass existing unit tests. there's a small change in the test output, because we always evaluate the limit now, plus we remove the test for limit=0, since it means something different now.
Reviewers: lcharignon, durham
Reviewed By: durham
Subscribers: trunkagent, mitrandir, mjpieters
Differential Revision: https://phabricator.intern.facebook.com/D3544997
Signature: t1:3544997:1468281604:8f78f00ebf2afd8f3f1fbefbd82316b97cc4b193
2016-07-12 03:33:37 +03:00
|
|
|
def prune(self):
|
2016-07-13 03:09:15 +03:00
|
|
|
return self.makeroomfor(0, set())
|
2016-05-26 22:34:38 +03:00
|
|
|
|
|
|
|
def pruneall(self):
|
2016-06-17 19:35:39 +03:00
|
|
|
for entry in reversed(list(self.ondiskcache)):
|
|
|
|
self.debug("[FM] removing cached manifest fast%s\n" % entry)
|
|
|
|
del self.ondiskcache[entry]
|
2016-05-26 22:34:38 +03:00
|
|
|
|
2016-07-12 03:34:01 +03:00
|
|
|
def makeroomfor(self, needed, excluded):
|
|
|
|
"""Make room on disk for a cache entry of size `needed`. Cache entries
|
|
|
|
in `excluded` are not subjected to removal.
|
|
|
|
"""
|
|
|
|
cacheentries = collections.deque(self.ondiskcache.items())
|
|
|
|
maxtotal = self.limit.bytes() - needed
|
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
while len(cacheentries) > 0 and self.ondiskcache.totalsize()[0] > maxtotal:
|
2016-07-12 03:34:01 +03:00
|
|
|
candidate = cacheentries.pop()
|
|
|
|
|
|
|
|
if candidate in excluded:
|
|
|
|
# it's immune, so skip it.
|
|
|
|
continue
|
|
|
|
|
2016-07-13 03:09:15 +03:00
|
|
|
self.debug("[FM] removing cached manifest fast%s\n" % (candidate,))
|
2016-07-12 03:34:01 +03:00
|
|
|
del self.ondiskcache[candidate]
|
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2016-09-15 02:08:55 +03:00
|
|
|
class hybridmanifestctx(object):
|
2016-09-09 21:06:43 +03:00
|
|
|
"""A class representing a single revision of a manifest, including its
|
|
|
|
contents, its parent revs, and its linkrev.
|
|
|
|
"""
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2017-03-07 21:27:05 +03:00
|
|
|
def __init__(self, ui, manifestlog, revlog, node):
|
2016-09-15 02:08:55 +03:00
|
|
|
self._ui = ui
|
2017-03-07 21:27:05 +03:00
|
|
|
self._manifestlog = manifestlog
|
2018-03-12 21:10:15 +03:00
|
|
|
self._opener = manifestlog._opener
|
2016-09-09 21:06:43 +03:00
|
|
|
self._revlog = revlog
|
|
|
|
self._node = node
|
2017-02-01 22:58:59 +03:00
|
|
|
self._hybridmanifest = None
|
2016-09-09 21:06:43 +03:00
|
|
|
|
2018-03-12 21:10:15 +03:00
|
|
|
@propertycache
|
|
|
|
def revlog(self):
|
|
|
|
if self._revlog is None:
|
2018-05-30 12:16:33 +03:00
|
|
|
raise error.ProgrammingError(
|
|
|
|
"cannot access flat manifest revlog " "for treeonly repository"
|
|
|
|
)
|
2018-03-12 21:10:15 +03:00
|
|
|
return self._revlog
|
|
|
|
|
2016-11-16 23:11:06 +03:00
|
|
|
def copy(self):
|
2017-03-07 21:27:05 +03:00
|
|
|
memmf = manifest.memmanifestctx(self._manifestlog)
|
2016-11-16 23:11:06 +03:00
|
|
|
memmf._manifestdict = self.read().copy()
|
|
|
|
return memmf
|
|
|
|
|
2016-12-14 20:41:15 +03:00
|
|
|
@propertycache
|
|
|
|
def parents(self):
|
2018-05-30 12:16:33 +03:00
|
|
|
if util.safehasattr(self._manifestlog, "historystore"):
|
2017-11-02 03:10:05 +03:00
|
|
|
store = self._manifestlog.historystore
|
|
|
|
try:
|
2018-05-30 12:16:33 +03:00
|
|
|
p1, p2, linknode, copyfrom = store.getnodeinfo("", self._node)
|
2017-11-02 03:10:05 +03:00
|
|
|
return p1, p2
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2018-03-12 21:10:15 +03:00
|
|
|
return self.revlog.parents(self._node)
|
2016-12-14 20:41:15 +03:00
|
|
|
|
2016-09-15 02:08:55 +03:00
|
|
|
def read(self):
|
2017-02-01 22:58:59 +03:00
|
|
|
if self._hybridmanifest is None:
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2017-02-01 22:58:59 +03:00
|
|
|
def loadflat():
|
|
|
|
# This should eventually be made lazy loaded, so consumers can
|
|
|
|
# access the node/p1/linkrev data without having to parse the
|
|
|
|
# whole manifest.
|
2018-03-12 21:10:15 +03:00
|
|
|
data = self.revlog.revision(self._node)
|
2017-03-13 21:22:18 +03:00
|
|
|
arraytext = bytearray(data)
|
2018-03-12 21:10:15 +03:00
|
|
|
self.revlog._fulltextcache[self._node] = arraytext
|
2017-02-01 22:58:59 +03:00
|
|
|
return manifest.manifestdict(data)
|
|
|
|
|
|
|
|
self._hybridmanifest = hybridmanifest(
|
2018-05-30 12:16:33 +03:00
|
|
|
self._ui,
|
|
|
|
self._opener,
|
|
|
|
self._manifestlog,
|
|
|
|
loadflat=loadflat,
|
|
|
|
node=self._node,
|
|
|
|
)
|
2017-02-01 22:58:59 +03:00
|
|
|
return self._hybridmanifest
|
2016-09-09 21:06:43 +03:00
|
|
|
|
2017-02-10 04:36:26 +03:00
|
|
|
def readdelta(self, shallow=False):
|
2017-11-02 03:10:05 +03:00
|
|
|
p1, p2 = self.parents
|
|
|
|
mf = self.read()
|
|
|
|
parentmf = self._manifestlog[p1].read()
|
|
|
|
|
|
|
|
treemf = mf._treemanifest()
|
|
|
|
ptreemf = parentmf._treemanifest()
|
|
|
|
if treemf is not None and ptreemf is not None:
|
|
|
|
diff = ptreemf.diff(treemf)
|
|
|
|
result = manifest.manifestdict()
|
|
|
|
for path, ((oldn, oldf), (newn, newf)) in diff.iteritems():
|
|
|
|
if newn is not None:
|
|
|
|
result[path] = newn
|
|
|
|
if newf:
|
|
|
|
result.setflag(path, newf)
|
|
|
|
return mf._converttohybridmanifest(result)
|
|
|
|
|
2018-03-12 21:10:15 +03:00
|
|
|
rl = self.revlog
|
2016-10-25 19:30:26 +03:00
|
|
|
if rl._usemanifestv2:
|
|
|
|
# Need to perform a slow delta
|
|
|
|
r0 = revlog.deltaparent(revlog.rev(self._node))
|
2017-03-07 21:27:05 +03:00
|
|
|
m0 = manifest.manifestctx(self._manifestlog, rl.node(r0)).read()
|
2016-10-25 19:30:26 +03:00
|
|
|
m1 = self.read()
|
2016-11-25 03:23:21 +03:00
|
|
|
md = manifest.manifestdict()
|
2016-10-25 19:30:26 +03:00
|
|
|
for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).iteritems():
|
|
|
|
if n1:
|
|
|
|
md[f] = n1
|
|
|
|
if fl1:
|
|
|
|
md.setflag(f, fl1)
|
|
|
|
return md
|
|
|
|
|
|
|
|
r = rl.rev(self._node)
|
|
|
|
d = mdiff.patchtext(rl.revdiff(rl.deltaparent(r), r))
|
|
|
|
return manifest.manifestdict(d)
|
2016-09-30 04:09:43 +03:00
|
|
|
|
2017-02-10 04:36:26 +03:00
|
|
|
def readfast(self, shallow=False):
|
2017-02-27 22:05:03 +03:00
|
|
|
"""readfast returns a manifest containing either A) the list of files
|
|
|
|
added/modified in this manifest or B) the entire manifest, depending on
|
|
|
|
which is faster to compute. In a flat manifest world, option A is very
|
|
|
|
fast if the delta base is equal to p1. In a tree world, we don't have
|
|
|
|
that optimization, but we have efficient diffs, so we use that instead.
|
|
|
|
"""
|
|
|
|
mf = self.read()
|
|
|
|
|
2017-02-27 22:07:16 +03:00
|
|
|
p1, p2 = self.parents
|
2017-02-27 22:05:03 +03:00
|
|
|
if p1 == revlog.nullid:
|
|
|
|
return mf
|
|
|
|
|
2017-03-07 21:27:05 +03:00
|
|
|
parentmf = self._manifestlog[p1].read()
|
2017-02-27 22:05:03 +03:00
|
|
|
|
|
|
|
fastmf = None
|
|
|
|
pfastmf = None
|
|
|
|
|
|
|
|
# If both trees, take diff fast path
|
|
|
|
treemf = mf._treemanifest()
|
|
|
|
ptreemf = parentmf._treemanifest()
|
|
|
|
if treemf is not None and ptreemf is not None:
|
|
|
|
fastmf = treemf
|
|
|
|
pfastmf = ptreemf
|
|
|
|
|
|
|
|
if fastmf is None:
|
|
|
|
# If both cached, take diff fast path
|
|
|
|
cachedmf = mf._cachedmanifest()
|
|
|
|
pcachedmf = parentmf._cachedmanifest()
|
|
|
|
if cachedmf is not None and pcachedmf is not None:
|
|
|
|
fastmf = cachedmf
|
|
|
|
pfastmf = pcachedmf
|
|
|
|
|
|
|
|
if fastmf is not None:
|
|
|
|
diff = pfastmf.diff(fastmf)
|
|
|
|
result = manifest.manifestdict()
|
|
|
|
for path, ((oldn, oldf), (newn, newf)) in diff.iteritems():
|
|
|
|
if newn is not None:
|
|
|
|
result[path] = newn
|
|
|
|
result.setflag(path, newf)
|
|
|
|
else:
|
|
|
|
# Otherwise, fall back to flat readfast
|
2017-03-07 21:27:05 +03:00
|
|
|
flatctx = manifest.manifestctx(self._manifestlog, self._node)
|
2017-02-27 22:05:03 +03:00
|
|
|
result = flatctx.readfast(shallow=shallow)
|
|
|
|
|
|
|
|
return mf._converttohybridmanifest(result)
|
2016-10-01 03:34:50 +03:00
|
|
|
|
2016-09-09 21:06:43 +03:00
|
|
|
def node(self):
|
|
|
|
return self._node
|
2016-07-12 03:34:01 +03:00
|
|
|
|
2016-11-18 19:56:35 +03:00
|
|
|
def find(self, path):
|
|
|
|
return self.read().find(path)
|
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2016-05-26 22:34:38 +03:00
|
|
|
class manifestfactory(object):
|
|
|
|
def __init__(self, ui):
|
|
|
|
self.ui = ui
|
|
|
|
|
2016-09-09 21:06:43 +03:00
|
|
|
def newgetitem(self, orig, *args, **kwargs):
|
2017-02-01 22:58:59 +03:00
|
|
|
mfl = args[0]
|
|
|
|
node = args[1]
|
2018-05-30 12:16:33 +03:00
|
|
|
dir = ""
|
2017-02-01 22:58:59 +03:00
|
|
|
|
|
|
|
if node in mfl._dirmancache.get(dir, ()):
|
|
|
|
return mfl._dirmancache[dir][node]
|
|
|
|
|
2017-03-07 21:27:05 +03:00
|
|
|
m = hybridmanifestctx(self.ui, mfl, mfl._revlog, node)
|
2017-02-01 22:58:59 +03:00
|
|
|
|
|
|
|
if node != revlog.nullid:
|
|
|
|
mancache = mfl._dirmancache.get(dir)
|
|
|
|
if mancache is None:
|
|
|
|
mancache = util.lrucachedict(mfl.cachesize)
|
|
|
|
mfl._dirmancache[dir] = mancache
|
|
|
|
mancache[node] = m
|
|
|
|
|
|
|
|
return m
|
2016-09-09 21:06:43 +03:00
|
|
|
|
2017-02-10 04:36:26 +03:00
|
|
|
def newgetdirmanifestctx(self, orig, mfl, dir, node, *args):
|
2018-05-30 12:16:33 +03:00
|
|
|
if dir != "":
|
2017-02-10 04:36:26 +03:00
|
|
|
raise NotImplemented("fastmanifest doesn't support trees")
|
|
|
|
|
|
|
|
return self.newgetitem(None, mfl, node)
|
|
|
|
|
2016-06-08 20:46:11 +03:00
|
|
|
def add(self, orig, *args, **kwargs):
|
|
|
|
origself, m, transaction, link, p1, p2, added, removed = args[:8]
|
|
|
|
fastcache = fastmanifestcache.getinstance(origself.opener, self.ui)
|
|
|
|
|
2016-12-03 01:37:37 +03:00
|
|
|
p1text = None
|
|
|
|
|
2016-06-08 20:46:11 +03:00
|
|
|
p1hexnode = revlog.hex(p1)
|
2017-10-25 03:54:02 +03:00
|
|
|
cacheenabled = self.ui.configbool("fastmanifest", "usecache")
|
|
|
|
treeenabled = self.ui.configbool("fastmanifest", "usetree")
|
2016-12-03 01:37:40 +03:00
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
if (
|
|
|
|
cacheenabled
|
|
|
|
and p1hexnode in fastcache
|
|
|
|
and isinstance(m, hybridmanifest)
|
|
|
|
and m._incache()
|
|
|
|
):
|
2016-12-03 01:37:37 +03:00
|
|
|
p1text = fastcache[p1hexnode].text()
|
2016-12-03 01:37:40 +03:00
|
|
|
elif treeenabled:
|
|
|
|
tree = m._treemanifest()
|
|
|
|
if tree is not None:
|
|
|
|
p1text = origself.revision(p1)
|
2016-06-08 20:46:11 +03:00
|
|
|
|
2016-12-03 01:37:37 +03:00
|
|
|
if p1text:
|
2016-06-08 20:46:11 +03:00
|
|
|
manifest._checkforbidden(added)
|
|
|
|
# combine the changed lists into one sorted iterator
|
2018-05-30 12:16:33 +03:00
|
|
|
work = heapq.merge(
|
|
|
|
[(x, False) for x in added], [(x, True) for x in removed]
|
|
|
|
)
|
2016-06-08 20:46:11 +03:00
|
|
|
|
|
|
|
# TODO: potential for optimization: avoid this silly conversion to a
|
|
|
|
# python array.
|
2017-03-13 21:22:18 +03:00
|
|
|
manifestarray = bytearray(p1text)
|
2016-06-08 20:46:11 +03:00
|
|
|
|
|
|
|
arraytext, deltatext = m.fastdelta(manifestarray, work)
|
|
|
|
cachedelta = origself.rev(p1), deltatext
|
|
|
|
text = util.buffer(arraytext)
|
2018-05-30 12:16:33 +03:00
|
|
|
node = origself.addrevision(text, transaction, link, p1, p2, cachedelta)
|
2016-06-08 20:46:11 +03:00
|
|
|
hexnode = revlog.hex(node)
|
2016-10-12 18:50:47 +03:00
|
|
|
|
2016-12-03 01:37:37 +03:00
|
|
|
# Even though we may have checked 'm._incache()' above, it may have
|
|
|
|
# since disappeared, since background processes could be modifying
|
|
|
|
# the cache.
|
2016-10-12 18:50:47 +03:00
|
|
|
cachedmf = m._cachedmanifest()
|
|
|
|
if cachedmf:
|
|
|
|
fastcache.put_inmemory(hexnode, cachedmf)
|
2016-12-03 01:37:37 +03:00
|
|
|
self.ui.debug("[FM] wrote manifest %s\n" % (hexnode,))
|
2016-06-08 20:46:11 +03:00
|
|
|
else:
|
2016-12-03 01:37:37 +03:00
|
|
|
# If neither cache could help, fallback to the normal add
|
2016-10-21 21:02:26 +03:00
|
|
|
node = orig(*args, **kwargs)
|
|
|
|
|
2017-08-08 05:27:17 +03:00
|
|
|
return node
|
|
|
|
|
|
|
|
def ctxwrite(self, orig, mfctx, transaction, link, p1, p2, added, removed):
|
2017-11-07 20:06:24 +03:00
|
|
|
mfl = mfctx._manifestlog
|
2017-10-25 03:54:02 +03:00
|
|
|
treeenabled = self.ui.configbool("fastmanifest", "usetree")
|
2018-05-30 12:16:33 +03:00
|
|
|
if (
|
|
|
|
supportsctree
|
|
|
|
and treeenabled
|
|
|
|
and p1 not in mfl._revlog.nodemap
|
|
|
|
and not mfl.datastore.getmissing([("", p1)])
|
|
|
|
):
|
2017-11-07 20:06:24 +03:00
|
|
|
# If p1 is not in the flat manifest but is in the tree store, then
|
|
|
|
# this is a commit on top of a tree only commit and we should then
|
|
|
|
# produce a treeonly commit.
|
|
|
|
node = None
|
|
|
|
else:
|
|
|
|
node = orig(mfctx, transaction, link, p1, p2, added, removed)
|
|
|
|
|
2016-12-03 01:37:40 +03:00
|
|
|
if supportsctree and treeenabled:
|
2017-08-08 05:27:17 +03:00
|
|
|
opener = mfctx._revlog().opener
|
|
|
|
|
|
|
|
m = mfctx._manifestdict
|
|
|
|
|
|
|
|
# hybridmanifest requires you provide either a value or loadflat.
|
|
|
|
# Let's give it a dummy value, since we know we'll only be calling
|
|
|
|
# _treemanifest()
|
2016-11-16 23:11:15 +03:00
|
|
|
def loadflat():
|
2017-08-08 05:27:17 +03:00
|
|
|
raise RuntimeError("no-op loadflat should never be hit")
|
2018-05-30 12:16:33 +03:00
|
|
|
|
|
|
|
tree = hybridmanifest(
|
|
|
|
self.ui, opener, mfl, loadflat=loadflat, node=p1
|
|
|
|
)._treemanifest()
|
2017-08-08 05:27:17 +03:00
|
|
|
|
2017-04-27 20:44:34 +03:00
|
|
|
if tree is not None:
|
2016-10-21 21:02:26 +03:00
|
|
|
newtree = tree.copy()
|
|
|
|
for filename in removed:
|
|
|
|
del newtree[filename]
|
|
|
|
|
|
|
|
for filename in added:
|
|
|
|
fnode = m[filename]
|
|
|
|
fflag = m.flags(filename)
|
|
|
|
newtree.set(filename, fnode, fflag)
|
|
|
|
|
2018-02-27 22:10:21 +03:00
|
|
|
tmfl = mfl.treemanifestlog
|
2018-02-27 22:10:26 +03:00
|
|
|
|
|
|
|
# If the manifest was already committed as a flat manifest, use
|
|
|
|
# its node.
|
|
|
|
overridenode = None
|
|
|
|
overridep1node = None
|
|
|
|
if node is not None:
|
|
|
|
overridenode = node
|
|
|
|
overridep1node = p1
|
|
|
|
|
2018-03-15 23:40:09 +03:00
|
|
|
# linknode=None because linkrev is provided
|
2018-05-30 12:16:33 +03:00
|
|
|
node = tmfl.add(
|
|
|
|
self.ui,
|
|
|
|
newtree,
|
|
|
|
p1,
|
|
|
|
p2,
|
|
|
|
None,
|
|
|
|
overridenode=overridenode,
|
|
|
|
overridep1node=overridep1node,
|
|
|
|
tr=transaction,
|
|
|
|
linkrev=link,
|
|
|
|
)
|
|
|
|
|
|
|
|
treemanifestcache.getinstance(opener, mfl.ui)[node] = newtree
|
2016-10-21 21:02:26 +03:00
|
|
|
|
2018-02-27 22:10:17 +03:00
|
|
|
def finalize(tr):
|
2018-05-30 12:16:33 +03:00
|
|
|
treemanifestcache.getinstance(opener, mfl.ui).clear()
|
|
|
|
|
|
|
|
transaction.addfinalize("fastmanifesttreecache", finalize)
|
2018-02-27 22:10:17 +03:00
|
|
|
|
2016-10-21 21:02:26 +03:00
|
|
|
return node
|
2016-06-08 20:46:11 +03:00
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2016-05-26 22:34:38 +03:00
|
|
|
def _silent_debug(*args, **kwargs):
|
|
|
|
"""Replacement for ui.debug that silently swallows the arguments.
|
|
|
|
Typically enabled when running the mercurial test suite by setting:
|
|
|
|
--extra-config-opt=fastmanifest.silent=True"""
|