Fossil SCM
Make the intent of the code in commit_warning() clearer. Style cleanup.
Commit
3f78dfe593630c2efd8a41546b386bb07bec73ac
Parent
2e9be37f502f5d9…
2 files changed
+20
-12
+3
-2
+20
-12
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -907,11 +907,15 @@ | ||
| 907 | 907 | int encodingOk, /* Non-zero if encoding warnings should be disabled. */ |
| 908 | 908 | const char *zFilename /* The full name of the file being committed. */ |
| 909 | 909 | ){ |
| 910 | 910 | int bReverse; /* UTF-16 byte order is reversed? */ |
| 911 | 911 | int fUnicode; /* return value of could_be_utf16() */ |
| 912 | + int fBinary; /* does the blob content appear to be binary? */ | |
| 912 | 913 | int lookFlags; /* output flags from looks_like_utf8/utf16() */ |
| 914 | + int fHasAnyCr; /* the blob contains one or more CR chars */ | |
| 915 | + int fHasLoneCrOnly; /* all detected line endings are CR only */ | |
| 916 | + int fHasCrLfOnly; /* all detected line endings are CR/LF pairs */ | |
| 913 | 917 | char *zMsg; /* Warning message */ |
| 914 | 918 | Blob fname; /* Relative pathname of the file */ |
| 915 | 919 | static int allOk = 0; /* Set to true to disable this routine */ |
| 916 | 920 | |
| 917 | 921 | if( allOk ) return 0; |
| @@ -919,50 +923,54 @@ | ||
| 919 | 923 | if( fUnicode ){ |
| 920 | 924 | lookFlags = looks_like_utf16(p, bReverse, LOOK_NUL); |
| 921 | 925 | }else{ |
| 922 | 926 | lookFlags = looks_like_utf8(p, LOOK_NUL); |
| 923 | 927 | } |
| 924 | - if( lookFlags&(LOOK_BINARY|LOOK_LONG|LOOK_CR) || fUnicode ){ | |
| 928 | + fHasAnyCr = (lookFlags & LOOK_CR); | |
| 929 | + fBinary = (lookFlags & LOOK_BINARY); | |
| 930 | + fHasLoneCrOnly = ((lookFlags & LOOK_EOL) == LOOK_LONE_CR); | |
| 931 | + fHasCrLfOnly = ((lookFlags & LOOK_EOL) == LOOK_CRLF); | |
| 932 | + if( fUnicode || fHasAnyCr || fBinary ){ | |
| 925 | 933 | const char *zWarning; |
| 926 | 934 | const char *zDisable; |
| 927 | 935 | const char *zConvert = "c=convert/"; |
| 928 | 936 | Blob ans; |
| 929 | 937 | char cReply; |
| 930 | 938 | |
| 931 | - if( lookFlags&(LOOK_BINARY|LOOK_LONG) ){ | |
| 939 | + if( fBinary ){ | |
| 940 | + int fHasNul = (lookFlags & LOOK_NUL); /* contains NUL chars? */ | |
| 941 | + int fHasLong = (lookFlags & LOOK_LONG); /* overly long line? */ | |
| 932 | 942 | if( binOk ){ |
| 933 | 943 | return 0; /* We don't want binary warnings for this file. */ |
| 934 | 944 | } |
| 935 | - if( (lookFlags&LOOK_LONE_CR) && !(lookFlags&LOOK_NUL) ){ | |
| 936 | - zWarning = "CR line endings (would be handled as binary)"; | |
| 937 | - }else if( (lookFlags&LOOK_LONG) && !(lookFlags&LOOK_NUL) ){ | |
| 945 | + if( !fHasNul && fHasLong ){ | |
| 938 | 946 | zWarning = "long lines"; |
| 939 | 947 | zConvert = ""; /* We cannot convert binary files. */ |
| 940 | 948 | }else{ |
| 941 | 949 | zWarning = "binary data"; |
| 942 | 950 | zConvert = ""; /* We cannot convert binary files. */ |
| 943 | 951 | } |
| 944 | 952 | zDisable = "\"binary-glob\" setting"; |
| 945 | - }else if( (lookFlags&LOOK_CR) && fUnicode ){ | |
| 953 | + }else if( fUnicode && fHasAnyCr ){ | |
| 946 | 954 | if( crnlOk && encodingOk ){ |
| 947 | 955 | return 0; /* We don't want CR/NL and Unicode warnings for this file. */ |
| 948 | 956 | } |
| 949 | - if( (lookFlags&LOOK_EOL) == LOOK_LONE_CR ){ | |
| 957 | + if( fHasLoneCrOnly ){ | |
| 950 | 958 | zWarning = "CR line endings and Unicode"; |
| 951 | - }else if( (lookFlags&LOOK_EOL) == LOOK_CRLF ){ | |
| 959 | + }else if( fHasCrLfOnly ){ | |
| 952 | 960 | zWarning = "CR/NL line endings and Unicode"; |
| 953 | 961 | }else{ |
| 954 | 962 | zWarning = "mixed line endings and Unicode"; |
| 955 | 963 | } |
| 956 | 964 | zDisable = "\"crnl-glob\" and \"encoding-glob\" settings"; |
| 957 | - }else if( lookFlags&LOOK_CR ){ | |
| 965 | + }else if( fHasAnyCr ){ | |
| 958 | 966 | if( crnlOk ){ |
| 959 | 967 | return 0; /* We don't want CR/NL warnings for this file. */ |
| 960 | 968 | } |
| 961 | - if( (lookFlags&LOOK_EOL) == LOOK_LONE_CR ){ | |
| 969 | + if( fHasLoneCrOnly ){ | |
| 962 | 970 | zWarning = "CR line endings"; |
| 963 | - }else if( (lookFlags&LOOK_EOL) == LOOK_CRLF ){ | |
| 971 | + }else if( fHasCrLfOnly ){ | |
| 964 | 972 | zWarning = "CR/NL line endings"; |
| 965 | 973 | }else{ |
| 966 | 974 | zWarning = "mixed line endings"; |
| 967 | 975 | } |
| 968 | 976 | zDisable = "\"crnl-glob\" setting"; |
| @@ -997,11 +1005,11 @@ | ||
| 997 | 1005 | int bomSize; |
| 998 | 1006 | const unsigned char *bom = get_utf8_bom(&bomSize); |
| 999 | 1007 | fwrite(bom, 1, bomSize, f); |
| 1000 | 1008 | blob_to_utf8_no_bom(p, 0); |
| 1001 | 1009 | } |
| 1002 | - if( lookFlags&LOOK_CR ){ | |
| 1010 | + if( fHasAnyCr ){ | |
| 1003 | 1011 | blob_to_lf_only(p); |
| 1004 | 1012 | } |
| 1005 | 1013 | fwrite(blob_buffer(p), 1, blob_size(p), f); |
| 1006 | 1014 | fclose(f); |
| 1007 | 1015 | return 1; |
| 1008 | 1016 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -907,11 +907,15 @@ | |
| 907 | int encodingOk, /* Non-zero if encoding warnings should be disabled. */ |
| 908 | const char *zFilename /* The full name of the file being committed. */ |
| 909 | ){ |
| 910 | int bReverse; /* UTF-16 byte order is reversed? */ |
| 911 | int fUnicode; /* return value of could_be_utf16() */ |
| 912 | int lookFlags; /* output flags from looks_like_utf8/utf16() */ |
| 913 | char *zMsg; /* Warning message */ |
| 914 | Blob fname; /* Relative pathname of the file */ |
| 915 | static int allOk = 0; /* Set to true to disable this routine */ |
| 916 | |
| 917 | if( allOk ) return 0; |
| @@ -919,50 +923,54 @@ | |
| 919 | if( fUnicode ){ |
| 920 | lookFlags = looks_like_utf16(p, bReverse, LOOK_NUL); |
| 921 | }else{ |
| 922 | lookFlags = looks_like_utf8(p, LOOK_NUL); |
| 923 | } |
| 924 | if( lookFlags&(LOOK_BINARY|LOOK_LONG|LOOK_CR) || fUnicode ){ |
| 925 | const char *zWarning; |
| 926 | const char *zDisable; |
| 927 | const char *zConvert = "c=convert/"; |
| 928 | Blob ans; |
| 929 | char cReply; |
| 930 | |
| 931 | if( lookFlags&(LOOK_BINARY|LOOK_LONG) ){ |
| 932 | if( binOk ){ |
| 933 | return 0; /* We don't want binary warnings for this file. */ |
| 934 | } |
| 935 | if( (lookFlags&LOOK_LONE_CR) && !(lookFlags&LOOK_NUL) ){ |
| 936 | zWarning = "CR line endings (would be handled as binary)"; |
| 937 | }else if( (lookFlags&LOOK_LONG) && !(lookFlags&LOOK_NUL) ){ |
| 938 | zWarning = "long lines"; |
| 939 | zConvert = ""; /* We cannot convert binary files. */ |
| 940 | }else{ |
| 941 | zWarning = "binary data"; |
| 942 | zConvert = ""; /* We cannot convert binary files. */ |
| 943 | } |
| 944 | zDisable = "\"binary-glob\" setting"; |
| 945 | }else if( (lookFlags&LOOK_CR) && fUnicode ){ |
| 946 | if( crnlOk && encodingOk ){ |
| 947 | return 0; /* We don't want CR/NL and Unicode warnings for this file. */ |
| 948 | } |
| 949 | if( (lookFlags&LOOK_EOL) == LOOK_LONE_CR ){ |
| 950 | zWarning = "CR line endings and Unicode"; |
| 951 | }else if( (lookFlags&LOOK_EOL) == LOOK_CRLF ){ |
| 952 | zWarning = "CR/NL line endings and Unicode"; |
| 953 | }else{ |
| 954 | zWarning = "mixed line endings and Unicode"; |
| 955 | } |
| 956 | zDisable = "\"crnl-glob\" and \"encoding-glob\" settings"; |
| 957 | }else if( lookFlags&LOOK_CR ){ |
| 958 | if( crnlOk ){ |
| 959 | return 0; /* We don't want CR/NL warnings for this file. */ |
| 960 | } |
| 961 | if( (lookFlags&LOOK_EOL) == LOOK_LONE_CR ){ |
| 962 | zWarning = "CR line endings"; |
| 963 | }else if( (lookFlags&LOOK_EOL) == LOOK_CRLF ){ |
| 964 | zWarning = "CR/NL line endings"; |
| 965 | }else{ |
| 966 | zWarning = "mixed line endings"; |
| 967 | } |
| 968 | zDisable = "\"crnl-glob\" setting"; |
| @@ -997,11 +1005,11 @@ | |
| 997 | int bomSize; |
| 998 | const unsigned char *bom = get_utf8_bom(&bomSize); |
| 999 | fwrite(bom, 1, bomSize, f); |
| 1000 | blob_to_utf8_no_bom(p, 0); |
| 1001 | } |
| 1002 | if( lookFlags&LOOK_CR ){ |
| 1003 | blob_to_lf_only(p); |
| 1004 | } |
| 1005 | fwrite(blob_buffer(p), 1, blob_size(p), f); |
| 1006 | fclose(f); |
| 1007 | return 1; |
| 1008 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -907,11 +907,15 @@ | |
| 907 | int encodingOk, /* Non-zero if encoding warnings should be disabled. */ |
| 908 | const char *zFilename /* The full name of the file being committed. */ |
| 909 | ){ |
| 910 | int bReverse; /* UTF-16 byte order is reversed? */ |
| 911 | int fUnicode; /* return value of could_be_utf16() */ |
| 912 | int fBinary; /* does the blob content appear to be binary? */ |
| 913 | int lookFlags; /* output flags from looks_like_utf8/utf16() */ |
| 914 | int fHasAnyCr; /* the blob contains one or more CR chars */ |
| 915 | int fHasLoneCrOnly; /* all detected line endings are CR only */ |
| 916 | int fHasCrLfOnly; /* all detected line endings are CR/LF pairs */ |
| 917 | char *zMsg; /* Warning message */ |
| 918 | Blob fname; /* Relative pathname of the file */ |
| 919 | static int allOk = 0; /* Set to true to disable this routine */ |
| 920 | |
| 921 | if( allOk ) return 0; |
| @@ -919,50 +923,54 @@ | |
| 923 | if( fUnicode ){ |
| 924 | lookFlags = looks_like_utf16(p, bReverse, LOOK_NUL); |
| 925 | }else{ |
| 926 | lookFlags = looks_like_utf8(p, LOOK_NUL); |
| 927 | } |
| 928 | fHasAnyCr = (lookFlags & LOOK_CR); |
| 929 | fBinary = (lookFlags & LOOK_BINARY); |
| 930 | fHasLoneCrOnly = ((lookFlags & LOOK_EOL) == LOOK_LONE_CR); |
| 931 | fHasCrLfOnly = ((lookFlags & LOOK_EOL) == LOOK_CRLF); |
| 932 | if( fUnicode || fHasAnyCr || fBinary ){ |
| 933 | const char *zWarning; |
| 934 | const char *zDisable; |
| 935 | const char *zConvert = "c=convert/"; |
| 936 | Blob ans; |
| 937 | char cReply; |
| 938 | |
| 939 | if( fBinary ){ |
| 940 | int fHasNul = (lookFlags & LOOK_NUL); /* contains NUL chars? */ |
| 941 | int fHasLong = (lookFlags & LOOK_LONG); /* overly long line? */ |
| 942 | if( binOk ){ |
| 943 | return 0; /* We don't want binary warnings for this file. */ |
| 944 | } |
| 945 | if( !fHasNul && fHasLong ){ |
| 946 | zWarning = "long lines"; |
| 947 | zConvert = ""; /* We cannot convert binary files. */ |
| 948 | }else{ |
| 949 | zWarning = "binary data"; |
| 950 | zConvert = ""; /* We cannot convert binary files. */ |
| 951 | } |
| 952 | zDisable = "\"binary-glob\" setting"; |
| 953 | }else if( fUnicode && fHasAnyCr ){ |
| 954 | if( crnlOk && encodingOk ){ |
| 955 | return 0; /* We don't want CR/NL and Unicode warnings for this file. */ |
| 956 | } |
| 957 | if( fHasLoneCrOnly ){ |
| 958 | zWarning = "CR line endings and Unicode"; |
| 959 | }else if( fHasCrLfOnly ){ |
| 960 | zWarning = "CR/NL line endings and Unicode"; |
| 961 | }else{ |
| 962 | zWarning = "mixed line endings and Unicode"; |
| 963 | } |
| 964 | zDisable = "\"crnl-glob\" and \"encoding-glob\" settings"; |
| 965 | }else if( fHasAnyCr ){ |
| 966 | if( crnlOk ){ |
| 967 | return 0; /* We don't want CR/NL warnings for this file. */ |
| 968 | } |
| 969 | if( fHasLoneCrOnly ){ |
| 970 | zWarning = "CR line endings"; |
| 971 | }else if( fHasCrLfOnly ){ |
| 972 | zWarning = "CR/NL line endings"; |
| 973 | }else{ |
| 974 | zWarning = "mixed line endings"; |
| 975 | } |
| 976 | zDisable = "\"crnl-glob\" setting"; |
| @@ -997,11 +1005,11 @@ | |
| 1005 | int bomSize; |
| 1006 | const unsigned char *bom = get_utf8_bom(&bomSize); |
| 1007 | fwrite(bom, 1, bomSize, f); |
| 1008 | blob_to_utf8_no_bom(p, 0); |
| 1009 | } |
| 1010 | if( fHasAnyCr ){ |
| 1011 | blob_to_lf_only(p); |
| 1012 | } |
| 1013 | fwrite(blob_buffer(p), 1, blob_size(p), f); |
| 1014 | fclose(f); |
| 1015 | return 1; |
| 1016 |
+3
-2
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -61,11 +61,12 @@ | ||
| 61 | 61 | |
| 62 | 62 | /* |
| 63 | 63 | ** This macro is designed to return non-zero if the specified blob contains |
| 64 | 64 | ** data that MAY be binary in nature; otherwise, zero will be returned. |
| 65 | 65 | */ |
| 66 | -#define looks_like_binary(blob) ((looks_like_utf8(blob, LOOK_BINARY)&LOOK_BINARY)!=LOOK_NONE) | |
| 66 | +#define looks_like_binary(blob) \ | |
| 67 | + ((looks_like_utf8((blob), LOOK_BINARY) & LOOK_BINARY) != LOOK_NONE) | |
| 67 | 68 | |
| 68 | 69 | /* |
| 69 | 70 | ** Output flags for the looks_like_utf8() and looks_like_utf16() routines used |
| 70 | 71 | ** to convey status information about the blob content. |
| 71 | 72 | */ |
| @@ -79,11 +80,11 @@ | ||
| 79 | 80 | #define LOOK_LONG ((int)0x00000040) /* An over length line was found. */ |
| 80 | 81 | #define LOOK_ODD ((int)0x00000080) /* An odd number of bytes was found. */ |
| 81 | 82 | #define LOOK_SHORT ((int)0x00000100) /* Unable to perform full check. */ |
| 82 | 83 | #define LOOK_INVALID ((int)0x00000200) /* Invalid sequence was found. */ |
| 83 | 84 | #define LOOK_BINARY (LOOK_NUL | LOOK_LONG | LOOK_SHORT) /* May be binary. */ |
| 84 | -#define LOOK_EOL (LOOK_LONE_CR | LOOK_LONE_LF | LOOK_CRLF) /* Any eol type. */ | |
| 85 | +#define LOOK_EOL (LOOK_LONE_CR | LOOK_LONE_LF | LOOK_CRLF) /* Line seps. */ | |
| 85 | 86 | #endif /* INTERFACE */ |
| 86 | 87 | |
| 87 | 88 | /* |
| 88 | 89 | ** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes) |
| 89 | 90 | */ |
| 90 | 91 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -61,11 +61,12 @@ | |
| 61 | |
| 62 | /* |
| 63 | ** This macro is designed to return non-zero if the specified blob contains |
| 64 | ** data that MAY be binary in nature; otherwise, zero will be returned. |
| 65 | */ |
| 66 | #define looks_like_binary(blob) ((looks_like_utf8(blob, LOOK_BINARY)&LOOK_BINARY)!=LOOK_NONE) |
| 67 | |
| 68 | /* |
| 69 | ** Output flags for the looks_like_utf8() and looks_like_utf16() routines used |
| 70 | ** to convey status information about the blob content. |
| 71 | */ |
| @@ -79,11 +80,11 @@ | |
| 79 | #define LOOK_LONG ((int)0x00000040) /* An over length line was found. */ |
| 80 | #define LOOK_ODD ((int)0x00000080) /* An odd number of bytes was found. */ |
| 81 | #define LOOK_SHORT ((int)0x00000100) /* Unable to perform full check. */ |
| 82 | #define LOOK_INVALID ((int)0x00000200) /* Invalid sequence was found. */ |
| 83 | #define LOOK_BINARY (LOOK_NUL | LOOK_LONG | LOOK_SHORT) /* May be binary. */ |
| 84 | #define LOOK_EOL (LOOK_LONE_CR | LOOK_LONE_LF | LOOK_CRLF) /* Any eol type. */ |
| 85 | #endif /* INTERFACE */ |
| 86 | |
| 87 | /* |
| 88 | ** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes) |
| 89 | */ |
| 90 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -61,11 +61,12 @@ | |
| 61 | |
| 62 | /* |
| 63 | ** This macro is designed to return non-zero if the specified blob contains |
| 64 | ** data that MAY be binary in nature; otherwise, zero will be returned. |
| 65 | */ |
| 66 | #define looks_like_binary(blob) \ |
| 67 | ((looks_like_utf8((blob), LOOK_BINARY) & LOOK_BINARY) != LOOK_NONE) |
| 68 | |
| 69 | /* |
| 70 | ** Output flags for the looks_like_utf8() and looks_like_utf16() routines used |
| 71 | ** to convey status information about the blob content. |
| 72 | */ |
| @@ -79,11 +80,11 @@ | |
| 80 | #define LOOK_LONG ((int)0x00000040) /* An over length line was found. */ |
| 81 | #define LOOK_ODD ((int)0x00000080) /* An odd number of bytes was found. */ |
| 82 | #define LOOK_SHORT ((int)0x00000100) /* Unable to perform full check. */ |
| 83 | #define LOOK_INVALID ((int)0x00000200) /* Invalid sequence was found. */ |
| 84 | #define LOOK_BINARY (LOOK_NUL | LOOK_LONG | LOOK_SHORT) /* May be binary. */ |
| 85 | #define LOOK_EOL (LOOK_LONE_CR | LOOK_LONE_LF | LOOK_CRLF) /* Line seps. */ |
| 86 | #endif /* INTERFACE */ |
| 87 | |
| 88 | /* |
| 89 | ** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes) |
| 90 | */ |
| 91 |