Fossil SCM

Make the intent of the code in commit_warning() clearer. Style cleanup.

mistachkin 2013-03-27 23:13 trunk
Commit 3f78dfe593630c2efd8a41546b386bb07bec73ac
2 files changed +20 -12 +3 -2
+20 -12
--- src/checkin.c
+++ src/checkin.c
@@ -907,11 +907,15 @@
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 bReverse; /* UTF-16 byte order is reversed? */
911911
int fUnicode; /* return value of could_be_utf16() */
912
+ int fBinary; /* does the blob content appear to be binary? */
912913
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 */
913917
char *zMsg; /* Warning message */
914918
Blob fname; /* Relative pathname of the file */
915919
static int allOk = 0; /* Set to true to disable this routine */
916920
917921
if( allOk ) return 0;
@@ -919,50 +923,54 @@
919923
if( fUnicode ){
920924
lookFlags = looks_like_utf16(p, bReverse, LOOK_NUL);
921925
}else{
922926
lookFlags = looks_like_utf8(p, LOOK_NUL);
923927
}
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 ){
925933
const char *zWarning;
926934
const char *zDisable;
927935
const char *zConvert = "c=convert/";
928936
Blob ans;
929937
char cReply;
930938
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? */
932942
if( binOk ){
933943
return 0; /* We don't want binary warnings for this file. */
934944
}
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 ){
938946
zWarning = "long lines";
939947
zConvert = ""; /* We cannot convert binary files. */
940948
}else{
941949
zWarning = "binary data";
942950
zConvert = ""; /* We cannot convert binary files. */
943951
}
944952
zDisable = "\"binary-glob\" setting";
945
- }else if( (lookFlags&LOOK_CR) && fUnicode ){
953
+ }else if( fUnicode && fHasAnyCr ){
946954
if( crnlOk && encodingOk ){
947955
return 0; /* We don't want CR/NL and Unicode warnings for this file. */
948956
}
949
- if( (lookFlags&LOOK_EOL) == LOOK_LONE_CR ){
957
+ if( fHasLoneCrOnly ){
950958
zWarning = "CR line endings and Unicode";
951
- }else if( (lookFlags&LOOK_EOL) == LOOK_CRLF ){
959
+ }else if( fHasCrLfOnly ){
952960
zWarning = "CR/NL line endings and Unicode";
953961
}else{
954962
zWarning = "mixed line endings and Unicode";
955963
}
956964
zDisable = "\"crnl-glob\" and \"encoding-glob\" settings";
957
- }else if( lookFlags&LOOK_CR ){
965
+ }else if( fHasAnyCr ){
958966
if( crnlOk ){
959967
return 0; /* We don't want CR/NL warnings for this file. */
960968
}
961
- if( (lookFlags&LOOK_EOL) == LOOK_LONE_CR ){
969
+ if( fHasLoneCrOnly ){
962970
zWarning = "CR line endings";
963
- }else if( (lookFlags&LOOK_EOL) == LOOK_CRLF ){
971
+ }else if( fHasCrLfOnly ){
964972
zWarning = "CR/NL line endings";
965973
}else{
966974
zWarning = "mixed line endings";
967975
}
968976
zDisable = "\"crnl-glob\" setting";
@@ -997,11 +1005,11 @@
9971005
int bomSize;
9981006
const unsigned char *bom = get_utf8_bom(&bomSize);
9991007
fwrite(bom, 1, bomSize, f);
10001008
blob_to_utf8_no_bom(p, 0);
10011009
}
1002
- if( lookFlags&LOOK_CR ){
1010
+ if( fHasAnyCr ){
10031011
blob_to_lf_only(p);
10041012
}
10051013
fwrite(blob_buffer(p), 1, blob_size(p), f);
10061014
fclose(f);
10071015
return 1;
10081016
--- 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 @@
6161
6262
/*
6363
** This macro is designed to return non-zero if the specified blob contains
6464
** data that MAY be binary in nature; otherwise, zero will be returned.
6565
*/
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)
6768
6869
/*
6970
** Output flags for the looks_like_utf8() and looks_like_utf16() routines used
7071
** to convey status information about the blob content.
7172
*/
@@ -79,11 +80,11 @@
7980
#define LOOK_LONG ((int)0x00000040) /* An over length line was found. */
8081
#define LOOK_ODD ((int)0x00000080) /* An odd number of bytes was found. */
8182
#define LOOK_SHORT ((int)0x00000100) /* Unable to perform full check. */
8283
#define LOOK_INVALID ((int)0x00000200) /* Invalid sequence was found. */
8384
#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. */
8586
#endif /* INTERFACE */
8687
8788
/*
8889
** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes)
8990
*/
9091
--- 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

Keyboard Shortcuts

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