46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
*/
#define DIFF_CANNOT_COMPUTE_BINARY \
"cannot compute difference between binary files\n"
#define DIFF_CANNOT_COMPUTE_SYMLINK \
"cannot compute difference between symlink and regular file\n"
#define looks_like_binary(blob) (!(looks_like_text(blob)&1))
#endif /* INTERFACE */
/*
** Maximum length of a line in a text file. (8192)
*/
#define LENGTH_MASK_SZ 13
#define LENGTH_MASK ((1<<LENGTH_MASK_SZ)-1)
|
|
|
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
*/
#define DIFF_CANNOT_COMPUTE_BINARY \
"cannot compute difference between binary files\n"
#define DIFF_CANNOT_COMPUTE_SYMLINK \
"cannot compute difference between symlink and regular file\n"
#define looks_like_binary(blob) (looks_like_text((blob)) == 0)
#endif /* INTERFACE */
/*
** Maximum length of a line in a text file. (8192)
*/
#define LENGTH_MASK_SZ 13
#define LENGTH_MASK ((1<<LENGTH_MASK_SZ)-1)
|
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
** contains a line that is too long
** Returns -1, if the file appears text, but it contains CrLf
*/
int looks_like_text(const Blob *pContent){
const char *z = blob_buffer(pContent);
unsigned int n = blob_size(pContent);
int j, c;
int result = 1;
/* Check individual lines.
*/
if( n==0 ) return 1; /* Empty file -> text */
c = *z;
if( c==0 ) return 0; /* \000 byte in a file -> binary */
j = (c!='\n');
while( --n>0 ){
c = *++z; ++j;
if( c==0 ) return 0; /* \000 byte in a file -> binary */
if( c=='\n' ){
if( z[-1]=='\r' ){
result = -1; /* Contains CrLf, continue */
}
if( j>LENGTH_MASK ){
return 0; /* Very long line -> binary */
}
j = 0;
}
}
if( j>LENGTH_MASK ){
return 0; /* Very long line -> binary */
}
return result; /* No problems seen -> not binary */
}
/*
** Return true if two DLine elements are identical.
*/
static int same_dline(DLine *pA, DLine *pB){
return pA->h==pB->h && memcmp(pA->z,pB->z,pA->h & LENGTH_MASK)==0;
|
|
|
|
|
|
|
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
** contains a line that is too long
** Returns -1, if the file appears text, but it contains CrLf
*/
int looks_like_text(const Blob *pContent){
const char *z = blob_buffer(pContent);
unsigned int n = blob_size(pContent);
int j, c;
int result = 1; /* Assume text with no CrLf */
/* Check individual lines.
*/
if( n==0 ) return result; /* Empty file -> text */
c = *z;
if( c==0 ) return 0; /* \000 byte in a file -> binary */
j = (c!='\n');
while( --n>0 ){
c = *++z; ++j;
if( c==0 ) return 0; /* \000 byte in a file -> binary */
if( c=='\n' ){
if( z[-1]=='\r' ){
result = -1; /* Contains CrLf, continue */
}
if( j>LENGTH_MASK ){
return 0; /* Very long line -> binary */
}
j = 0;
}
}
if( j>LENGTH_MASK ){
return 0; /* Very long line -> binary */
}
return result; /* No problems seen -> not binary */
}
/*
** Return true if two DLine elements are identical.
*/
static int same_dline(DLine *pA, DLine *pB){
return pA->h==pB->h && memcmp(pA->z,pB->z,pA->h & LENGTH_MASK)==0;
|