view tests/hghave @ 5210:90d9ec0dc69d

merge: forcefully mark files that we get from the second parent as dirty After a hg merge, we want to include in the commit all the files that we got from the second parent, so that we have the correct file-level history. To make them visible to hg commit, we try to mark them as dirty. Unfortunately, right now we can't really mark them as dirty[1] - the best we can do is to mark them as needing a full comparison of their contents, but they will still be considered clean if they happen to be identical to the version in the first parent. This changeset extends the dirstate format in a compatible way, so that we can mark a file as dirty: Right now we use a negative file size to indicate we don't have valid stat data for this entry. In practice, this size is always -1. This patch uses -2 to indicate that the entry is dirty. Older versions of hg won't choke on this dirstate, but they may happily mark the file as clean after a full comparison, destroying all of our hard work. The patch adds a dirstate.normallookup method with the semantics of the current normaldirty, and changes normaldirty to forcefully mark the entry as dirty. This should fix issue522. [1] - well, we could put them in state 'm', but that state has a different meaning.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Thu, 23 Aug 2007 01:48:29 -0300
parents e5b21a549cc5
children 4fa0f2dff643
line wrap: on
line source

#!/usr/bin/env python
"""Test the running system for features availability. Exit with zero
if all features are there, non-zero otherwise. If a feature name is
prefixed with "no-", the absence of feature is tested.
"""
import optparse
import os
import sys
import tempfile

tempprefix = 'hg-hghave-'

def has_symlink():
    return hasattr(os, "symlink")

def has_fifo():
    return hasattr(os, "mkfifo")

def has_executablebit():
    fd, path = tempfile.mkstemp(prefix=tempprefix)
    os.close(fd)
    try:
        s = os.lstat(path).st_mode
        os.chmod(path, s | 0100)
        return (os.lstat(path).st_mode & 0100 != 0)
    finally:
        os.remove(path)

def has_eol_in_paths():
    try:
        fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r')
        os.close(fd)
        os.remove(path)
        return True
    except:
        return False

def has_hotshot():
    try:
        # hotshot.stats tests hotshot and many problematic dependencies
        # like profile.
        import hotshot.stats
        return True
    except ImportError:
        return False

def has_lsprof():
    try:
        import _lsprof
        return True
    except ImportError:
        return False

checks = {
    "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
    "execbit": (has_executablebit, "executable bit"),
    "fifo": (has_fifo, "named pipes"),
    "hotshot": (has_hotshot, "python hotshot module"),
    "lsprof": (has_lsprof, "python lsprof module"),
    "symlink": (has_symlink, "symbolic links"),
}

def list_features():
    for name, feature in checks.iteritems():
        desc = feature[1]
        print name + ':', desc

parser = optparse.OptionParser("%prog [options] [features]")
parser.add_option("--list-features", action="store_true",
                  help="list available features")
parser.add_option("-q", "--quiet", action="store_true",
                  help="check features silently")

if __name__ == '__main__':
    options, args = parser.parse_args()
    if options.list_features:
        list_features()
        sys.exit(0)

    quiet = options.quiet

    failures = 0

    def error(msg):
        global failures
        if not quiet:
            sys.stderr.write(msg + '\n')
        failures += 1

    for feature in args:
        negate = feature.startswith('no-')
        if negate:
            feature = feature[3:]

        if feature not in checks:
            error('hghave: unknown feature: ' + feature)
            continue

        check, desc = checks[feature]
        if not negate and not check():
            error('hghave: missing feature: ' + desc)
        elif negate and check():
            error('hghave: system supports %s' % desc)

    if failures != 0:
        sys.exit(1)