Fossil SCM

(expirimental) First implementation of "CR line endings" warning.

jan.nijtmans 2013-03-15 12:53 UTC trunk
Commit 5a886cfd9b499191a09f47b9bc712041e2ebd379
1 file changed +22 -15
+22 -15
--- src/checkin.c
+++ src/checkin.c
@@ -907,13 +907,10 @@
907907
int encodingOk, /* Non-zero if encoding warnings should be disabled. */
908908
const char *zFilename /* The full name of the file being committed. */
909909
){
910910
int fUnicode; /* return value of starts_with_utf16_bom() */
911911
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 */
915912
char *zMsg; /* Warning message */
916913
Blob fname; /* Relative pathname of the file */
917914
static int allOk = 0; /* Set to true to disable this routine */
918915
919916
if( allOk ) return 0;
@@ -927,42 +924,50 @@
927924
lookFlags = looks_like_utf8(p);
928925
}
929926
}else{
930927
lookFlags = looks_like_utf8(p);
931928
}
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 ){
936930
const char *zWarning;
937931
const char *zDisable;
938932
const char *zConvert = "c=convert/";
939933
Blob ans;
940934
char cReply;
941935
942
- if( fHasNul || fHasLength ){
936
+ if( lookFlags&(LOOK_NUL|LOOK_LENGTH) ){
943937
if( binOk ){
944938
return 0; /* We don't want binary warnings for this file. */
945939
}
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) ){
947943
zWarning = "long lines";
944
+ zConvert = ""; /* We cannot convert binary files. */
948945
}else{
949946
zWarning = "binary data";
947
+ zConvert = ""; /* We cannot convert binary files. */
950948
}
951949
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 ){
954951
if( crnlOk && encodingOk ){
955952
return 0; /* We don't want CR/NL and Unicode warnings for this file. */
956953
}
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
+ }
958959
zDisable = "\"crnl-glob\" and \"encoding-glob\" settings";
959
- }else if( fHasCrLf ){
960
+ }else if( lookFlags&(LOOK_LONE_CR|LOOK_CRLF) ){
960961
if( crnlOk ){
961962
return 0; /* We don't want CR/NL warnings for this file. */
962963
}
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
+ }
964969
zDisable = "\"crnl-glob\" setting";
965970
}else{
966971
if( encodingOk ){
967972
return 0; /* We don't want encoding warnings for this file. */
968973
}
@@ -993,11 +998,13 @@
993998
int bomSize;
994999
const unsigned char *bom = get_utf8_bom(&bomSize);
9951000
fwrite(bom, 1, bomSize, f);
9961001
blob_to_utf8_no_bom(p, 0);
9971002
}
998
- blob_remove_cr(p);
1003
+ if( lookFlags&(LOOK_LONE_CR|LOOK_CRLF) ){
1004
+ blob_remove_cr(p);
1005
+ }
9991006
fwrite(blob_buffer(p), 1, blob_size(p), f);
10001007
fclose(f);
10011008
return 1;
10021009
}else if( cReply!='y' && cReply!='Y' ){
10031010
fossil_fatal("Abandoning commit due to %s in %s",
10041011
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button