0
 ?÷     # localrepo.py - read/write repository class for mercurial
# coding: utf-8
#
# Copyright 2005-2007 Olivia Mackall <olivia@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.


import functools
import os
import random
import sys
import time
import weakref

from concurrent import futures
from .i18n import _
from .node import (
    bin,
    hex,
    nullrev,
    sha1nodeconstants,
    short,
)
from .pycompat import (
    delattr,
    getattr,
)
from . import (
    bookmarks,
    branchmap,
    bundle2,
    bundlecaches,
    changegroup,
    color,
    commit,
    context,
    dirstate,
    dirstateguard,
    discovery,
    encoding,
    error,
    exchange,
    extensions,
    filelog,
    hook,
    lock as lockmod,
    match as matchmod,
    mergestate as mergestatemod,
    mergeutil,
    namespaces,
    narrowspec,
    obsolete,
    pathutil,
    phases,
    pushkey,
    pycompat,
    rcutil,
    repoview,
    requirements as requirementsmod,
    revlog,
    revset,
    revsetlang,
    scmutil,
    sparse,
    store as storemod,
    subrepoutil,
    tags as tagsmod,
    transaction,
    txnutil,
    util,
    vfs as vfsmod,
    wireprototypes,
)

from .interfaces import (
    repository,
    util as interfaceutil,
)

from .utils import (
    hashutil,
    procutil,
    stringutil,
    urlutil,
)

from .revlogutils import (
    concurrency_checker as revlogchecker,
    constants as revlogconst,
    sidedata as sidedatamod,
)

release = lockmod.release
urlerr = util.urlerr
urlreq = util.urlreq

# set of (path, vfs-location) tuples. vfs-location is:
# - 'plain for vfs relative paths
# - '' for svfs relative paths
_cachedfiles = set()


class _basefilecache(scmutil.filecache):
    """All filecache usage on repo are done for logic that should be unfiltered"""

    def __get__(self, repo, type=None):
        if repo is None:
            return self
        # proxy to unfiltered __dict__ since filtered repo has no entry
        unfi = repo.unfiltered()
        try:
            return unfi.__dict__[self.sname]
        except KeyError:
            pass
        return super(_basefilecache, self).__get__(unfi, type)

    def set(self, repo, value):
        return super(_basefilecache, self).set(repo.unfiltered(), value)


class repofilecache(_basefilecache):
    """filecache for files in .hg but outside of .hg/store"""

    def __init__(self, *paths):
        super(repofilecache, self).__init__(*paths)
        for path in paths:
            _cachedfiles.add((path, b'plain'))

    def join(self, obj, fname):
        return obj.vfs.join(fname)


class storecache(_basefilecache):
    """filecache for files in the store"""

    def __init__(self, *paths):
        super(storecache, self).__init__(*paths)
        for path in paths:
            _cachedfiles.add((path, b''))

    def join(self, obj, fname):
        return obj.sjoin(fname)


class changelogcache(storecache):
    """filecache for the changelog"""

    def __init__(self):
        super(changelogcache, self).__init__()
        _cachedfiles.add((b'00changelog.i', b''))
        _cachedfiles.add((b'00changelog.n', b''))

    def tracked_paths(self, obj):
        paths = [self.join(obj, b'00changelog.i')]
        if obj.store.opener.options.get(b'persistent-nodemap', False):
            paths.append(self.join(obj, b'00changelog.n'))
        return paths


class manifestlogcache(storecache):
    """filecache for the manifestlog"""

    def __init__(self):
        super(manifestlogcache, self).__init__()
        _cachedfiles.add((b'00manifest.i', b''))
        _cachedfiles.add((b'00manifest.n', b''))

    def tracked_paths(self, obj):
        paths = [self.join(obj, b'00manifest.i')]
        if obj.store.opener.options.get(b'persistent-nodemap', False):
            paths.append(self.join(obj, b'00manifest.n'))
        return paths


class mixedrepostorecache(_basefilecache):
    """filecache for a mix files in .hg/store and outside"""

    def __init__(self, *pathsandlocations