view hgdemandimport/__init__.py @ 35665:1ad1e59b405e

lfs: control tracked file selection via a tracked file Since the lfs tracking policy can dramatically affect the repository, it makes more sense to have the policy file checked in, than to rely on all developers configuring their .hgrc properly. The inspiration for this is the .hgeol file. The configuration lives under '[track]', so that other things can be added in the future. Eventually, the config option should be limited to `convert` only. If the file can't be parsed for any reason (including unrecognized elements of the minifileset language), the commit will abort until the problem is corrected. This seems more useful than the warning that hgeol emits, and has no effect on reading the data, so there's no compatibility concerns. My initial thought was to read the file and change each "key = value" line into "((key) & (value))", so that each line could be ORed together, and make a single pass at compiling. Unfortunately, that prevents exclusions if there's a catchall rule. Consider what happens to a large *.c file here: [track] **.c = none() ** = size('>1MB') # ((**.c) & (none())) | ((**) & (size('>1MB'))) => anything > 1MB I also thought about having separate [include] and [exclude] sections. But that just seems to open things up to user mistakes. Consider: [include] **.zip = all() **.php = size('>10MB') [exclude] **.zip = all() # Who wins? **.php = none() # Effectively 'all()' (i.e. nothing excluded), or >10MB ? Therefore, it just compiles each key and value separately, and walks until the key matches something. I'm not sure how to enforce just file patterns on LHS without leaking knowledge about the minifileset here. That means this will allow odd looking lines like this: [track] **.c | **.txt = none() But that's also fewer lines to compile, so slightly more efficient? Some things like 'none()' won't work as expected on LHS though, because that won't match, so that line is skipped. For now, these quirks are not mentioned in the documentation. Jun previously expressed concern about efficiency when scaling to large repos, so I tried avoiding 'repo[None]'. (localrepo.commit() gets repo[None] already, but doesn't tie it to the workingcommitctx used here.) Therefore, I looked at the passed context for 'AMR' status. But that doesn't help with the normal case where the policy file is tracked, but clean. That requires looking up p1() to read the file. I don't see any way to get the content of one file without first creating the full parent context.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 14 Jan 2018 18:12:51 -0500
parents 3cfc9070245f
children 670eb4fa1b86
line wrap: on
line source

# hgdemandimport - global demand-loading of modules for Mercurial
#
# Copyright 2017 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.

'''demandimport - automatic demand-loading of modules'''

# This is in a separate package from mercurial because in Python 3,
# demand loading is per-package. Keeping demandimport in the mercurial package
# would disable demand loading for any modules in mercurial.

from __future__ import absolute_import

import os
import sys

if sys.version_info[0] >= 3:
    from . import demandimportpy3 as demandimport
else:
    from . import demandimportpy2 as demandimport

# Extensions can add to this list if necessary.
ignore = [
    '__future__',
    '_hashlib',
    # ImportError during pkg_resources/__init__.py:fixup_namespace_package
    '_imp',
    '_xmlplus',
    'fcntl',
    'nt', # pathlib2 tests the existence of built-in 'nt' module
    'win32com.gen_py',
    'win32com.shell', # 'appdirs' tries to import win32com.shell
    '_winreg', # 2.7 mimetypes needs immediate ImportError
    'pythoncom',
    # imported by tarfile, not available under Windows
    'pwd',
    'grp',
    # imported by profile, itself imported by hotshot.stats,
    # not available under Windows
    'resource',
    # this trips up many extension authors
    'gtk',
    # setuptools' pkg_resources.py expects "from __main__ import x" to
    # raise ImportError if x not defined
    '__main__',
    '_ssl', # conditional imports in the stdlib, issue1964
    '_sre', # issue4920
    'rfc822',
    'mimetools',
    'sqlalchemy.events', # has import-time side effects (issue5085)
    # setuptools 8 expects this module to explode early when not on windows
    'distutils.msvc9compiler',
    '__builtin__',
    'builtins',
    'urwid.command_map', # for pudb
    ]

_pypy = '__pypy__' in sys.builtin_module_names

if _pypy:
    ignore.extend([
        # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5)
        '_ctypes.pointer',
    ])

demandimport.init(ignore)

# Re-export.
isenabled = demandimport.isenabled
disable = demandimport.disable
deactivated = demandimport.deactivated

def enable():
    # chg pre-imports modules so do not enable demandimport for it
    if ('CHGINTERNALMARK' not in os.environ
        and os.environ.get('HGDEMANDIMPORT') != 'disable'):
        demandimport.enable()