Fossil SCM
Improvements to the way binary files are detected.
Commit
8a1c80fb34958c4757605c1a8412b667cbc81929
Parent
f41308d7800a96d…
2 files changed
+4
-3
+3
-3
+4
-3
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -901,17 +901,18 @@ | ||
| 901 | 901 | for(i=0; i<n-1; i++){ |
| 902 | 902 | unsigned char c = z[i]; |
| 903 | 903 | if( c==0 ) return; /* It's binary */ |
| 904 | 904 | if( c=='\n' ){ |
| 905 | 905 | if( i>0 && z[i-1]=='\r' ){ |
| 906 | - nCrNl++; | |
| 907 | - if( i>10000 ) break; | |
| 906 | + nCrNl = 1; | |
| 907 | + if( i>8191 ) break; | |
| 908 | 908 | } |
| 909 | 909 | lastNl = 0; |
| 910 | 910 | }else{ |
| 911 | 911 | lastNl++; |
| 912 | - if( lastNl>1000 ) return; /* Binary if any line longer than 1000 */ | |
| 912 | + /* Binary if any line longer than 8191, see looks_like_binary() */ | |
| 913 | + if( lastNl>8191 ) return; | |
| 913 | 914 | } |
| 914 | 915 | } |
| 915 | 916 | if( nCrNl ){ |
| 916 | 917 | char c; |
| 917 | 918 | file_relative_name(zFilename, &fname, 0); |
| 918 | 919 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -901,17 +901,18 @@ | |
| 901 | for(i=0; i<n-1; i++){ |
| 902 | unsigned char c = z[i]; |
| 903 | if( c==0 ) return; /* It's binary */ |
| 904 | if( c=='\n' ){ |
| 905 | if( i>0 && z[i-1]=='\r' ){ |
| 906 | nCrNl++; |
| 907 | if( i>10000 ) break; |
| 908 | } |
| 909 | lastNl = 0; |
| 910 | }else{ |
| 911 | lastNl++; |
| 912 | if( lastNl>1000 ) return; /* Binary if any line longer than 1000 */ |
| 913 | } |
| 914 | } |
| 915 | if( nCrNl ){ |
| 916 | char c; |
| 917 | file_relative_name(zFilename, &fname, 0); |
| 918 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -901,17 +901,18 @@ | |
| 901 | for(i=0; i<n-1; i++){ |
| 902 | unsigned char c = z[i]; |
| 903 | if( c==0 ) return; /* It's binary */ |
| 904 | if( c=='\n' ){ |
| 905 | if( i>0 && z[i-1]=='\r' ){ |
| 906 | nCrNl = 1; |
| 907 | if( i>8191 ) break; |
| 908 | } |
| 909 | lastNl = 0; |
| 910 | }else{ |
| 911 | lastNl++; |
| 912 | /* Binary if any line longer than 8191, see looks_like_binary() */ |
| 913 | if( lastNl>8191 ) return; |
| 914 | } |
| 915 | } |
| 916 | if( nCrNl ){ |
| 917 | char c; |
| 918 | file_relative_name(zFilename, &fname, 0); |
| 919 |
+3
-3
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -172,22 +172,22 @@ | ||
| 172 | 172 | |
| 173 | 173 | /* |
| 174 | 174 | ** Returns non-zero if the specified content appears to be binary or |
| 175 | 175 | ** contains a line that is too long. |
| 176 | 176 | */ |
| 177 | -int looks_like_binary(Blob *pContent){ | |
| 178 | - const char *z = blob_str(pContent); | |
| 177 | +int looks_like_binary(const Blob *pContent){ | |
| 178 | + const char *z = blob_buffer(pContent); | |
| 179 | 179 | int n = blob_size(pContent); |
| 180 | 180 | int i, j; |
| 181 | 181 | |
| 182 | 182 | /* Count the number of lines. Allocate space to hold |
| 183 | 183 | ** the returned array. |
| 184 | 184 | */ |
| 185 | 185 | for(i=j=0; i<n; i++, j++){ |
| 186 | 186 | int c = z[i]; |
| 187 | 187 | if( c==0 ) return 1; /* \000 byte in a file -> binary */ |
| 188 | - if( c=='\n' && z[i+1]!=0 ){ | |
| 188 | + if( c=='\n' ){ | |
| 189 | 189 | if( j>LENGTH_MASK ){ |
| 190 | 190 | return 1; /* Very long line -> binary */ |
| 191 | 191 | } |
| 192 | 192 | j = 0; |
| 193 | 193 | } |
| 194 | 194 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -172,22 +172,22 @@ | |
| 172 | |
| 173 | /* |
| 174 | ** Returns non-zero if the specified content appears to be binary or |
| 175 | ** contains a line that is too long. |
| 176 | */ |
| 177 | int looks_like_binary(Blob *pContent){ |
| 178 | const char *z = blob_str(pContent); |
| 179 | int n = blob_size(pContent); |
| 180 | int i, j; |
| 181 | |
| 182 | /* Count the number of lines. Allocate space to hold |
| 183 | ** the returned array. |
| 184 | */ |
| 185 | for(i=j=0; i<n; i++, j++){ |
| 186 | int c = z[i]; |
| 187 | if( c==0 ) return 1; /* \000 byte in a file -> binary */ |
| 188 | if( c=='\n' && z[i+1]!=0 ){ |
| 189 | if( j>LENGTH_MASK ){ |
| 190 | return 1; /* Very long line -> binary */ |
| 191 | } |
| 192 | j = 0; |
| 193 | } |
| 194 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -172,22 +172,22 @@ | |
| 172 | |
| 173 | /* |
| 174 | ** Returns non-zero if the specified content appears to be binary or |
| 175 | ** contains a line that is too long. |
| 176 | */ |
| 177 | int looks_like_binary(const Blob *pContent){ |
| 178 | const char *z = blob_buffer(pContent); |
| 179 | int n = blob_size(pContent); |
| 180 | int i, j; |
| 181 | |
| 182 | /* Count the number of lines. Allocate space to hold |
| 183 | ** the returned array. |
| 184 | */ |
| 185 | for(i=j=0; i<n; i++, j++){ |
| 186 | int c = z[i]; |
| 187 | if( c==0 ) return 1; /* \000 byte in a file -> binary */ |
| 188 | if( c=='\n' ){ |
| 189 | if( j>LENGTH_MASK ){ |
| 190 | return 1; /* Very long line -> binary */ |
| 191 | } |
| 192 | j = 0; |
| 193 | } |
| 194 |