Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Support arbitrary line lengths with synced horizontal scrolling in side-by-side diffs. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | sbsreloaded |
| Files: | files | file ages | folders |
| SHA1: |
4081a91c84c181ba77736a6e1bd9156c |
| User & Date: | joel 2013-07-06 02:35:39.303 |
Context
|
2013-07-09
| ||
| 10:54 | Comment enhancements. No changes to code. ... (check-in: f04a3242ec user: drh tags: sbsreloaded) | |
|
2013-07-06
| ||
| 02:35 | Support arbitrary line lengths with synced horizontal scrolling in side-by-side diffs. ... (check-in: 4081a91c84 user: joel tags: sbsreloaded) | |
|
2013-07-05
| ||
| 12:06 | Fix behavior of "fossil commit" on case-insensitive file systems. ... (check-in: c1611f7dfa user: jan.nijtmans tags: trunk) | |
Changes
Changes to src/diff.c.
| ︙ | ︙ | |||
49 50 51 52 53 54 55 |
*/
#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"
| | < < < | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
*/
#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 DIFF_TOO_MANY_CHANGES \
"more than 10,000 changes\n"
/*
** This macro is designed to return non-zero if the specified blob contains
** data that MAY be binary in nature; otherwise, zero will be returned.
*/
#define looks_like_binary(blob) \
((looks_like_utf8((blob), LOOK_BINARY) & LOOK_BINARY) != LOOK_NONE)
|
| ︙ | ︙ | |||
574 575 576 577 578 579 580 | int r; /* Index into R[] */ int nr; /* Number of COPY/DELETE/INSERT triples to process */ int mxr; /* Maximum value for r */ int na, nb; /* Number of lines shown from A and B */ int i, j; /* Loop counters */ int m; /* Number of lines to output */ int skip; /* Number of lines to skip */ | | | 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | int r; /* Index into R[] */ int nr; /* Number of COPY/DELETE/INSERT triples to process */ int mxr; /* Maximum value for r */ int na, nb; /* Number of lines shown from A and B */ int i, j; /* Loop counters */ int m; /* Number of lines to output */ int skip; /* Number of lines to skip */ static int nChunk = 0; /* Number of diff chunks seen so far */ int nContext; /* Number of lines of context */ int showLn; /* Show line numbers */ int html; /* Render as HTML */ int showDivider = 0; /* True to show the divider between diff blocks */ nContext = diff_context_lines(diffFlags); showLn = (diffFlags & DIFF_LINENO)!=0; |
| ︙ | ︙ | |||
655 656 657 658 659 660 661 |
nChunk++;
if( showLn ){
if( !showDivider ){
/* Do not show a top divider */
showDivider = 1;
}else if( html ){
blob_appendf(pOut, "<span class=\"diffhr\">%.80c</span>\n", '.');
| < > | 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
nChunk++;
if( showLn ){
if( !showDivider ){
/* Do not show a top divider */
showDivider = 1;
}else if( html ){
blob_appendf(pOut, "<span class=\"diffhr\">%.80c</span>\n", '.');
}else{
blob_appendf(pOut, "%.80c\n", '.');
}
if( html ) blob_appendf(pOut, "<span id=\"chunk%d\"></span>", nChunk);
}else{
if( html ) blob_appendf(pOut, "<span class=\"diffln\">");
/*
* If the patch changes an empty file or results in an empty file,
* the block header must use 0,0 as position indicator and not 1,0.
* Otherwise, patch would be confused and may reject the diff.
*/
|
| ︙ | ︙ | |||
725 726 727 728 729 730 731 |
}
/*
** Status of a single output line
*/
typedef struct SbsLine SbsLine;
struct SbsLine {
| | < | | | > > > > > > > > > > > | > > > > > > | > > > > | > | > < < | | < | < | | > > > < > | < | < | < | < < > | < | > | < | < < | | > > > > > > > > | < | | > > > | | > | > | | | | | | > > > | | < < > | 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 |
}
/*
** Status of a single output line
*/
typedef struct SbsLine SbsLine;
struct SbsLine {
Blob *apCols[5]; /* Array of pointers to output columns */
int width; /* Maximum width of a column in the output */
unsigned char escHtml; /* True to escape html characters */
int iStart; /* Write zStart prior to character iStart */
const char *zStart; /* A <span> tag */
int iEnd; /* Write </span> prior to character iEnd */
int iStart2; /* Write zStart2 prior to character iStart2 */
const char *zStart2; /* A <span> tag */
int iEnd2; /* Write </span> prior to character iEnd2 */
ReCompiled *pRe; /* Only colorize matching lines, if not NULL */
};
/*
** Column indices
*/
#define SBS_LNA 0
#define SBS_TXTA 1
#define SBS_MKR 2
#define SBS_LNB 3
#define SBS_TXTB 4
/*
** Append newlines to all columns.
*/
static void sbsWriteNewlines(SbsLine *p){
int i;
for( i=p->escHtml ? SBS_LNA : SBS_TXTB; i<=SBS_TXTB; i++ ){
blob_append(p->apCols[i], "\n", 1);
}
}
/*
** Append n spaces to the column.
*/
static void sbsWriteSpace(SbsLine *p, int n, int col){
blob_appendf(p->apCols[col], "%*s", n, "");
}
/*
** Write pLine to the column. If outputting HTML, write the full line.
** Otherwise, only write up to width characters. Translate tabs into
** spaces. Add newlines if col is SBS_TXTB. Translate HTML characters
** if escHtml is true. Pad the rendering out width bytes if col is
** SBS_TXTA and escHtml is false.
**
** This comment contains multibyte unicode characters (ü, Æ, ð) in order
** to test the ability of the diff code to handle such characters.
*/
static void sbsWriteText(SbsLine *p, DLine *pLine, int col){
Blob *pCol = p->apCols[col];
int n = pLine->h & LENGTH_MASK;
int i; /* Number of input characters consumed */
int k; /* Cursor position */
int needEndSpan = 0;
const char *zIn = pLine->z;
int w = p->width;
int colorize = p->escHtml;
if( colorize && p->pRe && re_dline_match(p->pRe, pLine, 1)==0 ){
colorize = 0;
}
for(i=k=0; (p->escHtml || k<w) && i<n; i++, k++){
char c = zIn[i];
if( colorize ){
if( i==p->iStart ){
int x = strlen(p->zStart);
blob_append(pCol, p->zStart, x);
needEndSpan = 1;
if( p->iStart2 ){
p->iStart = p->iStart2;
p->zStart = p->zStart2;
p->iStart2 = 0;
}
}else if( i==p->iEnd ){
blob_append(pCol, "</span>", 7);
needEndSpan = 0;
if( p->iEnd2 ){
p->iEnd = p->iEnd2;
p->iEnd2 = 0;
}
}
}
if( c=='\t' ){
blob_append(pCol, " ", 1);
while( (k&7)!=7 && (p->escHtml || k<w) ){
blob_append(pCol, " ", 1);
k++;
}
}else if( c=='\r' || c=='\f' ){
blob_append(pCol, " ", 1);
}else if( c=='<' && p->escHtml ){
blob_append(pCol, "<", 4);
}else if( c=='&' && p->escHtml ){
blob_append(pCol, "&", 5);
}else if( c=='>' && p->escHtml ){
blob_append(pCol, ">", 4);
}else if( c=='"' && p->escHtml ){
blob_append(pCol, """, 6);
}else{
blob_append(pCol, &zIn[i], 1);
if( (c&0xc0)==0x80 ) k--;
}
}
if( needEndSpan ){
blob_append(pCol, "</span>", 7);
}
if( col==SBS_TXTB ){
sbsWriteNewlines(p);
}else if( !p->escHtml ){
sbsWriteSpace(p, w-k, SBS_TXTA);
}
}
/*
** Append a column to the final output blob.
*/
static void sbsWriteColumn(Blob *pOut, Blob *pCol, int col){
blob_appendf(pOut,
"<td><div class=\"diff%scol\">\n"
"<pre>\n"
"%s"
"</pre>\n"
"</div></td>\n",
col % 3 ? (col == SBS_MKR ? "mkr" : "txt") : "ln",
blob_str(pCol)
);
}
/*
** Append separator to the column.
*/
static void sbsWriteSep(SbsLine *p, int len, int col){
char ch = '.';
if( len<1 ){
len = 1;
ch = ' ';
}
blob_appendf(p->apCols[col], "<span class=\"diffhr\">%.*c</span>\n", len, ch);
}
/*
** Append the appropriate marker.
*/
static void sbsWriteMarker(SbsLine *p, const char *zTxt, const char *zHtml){
blob_append(p->apCols[SBS_MKR], p->escHtml ? zHtml : zTxt, -1);
}
/*
** Append a line number to the column.
*/
static void sbsWriteLineno(SbsLine *p, int ln, int col){
if( p->escHtml ){
blob_appendf(p->apCols[col], "%d", ln+1);
}else{
char zLn[7];
sqlite3_snprintf(7, zLn, "%5d ", ln+1);
blob_appendf(p->apCols[col], "%s ", zLn);
}
}
/*
** The two text segments zLeft and zRight are known to be different on
** both ends, but they might have a common segment in the middle. If
** they do not have a common segment, return 0. If they do have a large
** common segment, return 1 and before doing so set:
|
| ︙ | ︙ | |||
1016 1017 1018 1019 1020 1021 1022 |
if( nSuffix<nShort ){
while( nSuffix>0 && (zLeft[nLeft-nSuffix]&0xc0)==0x80 ) nSuffix--;
}
if( nSuffix==nLeft || nSuffix==nRight ) nPrefix = 0;
}
if( nPrefix+nSuffix > nShort ) nPrefix = nShort - nSuffix;
| < | | | | | | | | | | | | | | | | | | | | | | 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 |
if( nSuffix<nShort ){
while( nSuffix>0 && (zLeft[nLeft-nSuffix]&0xc0)==0x80 ) nSuffix--;
}
if( nSuffix==nLeft || nSuffix==nRight ) nPrefix = 0;
}
if( nPrefix+nSuffix > nShort ) nPrefix = nShort - nSuffix;
/* A single chunk of text inserted on the right */
if( nPrefix+nSuffix==nLeft ){
sbsWriteLineno(p, lnLeft, SBS_LNA);
p->iStart2 = p->iEnd2 = 0;
p->iStart = p->iEnd = -1;
sbsWriteText(p, pLeft, SBS_TXTA);
if( nLeft==nRight && zLeft[nLeft]==zRight[nRight] ){
sbsWriteMarker(p, " ", "");
}else{
sbsWriteMarker(p, " | ", "|");
}
sbsWriteLineno(p, lnRight, SBS_LNB);
p->iStart = nPrefix;
p->iEnd = nRight - nSuffix;
p->zStart = zClassAdd;
sbsWriteText(p, pRight, SBS_TXTB);
return;
}
/* A single chunk of text deleted from the left */
if( nPrefix+nSuffix==nRight ){
/* Text deleted from the left */
sbsWriteLineno(p, lnLeft, SBS_LNA);
p->iStart2 = p->iEnd2 = 0;
p->iStart = nPrefix;
p->iEnd = nLeft - nSuffix;
p->zStart = zClassRm;
sbsWriteText(p, pLeft, SBS_TXTA);
sbsWriteMarker(p, " | ", "|");
sbsWriteLineno(p, lnRight, SBS_LNB);
p->iStart = p->iEnd = -1;
sbsWriteText(p, pRight, SBS_TXTB);
return;
}
/* At this point we know that there is a chunk of text that has
** changed between the left and the right. Check to see if there
** is a large unchanged section in the middle of that changed block.
*/
nLeftDiff = nLeft - nSuffix - nPrefix;
nRightDiff = nRight - nSuffix - nPrefix;
if( p->escHtml
&& nLeftDiff >= 6
&& nRightDiff >= 6
&& textLCS(&zLeft[nPrefix], nLeftDiff, &zRight[nPrefix], nRightDiff, aLCS)
){
sbsWriteLineno(p, lnLeft, SBS_LNA);
p->iStart = nPrefix;
p->iEnd = nPrefix + aLCS[0];
if( aLCS[2]==0 ){
sbsShiftLeft(p, pLeft->z);
p->zStart = zClassRm;
}else{
p->zStart = zClassChng;
}
p->iStart2 = nPrefix + aLCS[1];
p->iEnd2 = nLeft - nSuffix;
p->zStart2 = aLCS[3]==nRightDiff ? zClassRm : zClassChng;
sbsSimplifyLine(p, zLeft+nPrefix);
sbsWriteText(p, pLeft, SBS_TXTA);
sbsWriteMarker(p, " | ", "|");
sbsWriteLineno(p, lnRight, SBS_LNB);
p->iStart = nPrefix;
p->iEnd = nPrefix + aLCS[2];
if( aLCS[0]==0 ){
sbsShiftLeft(p, pRight->z);
p->zStart = zClassAdd;
}else{
p->zStart = zClassChng;
}
p->iStart2 = nPrefix + aLCS[3];
p->iEnd2 = nRight - nSuffix;
p->zStart2 = aLCS[1]==nLeftDiff ? zClassAdd : zClassChng;
sbsSimplifyLine(p, zRight+nPrefix);
sbsWriteText(p, pRight, SBS_TXTB);
return;
}
/* If all else fails, show a single big change between left and right */
sbsWriteLineno(p, lnLeft, SBS_LNA);
p->iStart2 = p->iEnd2 = 0;
p->iStart = nPrefix;
p->iEnd = nLeft - nSuffix;
p->zStart = zClassChng;
sbsWriteText(p, pLeft, SBS_TXTA);
sbsWriteMarker(p, " | ", "|");
sbsWriteLineno(p, lnRight, SBS_LNB);
p->iEnd = nRight - nSuffix;
sbsWriteText(p, pRight, SBS_TXTB);
}
/*
** Minimum of two values
*/
static int minInt(int a, int b){ return a<b ? a : b; }
|
| ︙ | ︙ | |||
1355 1356 1357 1358 1359 1360 1361 | int r; /* Index into R[] */ int nr; /* Number of COPY/DELETE/INSERT triples to process */ int mxr; /* Maximum value for r */ int na, nb; /* Number of lines shown from A and B */ int i, j; /* Loop counters */ int m, ma, mb;/* Number of lines to output */ int skip; /* Number of lines to skip */ | | > < < > > > > > > > > > > > | 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 |
int r; /* Index into R[] */
int nr; /* Number of COPY/DELETE/INSERT triples to process */
int mxr; /* Maximum value for r */
int na, nb; /* Number of lines shown from A and B */
int i, j; /* Loop counters */
int m, ma, mb;/* Number of lines to output */
int skip; /* Number of lines to skip */
static int nChunk = 0; /* Number of chunks of diff output seen so far */
SbsLine s; /* Output line buffer */
int nContext; /* Lines of context above and below each change */
int showDivider = 0; /* True to show the divider */
Blob aCols[5]; /* Array of column blobs */
memset(&s, 0, sizeof(s));
s.width = diff_width(diffFlags);
nContext = diff_context_lines(diffFlags);
s.escHtml = (diffFlags & DIFF_HTML)!=0;
if( s.escHtml ){
for(i=SBS_LNA; i<=SBS_TXTB; i++){
blob_zero(&aCols[i]);
s.apCols[i] = &aCols[i];
}
}else{
for(i=SBS_LNA; i<=SBS_TXTB; i++){
s.apCols[i] = pOut;
}
}
s.pRe = pRe;
s.iStart = -1;
s.iStart2 = 0;
s.iEnd = -1;
A = p->aFrom;
B = p->aTo;
R = p->aEdit;
mxr = p->nEdit;
while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; }
for(r=0; r<mxr; r += 3*nr){
/* Figure out how many triples to show in a single block */
for(nr=1; R[r+nr*3]>0 && R[r+nr*3]<nContext*2; nr++){}
/* printf("r=%d nr=%d\n", r, nr); */
/* If there is a regex, skip this block (generate no diff output)
** if the regex matches or does not match both insert and delete.
|
| ︙ | ︙ | |||
1434 1435 1436 1437 1438 1439 1440 |
na += R[r+i*3];
nb += R[r+i*3];
}
/* Draw the separator between blocks */
if( showDivider ){
if( s.escHtml ){
| | > > | > > > > | < | | | | | < | 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 |
na += R[r+i*3];
nb += R[r+i*3];
}
/* Draw the separator between blocks */
if( showDivider ){
if( s.escHtml ){
char zLn[10];
sqlite3_snprintf(sizeof(zLn), zLn, "%d", a+skip+1);
sbsWriteSep(&s, strlen(zLn), SBS_LNA);
sbsWriteSep(&s, s.width, SBS_TXTA);
sbsWriteSep(&s, 0, SBS_MKR);
sqlite3_snprintf(sizeof(zLn), zLn, "%d", b+skip+1);
sbsWriteSep(&s, strlen(zLn), SBS_LNB);
sbsWriteSep(&s, s.width, SBS_TXTB);
}else{
blob_appendf(pOut, "%.*c\n", s.width*2+16, '.');
}
}
showDivider = 1;
nChunk++;
if( s.escHtml ){
blob_appendf(s.apCols[SBS_LNA], "<span id=\"chunk%d\"></span>", nChunk);
}
/* Show the initial common area */
a += skip;
b += skip;
m = R[r] - skip;
for(j=0; j<m; j++){
sbsWriteLineno(&s, a+j, SBS_LNA);
s.iStart = s.iEnd = -1;
sbsWriteText(&s, &A[a+j], SBS_TXTA);
sbsWriteMarker(&s, " ", "");
sbsWriteLineno(&s, b+j, SBS_LNB);
sbsWriteText(&s, &B[b+j], SBS_TXTB);
}
a += m;
b += m;
/* Show the differences */
for(i=0; i<nr; i++){
unsigned char *alignment;
|
| ︙ | ︙ | |||
1483 1484 1485 1486 1487 1488 1489 |
mb += R[r+i*3+2] + m;
}
alignment = sbsAlignment(&A[a], ma, &B[b], mb);
for(j=0; ma+mb>0; j++){
if( alignment[j]==1 ){
/* Delete one line from the left */
| < | | < | < | < < < < | | < < < < > | | < < | | | | | < < < | | | | | < < | | | | | > > > > | > > > > < | 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 |
mb += R[r+i*3+2] + m;
}
alignment = sbsAlignment(&A[a], ma, &B[b], mb);
for(j=0; ma+mb>0; j++){
if( alignment[j]==1 ){
/* Delete one line from the left */
sbsWriteLineno(&s, a, SBS_LNA);
s.iStart = 0;
s.zStart = "<span class=\"diffrm\">";
s.iEnd = LENGTH(&A[a]);
sbsWriteText(&s, &A[a], SBS_TXTA);
sbsWriteMarker(&s, " <", "<");
sbsWriteNewlines(&s);
assert( ma>0 );
ma--;
a++;
}else if( alignment[j]==3 ){
/* The left line is changed into the right line */
sbsWriteLineChange(&s, &A[a], a, &B[b], b);
assert( ma>0 && mb>0 );
ma--;
mb--;
a++;
b++;
}else if( alignment[j]==2 ){
/* Insert one line on the right */
if( !s.escHtml ){
sbsWriteSpace(&s, s.width + 7, SBS_TXTA);
}
sbsWriteMarker(&s, " > ", ">");
sbsWriteLineno(&s, b, SBS_LNB);
s.iStart = 0;
s.zStart = "<span class=\"diffadd\">";
s.iEnd = LENGTH(&B[b]);
sbsWriteText(&s, &B[b], SBS_TXTB);
assert( mb>0 );
mb--;
b++;
}else{
/* Delete from the left and insert on the right */
sbsWriteLineno(&s, a, SBS_LNA);
s.iStart = 0;
s.zStart = "<span class=\"diffrm\">";
s.iEnd = LENGTH(&A[a]);
sbsWriteText(&s, &A[a], SBS_TXTA);
sbsWriteMarker(&s, " | ", "|");
sbsWriteLineno(&s, b, SBS_LNB);
s.iStart = 0;
s.zStart = "<span class=\"diffadd\">";
s.iEnd = LENGTH(&B[b]);
sbsWriteText(&s, &B[b], SBS_TXTB);
ma--;
mb--;
a++;
b++;
}
}
fossil_free(alignment);
if( i<nr-1 ){
m = R[r+i*3+3];
for(j=0; j<m; j++){
sbsWriteLineno(&s, a+j, SBS_LNA);
s.iStart = s.iEnd = -1;
sbsWriteText(&s, &A[a+j], SBS_TXTA);
sbsWriteMarker(&s, " ", "");
sbsWriteLineno(&s, b+j, SBS_LNB);
sbsWriteText(&s, &B[b+j], SBS_TXTB);
}
b += m;
a += m;
}
}
/* Show the final common area */
assert( nr==i );
m = R[r+nr*3];
if( m>nContext ) m = nContext;
for(j=0; j<m; j++){
sbsWriteLineno(&s, a+j, SBS_LNA);
s.iStart = s.iEnd = -1;
sbsWriteText(&s, &A[a+j], SBS_TXTA);
sbsWriteMarker(&s, " ", "");
sbsWriteLineno(&s, b+j, SBS_LNB);
sbsWriteText(&s, &B[b+j], SBS_TXTB);
}
}
if( s.escHtml && blob_size(s.apCols[SBS_LNA])>0 ){
blob_append(pOut, "<table class=\"sbsdiffcols\"><tr>\n", -1);
for(i=SBS_LNA; i<=SBS_TXTB; i++){
sbsWriteColumn(pOut, s.apCols[i], i);
blob_reset(s.apCols[i]);
}
blob_append(pOut, "</tr></table>\n", -1);
}
}
/*
** Compute the optimal longest common subsequence (LCS) using an
** exhaustive search. This version of the LCS is only used for
** shorter input strings since runtime is O(N*N) where N is the
** input string length.
|
| ︙ | ︙ | |||
1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 |
** appropriate default if no width is given.
*/
int diff_width(u64 diffFlags){
int w = (diffFlags & DIFF_WIDTH_MASK)/(DIFF_CONTEXT_MASK+1);
if( w==0 ) w = 80;
return w;
}
/*
** Generate a report of the differences between files pA and pB.
** If pOut is not NULL then a unified diff is appended there. It
** is assumed that pOut has already been initialized. If pOut is
** NULL, then a pointer to an array of integers is returned.
** The integers come in triples. For each triple,
| > > > > > > > > > > > | 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 |
** appropriate default if no width is given.
*/
int diff_width(u64 diffFlags){
int w = (diffFlags & DIFF_WIDTH_MASK)/(DIFF_CONTEXT_MASK+1);
if( w==0 ) w = 80;
return w;
}
/*
** Append the error message to pOut.
*/
void diff_errmsg(Blob *pOut, const char *msg, int diffFlags){
if( diffFlags & DIFF_HTML ){
blob_appendf(pOut, "<p class=\"generalError\">%s</p>", msg);
}else{
blob_append(pOut, msg, -1);
}
}
/*
** Generate a report of the differences between files pA and pB.
** If pOut is not NULL then a unified diff is appended there. It
** is assumed that pOut has already been initialized. If pOut is
** NULL, then a pointer to an array of integers is returned.
** The integers come in triples. For each triple,
|
| ︙ | ︙ | |||
2030 2031 2032 2033 2034 2035 2036 |
&c.nFrom, ignoreEolWs);
c.aTo = break_into_lines(blob_str(pB_Blob), blob_size(pB_Blob),
&c.nTo, ignoreEolWs);
if( c.aFrom==0 || c.aTo==0 ){
fossil_free(c.aFrom);
fossil_free(c.aTo);
if( pOut ){
| | < < < | < | 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 |
&c.nFrom, ignoreEolWs);
c.aTo = break_into_lines(blob_str(pB_Blob), blob_size(pB_Blob),
&c.nTo, ignoreEolWs);
if( c.aFrom==0 || c.aTo==0 ){
fossil_free(c.aFrom);
fossil_free(c.aTo);
if( pOut ){
diff_errmsg(pOut, DIFF_CANNOT_COMPUTE_BINARY, diffFlags);
}
return 0;
}
/* Compute the difference */
diff_all(&c);
if( (diffFlags & DIFF_NOTTOOBIG)!=0 ){
int i, m, n;
int *a = c.aEdit;
int mx = c.nEdit;
for(i=m=n=0; i<mx; i+=3){ m += a[i]; n += a[i+1]+a[i+2]; }
if( n>10000 ){
fossil_free(c.aFrom);
fossil_free(c.aTo);
fossil_free(c.aEdit);
diff_errmsg(pOut, DIFF_TOO_MANY_CHANGES, diffFlags);
return 0;
}
}
if( (diffFlags & DIFF_NOOPT)==0 ){
diff_optimize(&c);
}
|
| ︙ | ︙ | |||
2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 |
ReCompiled *pRe = 0; /* Regex filter for diff output */
if( find_option("tk",0,0)!=0 ){
diff_tk("test-diff", 2);
return;
}
find_option("i",0,0);
zRe = find_option("regexp","e",1);
if( zRe ){
const char *zErr = re_compile(&pRe, zRe, 0);
if( zErr ) fossil_fatal("regex error: %s", zErr);
}
diffFlag = diff_options();
verify_all_options();
| > | 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 |
ReCompiled *pRe = 0; /* Regex filter for diff output */
if( find_option("tk",0,0)!=0 ){
diff_tk("test-diff", 2);
return;
}
find_option("i",0,0);
find_option("v",0,0);
zRe = find_option("regexp","e",1);
if( zRe ){
const char *zErr = re_compile(&pRe, zRe, 0);
if( zErr ) fossil_fatal("regex error: %s", zErr);
}
diffFlag = diff_options();
verify_all_options();
|
| ︙ | ︙ |
Changes to src/diffcmd.c.
| ︙ | ︙ | |||
595 596 597 598 599 600 601 |
zName = "diff-command";
}
return db_get(zName, zDefault);
}
/* A Tcl/Tk script used to render diff output.
*/
| | > | | < | | | | | | < | | | > > > > > > > > > > > > > > > > > > > | > > > > > > > > | < | > | | | > > > | > > > > > > > > > > > > > > | > | > > > | > > > > > > > > | > > | > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > | < > > > > | > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > | > > > > > > > > > > > | | | 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 |
zName = "diff-command";
}
return db_get(zName, zDefault);
}
/* A Tcl/Tk script used to render diff output.
*/
static const char zDiffScript[] =
@ package require Tk
@
@ array set CFG {
@ TITLE {Fossil Diff}
@ LN_COL_BG #dddddd
@ LN_COL_FG #444444
@ TXT_COL_BG #ffffff
@ TXT_COL_FG #000000
@ MKR_COL_BG #444444
@ MKR_COL_FG #dddddd
@ CHNG_BG #d0d0ff
@ ADD_BG #c0ffc0
@ RM_BG #ffc0c0
@ HR_FG #888888
@ HR_PAD_TOP 4
@ HR_PAD_BTM 8
@ FONTS {{DejaVu Sans Mono} Consolas Monaco fixed}
@ FONT_SIZE 9
@ PADX 5
@ WIDTH 80
@ HEIGHT 45
@ }
@
@ if {![namespace exists ttk]} {
@ interp alias {} ::ttk::scrollbar {} ::scrollbar
@ interp alias {} ::ttk::menubutton {} ::menubutton
@ }
@
@ proc dehtml {x} {
@ set x [regsub -all {<[^>]*>} $x {}]
@ return [string map {& & < < > > ' ' " \"} $x]
@ }
@
@ proc cols {} {
@ return [list .lnA .txtA .mkr .lnB .txtB]
@ }
@
@ proc colType {c} {
@ regexp {[a-z]+} $c type
@ return $type
@ }
@
@ proc readDiffs {cmd} {
@ global gDiffs
@ set in [open $cmd r]
@ set idx -1
@ while {[gets $in line] != -1} {
@ if {![regexp {^=+\s+(.*?)\s+=+$} $line all fn]} {
@ continue
@ }
@
@ if {[string compare -length 6 [gets $in] "<table"]} {
@ continue
@ }
@
@ incr idx
@ .files.menu add radiobutton -variable gIdx -value $idx -label $fn \
@ -command "viewDiff $idx"
@ array set widths {txt 0 ln 0 mkr 0}
@
@ foreach c [cols] {
@ while {[gets $in] ne "<pre>"} continue
@ set type [colType $c]
@ set str {}
@ while {[set line [gets $in]] ne "</pre>"} {
@ set len [string length [dehtml $line]]
@ if {$len > $widths($type)} {
@ set widths($type) $len
@ }
@ append str $line\n
@ }
@
@ set str [string range $str 0 end-1]
@ set colData {}
@ set re {<span class="diff([a-z]+)">([^<]*)</span>}
@ # Use \r as separator since it can't appear in the diff output (it gets
@ # converted to a space).
@ set str [regsub -all $re $str "\r\\1\r\\2\r"]
@ foreach {pre class mid} [split $str \r] {
@ if {$class ne ""} {
@ lappend colData [dehtml $pre] - [dehtml $mid] [list $class -]
@ } else {
@ lappend colData [dehtml $pre] -
@ }
@ }
@ set gDiffs($idx,$c) $colData
@ }
@
@ foreach {type width} [array get widths] {
@ set gDiffs($idx,$type-width) $width
@ }
@ }
@ close $in
@ }
@
@ proc viewDiff {idx} {
@ global gDiffs
@ .files config -text [.files.menu entrycget $idx -label]
@
@ foreach c [cols] {
@ $c config -state normal
@ $c delete 1.0 end
@ foreach {content tag} $gDiffs($idx,$c) {
@ $c insert end $content $tag
@ }
@ }
@
@ foreach c {.lnA .lnB .mkr} {
@ $c config -width $gDiffs($idx,[colType $c]-width)
@ }
@
@ # Add whitespace to equalize line lengths.
@ regexp {\d+} [.txtA index {end -1c}] numLines
@ set width $gDiffs($idx,txt-width)
@ foreach c {.txtA .txtB} {
@ for {set ln 1} {$ln <= $numLines} {incr ln} {
@ regexp {\d+$} [$c index $ln.end] len
@ $c insert $ln.end [string repeat " " [expr {$width-$len}]] ws
@ }
@ }
@
@ foreach c [cols] {
@ $c config -state disabled
@ }
@ }
@
@ proc cycleDiffs {{inc 1}} {
@ global gIdx
@ .files.menu invoke [expr {($gIdx+$inc) % ([.files.menu index last]+1)}]
@ }
@
@ proc scrollSync {axis sbs first last} {
@ foreach c [cols] {
@ $c ${axis}view moveto $first
@ }
@ foreach sb $sbs {
@ if {$first <= 0 && $last >= 1} {
@ grid remove $sb
@ } else {
@ grid $sb
@ $sb set $first $last
@ }
@ }
@ }
@
@ proc copyText {c} {
@ set txt ""
@ # Copy selection without excess trailing whitespace
@ $c tag config ws -elide 1
@ catch {
@ $c tag add sel sel.first sel.last
@ set txt [selection get]
@ }
@ $c tag config ws -elide 0
@ clipboard clear
@ clipboard append $txt
@ }
@
@ wm withdraw .
@ wm title . $CFG(TITLE)
@ wm iconname . $CFG(TITLE)
@ bind . <q> exit
@ bind . <Tab> {cycleDiffs; break}
@ bind . <<PrevWindow>> {cycleDiffs -1; break}
@ bind . <Return> {
@ event generate .files <1>
@ event generate .files <ButtonRelease-1>
@ break
@ }
@ foreach {key axis args} {
@ Up y {scroll -5 units}
@ Down y {scroll 5 units}
@ Left x {scroll -5 units}
@ Right x {scroll 5 units}
@ Prior y {scroll -1 page}
@ Next y {scroll 1 page}
@ Home y {moveto 0}
@ End y {moveto 1}
@ } {
@ bind . <$key> ".txtA ${axis}view $args; break"
@ bind . <Shift-$key> continue
@ }
@
@ ::ttk::menubutton .files -menu .files.menu
@ menu .files.menu -tearoff 0
@ readDiffs $cmd
@ if {[.files.menu index 0] eq "none"} {
@ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes"
@ exit
@ }
@
@ foreach side {A B} {
@ set ln .ln$side
@ text $ln
@ $ln tag config - -justify right
@
@ set txt .txt$side
@ text $txt -width $CFG(WIDTH) -height $CFG(HEIGHT) -wrap none \
@ -xscroll {scrollSync x {.sbxA .sbxB}}
@ foreach tag {add rm chng} {
@ $txt tag config $tag -background $CFG([string toupper $tag]_BG)
@ $txt tag lower $tag
@ }
@ bind $txt <<Copy>> {copyText %W; break}
@ bind $txt <<Cut>> {copyText %W; break}
@ }
@ text .mkr
@
@ font create mono -family courier -size $CFG(FONT_SIZE)
@ foreach font $CFG(FONTS) {
@ if {[lsearch -exact [font families] $font] != -1} {
@ font config mono -family $font
@ break
@ }
@ }
@ foreach c [cols] {
@ set keyPrefix [string toupper [colType $c]]_COL_
@ $c config -bg $CFG(${keyPrefix}BG) -fg $CFG(${keyPrefix}FG) -borderwidth 0 \
@ -font mono -padx $CFG(PADX) -insertontime 0 -yscroll {scrollSync y .sby}
@ $c tag config hr -spacing1 $CFG(HR_PAD_TOP) -spacing3 $CFG(HR_PAD_BTM) \
@ -foreground $CFG(HR_FG)
@ bindtags $c ". $c Text all"
@ bind $c <1> {focus %W}
@ }
@
@ ::ttk::scrollbar .sby -command {.txtA yview} -orient vertical
@ ::ttk::scrollbar .sbxA -command {.txtA xview} -orient horizontal
@ ::ttk::scrollbar .sbxB -command {.txtA xview} -orient horizontal
@
@ grid rowconfigure . 1 -weight 1
@ grid columnconfigure . 1 -weight 1
@ grid columnconfigure . 4 -weight 1
@ grid .files -columnspan 6
@ eval grid [cols] .sby -sticky nsew
@ grid .sbxA -row 2 -column 0 -columnspan 2 -sticky ew
@ grid .sbxB -row 2 -column 3 -columnspan 2 -sticky ew
@
@ .files.menu invoke 0
@ wm deiconify .
;
/*
** Show diff output in a Tcl/Tk window, in response to the --tk option
** to the diff command.
**
** Steps:
** (1) Write the Tcl/Tk script used for rendering into a temp file.
** (2) Invoke "wish" on the temp file using fossil_system().
** (3) Delete the temp file.
*/
void diff_tk(const char *zSubCmd, int firstArg){
int i;
Blob script;
char *zTempFile;
char *zCmd;
blob_zero(&script);
blob_appendf(&script, "set cmd {| \"%/\" %s --html -y -i -v",
g.nameOfExe, zSubCmd);
for(i=firstArg; i<g.argc; i++){
const char *z = g.argv[i];
if( z[0]=='-' ){
if( strglob("*-html",z) ) continue;
if( strglob("*-y",z) ) continue;
if( strglob("*-i",z) ) continue;
|
| ︙ | ︙ |
Changes to src/info.c.
| ︙ | ︙ | |||
314 315 316 317 318 319 320 |
content_get(toid, &to);
}else{
blob_zero(&to);
}
blob_zero(&out);
if( diffFlags & DIFF_SIDEBYSIDE ){
text_diff(&from, &to, &out, pRe, diffFlags | DIFF_HTML | DIFF_NOTTOOBIG);
| < < | | < | 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
content_get(toid, &to);
}else{
blob_zero(&to);
}
blob_zero(&out);
if( diffFlags & DIFF_SIDEBYSIDE ){
text_diff(&from, &to, &out, pRe, diffFlags | DIFF_HTML | DIFF_NOTTOOBIG);
@ %s(blob_str(&out))
}else{
text_diff(&from, &to, &out, pRe,
diffFlags | DIFF_LINENO | DIFF_HTML | DIFF_NOTTOOBIG);
@ <pre class="udiff">
@ %s(blob_str(&out))
@ </pre>
}
blob_reset(&from);
blob_reset(&to);
blob_reset(&out);
}
/*
** Write a line of web-page output that shows changes that have occurred
** to a file between two check-ins.
*/
static void append_file_change_line(
const char *zName, /* Name of the file that has changed */
|
| ︙ | ︙ | |||
357 358 359 360 361 362 363 |
}else if( fossil_strcmp(zNew, zOld)==0 ){
@ <p>Execute permission %s(( mperm==PERM_EXE )?"set":"cleared")
@ for %h(zName)</p>
}else{
@ <p>Changes to %h(zName)</p>
}
if( diffFlags ){
| < < | 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
}else if( fossil_strcmp(zNew, zOld)==0 ){
@ <p>Execute permission %s(( mperm==PERM_EXE )?"set":"cleared")
@ for %h(zName)</p>
}else{
@ <p>Changes to %h(zName)</p>
}
if( diffFlags ){
append_diff(zOld, zNew, diffFlags, pRe);
}
}else{
if( zOld && zNew ){
if( fossil_strcmp(zOld, zNew)!=0 ){
@ <p>Modified %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
@ from %z(href("%R/artifact/%s",zOld))[%S(zOld)]</a>
@ to %z(href("%R/artifact/%s",zNew))[%S(zNew)].</a>
|
| ︙ | ︙ | |||
383 384 385 386 387 388 389 |
@ <p>Deleted %z(href("%s/finfo?name=%T",g.zTop,zName))%h(zName)</a>
@ version %z(href("%R/artifact/%s",zOld))[%S(zOld)]</a>
}else{
@ <p>Added %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
@ version %z(href("%R/artifact/%s",zNew))[%S(zNew)]</a>
}
if( diffFlags ){
| < < < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
@ <p>Deleted %z(href("%s/finfo?name=%T",g.zTop,zName))%h(zName)</a>
@ version %z(href("%R/artifact/%s",zOld))[%S(zOld)]</a>
}else{
@ <p>Added %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
@ version %z(href("%R/artifact/%s",zNew))[%S(zNew)]</a>
}
if( diffFlags ){
append_diff(zOld, zNew, diffFlags, pRe);
}else if( zOld && zNew && fossil_strcmp(zOld,zNew)!=0 ){
@
@ %z(href("%R/fdiff?v1=%S&v2=%S&sbs=1",zOld,zNew))[diff]</a>
}
}
}
/*
** Generate javascript to enhance HTML diffs.
*/
void append_diff_javascript(int sideBySide){
if( !sideBySide ) return;
@ <script>(function(){
@ var SCROLL_LEN = 25;
@ function initSbsDiff(diff){
@ var txtCols = diff.querySelectorAll('.difftxtcol');
@ var width = Math.max(txtCols[0].scrollWidth, txtCols[1].scrollWidth);
@ for(var i=0; i<2; i++){
@ txtCols[i].children[0].style.width = width + 'px';
@ txtCols[i].onscroll = function(e){
@ txtCols[0].scrollLeft = txtCols[1].scrollLeft = this.scrollLeft;
@ };
@ }
@ diff.tabIndex = 0;
@ diff.onkeydown = function(e){
@ e = e || event;
@ var len = {37: -SCROLL_LEN, 39: SCROLL_LEN}[e.keyCode];
@ if( !len ) return;
@ txtCols[0].scrollLeft += len;
@ return false;
@ };
@ }
@
@ var diffs = document.querySelectorAll('.sbsdiffcols');
@ for(var i=0; i<diffs.length; i++){
@ initSbsDiff(diffs[i]);
@ }
@ }())</script>
}
/*
** Construct an appropriate diffFlag for text_diff() based on query
** parameters and the to boolean arguments.
*/
u64 construct_diff_flags(int verboseFlag, int sideBySide){
u64 diffFlags;
|
| ︙ | ︙ | |||
673 674 675 676 677 678 679 680 681 682 683 684 685 686 |
const char *zOld = db_column_text(&q,2);
const char *zNew = db_column_text(&q,3);
const char *zOldName = db_column_text(&q, 4);
append_file_change_line(zName, zOld, zNew, zOldName, diffFlags,pRe,mperm);
}
db_finalize(&q);
}
style_footer();
}
/*
** WEBPAGE: winfo
** URL: /winfo?name=UUID
**
| > | 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
const char *zOld = db_column_text(&q,2);
const char *zNew = db_column_text(&q,3);
const char *zOldName = db_column_text(&q, 4);
append_file_change_line(zName, zOld, zNew, zOldName, diffFlags,pRe,mperm);
}
db_finalize(&q);
}
append_diff_javascript(sideBySide);
style_footer();
}
/*
** WEBPAGE: winfo
** URL: /winfo?name=UUID
**
|
| ︙ | ︙ | |||
986 987 988 989 990 991 992 |
manifest_file_mperm(pFileTo));
pFileFrom = manifest_file_next(pFrom, 0);
pFileTo = manifest_file_next(pTo, 0);
}
}
manifest_destroy(pFrom);
manifest_destroy(pTo);
| | | 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 |
manifest_file_mperm(pFileTo));
pFileFrom = manifest_file_next(pFrom, 0);
pFileTo = manifest_file_next(pTo, 0);
}
}
manifest_destroy(pFrom);
manifest_destroy(pTo);
append_diff_javascript(sideBySide);
style_footer();
}
#if INTERFACE
/*
** Possible return values from object_description()
*/
|
| ︙ | ︙ | |||
1242 1243 1244 1245 1246 1247 1248 |
** difference between the two artifacts. Show diff side by side unless sbs
** is 0. Generate plaintext if "patch" is present.
*/
void diff_page(void){
int v1, v2;
int isPatch;
int sideBySide;
| < < | | < > < < < < < < < < < < < < < | | | | | > > | > > > > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | < | | < | 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 |
** difference between the two artifacts. Show diff side by side unless sbs
** is 0. Generate plaintext if "patch" is present.
*/
void diff_page(void){
int v1, v2;
int isPatch;
int sideBySide;
char *zV1;
char *zV2;
const char *zRe;
ReCompiled *pRe = 0;
u64 diffFlags;
login_check_credentials();
if( !g.perm.Read ){ login_needed(); return; }
v1 = name_to_rid_www("v1");
v2 = name_to_rid_www("v2");
if( v1==0 || v2==0 ) fossil_redirect_home();
zRe = P("regex");
if( zRe ) re_compile(&pRe, zRe, 0);
isPatch = P("patch")!=0;
if( isPatch ){
Blob c1, c2, *pOut;
pOut = cgi_output_blob();
cgi_set_content_type("text/plain");
diffFlags = 4;
content_get(v1, &c1);
content_get(v2, &c2);
text_diff(&c1, &c2, pOut, pRe, diffFlags);
blob_reset(&c1);
blob_reset(&c2);
return;
}
sideBySide = !is_false(PD("sbs","1"));
zV1 = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", v1);
zV2 = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", v2);
diffFlags = construct_diff_flags(1, sideBySide) | DIFF_HTML;
style_header("Diff");
style_submenu_element("Patch", "Patch", "%s/fdiff?v1=%T&v2=%T&patch",
g.zTop, P("v1"), P("v2"));
if( !sideBySide ){
style_submenu_element("Side-by-side Diff", "sbsdiff",
"%s/fdiff?v1=%T&v2=%T&sbs=1",
g.zTop, P("v1"), P("v2"));
}else{
style_submenu_element("Unified Diff", "udiff",
"%s/fdiff?v1=%T&v2=%T&sbs=0",
g.zTop, P("v1"), P("v2"));
}
if( P("smhdr")!=0 ){
@ <h2>Differences From Artifact
@ %z(href("%R/artifact/%S",zV1))[%S(zV1)]</a> To
@ %z(href("%R/artifact/%S",zV2))[%S(zV2)]</a>.</h2>
}else{
@ <h2>Differences From
@ Artifact %z(href("%R/artifact/%S",zV1))[%S(zV1)]</a>:</h2>
object_description(v1, 0, 0);
@ <h2>To Artifact %z(href("%R/artifact/%S",zV2))[%S(zV2)]</a>:</h2>
object_description(v2, 0, 0);
}
if( pRe ){
@ <b>Only differences that match regular expression "%h(zRe)"
@ are shown.</b>
}
@ <hr />
append_diff(zV1, zV2, diffFlags, pRe);
append_diff_javascript(sideBySide);
style_footer();
}
/*
** WEBPAGE: raw
** URL: /raw?name=ARTIFACTID&m=TYPE
**
** Return the uninterpreted content of an artifact. Used primarily
|
| ︙ | ︙ |
Changes to src/style.c.
| ︙ | ︙ | |||
460 461 462 463 464 465 466 | @ </div> @ </body></html> ; /* ** The default Cascading Style Sheet. ** It's assembled by different strings for each class. | | | 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
@ </div>
@ </body></html>
;
/*
** The default Cascading Style Sheet.
** It's assembled by different strings for each class.
** The default css contains all definitions.
** The style sheet, send to the client only contains the ones,
** not defined in the user defined css.
*/
const char zDefaultCSS[] =
@ /* General settings for the entire page */
@ body {
@ margin: 0ex 1ex;
|
| ︙ | ︙ | |||
963 964 965 966 967 968 969 |
@ color: red;
},
{ "ul.filelist",
"List of files in a timeline",
@ margin-top: 3px;
@ line-height: 100%;
},
| | | > | > > > > > > > > > > > | > | | | > > | > > > | > > > > > > > | 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 |
@ color: red;
},
{ "ul.filelist",
"List of files in a timeline",
@ margin-top: 3px;
@ line-height: 100%;
},
{ "table.sbsdiffcols",
"side-by-side diff display (column-based)",
@ border-spacing: 0;
@ font-size: xx-small;
},
{ "table.sbsdiffcols td",
"sbs diff table cell",
@ padding: 0;
@ vertical-align: top;
},
{ "table.sbsdiffcols pre",
"sbs diff pre block",
@ margin: 0;
@ padding: 0;
@ border: 0;
@ font-size: inherit;
@ background: inherit;
@ color: inherit;
},
{ "div.difflncol",
"diff line number column",
@ padding-right: 1em;
@ text-align: right;
@ color: #a0a0a0;
},
{ "div.difftxtcol",
"diff text column",
@ width: 45em;
@ overflow-x: auto;
},
{ "div.diffmkrcol",
"diff marker column",
@ padding: 0 1em;
},
{ "span.diffchng",
"changes in a diff",
@ background-color: #c0c0ff;
},
{ "span.diffadd",
"added code in a diff",
@ background-color: #c0ffc0;
},
{ "span.diffrm",
"deleted in a diff",
@ background-color: #ffc8c8;
},
{ "span.diffhr",
"suppressed lines in a diff",
@ display: inline-block;
@ margin: .5em 0 1em;
@ color: #0000ff;
},
{ "span.diffln",
"line numbers in a diff",
@ color: #a0a0a0;
},
{ "span.modpending",
|
| ︙ | ︙ |
Changes to src/wiki.c.
| ︙ | ︙ | |||
784 785 786 787 788 789 790 |
blob_zero(&w2);
if( rid2 && (pW2 = manifest_get(rid2, CFTYPE_WIKI))!=0 ){
blob_init(&w2, pW2->zWiki, -1);
}
blob_zero(&d);
diffFlags = construct_diff_flags(1,0);
text_diff(&w2, &w1, &d, 0, diffFlags | DIFF_HTML | DIFF_LINENO);
| | | | 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 |
blob_zero(&w2);
if( rid2 && (pW2 = manifest_get(rid2, CFTYPE_WIKI))!=0 ){
blob_init(&w2, pW2->zWiki, -1);
}
blob_zero(&d);
diffFlags = construct_diff_flags(1,0);
text_diff(&w2, &w1, &d, 0, diffFlags | DIFF_HTML | DIFF_LINENO);
@ <pre class="udiff">
@ %s(blob_str(&d))
@ <pre>
manifest_destroy(pW1);
manifest_destroy(pW2);
style_footer();
}
/*
** prepare()s pStmt with a query requesting:
|
| ︙ | ︙ |
Changes to test/diff-test-1.wiki.
1 2 3 4 5 6 | <title>Graph Test One</title> This page contains list of URLs of interesting diffs. Click on all URLs, one by one, to verify the correct operation of the diff logic. | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<title>Graph Test One</title>
This page contains list of URLs of interesting diffs.
Click on all URLs, one by one, to verify
the correct operation of the diff logic.
* <a href="../../../info/030035345c#chunk73" target="testwindow">
Multiple edits on a single line.</a> This is an SQLite version
update diff. It is a large diff and contains many other interesting
features. Scan the whole diff.
* <a href="../../../fdiff?v1=6da016415dc52d61&v2=af6df3466e3c4a88"
target="testwindow">Tricky alignment and multiple edits per line</a>.
* <a href="../../../fdiff?v1=7108d4748b111d23&v2=2303a98525b39d19#chunk3"
target="testwindow">Add a column to a table</a>
* <a href="../../../fdiff?v1=d1c60722e0b9d775&v2=58d1a8991bacb113"
target="testwindow">Column alignment with multibyte characters.</a>
The edit of a line with multibyte characters is the first chunk.
* <a href="../../../fdiff?v1=57b0d8183cab0e3d&v2=37b3ef49d73cdfe6"
target="testwindow">Large diff of sqlite3.c</a>. This diff was very
slow prior to the performance enhancement change [9e15437e97].
* <a href="../../../info/bda00cbada#chunk49" target="testwindow">
A difficult indentation change.
* <a href="../../../fdiff?v1=955cc67ace8fb622&v2=e2e1c87b86664b45#chunk13"
target="testwindow">Another tricky indentation.</a> Notice especially
lines 59398 and 59407 on the left.
* <a href="../../../fdiff?v2=955cc67ace8fb622&v1=e2e1c87b86664b45#chunk13"
target="testwindow">Inverse of the previous.</a>
* <a href="../../../fdiff?v1=955cc67ace8fb622&v2=e2e1c87b86664b45#chunk24"
|
| ︙ | ︙ |