Fossil SCM
Add warning for overly long lines found during the commit process.
Commit
10fbcda270363ce07ad379c105ffb336ee8fcdbb
Parent
ccdd1abba7c752a…
2 files changed
+8
-2
+9
-3
+8
-2
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -902,17 +902,19 @@ | ||
| 902 | 902 | int encodingOk, /* Non-zero if encoding warnings should be disabled. */ |
| 903 | 903 | const char *zFilename /* The full name of the file being committed. */ |
| 904 | 904 | ){ |
| 905 | 905 | int eType; /* return value of looks_like_utf8/utf16() */ |
| 906 | 906 | int fUnicode; /* return value of starts_with_utf16_bom() */ |
| 907 | + int longLine; /* non-zero if blob has "long lines" */ | |
| 907 | 908 | char *zMsg; /* Warning message */ |
| 908 | 909 | Blob fname; /* Relative pathname of the file */ |
| 909 | 910 | static int allOk = 0; /* Set to true to disable this routine */ |
| 910 | 911 | |
| 911 | 912 | if( allOk ) return 0; |
| 912 | 913 | fUnicode = starts_with_utf16_bom(p, 0, 0); |
| 913 | - eType = fUnicode ? looks_like_utf16(p) : looks_like_utf8(p); | |
| 914 | + eType = fUnicode ? looks_like_utf16(p, &longLine) : | |
| 915 | + looks_like_utf8(p, &longLine); | |
| 914 | 916 | if( eType==0 || eType==-1 || fUnicode ){ |
| 915 | 917 | const char *zWarning; |
| 916 | 918 | const char *zDisable; |
| 917 | 919 | const char *zConvert = "c=convert/"; |
| 918 | 920 | Blob ans; |
| @@ -932,11 +934,15 @@ | ||
| 932 | 934 | zDisable = "\"crnl-glob\" setting"; |
| 933 | 935 | }else if( eType==0 ){ |
| 934 | 936 | if( binOk ){ |
| 935 | 937 | return 0; /* We don't want binary warnings for this file. */ |
| 936 | 938 | } |
| 937 | - zWarning = "binary data"; | |
| 939 | + if( longLine ){ | |
| 940 | + zWarning = "long lines"; | |
| 941 | + }else{ | |
| 942 | + zWarning = "binary data"; | |
| 943 | + } | |
| 938 | 944 | zDisable = "\"binary-glob\" setting"; |
| 939 | 945 | zConvert = ""; /* We cannot convert binary files. */ |
| 940 | 946 | }else{ |
| 941 | 947 | if ( encodingOk ){ |
| 942 | 948 | return 0; /* We don't want encoding warnings for this file. */ |
| 943 | 949 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -902,17 +902,19 @@ | |
| 902 | int encodingOk, /* Non-zero if encoding warnings should be disabled. */ |
| 903 | const char *zFilename /* The full name of the file being committed. */ |
| 904 | ){ |
| 905 | int eType; /* return value of looks_like_utf8/utf16() */ |
| 906 | int fUnicode; /* return value of starts_with_utf16_bom() */ |
| 907 | char *zMsg; /* Warning message */ |
| 908 | Blob fname; /* Relative pathname of the file */ |
| 909 | static int allOk = 0; /* Set to true to disable this routine */ |
| 910 | |
| 911 | if( allOk ) return 0; |
| 912 | fUnicode = starts_with_utf16_bom(p, 0, 0); |
| 913 | eType = fUnicode ? looks_like_utf16(p) : looks_like_utf8(p); |
| 914 | if( eType==0 || eType==-1 || fUnicode ){ |
| 915 | const char *zWarning; |
| 916 | const char *zDisable; |
| 917 | const char *zConvert = "c=convert/"; |
| 918 | Blob ans; |
| @@ -932,11 +934,15 @@ | |
| 932 | zDisable = "\"crnl-glob\" setting"; |
| 933 | }else if( eType==0 ){ |
| 934 | if( binOk ){ |
| 935 | return 0; /* We don't want binary warnings for this file. */ |
| 936 | } |
| 937 | zWarning = "binary data"; |
| 938 | zDisable = "\"binary-glob\" setting"; |
| 939 | zConvert = ""; /* We cannot convert binary files. */ |
| 940 | }else{ |
| 941 | if ( encodingOk ){ |
| 942 | return 0; /* We don't want encoding warnings for this file. */ |
| 943 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -902,17 +902,19 @@ | |
| 902 | int encodingOk, /* Non-zero if encoding warnings should be disabled. */ |
| 903 | const char *zFilename /* The full name of the file being committed. */ |
| 904 | ){ |
| 905 | int eType; /* return value of looks_like_utf8/utf16() */ |
| 906 | int fUnicode; /* return value of starts_with_utf16_bom() */ |
| 907 | int longLine; /* non-zero if blob has "long lines" */ |
| 908 | char *zMsg; /* Warning message */ |
| 909 | Blob fname; /* Relative pathname of the file */ |
| 910 | static int allOk = 0; /* Set to true to disable this routine */ |
| 911 | |
| 912 | if( allOk ) return 0; |
| 913 | fUnicode = starts_with_utf16_bom(p, 0, 0); |
| 914 | eType = fUnicode ? looks_like_utf16(p, &longLine) : |
| 915 | looks_like_utf8(p, &longLine); |
| 916 | if( eType==0 || eType==-1 || fUnicode ){ |
| 917 | const char *zWarning; |
| 918 | const char *zDisable; |
| 919 | const char *zConvert = "c=convert/"; |
| 920 | Blob ans; |
| @@ -932,11 +934,15 @@ | |
| 934 | zDisable = "\"crnl-glob\" setting"; |
| 935 | }else if( eType==0 ){ |
| 936 | if( binOk ){ |
| 937 | return 0; /* We don't want binary warnings for this file. */ |
| 938 | } |
| 939 | if( longLine ){ |
| 940 | zWarning = "long lines"; |
| 941 | }else{ |
| 942 | zWarning = "binary data"; |
| 943 | } |
| 944 | zDisable = "\"binary-glob\" setting"; |
| 945 | zConvert = ""; /* We cannot convert binary files. */ |
| 946 | }else{ |
| 947 | if ( encodingOk ){ |
| 948 | return 0; /* We don't want encoding warnings for this file. */ |
| 949 |
+9
-3
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -57,11 +57,11 @@ | ||
| 57 | 57 | "more than 10,000 changes\n" |
| 58 | 58 | |
| 59 | 59 | #define DIFF_TOO_MANY_CHANGES_HTML \ |
| 60 | 60 | "<p class='generalError'>More than 10,000 changes</p>\n" |
| 61 | 61 | |
| 62 | -#define looks_like_binary(blob) (looks_like_utf8((blob)) == 0) | |
| 62 | +#define looks_like_binary(blob) (looks_like_utf8((blob), 0) == 0) | |
| 63 | 63 | #endif /* INTERFACE */ |
| 64 | 64 | |
| 65 | 65 | /* |
| 66 | 66 | ** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes) |
| 67 | 67 | */ |
| @@ -211,18 +211,19 @@ | ||
| 211 | 211 | ** The only code points that this function cares about are the NUL character, |
| 212 | 212 | ** carriage-return, and line-feed. |
| 213 | 213 | ** |
| 214 | 214 | ************************************ WARNING ********************************** |
| 215 | 215 | */ |
| 216 | -int looks_like_utf8(const Blob *pContent){ | |
| 216 | +int looks_like_utf8(const Blob *pContent, int *pbLongLine){ | |
| 217 | 217 | const char *z = blob_buffer(pContent); |
| 218 | 218 | unsigned int n = blob_size(pContent); |
| 219 | 219 | int j, c; |
| 220 | 220 | int result = 1; /* Assume UTF-8 text with no CR/NL */ |
| 221 | 221 | |
| 222 | 222 | /* Check individual lines. |
| 223 | 223 | */ |
| 224 | + if( pbLongLine ) *pbLongLine = 0; | |
| 224 | 225 | if( n==0 ) return result; /* Empty file -> text */ |
| 225 | 226 | c = *z; |
| 226 | 227 | if( c==0 ) return 0; /* Zero byte in a file -> binary */ |
| 227 | 228 | j = (c!='\n'); |
| 228 | 229 | while( --n>0 ){ |
| @@ -232,16 +233,18 @@ | ||
| 232 | 233 | int c2 = z[-1]; |
| 233 | 234 | if( c2=='\r' ){ |
| 234 | 235 | result = -1; /* Contains CR/NL, continue */ |
| 235 | 236 | } |
| 236 | 237 | if( j>LENGTH_MASK ){ |
| 238 | + if( pbLongLine ) *pbLongLine = 1; | |
| 237 | 239 | return 0; /* Very long line -> binary */ |
| 238 | 240 | } |
| 239 | 241 | j = 0; |
| 240 | 242 | } |
| 241 | 243 | } |
| 242 | 244 | if( j>LENGTH_MASK ){ |
| 245 | + if( pbLongLine ) *pbLongLine = 1; | |
| 243 | 246 | return 0; /* Very long line -> binary */ |
| 244 | 247 | } |
| 245 | 248 | return result; /* No problems seen -> not binary */ |
| 246 | 249 | } |
| 247 | 250 | |
| @@ -301,18 +304,19 @@ | ||
| 301 | 304 | ** The only code points that this function cares about are the NUL character, |
| 302 | 305 | ** carriage-return, and line-feed. |
| 303 | 306 | ** |
| 304 | 307 | ************************************ WARNING ********************************** |
| 305 | 308 | */ |
| 306 | -int looks_like_utf16(const Blob *pContent){ | |
| 309 | +int looks_like_utf16(const Blob *pContent, int *pbLongLine){ | |
| 307 | 310 | const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent); |
| 308 | 311 | unsigned int n = blob_size(pContent); |
| 309 | 312 | int j, c; |
| 310 | 313 | int result = 1; /* Assume UTF-16 text with no CR/NL */ |
| 311 | 314 | |
| 312 | 315 | /* Check individual lines. |
| 313 | 316 | */ |
| 317 | + if( pbLongLine ) *pbLongLine = 0; | |
| 314 | 318 | if( n==0 ) return result; /* Empty file -> text */ |
| 315 | 319 | if( n%2 ) return 0; /* Odd number of bytes -> binary (or UTF-8) */ |
| 316 | 320 | c = *z; |
| 317 | 321 | if( c==0 ) return 0; /* NUL character in a file -> binary */ |
| 318 | 322 | j = ((c!=UTF16BE_LF) && (c!=UTF16LE_LF)); |
| @@ -323,16 +327,18 @@ | ||
| 323 | 327 | int c2 = z[-1]; |
| 324 | 328 | if( c2==UTF16BE_CR || c2==UTF16LE_CR ){ |
| 325 | 329 | result = -1; /* Contains CR/NL, continue */ |
| 326 | 330 | } |
| 327 | 331 | if( j>UTF16_LENGTH_MASK ){ |
| 332 | + if( pbLongLine ) *pbLongLine = 1; | |
| 328 | 333 | return 0; /* Very long line -> binary */ |
| 329 | 334 | } |
| 330 | 335 | j = 0; |
| 331 | 336 | } |
| 332 | 337 | } |
| 333 | 338 | if( j>UTF16_LENGTH_MASK ){ |
| 339 | + if( pbLongLine ) *pbLongLine = 1; | |
| 334 | 340 | return 0; /* Very long line -> binary */ |
| 335 | 341 | } |
| 336 | 342 | return result; /* No problems seen -> not binary */ |
| 337 | 343 | } |
| 338 | 344 | |
| 339 | 345 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -57,11 +57,11 @@ | |
| 57 | "more than 10,000 changes\n" |
| 58 | |
| 59 | #define DIFF_TOO_MANY_CHANGES_HTML \ |
| 60 | "<p class='generalError'>More than 10,000 changes</p>\n" |
| 61 | |
| 62 | #define looks_like_binary(blob) (looks_like_utf8((blob)) == 0) |
| 63 | #endif /* INTERFACE */ |
| 64 | |
| 65 | /* |
| 66 | ** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes) |
| 67 | */ |
| @@ -211,18 +211,19 @@ | |
| 211 | ** The only code points that this function cares about are the NUL character, |
| 212 | ** carriage-return, and line-feed. |
| 213 | ** |
| 214 | ************************************ WARNING ********************************** |
| 215 | */ |
| 216 | int looks_like_utf8(const Blob *pContent){ |
| 217 | const char *z = blob_buffer(pContent); |
| 218 | unsigned int n = blob_size(pContent); |
| 219 | int j, c; |
| 220 | int result = 1; /* Assume UTF-8 text with no CR/NL */ |
| 221 | |
| 222 | /* Check individual lines. |
| 223 | */ |
| 224 | if( n==0 ) return result; /* Empty file -> text */ |
| 225 | c = *z; |
| 226 | if( c==0 ) return 0; /* Zero byte in a file -> binary */ |
| 227 | j = (c!='\n'); |
| 228 | while( --n>0 ){ |
| @@ -232,16 +233,18 @@ | |
| 232 | int c2 = z[-1]; |
| 233 | if( c2=='\r' ){ |
| 234 | result = -1; /* Contains CR/NL, continue */ |
| 235 | } |
| 236 | if( j>LENGTH_MASK ){ |
| 237 | return 0; /* Very long line -> binary */ |
| 238 | } |
| 239 | j = 0; |
| 240 | } |
| 241 | } |
| 242 | if( j>LENGTH_MASK ){ |
| 243 | return 0; /* Very long line -> binary */ |
| 244 | } |
| 245 | return result; /* No problems seen -> not binary */ |
| 246 | } |
| 247 | |
| @@ -301,18 +304,19 @@ | |
| 301 | ** The only code points that this function cares about are the NUL character, |
| 302 | ** carriage-return, and line-feed. |
| 303 | ** |
| 304 | ************************************ WARNING ********************************** |
| 305 | */ |
| 306 | int looks_like_utf16(const Blob *pContent){ |
| 307 | const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent); |
| 308 | unsigned int n = blob_size(pContent); |
| 309 | int j, c; |
| 310 | int result = 1; /* Assume UTF-16 text with no CR/NL */ |
| 311 | |
| 312 | /* Check individual lines. |
| 313 | */ |
| 314 | if( n==0 ) return result; /* Empty file -> text */ |
| 315 | if( n%2 ) return 0; /* Odd number of bytes -> binary (or UTF-8) */ |
| 316 | c = *z; |
| 317 | if( c==0 ) return 0; /* NUL character in a file -> binary */ |
| 318 | j = ((c!=UTF16BE_LF) && (c!=UTF16LE_LF)); |
| @@ -323,16 +327,18 @@ | |
| 323 | int c2 = z[-1]; |
| 324 | if( c2==UTF16BE_CR || c2==UTF16LE_CR ){ |
| 325 | result = -1; /* Contains CR/NL, continue */ |
| 326 | } |
| 327 | if( j>UTF16_LENGTH_MASK ){ |
| 328 | return 0; /* Very long line -> binary */ |
| 329 | } |
| 330 | j = 0; |
| 331 | } |
| 332 | } |
| 333 | if( j>UTF16_LENGTH_MASK ){ |
| 334 | return 0; /* Very long line -> binary */ |
| 335 | } |
| 336 | return result; /* No problems seen -> not binary */ |
| 337 | } |
| 338 | |
| 339 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -57,11 +57,11 @@ | |
| 57 | "more than 10,000 changes\n" |
| 58 | |
| 59 | #define DIFF_TOO_MANY_CHANGES_HTML \ |
| 60 | "<p class='generalError'>More than 10,000 changes</p>\n" |
| 61 | |
| 62 | #define looks_like_binary(blob) (looks_like_utf8((blob), 0) == 0) |
| 63 | #endif /* INTERFACE */ |
| 64 | |
| 65 | /* |
| 66 | ** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes) |
| 67 | */ |
| @@ -211,18 +211,19 @@ | |
| 211 | ** The only code points that this function cares about are the NUL character, |
| 212 | ** carriage-return, and line-feed. |
| 213 | ** |
| 214 | ************************************ WARNING ********************************** |
| 215 | */ |
| 216 | int looks_like_utf8(const Blob *pContent, int *pbLongLine){ |
| 217 | const char *z = blob_buffer(pContent); |
| 218 | unsigned int n = blob_size(pContent); |
| 219 | int j, c; |
| 220 | int result = 1; /* Assume UTF-8 text with no CR/NL */ |
| 221 | |
| 222 | /* Check individual lines. |
| 223 | */ |
| 224 | if( pbLongLine ) *pbLongLine = 0; |
| 225 | if( n==0 ) return result; /* Empty file -> text */ |
| 226 | c = *z; |
| 227 | if( c==0 ) return 0; /* Zero byte in a file -> binary */ |
| 228 | j = (c!='\n'); |
| 229 | while( --n>0 ){ |
| @@ -232,16 +233,18 @@ | |
| 233 | int c2 = z[-1]; |
| 234 | if( c2=='\r' ){ |
| 235 | result = -1; /* Contains CR/NL, continue */ |
| 236 | } |
| 237 | if( j>LENGTH_MASK ){ |
| 238 | if( pbLongLine ) *pbLongLine = 1; |
| 239 | return 0; /* Very long line -> binary */ |
| 240 | } |
| 241 | j = 0; |
| 242 | } |
| 243 | } |
| 244 | if( j>LENGTH_MASK ){ |
| 245 | if( pbLongLine ) *pbLongLine = 1; |
| 246 | return 0; /* Very long line -> binary */ |
| 247 | } |
| 248 | return result; /* No problems seen -> not binary */ |
| 249 | } |
| 250 | |
| @@ -301,18 +304,19 @@ | |
| 304 | ** The only code points that this function cares about are the NUL character, |
| 305 | ** carriage-return, and line-feed. |
| 306 | ** |
| 307 | ************************************ WARNING ********************************** |
| 308 | */ |
| 309 | int looks_like_utf16(const Blob *pContent, int *pbLongLine){ |
| 310 | const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent); |
| 311 | unsigned int n = blob_size(pContent); |
| 312 | int j, c; |
| 313 | int result = 1; /* Assume UTF-16 text with no CR/NL */ |
| 314 | |
| 315 | /* Check individual lines. |
| 316 | */ |
| 317 | if( pbLongLine ) *pbLongLine = 0; |
| 318 | if( n==0 ) return result; /* Empty file -> text */ |
| 319 | if( n%2 ) return 0; /* Odd number of bytes -> binary (or UTF-8) */ |
| 320 | c = *z; |
| 321 | if( c==0 ) return 0; /* NUL character in a file -> binary */ |
| 322 | j = ((c!=UTF16BE_LF) && (c!=UTF16LE_LF)); |
| @@ -323,16 +327,18 @@ | |
| 327 | int c2 = z[-1]; |
| 328 | if( c2==UTF16BE_CR || c2==UTF16LE_CR ){ |
| 329 | result = -1; /* Contains CR/NL, continue */ |
| 330 | } |
| 331 | if( j>UTF16_LENGTH_MASK ){ |
| 332 | if( pbLongLine ) *pbLongLine = 1; |
| 333 | return 0; /* Very long line -> binary */ |
| 334 | } |
| 335 | j = 0; |
| 336 | } |
| 337 | } |
| 338 | if( j>UTF16_LENGTH_MASK ){ |
| 339 | if( pbLongLine ) *pbLongLine = 1; |
| 340 | return 0; /* Very long line -> binary */ |
| 341 | } |
| 342 | return result; /* No problems seen -> not binary */ |
| 343 | } |
| 344 | |
| 345 |