Fossil SCM

Limit the complexiting of the diff display on check-in information pages.

drh 2013-02-16 14:12 trunk
Commit 4f95ea8c56718447fc29f7566048b1c27edb6b8d
2 files changed +28 -1 +3 -61
+28 -1
--- src/diff.c
+++ src/diff.c
@@ -39,10 +39,11 @@
3939
#define DIFF_LINENO ((u64)0x20000000) /* Show line numbers */
4040
#define DIFF_WS_WARNING ((u64)0x40000000) /* Warn about whitespace */
4141
#define DIFF_NOOPT (((u64)0x01)<<32) /* Suppress optimizations (debug) */
4242
#define DIFF_INVERT (((u64)0x02)<<32) /* Invert the diff (debug) */
4343
#define DIFF_CONTEXT_EX (((u64)0x04)<<32) /* Use context even if zero */
44
+#define DIFF_NOTTOOBIG (((u64)0x08)<<32) /* Only display if not too big */
4445
4546
/*
4647
** These error messages are shared in multiple locations. They are defined
4748
** here for consistency.
4849
*/
@@ -50,10 +51,16 @@
5051
"cannot compute difference between binary files\n"
5152
5253
#define DIFF_CANNOT_COMPUTE_SYMLINK \
5354
"cannot compute difference between symlink and regular file\n"
5455
56
+#define DIFF_TOO_MANY_CHANGES_TXT \
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
+
5562
#define looks_like_binary(blob) (looks_like_utf8((blob)) == 0)
5663
#endif /* INTERFACE */
5764
5865
/*
5966
** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes)
@@ -1904,10 +1911,11 @@
19041911
ReCompiled *pRe, /* Only output changes where this Regexp matches */
19051912
u64 diffFlags /* DIFF_* flags defined above */
19061913
){
19071914
int ignoreEolWs; /* Ignore whitespace at the end of lines */
19081915
DContext c;
1916
+ int i, nChng;
19091917
19101918
if( diffFlags & DIFF_INVERT ){
19111919
Blob *pTemp = pA_Blob;
19121920
pA_Blob = pB_Blob;
19131921
pB_Blob = pTemp;
@@ -1929,11 +1937,30 @@
19291937
return 0;
19301938
}
19311939
19321940
/* Compute the difference */
19331941
diff_all(&c);
1934
- if( (diffFlags & DIFF_NOOPT)==0 ) diff_optimize(&c);
1942
+ if( (diffFlags & DIFF_NOTTOOBIG)!=0 ){
1943
+ int i, m, n;
1944
+ int *a = c.aEdit;
1945
+ int mx = c.nEdit;
1946
+ for(i=m=n=0; i<mx; i+=3){ m += a[i]; n += a[i+1]+a[i+2]; }
1947
+ if( n>10000 ){
1948
+ fossil_free(c.aFrom);
1949
+ fossil_free(c.aTo);
1950
+ fossil_free(c.aEdit);
1951
+ if( diffFlags & DIFF_HTML ){
1952
+ blob_append(pOut, DIFF_TOO_MANY_CHANGES_HTML, -1);
1953
+ }else{
1954
+ blob_append(pOut, DIFF_TOO_MANY_CHANGES_TXT, -1);
1955
+ }
1956
+ return 0;
1957
+ }
1958
+ }
1959
+ if( (diffFlags & DIFF_NOOPT)==0 ){
1960
+ diff_optimize(&c);
1961
+ }
19351962
19361963
if( pOut ){
19371964
/* Compute a context or side-by-side diff into pOut */
19381965
if( diffFlags & DIFF_SIDEBYSIDE ){
19391966
sbsDiff(&c, pOut, pRe, diffFlags);
19401967
--- src/diff.c
+++ src/diff.c
@@ -39,10 +39,11 @@
39 #define DIFF_LINENO ((u64)0x20000000) /* Show line numbers */
40 #define DIFF_WS_WARNING ((u64)0x40000000) /* Warn about whitespace */
41 #define DIFF_NOOPT (((u64)0x01)<<32) /* Suppress optimizations (debug) */
42 #define DIFF_INVERT (((u64)0x02)<<32) /* Invert the diff (debug) */
43 #define DIFF_CONTEXT_EX (((u64)0x04)<<32) /* Use context even if zero */
 
44
45 /*
46 ** These error messages are shared in multiple locations. They are defined
47 ** here for consistency.
48 */
@@ -50,10 +51,16 @@
50 "cannot compute difference between binary files\n"
51
52 #define DIFF_CANNOT_COMPUTE_SYMLINK \
53 "cannot compute difference between symlink and regular file\n"
54
 
 
 
 
 
 
55 #define looks_like_binary(blob) (looks_like_utf8((blob)) == 0)
56 #endif /* INTERFACE */
57
58 /*
59 ** Maximum length of a line in a text file, in bytes. (2**13 = 8192 bytes)
@@ -1904,10 +1911,11 @@
1904 ReCompiled *pRe, /* Only output changes where this Regexp matches */
1905 u64 diffFlags /* DIFF_* flags defined above */
1906 ){
1907 int ignoreEolWs; /* Ignore whitespace at the end of lines */
1908 DContext c;
 
1909
1910 if( diffFlags & DIFF_INVERT ){
1911 Blob *pTemp = pA_Blob;
1912 pA_Blob = pB_Blob;
1913 pB_Blob = pTemp;
@@ -1929,11 +1937,30 @@
1929 return 0;
1930 }
1931
1932 /* Compute the difference */
1933 diff_all(&c);
1934 if( (diffFlags & DIFF_NOOPT)==0 ) diff_optimize(&c);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1935
1936 if( pOut ){
1937 /* Compute a context or side-by-side diff into pOut */
1938 if( diffFlags & DIFF_SIDEBYSIDE ){
1939 sbsDiff(&c, pOut, pRe, diffFlags);
1940
--- src/diff.c
+++ src/diff.c
@@ -39,10 +39,11 @@
39 #define DIFF_LINENO ((u64)0x20000000) /* Show line numbers */
40 #define DIFF_WS_WARNING ((u64)0x40000000) /* Warn about whitespace */
41 #define DIFF_NOOPT (((u64)0x01)<<32) /* Suppress optimizations (debug) */
42 #define DIFF_INVERT (((u64)0x02)<<32) /* Invert the diff (debug) */
43 #define DIFF_CONTEXT_EX (((u64)0x04)<<32) /* Use context even if zero */
44 #define DIFF_NOTTOOBIG (((u64)0x08)<<32) /* Only display if not too big */
45
46 /*
47 ** These error messages are shared in multiple locations. They are defined
48 ** here for consistency.
49 */
@@ -50,10 +51,16 @@
51 "cannot compute difference between binary files\n"
52
53 #define DIFF_CANNOT_COMPUTE_SYMLINK \
54 "cannot compute difference between symlink and regular file\n"
55
56 #define DIFF_TOO_MANY_CHANGES_TXT \
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)
@@ -1904,10 +1911,11 @@
1911 ReCompiled *pRe, /* Only output changes where this Regexp matches */
1912 u64 diffFlags /* DIFF_* flags defined above */
1913 ){
1914 int ignoreEolWs; /* Ignore whitespace at the end of lines */
1915 DContext c;
1916 int i, nChng;
1917
1918 if( diffFlags & DIFF_INVERT ){
1919 Blob *pTemp = pA_Blob;
1920 pA_Blob = pB_Blob;
1921 pB_Blob = pTemp;
@@ -1929,11 +1937,30 @@
1937 return 0;
1938 }
1939
1940 /* Compute the difference */
1941 diff_all(&c);
1942 if( (diffFlags & DIFF_NOTTOOBIG)!=0 ){
1943 int i, m, n;
1944 int *a = c.aEdit;
1945 int mx = c.nEdit;
1946 for(i=m=n=0; i<mx; i+=3){ m += a[i]; n += a[i+1]+a[i+2]; }
1947 if( n>10000 ){
1948 fossil_free(c.aFrom);
1949 fossil_free(c.aTo);
1950 fossil_free(c.aEdit);
1951 if( diffFlags & DIFF_HTML ){
1952 blob_append(pOut, DIFF_TOO_MANY_CHANGES_HTML, -1);
1953 }else{
1954 blob_append(pOut, DIFF_TOO_MANY_CHANGES_TXT, -1);
1955 }
1956 return 0;
1957 }
1958 }
1959 if( (diffFlags & DIFF_NOOPT)==0 ){
1960 diff_optimize(&c);
1961 }
1962
1963 if( pOut ){
1964 /* Compute a context or side-by-side diff into pOut */
1965 if( diffFlags & DIFF_SIDEBYSIDE ){
1966 sbsDiff(&c, pOut, pRe, diffFlags);
1967
+3 -61
--- src/info.c
+++ src/info.c
@@ -314,16 +314,17 @@
314314
}else{
315315
blob_zero(&to);
316316
}
317317
blob_zero(&out);
318318
if( diffFlags & DIFF_SIDEBYSIDE ){
319
- text_diff(&from, &to, &out, pRe, diffFlags | DIFF_HTML);
319
+ text_diff(&from, &to, &out, pRe, diffFlags | DIFF_HTML | DIFF_NOTTOOBIG);
320320
@ <div class="sbsdiff">
321321
@ %s(blob_str(&out))
322322
@ </div>
323323
}else{
324
- text_diff(&from, &to, &out, pRe, diffFlags | DIFF_LINENO | DIFF_HTML);
324
+ text_diff(&from, &to, &out, pRe,
325
+ diffFlags | DIFF_LINENO | DIFF_HTML | DIFF_NOTTOOBIG);
325326
@ <div class="udiff">
326327
@ %s(blob_str(&out))
327328
@ </div>
328329
}
329330
blob_reset(&from);
@@ -491,15 +492,10 @@
491492
char *zEUser, *zEComment;
492493
const char *zUser;
493494
const char *zComment;
494495
const char *zDate;
495496
const char *zOrigDate;
496
-#if 0
497
- char *zThisBranch;
498
- double thisMtime;
499
- int seenDiffTitle = 0;
500
-#endif
501497
502498
style_header(zTitle);
503499
login_anonymous_available();
504500
free(zTitle);
505501
zEUser = db_text(0,
@@ -510,13 +506,10 @@
510506
TAG_COMMENT, rid);
511507
zUser = db_column_text(&q, 2);
512508
zComment = db_column_text(&q, 3);
513509
zDate = db_column_text(&q,1);
514510
zOrigDate = db_column_text(&q, 4);
515
-#if 0
516
- thisMtime = db_column_double(&q, 5);
517
-#endif
518511
@ <div class="section">Overview</div>
519512
@ <table class="label-value">
520513
@ <tr><th>SHA1&nbsp;Hash:</th><td>%s(zUuid)
521514
if( g.perm.Setup ){
522515
@ (Record ID: %d(rid))
@@ -581,61 +574,10 @@
581574
const char *zTagName = db_column_text(&q, 0);
582575
@ | %z(href("%R/timeline?r=%T",zTagName))%h(zTagName)</a>
583576
}
584577
db_finalize(&q);
585578
586
-#if 0
587
- /* Select a few other branches to diff against */
588
- zThisBranch = db_text("trunk", "SELECT value FROM tagxref"
589
- " WHERE tagid=%d AND tagtype>0"
590
- " AND rid=%d",
591
- TAG_BRANCH, rid);
592
-
593
- /* Find nearby leaves to offer to diff against */
594
- db_prepare(&q,
595
- "SELECT tagxref.value, blob.uuid, min(%.17g-event.mtime)"
596
- " FROM leaf, event, tagxref, blob"
597
- " WHERE event.mtime BETWEEN %.17g AND %.17g"
598
- " AND event.type='ci'"
599
- " AND event.objid=leaf.rid"
600
- " AND NOT %z"
601
- " AND tagxref.rid=event.objid"
602
- " AND tagxref.tagid=%d AND tagxref.tagtype>0"
603
- " AND tagxref.value!=%Q"
604
- " AND blob.rid=tagxref.rid"
605
- " GROUP BY 1 ORDER BY 3",
606
- thisMtime, thisMtime-7, thisMtime+7,
607
- leaf_is_closed_sql("leaf.rid"),
608
- TAG_BRANCH, zThisBranch
609
- );
610
- while( db_step(&q)==SQLITE_ROW ){
611
- const char *zBr = db_column_text(&q, 0);
612
- const char *zId = db_column_text(&q, 1);
613
- if( !seenDiffTitle ){
614
- @ <tr><th valign="top">Diffs:</th><td valign="top">
615
- seenDiffTitle = 1;
616
- }else{
617
- @ |
618
- }
619
- @ %z(href("%R/vdiff?from=%S&to=%S",zId, zUuid))%h(zBr)</a>
620
- }
621
- db_finalize(&q);
622
-
623
- if( fossil_strcmp(zThisBranch,"trunk")!=0 ){
624
- if( !seenDiffTitle ){
625
- @ <tr><th valign="top">Diffs:</th><td valign="top">
626
- seenDiffTitle = 1;
627
- }else{
628
- @ |
629
- }
630
- @ %z(href("%R/vdiff?from=root:%S&to=%S",zUuid,zUuid))root of
631
- @ this branch</a>
632
- }
633
- if( seenDiffTitle ){
634
- @ </td></tr>
635
- }
636
-#endif
637579
638580
/* The Download: line */
639581
if( g.perm.Zip ){
640582
char *zUrl = mprintf("%R/tarball/%t-%S.tar.gz?uuid=%s",
641583
zProjName, zUuid, zUuid);
642584
--- src/info.c
+++ src/info.c
@@ -314,16 +314,17 @@
314 }else{
315 blob_zero(&to);
316 }
317 blob_zero(&out);
318 if( diffFlags & DIFF_SIDEBYSIDE ){
319 text_diff(&from, &to, &out, pRe, diffFlags | DIFF_HTML);
320 @ <div class="sbsdiff">
321 @ %s(blob_str(&out))
322 @ </div>
323 }else{
324 text_diff(&from, &to, &out, pRe, diffFlags | DIFF_LINENO | DIFF_HTML);
 
325 @ <div class="udiff">
326 @ %s(blob_str(&out))
327 @ </div>
328 }
329 blob_reset(&from);
@@ -491,15 +492,10 @@
491 char *zEUser, *zEComment;
492 const char *zUser;
493 const char *zComment;
494 const char *zDate;
495 const char *zOrigDate;
496 #if 0
497 char *zThisBranch;
498 double thisMtime;
499 int seenDiffTitle = 0;
500 #endif
501
502 style_header(zTitle);
503 login_anonymous_available();
504 free(zTitle);
505 zEUser = db_text(0,
@@ -510,13 +506,10 @@
510 TAG_COMMENT, rid);
511 zUser = db_column_text(&q, 2);
512 zComment = db_column_text(&q, 3);
513 zDate = db_column_text(&q,1);
514 zOrigDate = db_column_text(&q, 4);
515 #if 0
516 thisMtime = db_column_double(&q, 5);
517 #endif
518 @ <div class="section">Overview</div>
519 @ <table class="label-value">
520 @ <tr><th>SHA1&nbsp;Hash:</th><td>%s(zUuid)
521 if( g.perm.Setup ){
522 @ (Record ID: %d(rid))
@@ -581,61 +574,10 @@
581 const char *zTagName = db_column_text(&q, 0);
582 @ | %z(href("%R/timeline?r=%T",zTagName))%h(zTagName)</a>
583 }
584 db_finalize(&q);
585
586 #if 0
587 /* Select a few other branches to diff against */
588 zThisBranch = db_text("trunk", "SELECT value FROM tagxref"
589 " WHERE tagid=%d AND tagtype>0"
590 " AND rid=%d",
591 TAG_BRANCH, rid);
592
593 /* Find nearby leaves to offer to diff against */
594 db_prepare(&q,
595 "SELECT tagxref.value, blob.uuid, min(%.17g-event.mtime)"
596 " FROM leaf, event, tagxref, blob"
597 " WHERE event.mtime BETWEEN %.17g AND %.17g"
598 " AND event.type='ci'"
599 " AND event.objid=leaf.rid"
600 " AND NOT %z"
601 " AND tagxref.rid=event.objid"
602 " AND tagxref.tagid=%d AND tagxref.tagtype>0"
603 " AND tagxref.value!=%Q"
604 " AND blob.rid=tagxref.rid"
605 " GROUP BY 1 ORDER BY 3",
606 thisMtime, thisMtime-7, thisMtime+7,
607 leaf_is_closed_sql("leaf.rid"),
608 TAG_BRANCH, zThisBranch
609 );
610 while( db_step(&q)==SQLITE_ROW ){
611 const char *zBr = db_column_text(&q, 0);
612 const char *zId = db_column_text(&q, 1);
613 if( !seenDiffTitle ){
614 @ <tr><th valign="top">Diffs:</th><td valign="top">
615 seenDiffTitle = 1;
616 }else{
617 @ |
618 }
619 @ %z(href("%R/vdiff?from=%S&to=%S",zId, zUuid))%h(zBr)</a>
620 }
621 db_finalize(&q);
622
623 if( fossil_strcmp(zThisBranch,"trunk")!=0 ){
624 if( !seenDiffTitle ){
625 @ <tr><th valign="top">Diffs:</th><td valign="top">
626 seenDiffTitle = 1;
627 }else{
628 @ |
629 }
630 @ %z(href("%R/vdiff?from=root:%S&to=%S",zUuid,zUuid))root of
631 @ this branch</a>
632 }
633 if( seenDiffTitle ){
634 @ </td></tr>
635 }
636 #endif
637
638 /* The Download: line */
639 if( g.perm.Zip ){
640 char *zUrl = mprintf("%R/tarball/%t-%S.tar.gz?uuid=%s",
641 zProjName, zUuid, zUuid);
642
--- src/info.c
+++ src/info.c
@@ -314,16 +314,17 @@
314 }else{
315 blob_zero(&to);
316 }
317 blob_zero(&out);
318 if( diffFlags & DIFF_SIDEBYSIDE ){
319 text_diff(&from, &to, &out, pRe, diffFlags | DIFF_HTML | DIFF_NOTTOOBIG);
320 @ <div class="sbsdiff">
321 @ %s(blob_str(&out))
322 @ </div>
323 }else{
324 text_diff(&from, &to, &out, pRe,
325 diffFlags | DIFF_LINENO | DIFF_HTML | DIFF_NOTTOOBIG);
326 @ <div class="udiff">
327 @ %s(blob_str(&out))
328 @ </div>
329 }
330 blob_reset(&from);
@@ -491,15 +492,10 @@
492 char *zEUser, *zEComment;
493 const char *zUser;
494 const char *zComment;
495 const char *zDate;
496 const char *zOrigDate;
 
 
 
 
 
497
498 style_header(zTitle);
499 login_anonymous_available();
500 free(zTitle);
501 zEUser = db_text(0,
@@ -510,13 +506,10 @@
506 TAG_COMMENT, rid);
507 zUser = db_column_text(&q, 2);
508 zComment = db_column_text(&q, 3);
509 zDate = db_column_text(&q,1);
510 zOrigDate = db_column_text(&q, 4);
 
 
 
511 @ <div class="section">Overview</div>
512 @ <table class="label-value">
513 @ <tr><th>SHA1&nbsp;Hash:</th><td>%s(zUuid)
514 if( g.perm.Setup ){
515 @ (Record ID: %d(rid))
@@ -581,61 +574,10 @@
574 const char *zTagName = db_column_text(&q, 0);
575 @ | %z(href("%R/timeline?r=%T",zTagName))%h(zTagName)</a>
576 }
577 db_finalize(&q);
578
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
579
580 /* The Download: line */
581 if( g.perm.Zip ){
582 char *zUrl = mprintf("%R/tarball/%t-%S.tar.gz?uuid=%s",
583 zProjName, zUuid, zUuid);
584

Keyboard Shortcuts

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