Fossil SCM

Modify the commit_warning() function so the warning for possible binary content is higher priority than the other warnings.

mistachkin 2013-03-06 20:46 trunk
Commit 2d9ae4ee73f72232444f9931585ffa9dc0965372
2 files changed +12 -12 +26 -22
+12 -12
--- src/checkin.c
+++ src/checkin.c
@@ -925,11 +925,22 @@
925925
const char *zDisable;
926926
const char *zConvert = "c=convert/";
927927
Blob ans;
928928
char cReply;
929929
930
- if( fHasCrLf && fUnicode ){
930
+ if( eType==0 ){
931
+ if( binOk ){
932
+ return 0; /* We don't want binary warnings for this file. */
933
+ }
934
+ if( fHasLength ){
935
+ zWarning = "long lines";
936
+ }else{
937
+ zWarning = "binary data";
938
+ }
939
+ zDisable = "\"binary-glob\" setting";
940
+ zConvert = ""; /* We cannot convert binary files. */
941
+ }else if( fHasCrLf && fUnicode ){
931942
if ( crnlOk && encodingOk ){
932943
return 0; /* We don't want CR/NL and Unicode warnings for this file. */
933944
}
934945
zWarning = "CR/NL line endings and Unicode";
935946
zDisable = "\"crnl-glob\" and \"encoding-glob\" settings";
@@ -937,21 +948,10 @@
937948
if( crnlOk ){
938949
return 0; /* We don't want CR/NL warnings for this file. */
939950
}
940951
zWarning = "CR/NL line endings";
941952
zDisable = "\"crnl-glob\" setting";
942
- }else if( eType==0 ){
943
- if( binOk ){
944
- return 0; /* We don't want binary warnings for this file. */
945
- }
946
- if( fHasLength ){
947
- zWarning = "long lines";
948
- }else{
949
- zWarning = "binary data";
950
- }
951
- zDisable = "\"binary-glob\" setting";
952
- zConvert = ""; /* We cannot convert binary files. */
953953
}else{
954954
if ( encodingOk ){
955955
return 0; /* We don't want encoding warnings for this file. */
956956
}
957957
zWarning = "Unicode";
958958
--- src/checkin.c
+++ src/checkin.c
@@ -925,11 +925,22 @@
925 const char *zDisable;
926 const char *zConvert = "c=convert/";
927 Blob ans;
928 char cReply;
929
930 if( fHasCrLf && fUnicode ){
 
 
 
 
 
 
 
 
 
 
 
931 if ( crnlOk && encodingOk ){
932 return 0; /* We don't want CR/NL and Unicode warnings for this file. */
933 }
934 zWarning = "CR/NL line endings and Unicode";
935 zDisable = "\"crnl-glob\" and \"encoding-glob\" settings";
@@ -937,21 +948,10 @@
937 if( crnlOk ){
938 return 0; /* We don't want CR/NL warnings for this file. */
939 }
940 zWarning = "CR/NL line endings";
941 zDisable = "\"crnl-glob\" setting";
942 }else if( eType==0 ){
943 if( binOk ){
944 return 0; /* We don't want binary warnings for this file. */
945 }
946 if( fHasLength ){
947 zWarning = "long lines";
948 }else{
949 zWarning = "binary data";
950 }
951 zDisable = "\"binary-glob\" setting";
952 zConvert = ""; /* We cannot convert binary files. */
953 }else{
954 if ( encodingOk ){
955 return 0; /* We don't want encoding warnings for this file. */
956 }
957 zWarning = "Unicode";
958
--- src/checkin.c
+++ src/checkin.c
@@ -925,11 +925,22 @@
925 const char *zDisable;
926 const char *zConvert = "c=convert/";
927 Blob ans;
928 char cReply;
929
930 if( eType==0 ){
931 if( binOk ){
932 return 0; /* We don't want binary warnings for this file. */
933 }
934 if( fHasLength ){
935 zWarning = "long lines";
936 }else{
937 zWarning = "binary data";
938 }
939 zDisable = "\"binary-glob\" setting";
940 zConvert = ""; /* We cannot convert binary files. */
941 }else if( fHasCrLf && fUnicode ){
942 if ( crnlOk && encodingOk ){
943 return 0; /* We don't want CR/NL and Unicode warnings for this file. */
944 }
945 zWarning = "CR/NL line endings and Unicode";
946 zDisable = "\"crnl-glob\" and \"encoding-glob\" settings";
@@ -937,21 +948,10 @@
948 if( crnlOk ){
949 return 0; /* We don't want CR/NL warnings for this file. */
950 }
951 zWarning = "CR/NL line endings";
952 zDisable = "\"crnl-glob\" setting";
 
 
 
 
 
 
 
 
 
 
 
953 }else{
954 if ( encodingOk ){
955 return 0; /* We don't want encoding warnings for this file. */
956 }
957 zWarning = "Unicode";
958
+26 -22
--- src/diff.c
+++ src/diff.c
@@ -223,43 +223,45 @@
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, flags = LOOK_NONE;
228
+ int j, c;
229229
230
- if( pFlags ) *pFlags = flags;
230
+ if( pFlags ) *pFlags = LOOK_NONE;
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
- flags |= LOOK_LF;
247
- if( c2=='\r' ){
248
- flags |= LOOK_CRLF;
246
+ if( pFlags ){
247
+ *pFlags |= LOOK_LF;
248
+ if( c2=='\r' ){
249
+ *pFlags |= LOOK_CRLF;
250
+ }
249251
}
250252
if( j>LENGTH_MASK ){
251
- flags |= LOOK_LENGTH;
253
+ if( pFlags ) *pFlags |= LOOK_LENGTH;
254
+ return 0; /* Very long line -> binary */
252255
}
253256
j = 0;
254257
}
255258
}
256
- if( (flags&LOOK_LENGTH) || (j>LENGTH_MASK) ){
257
- if( pFlags ) *pFlags = LOOK_LENGTH;
259
+ if( j>LENGTH_MASK ){
260
+ if( pFlags ) *pFlags |= LOOK_LENGTH;
258261
return 0; /* Very long line -> binary */
259262
}
260
- if( pFlags ) *pFlags = flags;
261263
return 1; /* No problems seen -> not binary */
262264
}
263265
264266
/*
265267
** Define the type needed to represent a Unicode (UTF-16) character.
@@ -315,44 +317,46 @@
315317
************************************ WARNING **********************************
316318
*/
317319
int looks_like_utf16(const Blob *pContent, int *pFlags){
318320
const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent);
319321
unsigned int n = blob_size(pContent);
320
- int j, c, flags = LOOK_NONE;
322
+ int j, c;
321323
322
- if( pFlags ) *pFlags = flags;
324
+ if( pFlags ) *pFlags = LOOK_NONE;
323325
if( n==0 ) return 1; /* Empty file -> text */
324326
if( n%2 ) return 0; /* Odd number of bytes -> binary (or UTF-8) */
325327
c = *z;
326328
if( c==0 ){
327
- if( pFlags ) *pFlags = LOOK_NUL;
329
+ if( pFlags ) *pFlags |= LOOK_NUL;
328330
return 0; /* NUL character in a file -> binary */
329331
}
330332
j = ((c!=UTF16BE_LF) && (c!=UTF16LE_LF));
331333
while( (n-=2)>0 ){
332334
c = *++z; ++j;
333335
if( c==0 ){
334
- if( pFlags ) *pFlags = LOOK_NUL;
336
+ if( pFlags ) *pFlags |= LOOK_NUL;
335337
return 0; /* NUL character in a file -> binary */
336338
}
337339
if( c==UTF16BE_LF || c==UTF16LE_LF ){
338340
int c2 = z[-1];
339
- flags |= LOOK_LF;
340
- if( c2==UTF16BE_CR || c2==UTF16LE_CR ){
341
- flags |= LOOK_CRLF;
341
+ if( pFlags ){
342
+ *pFlags |= LOOK_LF;
343
+ if( c2==UTF16BE_CR || c2==UTF16LE_CR ){
344
+ *pFlags |= LOOK_CRLF;
345
+ }
342346
}
343347
if( j>UTF16_LENGTH_MASK ){
344
- flags |= LOOK_LENGTH;
348
+ if( pFlags ) *pFlags |= LOOK_LENGTH;
349
+ return 0; /* Very long line -> binary */
345350
}
346351
j = 0;
347352
}
348353
}
349
- if( (flags&LOOK_LENGTH) || (j>UTF16_LENGTH_MASK) ){
350
- if( pFlags ) *pFlags = LOOK_LENGTH;
354
+ if( j>UTF16_LENGTH_MASK ){
355
+ if( pFlags ) *pFlags |= LOOK_LENGTH;
351356
return 0; /* Very long line -> binary */
352357
}
353
- if( pFlags ) *pFlags = flags;
354358
return 1; /* No problems seen -> not binary */
355359
}
356360
357361
/*
358362
** This function returns an array of bytes representing the byte-order-mark
359363
--- src/diff.c
+++ src/diff.c
@@ -223,43 +223,45 @@
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.
@@ -315,44 +317,46 @@
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
--- src/diff.c
+++ src/diff.c
@@ -223,43 +223,45 @@
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.
@@ -315,44 +317,46 @@
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

Keyboard Shortcuts

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