view contrib/casesmash.py @ 22313:d226fe36e362

memctx: allow extensions to determine what filectxfn should do Rev 650b5b6e75ed switched the contract for filectxfn from "raise IOError if file is missing" to "return None if file is missing". Out of tree extensions need to be updated for that, but for extensions interested in compatibility with both Mercurial <= 3.1 and default, it is next to impossible to introspect core Mercurial to figure out what to do. This patch adds a field to memctx for extensions to use.
author Siddharth Agarwal <sid0@fb.com>
date Sat, 30 Aug 2014 05:29:38 -0700
parents 9de689d20230
children 42a7301fb4d5
line wrap: on
line source

import os, __builtin__
from mercurial import util

def lowerwrap(scope, funcname):
    f = getattr(scope, funcname)
    def wrap(fname, *args, **kwargs):
        d, base = os.path.split(fname)
        try:
            files = os.listdir(d or '.')
        except OSError:
            files = []
        if base in files:
            return f(fname, *args, **kwargs)
        for fn in files:
            if fn.lower() == base.lower():
                return f(os.path.join(d, fn), *args, **kwargs)
        return f(fname, *args, **kwargs)
    scope.__dict__[funcname] = wrap

def normcase(path):
    return path.lower()

os.path.normcase = normcase

for f in 'file open'.split():
    lowerwrap(__builtin__, f)

for f in "chmod chown open lstat stat remove unlink".split():
    lowerwrap(os, f)

for f in "exists lexists".split():
    lowerwrap(os.path, f)

lowerwrap(util, 'posixfile')