Пример #1
0
def check(text, truecases, falsecases):
    f = minifileset.compile(text)
    for args in truecases:
        if not f(*args):
            print('unexpected: %r should include %r' % (text, args))
    for args in falsecases:
        if f(*args):
            print('unexpected: %r should exclude %r' % (text, args))
Пример #2
0
def _trackedmatcher(repo):
    """Return a function (path, size) -> bool indicating whether or not to
    track a given file with lfs."""
    if not repo.wvfs.exists(b'.hglfs'):
        # No '.hglfs' in wdir.  Fallback to config for now.
        trackspec = repo.ui.config(b'lfs', b'track')

        # deprecated config: lfs.threshold
        threshold = repo.ui.configbytes(b'lfs', b'threshold')
        if threshold:
            filesetlang.parse(
                trackspec)  # make sure syntax errors are confined
            trackspec = b"(%s) | size('>%d')" % (trackspec, threshold)

        return minifileset.compile(trackspec)

    data = repo.wvfs.tryread(b'.hglfs')
    if not data:
        return lambda p, s: False

    # Parse errors here will abort with a message that points to the .hglfs file
    # and line number.
    cfg = config.config()
    cfg.parse(b'.hglfs', data)

    try:
        rules = [(minifileset.compile(pattern), minifileset.compile(rule))
                 for pattern, rule in cfg.items(b'track')]
    except error.ParseError as e:
        # The original exception gives no indicator that the error is in the
        # .hglfs file, so add that.

        # TODO: See if the line number of the file can be made available.
        raise error.Abort(_(b'parse error in .hglfs: %s') % e)

    def _match(path, size):
        for pat, rule in rules:
            if pat(path, size):
                return rule(path, size)

        return False

    return _match