Git fork

userdiff: add built-in pattern for CSS

CSS is widely used, motivating it being included as a built-in pattern.

It must be noted that the word_regex for CSS (i.e. the regex defining
what is a word in the language) does not consider '.' and '#' characters
(in CSS selectors) to be part of the word. This behavior is documented
by the test t/t4018/css-rule.
The logic behind this behavior is the following: identifiers in CSS
selectors are identifiers in a HTML/XML document. Therefore, the '.'/'#'
character are not part of the identifier, but an indicator of the nature
of the identifier in HTML/XML (class or id). Diffing ".class1" and
".class2" must show that the class name is changed, but we still are
selecting a class.

Logic behind the "pattern" regex is:
1. reject lines ending with a colon/semicolon (properties)
2. if a line begins with a name in column 1, pick the whole line

Credits to Johannes Sixt (j6t@kdbg.org) for the pattern regex and most
of the tests.

Signed-off-by: William Duclot <william.duclot@ensimag.grenoble-inp.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Reviewed-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

William Duclot and committed by
Junio C Hamano
0719f3ee 4b0891ff

+90
+2
Documentation/gitattributes.txt
··· 525 525 526 526 - `csharp` suitable for source code in the C# language. 527 527 528 + - `css` suitable for cascading style sheets. 529 + 528 530 - `fortran` suitable for source code in the Fortran language. 529 531 530 532 - `fountain` suitable for Fountain documents.
+1
t/t4018-diff-funcname.sh
··· 30 30 bibtex 31 31 cpp 32 32 csharp 33 + css 33 34 fortran 34 35 fountain 35 36 html
+5
t/t4018/css-brace-in-col-1
··· 1 + RIGHT label.control-label 2 + { 3 + margin-top: 10px!important; 4 + border : 10px ChangeMe #C6C6C6; 5 + }
+4
t/t4018/css-colon-eol
··· 1 + RIGHT h1 { 2 + color: 3 + ChangeMe; 4 + }
+5
t/t4018/css-colon-selector
··· 1 + RIGHT a:hover { 2 + margin-top: 3 + 10px!important; 4 + border : 10px ChangeMe #C6C6C6; 5 + }
+4
t/t4018/css-common
··· 1 + RIGHT label.control-label { 2 + margin-top: 10px!important; 3 + border : 10px ChangeMe #C6C6C6; 4 + }
+6
t/t4018/css-long-selector-list
··· 1 + p.header, 2 + label.control-label, 3 + div ul#RIGHT { 4 + margin-top: 10px!important; 5 + border : 10px ChangeMe #C6C6C6; 6 + }
+5
t/t4018/css-prop-sans-indent
··· 1 + RIGHT, label.control-label { 2 + margin-top: 10px!important; 3 + padding: 0; 4 + border : 10px ChangeMe #C6C6C6; 5 + }
+4
t/t4018/css-short-selector-list
··· 1 + label.control, div ul#RIGHT { 2 + margin-top: 10px!important; 3 + border : 10px ChangeMe #C6C6C6; 4 + }
+5
t/t4018/css-trailing-space
··· 1 + RIGHT label.control-label { 2 + margin:10px; 3 + padding:10px; 4 + border : 10px ChangeMe #C6C6C6; 5 + }
+1
t/t4034-diff-words.sh
··· 302 302 test_language_driver bibtex 303 303 test_language_driver cpp 304 304 test_language_driver csharp 305 + test_language_driver css 305 306 test_language_driver fortran 306 307 test_language_driver html 307 308 test_language_driver java
+16
t/t4034/css/expect
··· 1 + <BOLD>diff --git a/pre b/post<RESET> 2 + <BOLD>index b8ae0bb..fe500b7 100644<RESET> 3 + <BOLD>--- a/pre<RESET> 4 + <BOLD>+++ b/post<RESET> 5 + <CYAN>@@ -1,10 +1,10 @@<RESET> 6 + .<RED>class-form<RESET><GREEN>other-form<RESET> label.control-label { 7 + margin-top: <RED>10<RESET><GREEN>15<RESET>px!important; 8 + border : 10px <RED>dashed<RESET><GREEN>dotted<RESET> #C6C6C6; 9 + }<RESET> 10 + <RED>#CCCCCC<RESET><GREEN>#CCCCCB<RESET> 11 + 10em<RESET> 12 + <RED>padding-bottom<RESET><GREEN>margin-left<RESET> 13 + 150<RED>px<RESET><GREEN>em<RESET> 14 + 10px 15 + <RED>!important<RESET> 16 + <RED>div<RESET><GREEN>li<RESET>.class#id
+10
t/t4034/css/post
··· 1 + .other-form label.control-label { 2 + margin-top: 15px!important; 3 + border : 10px dotted #C6C6C6; 4 + } 5 + #CCCCCB 6 + 10em 7 + margin-left 8 + 150em 9 + 10px 10 + li.class#id
+10
t/t4034/css/pre
··· 1 + .class-form label.control-label { 2 + margin-top: 10px!important; 3 + border : 10px dashed #C6C6C6; 4 + } 5 + #CCCCCC 6 + 10em 7 + padding-bottom 8 + 150px 9 + 10px!important 10 + div.class#id
+12
userdiff.c
··· 148 148 "[a-zA-Z_][a-zA-Z0-9_]*" 149 149 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" 150 150 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"), 151 + IPATTERN("css", 152 + "![:;][[:space:]]*$\n" 153 + "^[_a-z0-9].*$", 154 + /* -- */ 155 + /* 156 + * This regex comes from W3C CSS specs. Should theoretically also 157 + * allow ISO 10646 characters U+00A0 and higher, 158 + * but they are not handled in this regex. 159 + */ 160 + "-?[_a-zA-Z][-_a-zA-Z0-9]*" /* identifiers */ 161 + "|-?[0-9]+|\\#[0-9a-fA-F]+" /* numbers */ 162 + ), 151 163 { "default", NULL, -1, { NULL, 0 } }, 152 164 }; 153 165 #undef PATTERNS