hgext/win32mbcs.py
author Matt Mackall <mpm@selenic.com>
Thu, 08 Oct 2009 01:16:32 -0500
changeset 9569 ceb0f59e1327
parent 9467 4c041f1ee1b4
parent 9567 02c43e8e0835
child 10050 dd37f044f1fa
child 10263 25e572394f5c
permissions -rw-r--r--
Merge with i18n
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6887
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
     1
# win32mbcs.py -- MBCS filename support for Mercurial
5846
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
     2
#
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
     3
# Copyright (c) 2008 Shun-ichi Goto <shunichi.goto@gmail.com>
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
     4
#
6887
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
     5
# Version: 0.2
5846
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
     6
# Author:  Shun-ichi Goto <shunichi.goto@gmail.com>
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
     7
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8001
diff changeset
     8
# This software may be used and distributed according to the terms of the
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8001
diff changeset
     9
# GNU General Public License version 2, incorporated herein by reference.
5846
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
    10
#
8228
eee2319c5895 add blank line after copyright notices and after header
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
    11
8932
f87884329419 extensions: fix up description lines some more
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8894
diff changeset
    12
'''allow the use of MBCS paths with problematic encodings
5846
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
    13
8001
c0e3aca616de win32mbcs: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7983
diff changeset
    14
Some MBCS encodings are not good for some path operations (i.e.
c0e3aca616de win32mbcs: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7983
diff changeset
    15
splitting path, case conversion, etc.) with its encoded bytes. We call
c0e3aca616de win32mbcs: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7983
diff changeset
    16
such a encoding (i.e. shift_jis and big5) as "problematic encoding".
c0e3aca616de win32mbcs: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7983
diff changeset
    17
This extension can be used to fix the issue with those encodings by
8665
e4ad46f9a004 win32mbcs: capitalize Unicode
Martin Geisler <mg@lazybytes.net>
parents: 8491
diff changeset
    18
wrapping some functions to convert to Unicode string before path
8001
c0e3aca616de win32mbcs: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7983
diff changeset
    19
operation.
5846
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
    20
8668
aea3a23151bd fixed typos found in translatable strings
Martin Geisler <mg@lazybytes.net>
parents: 8667
diff changeset
    21
This extension is useful for:
9216
9b2649b6ce5c win32mbcs: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9154
diff changeset
    22
9b2649b6ce5c win32mbcs: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9154
diff changeset
    23
- Japanese Windows users using shift_jis encoding.
9b2649b6ce5c win32mbcs: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9154
diff changeset
    24
- Chinese Windows users using big5 encoding.
9b2649b6ce5c win32mbcs: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9154
diff changeset
    25
- All users who use a repository with one of problematic encodings on
9b2649b6ce5c win32mbcs: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9154
diff changeset
    26
  case-insensitive file system.
6887
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
    27
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
    28
This extension is not needed for:
9216
9b2649b6ce5c win32mbcs: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9154
diff changeset
    29
9b2649b6ce5c win32mbcs: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9154
diff changeset
    30
- Any user who use only ASCII chars in path.
9b2649b6ce5c win32mbcs: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9154
diff changeset
    31
- Any user who do not use any of problematic encodings.
5846
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
    32
6887
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
    33
Note that there are some limitations on using this extension:
9216
9b2649b6ce5c win32mbcs: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9154
diff changeset
    34
9b2649b6ce5c win32mbcs: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9154
diff changeset
    35
- You should use single encoding in one repository.
9275
8164d1abaa36 win32mbcs: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9216
diff changeset
    36
- You should set same encoding for the repository by locale or
8164d1abaa36 win32mbcs: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9216
diff changeset
    37
  HGENCODING.
6887
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
    38
8665
e4ad46f9a004 win32mbcs: capitalize Unicode
Martin Geisler <mg@lazybytes.net>
parents: 8491
diff changeset
    39
Path encoding conversion are done between Unicode and
8760
bf17aeafb869 Spell Mercurial as a proper noun
timeless <timeless@gmail.com>
parents: 8714
diff changeset
    40
encoding.encoding which is decided by Mercurial from current locale
8001
c0e3aca616de win32mbcs: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents: 7983
diff changeset
    41
setting or HGENCODING.
8894
868670dbc237 extensions: improve the consistency of synopses
Cédric Duval <cedricduval@free.fr>
parents: 8866
diff changeset
    42
'''
5846
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
    43
9098
5e4654f5522d win32mbcs: look up modules using sys.modules (issue1729)
Brodie Rao <me+hg@dackz.net>
parents: 8932
diff changeset
    44
import os, sys
5846
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
    45
from mercurial.i18n import _
7948
de377b1a9a84 move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents: 7877
diff changeset
    46
from mercurial import util, encoding
5846
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
    47
6887
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
    48
def decode(arg):
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    49
    if isinstance(arg, str):
7948
de377b1a9a84 move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents: 7877
diff changeset
    50
        uarg = arg.decode(encoding.encoding)
de377b1a9a84 move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents: 7877
diff changeset
    51
        if arg == uarg.encode(encoding.encoding):
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    52
            return uarg
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    53
        raise UnicodeError("Not local encoding")
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    54
    elif isinstance(arg, tuple):
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    55
        return tuple(map(decode, arg))
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    56
    elif isinstance(arg, list):
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    57
        return map(decode, arg)
9131
2bbb8419720d win32mbcs: wrapper supports keyword arguments and dict result.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9100
diff changeset
    58
    elif isinstance(arg, dict):
2bbb8419720d win32mbcs: wrapper supports keyword arguments and dict result.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9100
diff changeset
    59
        for k, v in arg.items():
2bbb8419720d win32mbcs: wrapper supports keyword arguments and dict result.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9100
diff changeset
    60
            arg[k] = decode(v)
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    61
    return arg
6887
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
    62
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
    63
def encode(arg):
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    64
    if isinstance(arg, unicode):
7948
de377b1a9a84 move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents: 7877
diff changeset
    65
        return arg.encode(encoding.encoding)
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    66
    elif isinstance(arg, tuple):
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    67
        return tuple(map(encode, arg))
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    68
    elif isinstance(arg, list):
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    69
        return map(encode, arg)
9131
2bbb8419720d win32mbcs: wrapper supports keyword arguments and dict result.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9100
diff changeset
    70
    elif isinstance(arg, dict):
2bbb8419720d win32mbcs: wrapper supports keyword arguments and dict result.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9100
diff changeset
    71
        for k, v in arg.items():
2bbb8419720d win32mbcs: wrapper supports keyword arguments and dict result.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9100
diff changeset
    72
            arg[k] = encode(v)
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    73
    return arg
6887
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
    74
9132
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
    75
def appendsep(s):
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
    76
    # ensure the path ends with os.sep, appending it if necessary.
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
    77
    try:
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
    78
        us = decode(s)
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
    79
    except UnicodeError:
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
    80
        us = s
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
    81
    if us and us[-1] not in ':/\\':
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
    82
        s += os.sep
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
    83
    return s
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
    84
9131
2bbb8419720d win32mbcs: wrapper supports keyword arguments and dict result.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9100
diff changeset
    85
def wrapper(func, args, kwds):
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    86
    # check argument is unicode, then call original
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    87
    for arg in args:
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    88
        if isinstance(arg, unicode):
9131
2bbb8419720d win32mbcs: wrapper supports keyword arguments and dict result.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9100
diff changeset
    89
            return func(*args, **kwds)
5846
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
    90
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    91
    try:
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    92
        # convert arguments to unicode, call func, then convert back
9131
2bbb8419720d win32mbcs: wrapper supports keyword arguments and dict result.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9100
diff changeset
    93
        return encode(func(*decode(args), **decode(kwds)))
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
    94
    except UnicodeError:
9132
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
    95
        raise util.Abort(_("[win32mbcs] filename conversion failed with"
7948
de377b1a9a84 move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents: 7877
diff changeset
    96
                         " %s encoding\n") % (encoding.encoding))
6887
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
    97
9132
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
    98
def wrapperforlistdir(func, args, kwds):
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
    99
    # Ensure 'path' argument ends with os.sep to avoids
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
   100
    # misinterpreting last 0x5c of MBCS 2nd byte as path separator.
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
   101
    if args:
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
   102
        args = list(args)
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
   103
        args[0] = appendsep(args[0])
9391
2705e6816d33 use 'x in dict' instead of 'dict.has_key(x)'
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9275
diff changeset
   104
    if 'path' in kwds:
9132
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
   105
        kwds['path'] = appendsep(kwds['path'])
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
   106
    return func(*args, **kwds)
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
   107
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
   108
def wrapname(name, wrapper):
9098
5e4654f5522d win32mbcs: look up modules using sys.modules (issue1729)
Brodie Rao <me+hg@dackz.net>
parents: 8932
diff changeset
   109
    module, name = name.rsplit('.', 1)
5e4654f5522d win32mbcs: look up modules using sys.modules (issue1729)
Brodie Rao <me+hg@dackz.net>
parents: 8932
diff changeset
   110
    module = sys.modules[module]
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
   111
    func = getattr(module, name)
9131
2bbb8419720d win32mbcs: wrapper supports keyword arguments and dict result.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9100
diff changeset
   112
    def f(*args, **kwds):
2bbb8419720d win32mbcs: wrapper supports keyword arguments and dict result.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9100
diff changeset
   113
        return wrapper(func, args, kwds)
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
   114
    try:
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
   115
        f.__name__ = func.__name__                # fail with python23
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
   116
    except Exception:
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
   117
        pass
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
   118
    setattr(module, name, f)
6887
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
   119
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
   120
# List of functions to be wrapped.
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
   121
# NOTE: os.path.dirname() and os.path.basename() are safe because
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
   122
#       they use result of os.path.split()
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
   123
funcs = '''os.path.join os.path.split os.path.splitext
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
   124
 os.path.splitunc os.path.normpath os.path.normcase os.makedirs
9098
5e4654f5522d win32mbcs: look up modules using sys.modules (issue1729)
Brodie Rao <me+hg@dackz.net>
parents: 8932
diff changeset
   125
 mercurial.util.endswithsep mercurial.util.splitpath mercurial.util.checkcase
9465
661bc51f09b7 win32mbcs: util.normpath should be wrapped.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9441
diff changeset
   126
 mercurial.util.fspath mercurial.util.pconvert mercurial.util.normpath'''
5846
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
   127
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
   128
# codec and alias names of sjis and big5 to be faked.
6887
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
   129
problematic_encodings = '''big5 big5-tw csbig5 big5hkscs big5-hkscs
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
   130
 hkscs cp932 932 ms932 mskanji ms-kanji shift_jis csshiftjis shiftjis
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
   131
 sjis s_jis shift_jis_2004 shiftjis2004 sjis_2004 sjis2004
8714
505a96cbc923 Add cp950 as problematic encoding which is used in chinese windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 8668
diff changeset
   132
 shift_jisx0213 shiftjisx0213 sjisx0213 s_jisx0213 950 cp950 ms950 '''
5846
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
   133
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
   134
def reposetup(ui, repo):
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
   135
    # TODO: decide use of config section for this extension
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
   136
    if not os.path.supports_unicode_filenames:
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
   137
        ui.warn(_("[win32mbcs] cannot activate on this platform.\n"))
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
   138
        return
5846
02884e56c217 New extension to support problematic MBCS on Windows.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
diff changeset
   139
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
   140
    # fake is only for relevant environment.
7948
de377b1a9a84 move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents: 7877
diff changeset
   141
    if encoding.encoding.lower() in problematic_encodings.split():
7877
eba7f12b0c51 cleanup: whitespace cleanup
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7598
diff changeset
   142
        for f in funcs.split():
9132
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
   143
            wrapname(f, wrapper)
b47d7b440c5c win32mbcs: add special wrapper for osutil.listdir().
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents: 9131
diff changeset
   144
        wrapname("mercurial.osutil.listdir", wrapperforlistdir)
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 9466
diff changeset
   145
        ui.debug("[win32mbcs] activated with encoding: %s\n"
7948
de377b1a9a84 move encoding bits from util to encoding
Matt Mackall <mpm@selenic.com>
parents: 7877
diff changeset
   146
                 % encoding.encoding)
6887
304484c7e0ba Update win32mbcs extension
Shun-ichi Goto <shunichi.goto@gmail.com>
parents: 6210
diff changeset
   147