Fossil SCM

fix commit dialog for files containing crlf or long lines followed by nul byte. test-case: $ tclsh8.6 % set f [open abc w];fconfigure $f -translation binary;puts -nonewline $f \r\n\0;close $f;exit $ fossil add abc ADDED abc $ fossil commit --test ./abc contains CR/NL line endings. Use --no-warnings or the "crnl-glob" setting to disable this warning. Commit anyhow (a=all/c=convert/y/N)? n After correction: $ ./fossil commit --test ./abc contains binary data. Use --no-warnings or the "binary-glob" setting to disable this warning. Commit anyhow (a=all/y/N)? n

jan.nijtmans 2013-03-06 15:33 trunk
Commit af0ca3b4eb272bbc5337f7855ff47ec150572387
1 file changed +22 -26
+22 -26
--- src/diff.c
+++ src/diff.c
@@ -223,45 +223,43 @@
223223
************************************ WARNING **********************************
224224
*/
225225
int looks_like_utf8(const Blob *pContent, int *pFlags){
226226
const char *z = blob_buffer(pContent);
227227
unsigned int n = blob_size(pContent);
228
- int j, c;
228
+ int j, c, flags = LOOK_NONE;
229229
230
- if( pFlags ) *pFlags = LOOK_NONE;
230
+ if( pFlags ) *pFlags = flags;
231231
if( n==0 ) return 1; /* Empty file -> text */
232232
c = *z;
233233
if( c==0 ){
234
- if( pFlags ) *pFlags |= LOOK_NUL;
234
+ if( pFlags ) *pFlags = LOOK_NUL;
235235
return 0; /* NUL character in a file -> binary */
236236
}
237237
j = (c!='\n');
238238
while( --n>0 ){
239239
c = *++z; ++j;
240240
if( c==0 ){
241
- if( pFlags ) *pFlags |= LOOK_NUL;
241
+ if( pFlags ) *pFlags = LOOK_NUL;
242242
return 0; /* NUL character in a file -> binary */
243243
}
244244
if( c=='\n' ){
245245
int c2 = z[-1];
246
- if( pFlags ){
247
- *pFlags |= LOOK_LF;
248
- if( c2=='\r' ){
249
- *pFlags |= LOOK_CRLF;
250
- }
246
+ flags |= LOOK_LF;
247
+ if( c2=='\r' ){
248
+ flags |= LOOK_CRLF;
251249
}
252250
if( j>LENGTH_MASK ){
253
- if( pFlags ) *pFlags |= LOOK_LENGTH;
254
- return 0; /* Very long line -> binary */
251
+ flags |= LOOK_LENGTH;
255252
}
256253
j = 0;
257254
}
258255
}
259
- if( j>LENGTH_MASK ){
260
- if( pFlags ) *pFlags |= LOOK_LENGTH;
256
+ if( (flags&LOOK_LENGTH) || (j>LENGTH_MASK) ){
257
+ if( pFlags ) *pFlags = LOOK_LENGTH;
261258
return 0; /* Very long line -> binary */
262259
}
260
+ if( pFlags ) *pFlags = flags;
263261
return 1; /* No problems seen -> not binary */
264262
}
265263
266264
/*
267265
** Define the type needed to represent a Unicode (UTF-16) character.
@@ -317,46 +315,44 @@
317315
************************************ WARNING **********************************
318316
*/
319317
int looks_like_utf16(const Blob *pContent, int *pFlags){
320318
const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent);
321319
unsigned int n = blob_size(pContent);
322
- int j, c;
320
+ int j, c, flags = LOOK_NONE;
323321
324
- if( pFlags ) *pFlags = LOOK_NONE;
322
+ if( pFlags ) *pFlags = flags;
325323
if( n==0 ) return 1; /* Empty file -> text */
326324
if( n%2 ) return 0; /* Odd number of bytes -> binary (or UTF-8) */
327325
c = *z;
328326
if( c==0 ){
329
- if( pFlags ) *pFlags |= LOOK_NUL;
327
+ if( pFlags ) *pFlags = LOOK_NUL;
330328
return 0; /* NUL character in a file -> binary */
331329
}
332330
j = ((c!=UTF16BE_LF) && (c!=UTF16LE_LF));
333331
while( (n-=2)>0 ){
334332
c = *++z; ++j;
335333
if( c==0 ){
336
- if( pFlags ) *pFlags |= LOOK_NUL;
334
+ if( pFlags ) *pFlags = LOOK_NUL;
337335
return 0; /* NUL character in a file -> binary */
338336
}
339337
if( c==UTF16BE_LF || c==UTF16LE_LF ){
340338
int c2 = z[-1];
341
- if( pFlags ){
342
- *pFlags |= LOOK_LF;
343
- if( c2==UTF16BE_CR || c2==UTF16LE_CR ){
344
- *pFlags |= LOOK_CRLF;
345
- }
339
+ flags |= LOOK_LF;
340
+ if( c2==UTF16BE_CR || c2==UTF16LE_CR ){
341
+ flags |= LOOK_CRLF;
346342
}
347343
if( j>UTF16_LENGTH_MASK ){
348
- if( pFlags ) *pFlags |= LOOK_LENGTH;
349
- return 0; /* Very long line -> binary */
344
+ flags |= LOOK_LENGTH;
350345
}
351346
j = 0;
352347
}
353348
}
354
- if( j>UTF16_LENGTH_MASK ){
355
- if( pFlags ) *pFlags |= LOOK_LENGTH;
349
+ if( (flags&LOOK_LENGTH) || (j>UTF16_LENGTH_MASK) ){
350
+ if( pFlags ) *pFlags = LOOK_LENGTH;
356351
return 0; /* Very long line -> binary */
357352
}
353
+ if( pFlags ) *pFlags = flags;
358354
return 1; /* No problems seen -> not binary */
359355
}
360356
361357
/*
362358
** This function returns an array of bytes representing the byte-order-mark
363359
--- src/diff.c
+++ src/diff.c
@@ -223,45 +223,43 @@
223 ************************************ WARNING **********************************
224 */
225 int looks_like_utf8(const Blob *pContent, int *pFlags){
226 const char *z = blob_buffer(pContent);
227 unsigned int n = blob_size(pContent);
228 int j, c;
229
230 if( pFlags ) *pFlags = LOOK_NONE;
231 if( n==0 ) return 1; /* Empty file -> text */
232 c = *z;
233 if( c==0 ){
234 if( pFlags ) *pFlags |= LOOK_NUL;
235 return 0; /* NUL character in a file -> binary */
236 }
237 j = (c!='\n');
238 while( --n>0 ){
239 c = *++z; ++j;
240 if( c==0 ){
241 if( pFlags ) *pFlags |= LOOK_NUL;
242 return 0; /* NUL character in a file -> binary */
243 }
244 if( c=='\n' ){
245 int c2 = z[-1];
246 if( pFlags ){
247 *pFlags |= LOOK_LF;
248 if( c2=='\r' ){
249 *pFlags |= LOOK_CRLF;
250 }
251 }
252 if( j>LENGTH_MASK ){
253 if( pFlags ) *pFlags |= LOOK_LENGTH;
254 return 0; /* Very long line -> binary */
255 }
256 j = 0;
257 }
258 }
259 if( j>LENGTH_MASK ){
260 if( pFlags ) *pFlags |= LOOK_LENGTH;
261 return 0; /* Very long line -> binary */
262 }
 
263 return 1; /* No problems seen -> not binary */
264 }
265
266 /*
267 ** Define the type needed to represent a Unicode (UTF-16) character.
@@ -317,46 +315,44 @@
317 ************************************ WARNING **********************************
318 */
319 int looks_like_utf16(const Blob *pContent, int *pFlags){
320 const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent);
321 unsigned int n = blob_size(pContent);
322 int j, c;
323
324 if( pFlags ) *pFlags = LOOK_NONE;
325 if( n==0 ) return 1; /* Empty file -> text */
326 if( n%2 ) return 0; /* Odd number of bytes -> binary (or UTF-8) */
327 c = *z;
328 if( c==0 ){
329 if( pFlags ) *pFlags |= LOOK_NUL;
330 return 0; /* NUL character in a file -> binary */
331 }
332 j = ((c!=UTF16BE_LF) && (c!=UTF16LE_LF));
333 while( (n-=2)>0 ){
334 c = *++z; ++j;
335 if( c==0 ){
336 if( pFlags ) *pFlags |= LOOK_NUL;
337 return 0; /* NUL character in a file -> binary */
338 }
339 if( c==UTF16BE_LF || c==UTF16LE_LF ){
340 int c2 = z[-1];
341 if( pFlags ){
342 *pFlags |= LOOK_LF;
343 if( c2==UTF16BE_CR || c2==UTF16LE_CR ){
344 *pFlags |= LOOK_CRLF;
345 }
346 }
347 if( j>UTF16_LENGTH_MASK ){
348 if( pFlags ) *pFlags |= LOOK_LENGTH;
349 return 0; /* Very long line -> binary */
350 }
351 j = 0;
352 }
353 }
354 if( j>UTF16_LENGTH_MASK ){
355 if( pFlags ) *pFlags |= LOOK_LENGTH;
356 return 0; /* Very long line -> binary */
357 }
 
358 return 1; /* No problems seen -> not binary */
359 }
360
361 /*
362 ** This function returns an array of bytes representing the byte-order-mark
363
--- src/diff.c
+++ src/diff.c
@@ -223,45 +223,43 @@
223 ************************************ WARNING **********************************
224 */
225 int looks_like_utf8(const Blob *pContent, int *pFlags){
226 const char *z = blob_buffer(pContent);
227 unsigned int n = blob_size(pContent);
228 int j, c, flags = LOOK_NONE;
229
230 if( pFlags ) *pFlags = flags;
231 if( n==0 ) return 1; /* Empty file -> text */
232 c = *z;
233 if( c==0 ){
234 if( pFlags ) *pFlags = LOOK_NUL;
235 return 0; /* NUL character in a file -> binary */
236 }
237 j = (c!='\n');
238 while( --n>0 ){
239 c = *++z; ++j;
240 if( c==0 ){
241 if( pFlags ) *pFlags = LOOK_NUL;
242 return 0; /* NUL character in a file -> binary */
243 }
244 if( c=='\n' ){
245 int c2 = z[-1];
246 flags |= LOOK_LF;
247 if( c2=='\r' ){
248 flags |= LOOK_CRLF;
 
 
249 }
250 if( j>LENGTH_MASK ){
251 flags |= LOOK_LENGTH;
 
252 }
253 j = 0;
254 }
255 }
256 if( (flags&LOOK_LENGTH) || (j>LENGTH_MASK) ){
257 if( pFlags ) *pFlags = LOOK_LENGTH;
258 return 0; /* Very long line -> binary */
259 }
260 if( pFlags ) *pFlags = flags;
261 return 1; /* No problems seen -> not binary */
262 }
263
264 /*
265 ** Define the type needed to represent a Unicode (UTF-16) character.
@@ -317,46 +315,44 @@
315 ************************************ WARNING **********************************
316 */
317 int looks_like_utf16(const Blob *pContent, int *pFlags){
318 const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent);
319 unsigned int n = blob_size(pContent);
320 int j, c, flags = LOOK_NONE;
321
322 if( pFlags ) *pFlags = flags;
323 if( n==0 ) return 1; /* Empty file -> text */
324 if( n%2 ) return 0; /* Odd number of bytes -> binary (or UTF-8) */
325 c = *z;
326 if( c==0 ){
327 if( pFlags ) *pFlags = LOOK_NUL;
328 return 0; /* NUL character in a file -> binary */
329 }
330 j = ((c!=UTF16BE_LF) && (c!=UTF16LE_LF));
331 while( (n-=2)>0 ){
332 c = *++z; ++j;
333 if( c==0 ){
334 if( pFlags ) *pFlags = LOOK_NUL;
335 return 0; /* NUL character in a file -> binary */
336 }
337 if( c==UTF16BE_LF || c==UTF16LE_LF ){
338 int c2 = z[-1];
339 flags |= LOOK_LF;
340 if( c2==UTF16BE_CR || c2==UTF16LE_CR ){
341 flags |= LOOK_CRLF;
 
 
342 }
343 if( j>UTF16_LENGTH_MASK ){
344 flags |= LOOK_LENGTH;
 
345 }
346 j = 0;
347 }
348 }
349 if( (flags&LOOK_LENGTH) || (j>UTF16_LENGTH_MASK) ){
350 if( pFlags ) *pFlags = LOOK_LENGTH;
351 return 0; /* Very long line -> binary */
352 }
353 if( pFlags ) *pFlags = flags;
354 return 1; /* No problems seen -> not binary */
355 }
356
357 /*
358 ** This function returns an array of bytes representing the byte-order-mark
359

Keyboard Shortcuts

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