Fossil SCM

Add warning for overly long lines found during the commit process.

mistachkin 2013-03-05 02:06 trunk
Commit 10fbcda270363ce07ad379c105ffb336ee8fcdbb
2 files changed +8 -2 +9 -3
+8 -2
--- src/checkin.c
+++ src/checkin.c
@@ -902,17 +902,19 @@
902902
int encodingOk, /* Non-zero if encoding warnings should be disabled. */
903903
const char *zFilename /* The full name of the file being committed. */
904904
){
905905
int eType; /* return value of looks_like_utf8/utf16() */
906906
int fUnicode; /* return value of starts_with_utf16_bom() */
907
+ int longLine; /* non-zero if blob has "long lines" */
907908
char *zMsg; /* Warning message */
908909
Blob fname; /* Relative pathname of the file */
909910
static int allOk = 0; /* Set to true to disable this routine */
910911
911912
if( allOk ) return 0;
912913
fUnicode = starts_with_utf16_bom(p, 0, 0);
913
- eType = fUnicode ? looks_like_utf16(p) : looks_like_utf8(p);
914
+ eType = fUnicode ? looks_like_utf16(p, &longLine) :
915
+ looks_like_utf8(p, &longLine);
914916
if( eType==0 || eType==-1 || fUnicode ){
915917
const char *zWarning;
916918
const char *zDisable;
917919
const char *zConvert = "c=convert/";
918920
Blob ans;
@@ -932,11 +934,15 @@
932934
zDisable = "\"crnl-glob\" setting";
933935
}else if( eType==0 ){
934936
if( binOk ){
935937
return 0; /* We don't want binary warnings for this file. */
936938
}
937
- zWarning = "binary data";
939
+ if( longLine ){
940
+ zWarning = "long lines";
941
+ }else{
942
+ zWarning = "binary data";
943
+ }
938944
zDisable = "\"binary-glob\" setting";
939945
zConvert = ""; /* We cannot convert binary files. */
940946
}else{
941947
if ( encodingOk ){
942948
return 0; /* We don't want encoding warnings for this file. */
943949
--- src/checkin.c
+++ src/checkin.c
@@ -902,17 +902,19 @@
902 int encodingOk, /* Non-zero if encoding warnings should be disabled. */
903 const char *zFilename /* The full name of the file being committed. */
904 ){
905 int eType; /* return value of looks_like_utf8/utf16() */
906 int fUnicode; /* return value of starts_with_utf16_bom() */
 
907 char *zMsg; /* Warning message */
908 Blob fname; /* Relative pathname of the file */
909 static int allOk = 0; /* Set to true to disable this routine */
910
911 if( allOk ) return 0;
912 fUnicode = starts_with_utf16_bom(p, 0, 0);
913 eType = fUnicode ? looks_like_utf16(p) : looks_like_utf8(p);
 
914 if( eType==0 || eType==-1 || fUnicode ){
915 const char *zWarning;
916 const char *zDisable;
917 const char *zConvert = "c=convert/";
918 Blob ans;
@@ -932,11 +934,15 @@
932 zDisable = "\"crnl-glob\" setting";
933 }else if( eType==0 ){
934 if( binOk ){
935 return 0; /* We don't want binary warnings for this file. */
936 }
937 zWarning = "binary data";
 
 
 
 
938 zDisable = "\"binary-glob\" setting";
939 zConvert = ""; /* We cannot convert binary files. */
940 }else{
941 if ( encodingOk ){
942 return 0; /* We don't want encoding warnings for this file. */
943
--- src/checkin.c
+++ src/checkin.c
@@ -902,17 +902,19 @@
902 int encodingOk, /* Non-zero if encoding warnings should be disabled. */
903 const char *zFilename /* The full name of the file being committed. */
904 ){
905 int eType; /* return value of looks_like_utf8/utf16() */
906 int fUnicode; /* return value of starts_with_utf16_bom() */
907 int longLine; /* non-zero if blob has "long lines" */
908 char *zMsg; /* Warning message */
909 Blob fname; /* Relative pathname of the file */
910 static int allOk = 0; /* Set to true to disable this routine */
911
912 if( allOk ) return 0;
913 fUnicode = starts_with_utf16_bom(p, 0, 0);
914 eType = fUnicode ? looks_like_utf16(p, &longLine) :
915 looks_like_utf8(p, &longLine);
916 if( eType==0 || eType==-1 || fUnicode ){
917 const char *zWarning;
918 const char *zDisable;
919 const char *zConvert = "c=convert/";
920 Blob ans;
@@ -932,11 +934,15 @@
934 zDisable = "\"crnl-glob\" setting";
935 }else if( eType==0 ){
936 if( binOk ){
937 return 0; /* We don't want binary warnings for this file. */
938 }
939 if( longLine ){
940 zWarning = "long lines";
941 }else{
942 zWarning = "binary data";
943 }
944 zDisable = "\"binary-glob\" setting";
945 zConvert = ""; /* We cannot convert binary files. */
946 }else{
947 if ( encodingOk ){
948 return 0; /* We don't want encoding warnings for this file. */
949
+9 -3
--- src/diff.c
+++ src/diff.c
@@ -57,11 +57,11 @@
5757
"more than 10,000 changes\n"
5858
5959
#define DIFF_TOO_MANY_CHANGES_HTML \
6060
"<p class='generalError'>More than 10,000 changes</p>\n"
6161
62
-#define looks_like_binary(blob) (looks_like_utf8((blob)) == 0)
62
+#define looks_like_binary(blob) (looks_like_utf8((blob), 0) == 0)
6363
#endif /* INTERFACE */
6464
6565
/*
6666
** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes)
6767
*/
@@ -211,18 +211,19 @@
211211
** The only code points that this function cares about are the NUL character,
212212
** carriage-return, and line-feed.
213213
**
214214
************************************ WARNING **********************************
215215
*/
216
-int looks_like_utf8(const Blob *pContent){
216
+int looks_like_utf8(const Blob *pContent, int *pbLongLine){
217217
const char *z = blob_buffer(pContent);
218218
unsigned int n = blob_size(pContent);
219219
int j, c;
220220
int result = 1; /* Assume UTF-8 text with no CR/NL */
221221
222222
/* Check individual lines.
223223
*/
224
+ if( pbLongLine ) *pbLongLine = 0;
224225
if( n==0 ) return result; /* Empty file -> text */
225226
c = *z;
226227
if( c==0 ) return 0; /* Zero byte in a file -> binary */
227228
j = (c!='\n');
228229
while( --n>0 ){
@@ -232,16 +233,18 @@
232233
int c2 = z[-1];
233234
if( c2=='\r' ){
234235
result = -1; /* Contains CR/NL, continue */
235236
}
236237
if( j>LENGTH_MASK ){
238
+ if( pbLongLine ) *pbLongLine = 1;
237239
return 0; /* Very long line -> binary */
238240
}
239241
j = 0;
240242
}
241243
}
242244
if( j>LENGTH_MASK ){
245
+ if( pbLongLine ) *pbLongLine = 1;
243246
return 0; /* Very long line -> binary */
244247
}
245248
return result; /* No problems seen -> not binary */
246249
}
247250
@@ -301,18 +304,19 @@
301304
** The only code points that this function cares about are the NUL character,
302305
** carriage-return, and line-feed.
303306
**
304307
************************************ WARNING **********************************
305308
*/
306
-int looks_like_utf16(const Blob *pContent){
309
+int looks_like_utf16(const Blob *pContent, int *pbLongLine){
307310
const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent);
308311
unsigned int n = blob_size(pContent);
309312
int j, c;
310313
int result = 1; /* Assume UTF-16 text with no CR/NL */
311314
312315
/* Check individual lines.
313316
*/
317
+ if( pbLongLine ) *pbLongLine = 0;
314318
if( n==0 ) return result; /* Empty file -> text */
315319
if( n%2 ) return 0; /* Odd number of bytes -> binary (or UTF-8) */
316320
c = *z;
317321
if( c==0 ) return 0; /* NUL character in a file -> binary */
318322
j = ((c!=UTF16BE_LF) && (c!=UTF16LE_LF));
@@ -323,16 +327,18 @@
323327
int c2 = z[-1];
324328
if( c2==UTF16BE_CR || c2==UTF16LE_CR ){
325329
result = -1; /* Contains CR/NL, continue */
326330
}
327331
if( j>UTF16_LENGTH_MASK ){
332
+ if( pbLongLine ) *pbLongLine = 1;
328333
return 0; /* Very long line -> binary */
329334
}
330335
j = 0;
331336
}
332337
}
333338
if( j>UTF16_LENGTH_MASK ){
339
+ if( pbLongLine ) *pbLongLine = 1;
334340
return 0; /* Very long line -> binary */
335341
}
336342
return result; /* No problems seen -> not binary */
337343
}
338344
339345
--- src/diff.c
+++ src/diff.c
@@ -57,11 +57,11 @@
57 "more than 10,000 changes\n"
58
59 #define DIFF_TOO_MANY_CHANGES_HTML \
60 "<p class='generalError'>More than 10,000 changes</p>\n"
61
62 #define looks_like_binary(blob) (looks_like_utf8((blob)) == 0)
63 #endif /* INTERFACE */
64
65 /*
66 ** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes)
67 */
@@ -211,18 +211,19 @@
211 ** The only code points that this function cares about are the NUL character,
212 ** carriage-return, and line-feed.
213 **
214 ************************************ WARNING **********************************
215 */
216 int looks_like_utf8(const Blob *pContent){
217 const char *z = blob_buffer(pContent);
218 unsigned int n = blob_size(pContent);
219 int j, c;
220 int result = 1; /* Assume UTF-8 text with no CR/NL */
221
222 /* Check individual lines.
223 */
 
224 if( n==0 ) return result; /* Empty file -> text */
225 c = *z;
226 if( c==0 ) return 0; /* Zero byte in a file -> binary */
227 j = (c!='\n');
228 while( --n>0 ){
@@ -232,16 +233,18 @@
232 int c2 = z[-1];
233 if( c2=='\r' ){
234 result = -1; /* Contains CR/NL, continue */
235 }
236 if( j>LENGTH_MASK ){
 
237 return 0; /* Very long line -> binary */
238 }
239 j = 0;
240 }
241 }
242 if( j>LENGTH_MASK ){
 
243 return 0; /* Very long line -> binary */
244 }
245 return result; /* No problems seen -> not binary */
246 }
247
@@ -301,18 +304,19 @@
301 ** The only code points that this function cares about are the NUL character,
302 ** carriage-return, and line-feed.
303 **
304 ************************************ WARNING **********************************
305 */
306 int looks_like_utf16(const Blob *pContent){
307 const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent);
308 unsigned int n = blob_size(pContent);
309 int j, c;
310 int result = 1; /* Assume UTF-16 text with no CR/NL */
311
312 /* Check individual lines.
313 */
 
314 if( n==0 ) return result; /* Empty file -> text */
315 if( n%2 ) return 0; /* Odd number of bytes -> binary (or UTF-8) */
316 c = *z;
317 if( c==0 ) return 0; /* NUL character in a file -> binary */
318 j = ((c!=UTF16BE_LF) && (c!=UTF16LE_LF));
@@ -323,16 +327,18 @@
323 int c2 = z[-1];
324 if( c2==UTF16BE_CR || c2==UTF16LE_CR ){
325 result = -1; /* Contains CR/NL, continue */
326 }
327 if( j>UTF16_LENGTH_MASK ){
 
328 return 0; /* Very long line -> binary */
329 }
330 j = 0;
331 }
332 }
333 if( j>UTF16_LENGTH_MASK ){
 
334 return 0; /* Very long line -> binary */
335 }
336 return result; /* No problems seen -> not binary */
337 }
338
339
--- src/diff.c
+++ src/diff.c
@@ -57,11 +57,11 @@
57 "more than 10,000 changes\n"
58
59 #define DIFF_TOO_MANY_CHANGES_HTML \
60 "<p class='generalError'>More than 10,000 changes</p>\n"
61
62 #define looks_like_binary(blob) (looks_like_utf8((blob), 0) == 0)
63 #endif /* INTERFACE */
64
65 /*
66 ** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes)
67 */
@@ -211,18 +211,19 @@
211 ** The only code points that this function cares about are the NUL character,
212 ** carriage-return, and line-feed.
213 **
214 ************************************ WARNING **********************************
215 */
216 int looks_like_utf8(const Blob *pContent, int *pbLongLine){
217 const char *z = blob_buffer(pContent);
218 unsigned int n = blob_size(pContent);
219 int j, c;
220 int result = 1; /* Assume UTF-8 text with no CR/NL */
221
222 /* Check individual lines.
223 */
224 if( pbLongLine ) *pbLongLine = 0;
225 if( n==0 ) return result; /* Empty file -> text */
226 c = *z;
227 if( c==0 ) return 0; /* Zero byte in a file -> binary */
228 j = (c!='\n');
229 while( --n>0 ){
@@ -232,16 +233,18 @@
233 int c2 = z[-1];
234 if( c2=='\r' ){
235 result = -1; /* Contains CR/NL, continue */
236 }
237 if( j>LENGTH_MASK ){
238 if( pbLongLine ) *pbLongLine = 1;
239 return 0; /* Very long line -> binary */
240 }
241 j = 0;
242 }
243 }
244 if( j>LENGTH_MASK ){
245 if( pbLongLine ) *pbLongLine = 1;
246 return 0; /* Very long line -> binary */
247 }
248 return result; /* No problems seen -> not binary */
249 }
250
@@ -301,18 +304,19 @@
304 ** The only code points that this function cares about are the NUL character,
305 ** carriage-return, and line-feed.
306 **
307 ************************************ WARNING **********************************
308 */
309 int looks_like_utf16(const Blob *pContent, int *pbLongLine){
310 const WCHAR_T *z = (WCHAR_T *)blob_buffer(pContent);
311 unsigned int n = blob_size(pContent);
312 int j, c;
313 int result = 1; /* Assume UTF-16 text with no CR/NL */
314
315 /* Check individual lines.
316 */
317 if( pbLongLine ) *pbLongLine = 0;
318 if( n==0 ) return result; /* Empty file -> text */
319 if( n%2 ) return 0; /* Odd number of bytes -> binary (or UTF-8) */
320 c = *z;
321 if( c==0 ) return 0; /* NUL character in a file -> binary */
322 j = ((c!=UTF16BE_LF) && (c!=UTF16LE_LF));
@@ -323,16 +327,18 @@
327 int c2 = z[-1];
328 if( c2==UTF16BE_CR || c2==UTF16LE_CR ){
329 result = -1; /* Contains CR/NL, continue */
330 }
331 if( j>UTF16_LENGTH_MASK ){
332 if( pbLongLine ) *pbLongLine = 1;
333 return 0; /* Very long line -> binary */
334 }
335 j = 0;
336 }
337 }
338 if( j>UTF16_LENGTH_MASK ){
339 if( pbLongLine ) *pbLongLine = 1;
340 return 0; /* Very long line -> binary */
341 }
342 return result; /* No problems seen -> not binary */
343 }
344
345

Keyboard Shortcuts

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