# HG changeset patch # User FUJIWARA Katsunori # Date 2011-12-25 11:35:16 # Node ID 988409e44a7638de30b2c5e9fe76453d8ff07744 # Parent 9e6a13c2aeb985e90b3cdff3b7aabf52b9e62721 i18n: use "encoding.lower()" to normalize specified keywords for log searching some problematic encoding (e.g.: cp932) uses ASCII alphabet characters in byte sequence of multi byte characters. "str.lower()" on such byte sequence may treat distinct characters as same one, and cause unexpected log matching. this patch uses "encoding.lower()" instead of "str.lower()" to normalize strings for compare. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -3897,14 +3897,21 @@ def log(ui, repo, *pats, **opts): return if df and not df(ctx.date()[0]): return - if opts['user'] and not [k for k in opts['user'] - if k.lower() in ctx.user().lower()]: - return + + lower = encoding.lower + if opts.get('user'): + luser = lower(ctx.user()) + for k in [lower(x) for x in opts['user']]: + if (k in luser): + break + else: + return if opts.get('keyword'): - for k in [kw.lower() for kw in opts['keyword']]: - if (k in ctx.user().lower() or - k in ctx.description().lower() or - k in " ".join(ctx.files()).lower()): + luser = lower(ctx.user()) + ldesc = lower(ctx.description()) + lfiles = lower(" ".join(ctx.files())) + for k in [lower(x) for x in opts['keyword']]: + if (k in luser or k in ldesc or k in lfiles): break else: return diff --git a/tests/test-log.t b/tests/test-log.t --- a/tests/test-log.t +++ b/tests/test-log.t @@ -1159,3 +1159,56 @@ Diff here should be the same: $ hg log --template='{rev}:{node}\n' --hidden 1:a765632148dc55d38c35c4f247c618701886cb2f 0:9f758d63dcde62d547ebfb08e1e7ee96535f2b05 + +clear extensions configuration + $ echo '[extensions]' >> $HGRCPATH + $ echo "hidden=!" >> $HGRCPATH + $ cd .. + +test -u/-k for problematic encoding +# unicode: cp932: +# u30A2 0x83 0x41(= 'A') +# u30C2 0x83 0x61(= 'a') + + $ hg init problematicencoding + $ cd problematicencoding + + $ python > setup.sh < print u''' + > echo a > text + > hg add text + > hg --encoding utf-8 commit -u '\u30A2' -m none + > echo b > text + > hg --encoding utf-8 commit -u '\u30C2' -m none + > echo c > text + > hg --encoding utf-8 commit -u none -m '\u30A2' + > echo d > text + > hg --encoding utf-8 commit -u none -m '\u30C2' + > '''.encode('utf-8') + > EOF + $ sh < setup.sh + +test in problematic encoding + $ python > test.sh < print u''' + > hg --encoding cp932 log --template '{rev}\\n' -u '\u30A2' + > echo ==== + > hg --encoding cp932 log --template '{rev}\\n' -u '\u30C2' + > echo ==== + > hg --encoding cp932 log --template '{rev}\\n' -k '\u30A2' + > echo ==== + > hg --encoding cp932 log --template '{rev}\\n' -k '\u30C2' + > '''.encode('cp932') + > EOF + $ sh < test.sh + 0 + ==== + 1 + ==== + 2 + 0 + ==== + 3 + 1 + + $ cd ..