]> git.ipfire.org Git - thirdparty/git.git/commit
userdiff: simplify word-diff safeguard
authorJonathan Nieder <jrnieder@gmail.com>
Tue, 11 Jan 2011 21:48:50 +0000 (15:48 -0600)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Jan 2011 16:59:39 +0000 (08:59 -0800)
commit664d44ee7fb18bdfdd66a1be760c7ee1bbe911c6
treee7a26f9f61b8f3f05702c491a7bb28325d07d265
parent8d96e7288f2be9de6d09352dc445f18f89564500
userdiff: simplify word-diff safeguard

git's diff-words support has a detail that can be a little dangerous:
any text not matched by a given language's tokenization pattern is
treated as whitespace and changes in such text would go unnoticed.
Therefore each of the built-in regexes allows a special token type
consisting of a single non-whitespace character [^[:space:]].

To make sure UTF-8 sequences remain human readable, the builtin
regexes also have a special token type for runs of bytes with the high
bit set.  In English, non-ASCII characters are usually isolated so
this is analogous to the [^[:space:]] pattern, except it matches a
single _multibyte_ character despite use of the C locale.

Unfortunately it is easy to make typos or forget entirely to include
these catch-all token types when adding support for new languages (see
v1.7.3.5~16, userdiff: fix typo in ruby and python word regexes,
2010-12-18).  Avoid this by including them automatically within the
PATTERNS and IPATTERN macros.

While at it, change the UTF-8 sequence token type to match exactly one
non-ASCII multi-byte character, rather than an arbitrary run of them.

Suggested-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
userdiff.c