Fossil SCM
(expirimental) First implementation of "CR line endings" warning.
Commit
5a886cfd9b499191a09f47b9bc712041e2ebd379
Parent
276b34955bd4880…
1 file changed
+22
-15
+22
-15
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -907,13 +907,10 @@ | ||
| 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 fUnicode; /* return value of starts_with_utf16_bom() */ |
| 911 | 911 | int lookFlags; /* output flags from looks_like_utf8/utf16() */ |
| 912 | - int fHasNul; /* the blob contains one or more NUL chars */ | |
| 913 | - int fHasCrLf; /* the blob contains one or more CR/LF pairs */ | |
| 914 | - int fHasLength; /* the blob contains an overly long line */ | |
| 915 | 912 | char *zMsg; /* Warning message */ |
| 916 | 913 | Blob fname; /* Relative pathname of the file */ |
| 917 | 914 | static int allOk = 0; /* Set to true to disable this routine */ |
| 918 | 915 | |
| 919 | 916 | if( allOk ) return 0; |
| @@ -927,42 +924,50 @@ | ||
| 927 | 924 | lookFlags = looks_like_utf8(p); |
| 928 | 925 | } |
| 929 | 926 | }else{ |
| 930 | 927 | lookFlags = looks_like_utf8(p); |
| 931 | 928 | } |
| 932 | - fHasNul = (lookFlags & LOOK_NUL); | |
| 933 | - fHasCrLf = (lookFlags & LOOK_CRLF); | |
| 934 | - fHasLength = (lookFlags & LOOK_LENGTH); | |
| 935 | - if( fHasNul || fHasLength || fHasCrLf || fUnicode ){ | |
| 929 | + if( lookFlags&(LOOK_NUL|LOOK_LENGTH|LOOK_LONE_CR|LOOK_CRLF) || fUnicode ){ | |
| 936 | 930 | const char *zWarning; |
| 937 | 931 | const char *zDisable; |
| 938 | 932 | const char *zConvert = "c=convert/"; |
| 939 | 933 | Blob ans; |
| 940 | 934 | char cReply; |
| 941 | 935 | |
| 942 | - if( fHasNul || fHasLength ){ | |
| 936 | + if( lookFlags&(LOOK_NUL|LOOK_LENGTH) ){ | |
| 943 | 937 | if( binOk ){ |
| 944 | 938 | return 0; /* We don't want binary warnings for this file. */ |
| 945 | 939 | } |
| 946 | - if( !fHasNul && fHasLength ){ | |
| 940 | + if( (lookFlags&LOOK_LONE_CR) && !(lookFlags&LOOK_NUL) ){ | |
| 941 | + zWarning = "CR line endings (would be handled as binary)"; | |
| 942 | + }else if( (lookFlags&LOOK_LENGTH) && !(lookFlags&LOOK_NUL) ){ | |
| 947 | 943 | zWarning = "long lines"; |
| 944 | + zConvert = ""; /* We cannot convert binary files. */ | |
| 948 | 945 | }else{ |
| 949 | 946 | zWarning = "binary data"; |
| 947 | + zConvert = ""; /* We cannot convert binary files. */ | |
| 950 | 948 | } |
| 951 | 949 | zDisable = "\"binary-glob\" setting"; |
| 952 | - zConvert = ""; /* We cannot convert binary files. */ | |
| 953 | - }else if( fHasCrLf && fUnicode ){ | |
| 950 | + }else if( lookFlags&(LOOK_LONE_CR|LOOK_CRLF) && fUnicode ){ | |
| 954 | 951 | if( crnlOk && encodingOk ){ |
| 955 | 952 | return 0; /* We don't want CR/NL and Unicode warnings for this file. */ |
| 956 | 953 | } |
| 957 | - zWarning = "CR/NL line endings and Unicode"; | |
| 954 | + if( lookFlags&LOOK_LONE_CR ){ | |
| 955 | + zWarning = "CR line endings and Unicode"; | |
| 956 | + }else{ | |
| 957 | + zWarning = "CR/NL line endings and Unicode"; | |
| 958 | + } | |
| 958 | 959 | zDisable = "\"crnl-glob\" and \"encoding-glob\" settings"; |
| 959 | - }else if( fHasCrLf ){ | |
| 960 | + }else if( lookFlags&(LOOK_LONE_CR|LOOK_CRLF) ){ | |
| 960 | 961 | if( crnlOk ){ |
| 961 | 962 | return 0; /* We don't want CR/NL warnings for this file. */ |
| 962 | 963 | } |
| 963 | - zWarning = "CR/NL line endings"; | |
| 964 | + if( lookFlags&LOOK_LONE_CR ){ | |
| 965 | + zWarning = "CR line endings"; | |
| 966 | + }else{ | |
| 967 | + zWarning = "CR/NL line endings"; | |
| 968 | + } | |
| 964 | 969 | zDisable = "\"crnl-glob\" setting"; |
| 965 | 970 | }else{ |
| 966 | 971 | if( encodingOk ){ |
| 967 | 972 | return 0; /* We don't want encoding warnings for this file. */ |
| 968 | 973 | } |
| @@ -993,11 +998,13 @@ | ||
| 993 | 998 | int bomSize; |
| 994 | 999 | const unsigned char *bom = get_utf8_bom(&bomSize); |
| 995 | 1000 | fwrite(bom, 1, bomSize, f); |
| 996 | 1001 | blob_to_utf8_no_bom(p, 0); |
| 997 | 1002 | } |
| 998 | - blob_remove_cr(p); | |
| 1003 | + if( lookFlags&(LOOK_LONE_CR|LOOK_CRLF) ){ | |
| 1004 | + blob_remove_cr(p); | |
| 1005 | + } | |
| 999 | 1006 | fwrite(blob_buffer(p), 1, blob_size(p), f); |
| 1000 | 1007 | fclose(f); |
| 1001 | 1008 | return 1; |
| 1002 | 1009 | }else if( cReply!='y' && cReply!='Y' ){ |
| 1003 | 1010 | fossil_fatal("Abandoning commit due to %s in %s", |
| 1004 | 1011 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -907,13 +907,10 @@ | |
| 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 fUnicode; /* return value of starts_with_utf16_bom() */ |
| 911 | int lookFlags; /* output flags from looks_like_utf8/utf16() */ |
| 912 | int fHasNul; /* the blob contains one or more NUL chars */ |
| 913 | int fHasCrLf; /* the blob contains one or more CR/LF pairs */ |
| 914 | int fHasLength; /* the blob contains an overly long line */ |
| 915 | char *zMsg; /* Warning message */ |
| 916 | Blob fname; /* Relative pathname of the file */ |
| 917 | static int allOk = 0; /* Set to true to disable this routine */ |
| 918 | |
| 919 | if( allOk ) return 0; |
| @@ -927,42 +924,50 @@ | |
| 927 | lookFlags = looks_like_utf8(p); |
| 928 | } |
| 929 | }else{ |
| 930 | lookFlags = looks_like_utf8(p); |
| 931 | } |
| 932 | fHasNul = (lookFlags & LOOK_NUL); |
| 933 | fHasCrLf = (lookFlags & LOOK_CRLF); |
| 934 | fHasLength = (lookFlags & LOOK_LENGTH); |
| 935 | if( fHasNul || fHasLength || fHasCrLf || fUnicode ){ |
| 936 | const char *zWarning; |
| 937 | const char *zDisable; |
| 938 | const char *zConvert = "c=convert/"; |
| 939 | Blob ans; |
| 940 | char cReply; |
| 941 | |
| 942 | if( fHasNul || fHasLength ){ |
| 943 | if( binOk ){ |
| 944 | return 0; /* We don't want binary warnings for this file. */ |
| 945 | } |
| 946 | if( !fHasNul && 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 if( fHasCrLf && fUnicode ){ |
| 954 | if( crnlOk && encodingOk ){ |
| 955 | return 0; /* We don't want CR/NL and Unicode warnings for this file. */ |
| 956 | } |
| 957 | zWarning = "CR/NL line endings and Unicode"; |
| 958 | zDisable = "\"crnl-glob\" and \"encoding-glob\" settings"; |
| 959 | }else if( fHasCrLf ){ |
| 960 | if( crnlOk ){ |
| 961 | return 0; /* We don't want CR/NL warnings for this file. */ |
| 962 | } |
| 963 | zWarning = "CR/NL line endings"; |
| 964 | zDisable = "\"crnl-glob\" setting"; |
| 965 | }else{ |
| 966 | if( encodingOk ){ |
| 967 | return 0; /* We don't want encoding warnings for this file. */ |
| 968 | } |
| @@ -993,11 +998,13 @@ | |
| 993 | int bomSize; |
| 994 | const unsigned char *bom = get_utf8_bom(&bomSize); |
| 995 | fwrite(bom, 1, bomSize, f); |
| 996 | blob_to_utf8_no_bom(p, 0); |
| 997 | } |
| 998 | blob_remove_cr(p); |
| 999 | fwrite(blob_buffer(p), 1, blob_size(p), f); |
| 1000 | fclose(f); |
| 1001 | return 1; |
| 1002 | }else if( cReply!='y' && cReply!='Y' ){ |
| 1003 | fossil_fatal("Abandoning commit due to %s in %s", |
| 1004 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -907,13 +907,10 @@ | |
| 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 fUnicode; /* return value of starts_with_utf16_bom() */ |
| 911 | int lookFlags; /* output flags from looks_like_utf8/utf16() */ |
| 912 | char *zMsg; /* Warning message */ |
| 913 | Blob fname; /* Relative pathname of the file */ |
| 914 | static int allOk = 0; /* Set to true to disable this routine */ |
| 915 | |
| 916 | if( allOk ) return 0; |
| @@ -927,42 +924,50 @@ | |
| 924 | lookFlags = looks_like_utf8(p); |
| 925 | } |
| 926 | }else{ |
| 927 | lookFlags = looks_like_utf8(p); |
| 928 | } |
| 929 | if( lookFlags&(LOOK_NUL|LOOK_LENGTH|LOOK_LONE_CR|LOOK_CRLF) || fUnicode ){ |
| 930 | const char *zWarning; |
| 931 | const char *zDisable; |
| 932 | const char *zConvert = "c=convert/"; |
| 933 | Blob ans; |
| 934 | char cReply; |
| 935 | |
| 936 | if( lookFlags&(LOOK_NUL|LOOK_LENGTH) ){ |
| 937 | if( binOk ){ |
| 938 | return 0; /* We don't want binary warnings for this file. */ |
| 939 | } |
| 940 | if( (lookFlags&LOOK_LONE_CR) && !(lookFlags&LOOK_NUL) ){ |
| 941 | zWarning = "CR line endings (would be handled as binary)"; |
| 942 | }else if( (lookFlags&LOOK_LENGTH) && !(lookFlags&LOOK_NUL) ){ |
| 943 | zWarning = "long lines"; |
| 944 | zConvert = ""; /* We cannot convert binary files. */ |
| 945 | }else{ |
| 946 | zWarning = "binary data"; |
| 947 | zConvert = ""; /* We cannot convert binary files. */ |
| 948 | } |
| 949 | zDisable = "\"binary-glob\" setting"; |
| 950 | }else if( lookFlags&(LOOK_LONE_CR|LOOK_CRLF) && fUnicode ){ |
| 951 | if( crnlOk && encodingOk ){ |
| 952 | return 0; /* We don't want CR/NL and Unicode warnings for this file. */ |
| 953 | } |
| 954 | if( lookFlags&LOOK_LONE_CR ){ |
| 955 | zWarning = "CR line endings and Unicode"; |
| 956 | }else{ |
| 957 | zWarning = "CR/NL line endings and Unicode"; |
| 958 | } |
| 959 | zDisable = "\"crnl-glob\" and \"encoding-glob\" settings"; |
| 960 | }else if( lookFlags&(LOOK_LONE_CR|LOOK_CRLF) ){ |
| 961 | if( crnlOk ){ |
| 962 | return 0; /* We don't want CR/NL warnings for this file. */ |
| 963 | } |
| 964 | if( lookFlags&LOOK_LONE_CR ){ |
| 965 | zWarning = "CR line endings"; |
| 966 | }else{ |
| 967 | zWarning = "CR/NL line endings"; |
| 968 | } |
| 969 | zDisable = "\"crnl-glob\" setting"; |
| 970 | }else{ |
| 971 | if( encodingOk ){ |
| 972 | return 0; /* We don't want encoding warnings for this file. */ |
| 973 | } |
| @@ -993,11 +998,13 @@ | |
| 998 | int bomSize; |
| 999 | const unsigned char *bom = get_utf8_bom(&bomSize); |
| 1000 | fwrite(bom, 1, bomSize, f); |
| 1001 | blob_to_utf8_no_bom(p, 0); |
| 1002 | } |
| 1003 | if( lookFlags&(LOOK_LONE_CR|LOOK_CRLF) ){ |
| 1004 | blob_remove_cr(p); |
| 1005 | } |
| 1006 | fwrite(blob_buffer(p), 1, blob_size(p), f); |
| 1007 | fclose(f); |
| 1008 | return 1; |
| 1009 | }else if( cReply!='y' && cReply!='Y' ){ |
| 1010 | fossil_fatal("Abandoning commit due to %s in %s", |
| 1011 |