Fossil SCM
Modify the commit_warning() function so the warning for possible binary content is higher priority than the other warnings.
Commit
2d9ae4ee73f72232444f9931585ffa9dc0965372
Parent
08b96cedee3734b…
2 files changed
+12
-12
+26
-22
+12
-12
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -925,11 +925,22 @@ | ||
| 925 | 925 | const char *zDisable; |
| 926 | 926 | const char *zConvert = "c=convert/"; |
| 927 | 927 | Blob ans; |
| 928 | 928 | char cReply; |
| 929 | 929 | |
| 930 | - if( fHasCrLf && fUnicode ){ | |
| 930 | + if( eType==0 ){ | |
| 931 | + if( binOk ){ | |
| 932 | + return 0; /* We don't want binary warnings for this file. */ | |
| 933 | + } | |
| 934 | + if( fHasLength ){ | |
| 935 | + zWarning = "long lines"; | |
| 936 | + }else{ | |
| 937 | + zWarning = "binary data"; | |
| 938 | + } | |
| 939 | + zDisable = "\"binary-glob\" setting"; | |
| 940 | + zConvert = ""; /* We cannot convert binary files. */ | |
| 941 | + }else if( fHasCrLf && fUnicode ){ | |
| 931 | 942 | if ( crnlOk && encodingOk ){ |
| 932 | 943 | return 0; /* We don't want CR/NL and Unicode warnings for this file. */ |
| 933 | 944 | } |
| 934 | 945 | zWarning = "CR/NL line endings and Unicode"; |
| 935 | 946 | zDisable = "\"crnl-glob\" and \"encoding-glob\" settings"; |
| @@ -937,21 +948,10 @@ | ||
| 937 | 948 | if( crnlOk ){ |
| 938 | 949 | return 0; /* We don't want CR/NL warnings for this file. */ |
| 939 | 950 | } |
| 940 | 951 | zWarning = "CR/NL line endings"; |
| 941 | 952 | zDisable = "\"crnl-glob\" setting"; |
| 942 | - }else if( eType==0 ){ | |
| 943 | - if( binOk ){ | |
| 944 | - return 0; /* We don't want binary warnings for this file. */ | |
| 945 | - } | |
| 946 | - if( fHasLength ){ | |
| 947 | - zWarning = "long lines"; | |
| 948 | - }else{ | |
| 949 | - zWarning = "binary data"; | |
| 950 | - } | |
| 951 | - zDisable = "\"binary-glob\" setting"; | |
| 952 | - zConvert = ""; /* We cannot convert binary files. */ | |
| 953 | 953 | }else{ |
| 954 | 954 | if ( encodingOk ){ |
| 955 | 955 | return 0; /* We don't want encoding warnings for this file. */ |
| 956 | 956 | } |
| 957 | 957 | zWarning = "Unicode"; |
| 958 | 958 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -925,11 +925,22 @@ | |
| 925 | const char *zDisable; |
| 926 | const char *zConvert = "c=convert/"; |
| 927 | Blob ans; |
| 928 | char cReply; |
| 929 | |
| 930 | if( fHasCrLf && fUnicode ){ |
| 931 | if ( crnlOk && encodingOk ){ |
| 932 | return 0; /* We don't want CR/NL and Unicode warnings for this file. */ |
| 933 | } |
| 934 | zWarning = "CR/NL line endings and Unicode"; |
| 935 | zDisable = "\"crnl-glob\" and \"encoding-glob\" settings"; |
| @@ -937,21 +948,10 @@ | |
| 937 | if( crnlOk ){ |
| 938 | return 0; /* We don't want CR/NL warnings for this file. */ |
| 939 | } |
| 940 | zWarning = "CR/NL line endings"; |
| 941 | zDisable = "\"crnl-glob\" setting"; |
| 942 | }else if( eType==0 ){ |
| 943 | if( binOk ){ |
| 944 | return 0; /* We don't want binary warnings for this file. */ |
| 945 | } |
| 946 | if( fHasLength ){ |
| 947 | zWarning = "long lines"; |
| 948 | }else{ |
| 949 | zWarning = "binary data"; |
| 950 | } |
| 951 | zDisable = "\"binary-glob\" setting"; |
| 952 | zConvert = ""; /* We cannot convert binary files. */ |
| 953 | }else{ |
| 954 | if ( encodingOk ){ |
| 955 | return 0; /* We don't want encoding warnings for this file. */ |
| 956 | } |
| 957 | zWarning = "Unicode"; |
| 958 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -925,11 +925,22 @@ | |
| 925 | const char *zDisable; |
| 926 | const char *zConvert = "c=convert/"; |
| 927 | Blob ans; |
| 928 | char cReply; |
| 929 | |
| 930 | if( eType==0 ){ |
| 931 | if( binOk ){ |
| 932 | return 0; /* We don't want binary warnings for this file. */ |
| 933 | } |
| 934 | if( fHasLength ){ |
| 935 | zWarning = "long lines"; |
| 936 | }else{ |
| 937 | zWarning = "binary data"; |
| 938 | } |
| 939 | zDisable = "\"binary-glob\" setting"; |
| 940 | zConvert = ""; /* We cannot convert binary files. */ |
| 941 | }else if( fHasCrLf && fUnicode ){ |
| 942 | if ( crnlOk && encodingOk ){ |
| 943 | return 0; /* We don't want CR/NL and Unicode warnings for this file. */ |
| 944 | } |
| 945 | zWarning = "CR/NL line endings and Unicode"; |
| 946 | zDisable = "\"crnl-glob\" and \"encoding-glob\" settings"; |
| @@ -937,21 +948,10 @@ | |
| 948 | if( crnlOk ){ |
| 949 | return 0; /* We don't want CR/NL warnings for this file. */ |
| 950 | } |
| 951 | zWarning = "CR/NL line endings"; |
| 952 | zDisable = "\"crnl-glob\" setting"; |
| 953 | }else{ |
| 954 | if ( encodingOk ){ |
| 955 | return 0; /* We don't want encoding warnings for this file. */ |
| 956 | } |
| 957 | zWarning = "Unicode"; |
| 958 |
+26
-22
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -223,43 +223,45 @@ | ||
| 223 | 223 | ************************************ WARNING ********************************** |
| 224 | 224 | */ |
| 225 | 225 | int looks_like_utf8(const Blob *pContent, int *pFlags){ |
| 226 | 226 | const char *z = blob_buffer(pContent); |
| 227 | 227 | unsigned int n = blob_size(pContent); |
| 228 | - int j, c, flags = LOOK_NONE; | |
| 228 | + int j, c; | |
| 229 | 229 | |
| 230 | - if( pFlags ) *pFlags = flags; | |
| 230 | + if( pFlags ) *pFlags = LOOK_NONE; | |
| 231 | 231 | if( n==0 ) return 1; /* Empty file -> text */ |
| 232 | 232 | c = *z; |
| 233 | 233 | if( c==0 ){ |
| 234 | - if( pFlags ) *pFlags = LOOK_NUL; | |
| 234 | + if( pFlags ) *pFlags |= LOOK_NUL; | |
| 235 | 235 | return 0; /* NUL character in a file -> binary */ |
| 236 | 236 | } |
| 237 | 237 | j = (c!='\n'); |
| 238 | 238 | while( --n>0 ){ |
| 239 | 239 | c = *++z; ++j; |
| 240 | 240 | if( c==0 ){ |
| 241 | - if( pFlags ) *pFlags = LOOK_NUL; | |
| 241 | + if( pFlags ) *pFlags |= LOOK_NUL; | |
| 242 | 242 | return 0; /* NUL character in a file -> binary */ |
| 243 | 243 | } |
| 244 | 244 | if( c=='\n' ){ |
| 245 | 245 | int c2 = z[-1]; |
| 246 | - flags |= LOOK_LF; | |
| 247 | - if( c2=='\r' ){ | |
| 248 | - flags |= LOOK_CRLF; | |
| 246 | + if( pFlags ){ | |
| 247 | + *pFlags |= LOOK_LF; | |
| 248 | + if( c2=='\r' ){ | |
| 249 | + *pFlags |= LOOK_CRLF; | |
| 250 | + } | |
| 249 | 251 | } |
| 250 | 252 | if( j>LENGTH_MASK ){ |
| 251 | - flags |= LOOK_LENGTH; | |
| 253 | + if( pFlags ) *pFlags |= LOOK_LENGTH; | |
| 254 | + return 0; /* Very long line -> binary */ | |
| 252 | 255 | } |
| 253 | 256 | j = 0; |
| 254 | 257 | } |
| 255 | 258 | } |
| 256 | - if( (flags&LOOK_LENGTH) || (j>LENGTH_MASK) ){ | |
| 257 | - if( pFlags ) *pFlags = LOOK_LENGTH; | |
| 259 | + if( j>LENGTH_MASK ){ | |
| 260 | + if( pFlags ) *pFlags |= LOOK_LENGTH; | |
| 258 | 261 | return 0; /* Very long line -> binary */ |
| 259 | 262 | } |
| 260 | - if( pFlags ) *pFlags = flags; | |
| 261 | 263 | return 1; /* No problems seen -> not binary */ |
| 262 | 264 | } |
| 263 | 265 | |
| 264 | 266 | /* |
| 265 | 267 | ** Define the type needed to represent a Unicode (UTF-16) character. |
| @@ -315,44 +317,46 @@ | ||
| 315 | 317 | ************************************ WARNING ********************************** |
| 316 | 318 | */ |
| 317 | 319 | int looks_like_utf16(const Blob *pContent, int *pFlags){ |
| 318 | 320 | const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent); |
| 319 | 321 | unsigned int n = blob_size(pContent); |
| 320 | - int j, c, flags = LOOK_NONE; | |
| 322 | + int j, c; | |
| 321 | 323 | |
| 322 | - if( pFlags ) *pFlags = flags; | |
| 324 | + if( pFlags ) *pFlags = LOOK_NONE; | |
| 323 | 325 | if( n==0 ) return 1; /* Empty file -> text */ |
| 324 | 326 | if( n%2 ) return 0; /* Odd number of bytes -> binary (or UTF-8) */ |
| 325 | 327 | c = *z; |
| 326 | 328 | if( c==0 ){ |
| 327 | - if( pFlags ) *pFlags = LOOK_NUL; | |
| 329 | + if( pFlags ) *pFlags |= LOOK_NUL; | |
| 328 | 330 | return 0; /* NUL character in a file -> binary */ |
| 329 | 331 | } |
| 330 | 332 | j = ((c!=UTF16BE_LF) && (c!=UTF16LE_LF)); |
| 331 | 333 | while( (n-=2)>0 ){ |
| 332 | 334 | c = *++z; ++j; |
| 333 | 335 | if( c==0 ){ |
| 334 | - if( pFlags ) *pFlags = LOOK_NUL; | |
| 336 | + if( pFlags ) *pFlags |= LOOK_NUL; | |
| 335 | 337 | return 0; /* NUL character in a file -> binary */ |
| 336 | 338 | } |
| 337 | 339 | if( c==UTF16BE_LF || c==UTF16LE_LF ){ |
| 338 | 340 | int c2 = z[-1]; |
| 339 | - flags |= LOOK_LF; | |
| 340 | - if( c2==UTF16BE_CR || c2==UTF16LE_CR ){ | |
| 341 | - flags |= LOOK_CRLF; | |
| 341 | + if( pFlags ){ | |
| 342 | + *pFlags |= LOOK_LF; | |
| 343 | + if( c2==UTF16BE_CR || c2==UTF16LE_CR ){ | |
| 344 | + *pFlags |= LOOK_CRLF; | |
| 345 | + } | |
| 342 | 346 | } |
| 343 | 347 | if( j>UTF16_LENGTH_MASK ){ |
| 344 | - flags |= LOOK_LENGTH; | |
| 348 | + if( pFlags ) *pFlags |= LOOK_LENGTH; | |
| 349 | + return 0; /* Very long line -> binary */ | |
| 345 | 350 | } |
| 346 | 351 | j = 0; |
| 347 | 352 | } |
| 348 | 353 | } |
| 349 | - if( (flags&LOOK_LENGTH) || (j>UTF16_LENGTH_MASK) ){ | |
| 350 | - if( pFlags ) *pFlags = LOOK_LENGTH; | |
| 354 | + if( j>UTF16_LENGTH_MASK ){ | |
| 355 | + if( pFlags ) *pFlags |= LOOK_LENGTH; | |
| 351 | 356 | return 0; /* Very long line -> binary */ |
| 352 | 357 | } |
| 353 | - if( pFlags ) *pFlags = flags; | |
| 354 | 358 | return 1; /* No problems seen -> not binary */ |
| 355 | 359 | } |
| 356 | 360 | |
| 357 | 361 | /* |
| 358 | 362 | ** This function returns an array of bytes representing the byte-order-mark |
| 359 | 363 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -223,43 +223,45 @@ | |
| 223 | ************************************ WARNING ********************************** |
| 224 | */ |
| 225 | int looks_like_utf8(const Blob *pContent, int *pFlags){ |
| 226 | const char *z = blob_buffer(pContent); |
| 227 | unsigned int n = blob_size(pContent); |
| 228 | int j, c, flags = LOOK_NONE; |
| 229 | |
| 230 | if( pFlags ) *pFlags = flags; |
| 231 | if( n==0 ) return 1; /* Empty file -> text */ |
| 232 | c = *z; |
| 233 | if( c==0 ){ |
| 234 | if( pFlags ) *pFlags = LOOK_NUL; |
| 235 | return 0; /* NUL character in a file -> binary */ |
| 236 | } |
| 237 | j = (c!='\n'); |
| 238 | while( --n>0 ){ |
| 239 | c = *++z; ++j; |
| 240 | if( c==0 ){ |
| 241 | if( pFlags ) *pFlags = LOOK_NUL; |
| 242 | return 0; /* NUL character in a file -> binary */ |
| 243 | } |
| 244 | if( c=='\n' ){ |
| 245 | int c2 = z[-1]; |
| 246 | flags |= LOOK_LF; |
| 247 | if( c2=='\r' ){ |
| 248 | flags |= LOOK_CRLF; |
| 249 | } |
| 250 | if( j>LENGTH_MASK ){ |
| 251 | flags |= LOOK_LENGTH; |
| 252 | } |
| 253 | j = 0; |
| 254 | } |
| 255 | } |
| 256 | if( (flags&LOOK_LENGTH) || (j>LENGTH_MASK) ){ |
| 257 | if( pFlags ) *pFlags = LOOK_LENGTH; |
| 258 | return 0; /* Very long line -> binary */ |
| 259 | } |
| 260 | if( pFlags ) *pFlags = flags; |
| 261 | return 1; /* No problems seen -> not binary */ |
| 262 | } |
| 263 | |
| 264 | /* |
| 265 | ** Define the type needed to represent a Unicode (UTF-16) character. |
| @@ -315,44 +317,46 @@ | |
| 315 | ************************************ WARNING ********************************** |
| 316 | */ |
| 317 | int looks_like_utf16(const Blob *pContent, int *pFlags){ |
| 318 | const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent); |
| 319 | unsigned int n = blob_size(pContent); |
| 320 | int j, c, flags = LOOK_NONE; |
| 321 | |
| 322 | if( pFlags ) *pFlags = flags; |
| 323 | if( n==0 ) return 1; /* Empty file -> text */ |
| 324 | if( n%2 ) return 0; /* Odd number of bytes -> binary (or UTF-8) */ |
| 325 | c = *z; |
| 326 | if( c==0 ){ |
| 327 | if( pFlags ) *pFlags = LOOK_NUL; |
| 328 | return 0; /* NUL character in a file -> binary */ |
| 329 | } |
| 330 | j = ((c!=UTF16BE_LF) && (c!=UTF16LE_LF)); |
| 331 | while( (n-=2)>0 ){ |
| 332 | c = *++z; ++j; |
| 333 | if( c==0 ){ |
| 334 | if( pFlags ) *pFlags = LOOK_NUL; |
| 335 | return 0; /* NUL character in a file -> binary */ |
| 336 | } |
| 337 | if( c==UTF16BE_LF || c==UTF16LE_LF ){ |
| 338 | int c2 = z[-1]; |
| 339 | flags |= LOOK_LF; |
| 340 | if( c2==UTF16BE_CR || c2==UTF16LE_CR ){ |
| 341 | flags |= LOOK_CRLF; |
| 342 | } |
| 343 | if( j>UTF16_LENGTH_MASK ){ |
| 344 | flags |= LOOK_LENGTH; |
| 345 | } |
| 346 | j = 0; |
| 347 | } |
| 348 | } |
| 349 | if( (flags&LOOK_LENGTH) || (j>UTF16_LENGTH_MASK) ){ |
| 350 | if( pFlags ) *pFlags = LOOK_LENGTH; |
| 351 | return 0; /* Very long line -> binary */ |
| 352 | } |
| 353 | if( pFlags ) *pFlags = flags; |
| 354 | return 1; /* No problems seen -> not binary */ |
| 355 | } |
| 356 | |
| 357 | /* |
| 358 | ** This function returns an array of bytes representing the byte-order-mark |
| 359 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -223,43 +223,45 @@ | |
| 223 | ************************************ WARNING ********************************** |
| 224 | */ |
| 225 | int looks_like_utf8(const Blob *pContent, int *pFlags){ |
| 226 | const char *z = blob_buffer(pContent); |
| 227 | unsigned int n = blob_size(pContent); |
| 228 | int j, c; |
| 229 | |
| 230 | if( pFlags ) *pFlags = LOOK_NONE; |
| 231 | if( n==0 ) return 1; /* Empty file -> text */ |
| 232 | c = *z; |
| 233 | if( c==0 ){ |
| 234 | if( pFlags ) *pFlags |= LOOK_NUL; |
| 235 | return 0; /* NUL character in a file -> binary */ |
| 236 | } |
| 237 | j = (c!='\n'); |
| 238 | while( --n>0 ){ |
| 239 | c = *++z; ++j; |
| 240 | if( c==0 ){ |
| 241 | if( pFlags ) *pFlags |= LOOK_NUL; |
| 242 | return 0; /* NUL character in a file -> binary */ |
| 243 | } |
| 244 | if( c=='\n' ){ |
| 245 | int c2 = z[-1]; |
| 246 | if( pFlags ){ |
| 247 | *pFlags |= LOOK_LF; |
| 248 | if( c2=='\r' ){ |
| 249 | *pFlags |= LOOK_CRLF; |
| 250 | } |
| 251 | } |
| 252 | if( j>LENGTH_MASK ){ |
| 253 | if( pFlags ) *pFlags |= LOOK_LENGTH; |
| 254 | return 0; /* Very long line -> binary */ |
| 255 | } |
| 256 | j = 0; |
| 257 | } |
| 258 | } |
| 259 | if( j>LENGTH_MASK ){ |
| 260 | if( pFlags ) *pFlags |= LOOK_LENGTH; |
| 261 | return 0; /* Very long line -> binary */ |
| 262 | } |
| 263 | return 1; /* No problems seen -> not binary */ |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | ** Define the type needed to represent a Unicode (UTF-16) character. |
| @@ -315,44 +317,46 @@ | |
| 317 | ************************************ WARNING ********************************** |
| 318 | */ |
| 319 | int looks_like_utf16(const Blob *pContent, int *pFlags){ |
| 320 | const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent); |
| 321 | unsigned int n = blob_size(pContent); |
| 322 | int j, c; |
| 323 | |
| 324 | if( pFlags ) *pFlags = LOOK_NONE; |
| 325 | if( n==0 ) return 1; /* Empty file -> text */ |
| 326 | if( n%2 ) return 0; /* Odd number of bytes -> binary (or UTF-8) */ |
| 327 | c = *z; |
| 328 | if( c==0 ){ |
| 329 | if( pFlags ) *pFlags |= LOOK_NUL; |
| 330 | return 0; /* NUL character in a file -> binary */ |
| 331 | } |
| 332 | j = ((c!=UTF16BE_LF) && (c!=UTF16LE_LF)); |
| 333 | while( (n-=2)>0 ){ |
| 334 | c = *++z; ++j; |
| 335 | if( c==0 ){ |
| 336 | if( pFlags ) *pFlags |= LOOK_NUL; |
| 337 | return 0; /* NUL character in a file -> binary */ |
| 338 | } |
| 339 | if( c==UTF16BE_LF || c==UTF16LE_LF ){ |
| 340 | int c2 = z[-1]; |
| 341 | if( pFlags ){ |
| 342 | *pFlags |= LOOK_LF; |
| 343 | if( c2==UTF16BE_CR || c2==UTF16LE_CR ){ |
| 344 | *pFlags |= LOOK_CRLF; |
| 345 | } |
| 346 | } |
| 347 | if( j>UTF16_LENGTH_MASK ){ |
| 348 | if( pFlags ) *pFlags |= LOOK_LENGTH; |
| 349 | return 0; /* Very long line -> binary */ |
| 350 | } |
| 351 | j = 0; |
| 352 | } |
| 353 | } |
| 354 | if( j>UTF16_LENGTH_MASK ){ |
| 355 | if( pFlags ) *pFlags |= LOOK_LENGTH; |
| 356 | return 0; /* Very long line -> binary */ |
| 357 | } |
| 358 | return 1; /* No problems seen -> not binary */ |
| 359 | } |
| 360 | |
| 361 | /* |
| 362 | ** This function returns an array of bytes representing the byte-order-mark |
| 363 |