Fossil SCM
Simplify the looks_like_binary() macro. Remove literal tab character, adjust styling and comments in looks_like_text().
Commit
c8e72df08eeaeac71f4c64c31af4294d2c8e9a67
Parent
b2204034ecb389e…
1 file changed
+6
-6
+6
-6
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -48,11 +48,11 @@ | ||
| 48 | 48 | "cannot compute difference between binary files\n" |
| 49 | 49 | |
| 50 | 50 | #define DIFF_CANNOT_COMPUTE_SYMLINK \ |
| 51 | 51 | "cannot compute difference between symlink and regular file\n" |
| 52 | 52 | |
| 53 | -#define looks_like_binary(blob) (!(looks_like_text(blob)&1)) | |
| 53 | +#define looks_like_binary(blob) (looks_like_text((blob)) == 0) | |
| 54 | 54 | #endif /* INTERFACE */ |
| 55 | 55 | |
| 56 | 56 | /* |
| 57 | 57 | ** Maximum length of a line in a text file. (8192) |
| 58 | 58 | */ |
| @@ -179,35 +179,35 @@ | ||
| 179 | 179 | */ |
| 180 | 180 | int looks_like_text(const Blob *pContent){ |
| 181 | 181 | const char *z = blob_buffer(pContent); |
| 182 | 182 | unsigned int n = blob_size(pContent); |
| 183 | 183 | int j, c; |
| 184 | - int result = 1; | |
| 184 | + int result = 1; /* Assume text with no CrLf */ | |
| 185 | 185 | |
| 186 | 186 | /* Check individual lines. |
| 187 | 187 | */ |
| 188 | - if( n==0 ) return 1; /* Empty file -> text */ | |
| 188 | + if( n==0 ) return result; /* Empty file -> text */ | |
| 189 | 189 | c = *z; |
| 190 | 190 | if( c==0 ) return 0; /* \000 byte in a file -> binary */ |
| 191 | 191 | j = (c!='\n'); |
| 192 | 192 | while( --n>0 ){ |
| 193 | 193 | c = *++z; ++j; |
| 194 | 194 | if( c==0 ) return 0; /* \000 byte in a file -> binary */ |
| 195 | 195 | if( c=='\n' ){ |
| 196 | 196 | if( z[-1]=='\r' ){ |
| 197 | - result = -1; /* Contains CrLf, continue */ | |
| 197 | + result = -1; /* Contains CrLf, continue */ | |
| 198 | 198 | } |
| 199 | 199 | if( j>LENGTH_MASK ){ |
| 200 | - return 0; /* Very long line -> binary */ | |
| 200 | + return 0; /* Very long line -> binary */ | |
| 201 | 201 | } |
| 202 | 202 | j = 0; |
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | if( j>LENGTH_MASK ){ |
| 206 | 206 | return 0; /* Very long line -> binary */ |
| 207 | 207 | } |
| 208 | - return result; /* No problems seen -> not binary */ | |
| 208 | + return result; /* No problems seen -> not binary */ | |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /* |
| 212 | 212 | ** Return true if two DLine elements are identical. |
| 213 | 213 | */ |
| 214 | 214 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -48,11 +48,11 @@ | |
| 48 | "cannot compute difference between binary files\n" |
| 49 | |
| 50 | #define DIFF_CANNOT_COMPUTE_SYMLINK \ |
| 51 | "cannot compute difference between symlink and regular file\n" |
| 52 | |
| 53 | #define looks_like_binary(blob) (!(looks_like_text(blob)&1)) |
| 54 | #endif /* INTERFACE */ |
| 55 | |
| 56 | /* |
| 57 | ** Maximum length of a line in a text file. (8192) |
| 58 | */ |
| @@ -179,35 +179,35 @@ | |
| 179 | */ |
| 180 | int looks_like_text(const Blob *pContent){ |
| 181 | const char *z = blob_buffer(pContent); |
| 182 | unsigned int n = blob_size(pContent); |
| 183 | int j, c; |
| 184 | int result = 1; |
| 185 | |
| 186 | /* Check individual lines. |
| 187 | */ |
| 188 | if( n==0 ) return 1; /* Empty file -> text */ |
| 189 | c = *z; |
| 190 | if( c==0 ) return 0; /* \000 byte in a file -> binary */ |
| 191 | j = (c!='\n'); |
| 192 | while( --n>0 ){ |
| 193 | c = *++z; ++j; |
| 194 | if( c==0 ) return 0; /* \000 byte in a file -> binary */ |
| 195 | if( c=='\n' ){ |
| 196 | if( z[-1]=='\r' ){ |
| 197 | result = -1; /* Contains CrLf, continue */ |
| 198 | } |
| 199 | if( j>LENGTH_MASK ){ |
| 200 | return 0; /* Very long line -> binary */ |
| 201 | } |
| 202 | j = 0; |
| 203 | } |
| 204 | } |
| 205 | if( j>LENGTH_MASK ){ |
| 206 | return 0; /* Very long line -> binary */ |
| 207 | } |
| 208 | return result; /* No problems seen -> not binary */ |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | ** Return true if two DLine elements are identical. |
| 213 | */ |
| 214 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -48,11 +48,11 @@ | |
| 48 | "cannot compute difference between binary files\n" |
| 49 | |
| 50 | #define DIFF_CANNOT_COMPUTE_SYMLINK \ |
| 51 | "cannot compute difference between symlink and regular file\n" |
| 52 | |
| 53 | #define looks_like_binary(blob) (looks_like_text((blob)) == 0) |
| 54 | #endif /* INTERFACE */ |
| 55 | |
| 56 | /* |
| 57 | ** Maximum length of a line in a text file. (8192) |
| 58 | */ |
| @@ -179,35 +179,35 @@ | |
| 179 | */ |
| 180 | int looks_like_text(const Blob *pContent){ |
| 181 | const char *z = blob_buffer(pContent); |
| 182 | unsigned int n = blob_size(pContent); |
| 183 | int j, c; |
| 184 | int result = 1; /* Assume text with no CrLf */ |
| 185 | |
| 186 | /* Check individual lines. |
| 187 | */ |
| 188 | if( n==0 ) return result; /* Empty file -> text */ |
| 189 | c = *z; |
| 190 | if( c==0 ) return 0; /* \000 byte in a file -> binary */ |
| 191 | j = (c!='\n'); |
| 192 | while( --n>0 ){ |
| 193 | c = *++z; ++j; |
| 194 | if( c==0 ) return 0; /* \000 byte in a file -> binary */ |
| 195 | if( c=='\n' ){ |
| 196 | if( z[-1]=='\r' ){ |
| 197 | result = -1; /* Contains CrLf, continue */ |
| 198 | } |
| 199 | if( j>LENGTH_MASK ){ |
| 200 | return 0; /* Very long line -> binary */ |
| 201 | } |
| 202 | j = 0; |
| 203 | } |
| 204 | } |
| 205 | if( j>LENGTH_MASK ){ |
| 206 | return 0; /* Very long line -> binary */ |
| 207 | } |
| 208 | return result; /* No problems seen -> not binary */ |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | ** Return true if two DLine elements are identical. |
| 213 | */ |
| 214 |