Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Further diff enhancements: Allow up to two diff-marks per line on a side-by-side diff. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
937514b96854b8ba378850ebab10cd89 |
| User & Date: | drh 2012-02-11 18:25:16.775 |
Context
|
2012-02-11
| ||
| 21:23 | Update the built-in SQLite version to the latest from trunk, including the patch that sets -wal and -shm files to have the same owner as the database when running as root. That patch help to avoid configuration problems on Fossil servers. ... (check-in: 5ac8c0d713 user: drh tags: trunk) | |
| 18:25 | Further diff enhancements: Allow up to two diff-marks per line on a side-by-side diff. ... (check-in: 937514b968 user: drh tags: trunk) | |
|
2012-02-10
| ||
| 23:37 | Record --backout and --cherrypick merges in the VMERGE table with IDs -2 and -1, respectively. On a --cherrypick merge, make the default check-in comment be the same as the check-in comment for the cherrypicked change. ... (check-in: 9c28bca430 user: drh tags: trunk) | |
Changes
Changes to src/diff.c.
| ︙ | ︙ | |||
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 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 |
char *zLine; /* The output line under construction */
int n; /* Index of next unused slot in the zLine[] */
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 */
};
/*
** Flags for sbsWriteText()
*/
#define SBS_NEWLINE 0x0001 /* End with \n\000 */
#define SBS_PAD 0x0002 /* Pad output to width spaces */
/*
** Write up to width characters of pLine into z[]. Translate tabs into
** spaces. Add a newline if SBS_NEWLINE is set. Translate HTML characters
** if SBS_HTML is set. Pad the rendering out width bytes if SBS_PAD is set.
*/
static void sbsWriteText(SbsLine *p, DLine *pLine, unsigned flags){
int n = pLine->h & LENGTH_MASK;
int i; /* Number of input characters consumed */
int j; /* Number of output characters generated */
int k; /* Cursor position */
const char *zIn = pLine->z;
char *z = &p->zLine[p->n];
int w = p->width;
for(i=j=k=0; k<w && i<n; i++, k++){
char c = zIn[i];
if( p->escHtml ){
if( i==p->iStart ){
int x = strlen(p->zStart);
memcpy(z+j, p->zStart, x);
j += x;
}else if( i==p->iEnd ){
memcpy(z+j, "</span>", 7);
j += 7;
}
}
if( c=='\t' ){
z[j++] = ' ';
while( (k&7)!=7 && k<w ){ z[j++] = ' '; k++; }
}else if( c=='\r' || c=='\f' ){
z[j++] = ' ';
}else if( c=='<' && p->escHtml ){
memcpy(&z[j], "<", 4);
j += 4;
}else if( c=='&' && p->escHtml ){
memcpy(&z[j], "&", 5);
j += 5;
}else if( c=='>' && p->escHtml ){
memcpy(&z[j], ">", 4);
j += 4;
}else{
z[j++] = c;
}
}
| > > > > > > > > > > > > > > > | | 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 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 432 433 434 435 436 437 438 439 440 441 |
char *zLine; /* The output line under construction */
int n; /* Index of next unused slot in the zLine[] */
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 */
};
/*
** Flags for sbsWriteText()
*/
#define SBS_NEWLINE 0x0001 /* End with \n\000 */
#define SBS_PAD 0x0002 /* Pad output to width spaces */
/*
** Write up to width characters of pLine into z[]. Translate tabs into
** spaces. Add a newline if SBS_NEWLINE is set. Translate HTML characters
** if SBS_HTML is set. Pad the rendering out width bytes if SBS_PAD is set.
*/
static void sbsWriteText(SbsLine *p, DLine *pLine, unsigned flags){
int n = pLine->h & LENGTH_MASK;
int i; /* Number of input characters consumed */
int j; /* Number of output characters generated */
int k; /* Cursor position */
int needEndSpan = 0;
const char *zIn = pLine->z;
char *z = &p->zLine[p->n];
int w = p->width;
for(i=j=k=0; k<w && i<n; i++, k++){
char c = zIn[i];
if( p->escHtml ){
if( i==p->iStart ){
int x = strlen(p->zStart);
memcpy(z+j, p->zStart, x);
j += x;
needEndSpan = 1;
if( p->iStart2 ){
p->iStart = p->iStart2;
p->zStart = p->zStart2;
p->iStart2 = 0;
}
}else if( i==p->iEnd ){
memcpy(z+j, "</span>", 7);
j += 7;
needEndSpan = 0;
if( p->iEnd2 ){
p->iEnd = p->iEnd2;
p->iEnd2 = 0;
}
}
}
if( c=='\t' ){
z[j++] = ' ';
while( (k&7)!=7 && k<w ){ z[j++] = ' '; k++; }
}else if( c=='\r' || c=='\f' ){
z[j++] = ' ';
}else if( c=='<' && p->escHtml ){
memcpy(&z[j], "<", 4);
j += 4;
}else if( c=='&' && p->escHtml ){
memcpy(&z[j], "&", 5);
j += 5;
}else if( c=='>' && p->escHtml ){
memcpy(&z[j], ">", 4);
j += 4;
}else{
z[j++] = c;
}
}
if( needEndSpan ){
memcpy(&z[j], "</span>", 7);
j += 7;
}
if( (flags & SBS_PAD)!=0 ){
while( k<w ){ k++; z[j++] = ' '; }
}
if( flags & SBS_NEWLINE ){
|
| ︙ | ︙ | |||
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
static void sbsWriteLineno(SbsLine *p, int ln){
sbsWriteHtml(p, "<span class=\"diffln\">");
sqlite3_snprintf(7, &p->zLine[p->n], "%5d ", ln+1);
p->n += 6;
sbsWriteHtml(p, "</span>");
p->zLine[p->n++] = ' ';
}
/*
** Write out lines that have been edited. Adjust the highlight to cover
** only those parts of the line that actually changed.
*/
static void sbsWriteLineChange(
SbsLine *p, /* The SBS output line */
DLine *pLeft, /* Left line of the change */
int lnLeft, /* Line number for the left line */
DLine *pRight, /* Right line of the change */
int lnRight /* Line number of the right line */
){
int nLeft; /* Length of left line in bytes */
int nRight; /* Length of right line in bytes */
int nPrefix; /* Length of common prefix */
int nSuffix; /* Length of common suffix */
const char *zLeft; /* Text of the left line */
const char *zRight; /* Text of the right line */
nLeft = pLeft->h & LENGTH_MASK;
zLeft = pLeft->z;
nRight = pRight->h & LENGTH_MASK;
zRight = pRight->z;
nPrefix = 0;
while( nPrefix<nLeft && nPrefix<nRight && zLeft[nPrefix]==zRight[nPrefix] ){
nPrefix++;
}
nSuffix = 0;
if( nPrefix<nLeft && nPrefix<nRight ){
while( nSuffix<nLeft && nSuffix<nRight
&& zLeft[nLeft-nSuffix-1]==zRight[nRight-nSuffix-1] ){
nSuffix++;
}
if( nSuffix==nLeft || nSuffix==nRight ) nPrefix = 0;
}
if( nPrefix+nSuffix > nLeft ) nSuffix = nLeft - nPrefix;
if( nPrefix+nSuffix > nRight ) nSuffix = nRight - nPrefix;
if( nPrefix+nSuffix==nLeft ){
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < > | > > > > | > | > > | > | > > > > > > > > > > > > | > > > > > | > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > | 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 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 |
static void sbsWriteLineno(SbsLine *p, int ln){
sbsWriteHtml(p, "<span class=\"diffln\">");
sqlite3_snprintf(7, &p->zLine[p->n], "%5d ", ln+1);
p->n += 6;
sbsWriteHtml(p, "</span>");
p->zLine[p->n++] = ' ';
}
/*
** 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:
**
** aLCS[0] = start of the common segment in zLeft
** aLCS[1] = end of the common segment in zLeft
** aLCS[2] = start of the common segment in zLeft
** aLCS[3] = end of the common segment in zLeft
**
** This computation is for display purposes only and does not have to be
** optimal or exact.
*/
static int textLCS(
const char *zLeft, int nA, /* String on the left */
const char *zRight, int nB, /* String on the right */
int *aLCS /* Identify bounds of LCS here */
){
const unsigned char *zA = (const unsigned char*)zLeft; /* left string */
const unsigned char *zB = (const unsigned char*)zRight; /* right string */
int nt; /* Number of target points */
int ti[3]; /* Index for start of each 4-byte target */
unsigned int target[3]; /* 4-byte alignment targets */
unsigned int probe; /* probe to compare against target */
int iAS, iAE, iBS, iBE; /* Range of common segment */
int i, j; /* Loop counters */
int rc = 0; /* Result code. 1 for success */
if( nA<6 || nB<6 ) return 0;
memset(aLCS, 0, sizeof(int)*4);
ti[0] = i = nB/2-2;
target[0] = (zB[i]<<24) | (zB[i+1]<<16) | (zB[i+2]<<8) | zB[i+3];
probe = 0;
if( nB<16 ){
nt = 1;
}else{
ti[1] = i = nB/4-2;
target[1] = (zB[i]<<24) | (zB[i+1]<<16) | (zB[i+2]<<8) | zB[i+3];
ti[2] = i = (nB*3)/4-2;
target[2] = (zB[i]<<24) | (zB[i+1]<<16) | (zB[i+2]<<8) | zB[i+3];
nt = 3;
}
probe = (zA[0]<<16) | (zA[1]<<8) | zA[2];
for(i=3; i<nA; i++){
probe = (probe<<8) | zA[i];
for(j=0; j<nt; j++){
if( probe==target[j] ){
iAS = i-3;
iAE = i+1;
iBS = ti[j];
iBE = ti[j]+4;
while( iAE<nA && iBE<nB && zA[iAE]==zB[iBE] ){ iAE++; iBE++; }
while( iAS>0 && iBS>0 && zA[iAS-1]==zB[iBS-1] ){ iAS--; iBS--; }
if( iAE-iAS > aLCS[1] - aLCS[0] ){
aLCS[0] = iAS;
aLCS[1] = iAE;
aLCS[2] = iBS;
aLCS[3] = iBE;
rc = 1;
}
}
}
}
return rc;
}
/*
** Write out lines that have been edited. Adjust the highlight to cover
** only those parts of the line that actually changed.
*/
static void sbsWriteLineChange(
SbsLine *p, /* The SBS output line */
DLine *pLeft, /* Left line of the change */
int lnLeft, /* Line number for the left line */
DLine *pRight, /* Right line of the change */
int lnRight /* Line number of the right line */
){
int nLeft; /* Length of left line in bytes */
int nRight; /* Length of right line in bytes */
int nPrefix; /* Length of common prefix */
int nSuffix; /* Length of common suffix */
const char *zLeft; /* Text of the left line */
const char *zRight; /* Text of the right line */
int nLeftDiff; /* nLeft - nPrefix - nSuffix */
int nRightDiff; /* nRight - nPrefix - nSuffix */
int aLCS[4]; /* Bounds of common middle segment */
static const char zClassRm[] = "<span class=\"diffrm\">";
static const char zClassAdd[] = "<span class=\"diffadd\">";
static const char zClassChng[] = "<span class=\"diffchng\">";
nLeft = pLeft->h & LENGTH_MASK;
zLeft = pLeft->z;
nRight = pRight->h & LENGTH_MASK;
zRight = pRight->z;
nPrefix = 0;
while( nPrefix<nLeft && nPrefix<nRight && zLeft[nPrefix]==zRight[nPrefix] ){
nPrefix++;
}
nSuffix = 0;
if( nPrefix<nLeft && nPrefix<nRight ){
while( nSuffix<nLeft && nSuffix<nRight
&& zLeft[nLeft-nSuffix-1]==zRight[nRight-nSuffix-1] ){
nSuffix++;
}
if( nSuffix==nLeft || nSuffix==nRight ) nPrefix = 0;
}
if( nPrefix+nSuffix > nLeft ) nSuffix = nLeft - nPrefix;
if( nPrefix+nSuffix > nRight ) nSuffix = nRight - nPrefix;
/* A single chunk of text inserted on the right */
if( nPrefix+nSuffix==nLeft ){
sbsWriteLineno(p, lnLeft);
p->iStart2 = p->iEnd2 = 0;
p->iStart = p->iEnd = -1;
sbsWriteText(p, pLeft, SBS_PAD);
sbsWrite(p, " | ", 3);
sbsWriteLineno(p, lnRight);
p->iStart = nPrefix;
p->iEnd = nRight - nSuffix;
p->zStart = zClassAdd;
sbsWriteText(p, pRight, SBS_NEWLINE);
return;
}
/* A single chunk of text deleted from the left */
if( nPrefix+nSuffix==nRight ){
/* Text deleted from the left */
sbsWriteLineno(p, lnLeft);
p->iStart2 = p->iEnd2 = 0;
p->iStart = nPrefix;
p->iEnd = nLeft - nSuffix;
p->zStart = zClassRm;
sbsWriteText(p, pLeft, SBS_PAD);
sbsWrite(p, " | ", 3);
sbsWriteLineno(p, lnRight);
p->iStart = p->iEnd = -1;
sbsWriteText(p, pRight, SBS_NEWLINE);
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);
p->iStart = nPrefix;
p->iEnd = nPrefix + aLCS[0];
p->zStart = aLCS[2]==0 ? zClassRm : zClassChng;
p->iStart2 = nPrefix + aLCS[1];
p->iEnd2 = nLeft - nSuffix;
p->zStart2 = aLCS[3]==nRightDiff ? zClassRm : zClassChng;
if( p->iStart2==p->iEnd2 ) p->iStart2 = p->iEnd2 = 0;
if( p->iStart==p->iEnd ){
p->iStart = p->iStart2;
p->iEnd = p->iEnd2;
p->zStart = p->zStart2;
p->iStart2 = 0;
p->iEnd2 = 0;
}
if( p->iStart==p->iEnd ) p->iStart = p->iEnd = -1;
sbsWriteText(p, pLeft, SBS_PAD);
sbsWrite(p, " | ", 3);
sbsWriteLineno(p, lnRight);
p->iStart = nPrefix;
p->iEnd = nPrefix + aLCS[2];
p->zStart = aLCS[0]==0 ? zClassAdd : zClassChng;
p->iStart2 = nPrefix + aLCS[3];
p->iEnd2 = nRight - nSuffix;
p->zStart2 = aLCS[1]==nLeftDiff ? zClassAdd : zClassChng;
if( p->iStart2==p->iEnd2 ) p->iStart2 = p->iEnd2 = 0;
if( p->iStart==p->iEnd ){
p->iStart = p->iStart2;
p->iEnd = p->iEnd2;
p->zStart = p->zStart2;
p->iStart2 = 0;
p->iEnd2 = 0;
}
if( p->iStart==p->iEnd ) p->iStart = p->iEnd = -1;
sbsWriteText(p, pRight, SBS_NEWLINE);
return;
}
/* If all else fails, show a single big change between left and right */
sbsWriteLineno(p, lnLeft);
p->iStart2 = p->iEnd2 = 0;
p->iStart = nPrefix;
p->iEnd = nLeft - nSuffix;
p->zStart = zClassChng;
sbsWriteText(p, pLeft, SBS_PAD);
sbsWrite(p, " | ", 3);
sbsWriteLineno(p, lnRight);
p->iEnd = nRight - nSuffix;
sbsWriteText(p, pRight, SBS_NEWLINE);
}
/*
** Minimum of two values
*/
static int minInt(int a, int b){ return a<b ? a : b; }
|
| ︙ | ︙ | |||
732 733 734 735 736 737 738 | 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 */ int nChunk = 0; /* Number of chunks of diff output seen so far */ SbsLine s; /* Output line buffer */ | | | 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 | 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 */ int nChunk = 0; /* Number of chunks of diff output seen so far */ SbsLine s; /* Output line buffer */ s.zLine = fossil_malloc( 10*width + 200 ); if( s.zLine==0 ) return; s.width = width; s.escHtml = escHtml; s.iStart = -1; s.iEnd = -1; A = p->aFrom; B = p->aTo; |
| ︙ | ︙ |