Fossil SCM

Improvements to the way binary files are detected.

drh 2012-10-26 01:38 trunk merge
Commit 8a1c80fb34958c4757605c1a8412b667cbc81929
2 files changed +4 -3 +3 -3
+4 -3
--- src/checkin.c
+++ src/checkin.c
@@ -901,17 +901,18 @@
901901
for(i=0; i<n-1; i++){
902902
unsigned char c = z[i];
903903
if( c==0 ) return; /* It's binary */
904904
if( c=='\n' ){
905905
if( i>0 && z[i-1]=='\r' ){
906
- nCrNl++;
907
- if( i>10000 ) break;
906
+ nCrNl = 1;
907
+ if( i>8191 ) break;
908908
}
909909
lastNl = 0;
910910
}else{
911911
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;
913914
}
914915
}
915916
if( nCrNl ){
916917
char c;
917918
file_relative_name(zFilename, &fname, 0);
918919
--- 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 @@
172172
173173
/*
174174
** Returns non-zero if the specified content appears to be binary or
175175
** contains a line that is too long.
176176
*/
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);
179179
int n = blob_size(pContent);
180180
int i, j;
181181
182182
/* Count the number of lines. Allocate space to hold
183183
** the returned array.
184184
*/
185185
for(i=j=0; i<n; i++, j++){
186186
int c = z[i];
187187
if( c==0 ) return 1; /* \000 byte in a file -> binary */
188
- if( c=='\n' && z[i+1]!=0 ){
188
+ if( c=='\n' ){
189189
if( j>LENGTH_MASK ){
190190
return 1; /* Very long line -> binary */
191191
}
192192
j = 0;
193193
}
194194
--- 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

Keyboard Shortcuts

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