Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Add color to the retro sbs diff. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | retro-sbsdiff |
| Files: | files | file ages | folders |
| SHA1: |
7372c0a5c40dec58f7490923c0a49a32 |
| User & Date: | drh 2012-02-04 18:54:43.528 |
Context
|
2012-02-04
| ||
| 19:34 | Revised default color scheme. Add line-numbers to context diff. ... (check-in: 6a6697694c user: drh tags: retro-sbsdiff) | |
| 18:54 | Add color to the retro sbs diff. ... (check-in: 7372c0a5c4 user: drh tags: retro-sbsdiff) | |
| 15:02 | Merge recent trunk changes into the retro-sbsdiff branch. ... (check-in: 066adeedfe user: drh tags: retro-sbsdiff) | |
Changes
Changes to src/diff.c.
| ︙ | ︙ | |||
23 24 25 26 27 28 29 | #include <assert.h> #if INTERFACE /* ** Allowed flag parameters to the text_diff() and html_sbsdiff() funtions: */ | | | | | | | > | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <assert.h> #if INTERFACE /* ** Allowed flag parameters to the text_diff() and html_sbsdiff() funtions: */ #define DIFF_CONTEXT_MASK 0x0000ffff /* Lines of context. Default if 0 */ #define DIFF_WIDTH_MASK 0x00ff0000 /* side-by-side column width */ #define DIFF_IGNORE_EOLWS 0x01000000 /* Ignore end-of-line whitespace */ #define DIFF_SIDEBYSIDE 0x02000000 /* Generate a side-by-side diff */ #define DIFF_NEWFILE 0x04000000 /* Missing files are as empty files */ #define DIFF_INLINE 0x08000000 /* Inline (not side-by-side) diff */ #define DIFF_HTML 0x10000000 /* Render for HTML */ #endif /* INTERFACE */ /* ** Maximum length of a line in a text file. (8192) */ #define LENGTH_MASK_SZ 13 |
| ︙ | ︙ | |||
298 299 300 301 302 303 304 |
for(j=0; j<m; j++){
appendDiffLine(pOut, " ", &B[b+j]);
}
}
}
/*
| > > > > > > > > > > > | < | | | > > > > > > > > | < > | | > > > | | > > > > > > > > > > > > > | > > > > > > | > > > > > > | | > > > > > > > > > > > > | > > > > > > < < | < | | | > | 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 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 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 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 |
for(j=0; j<m; j++){
appendDiffLine(pOut, " ", &B[b+j]);
}
}
}
/*
** Status of a single output line
*/
typedef struct SbsLine SbsLine;
struct SbsLine {
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 */
};
/*
** Write a 6-digit line number followed by a single space onto the line.
*/
static void sbsWriteLineno(SbsLine *p, int ln){
sqlite3_snprintf(7, &p->zLine[p->n], "%6d", ln+1);
p->zLine[p->n+6] = ' ';
p->n += 7;
}
/*
** Flags for sbsWriteText()
*/
#define SBS_NEWLINE 0x0001 /* End with \n\000 */
#define SBS_PAD 0x0002 /* Pad output to width spaces */
#define SBS_ENDSPAN 0x0004 /* Write a </span> after text */
/*
** 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, j, k;
const char *zIn = pLine->z;
char *z = &p->zLine[p->n];
int w = p->width;
if( n>w ) n = w;
for(i=j=0; i<n; i++){
char c = zIn[i];
if( c=='\t' ){
z[j++] = ' ';
while( (j&7)!=0 && j<n ) z[j++] = ' ';
}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( (flags & SBS_ENDSPAN) && p->escHtml ){
memcpy(&z[j], "</span>", 7);
j += 7;
}
if( (flags & SBS_PAD)!=0 ){
while( i<w ){ i++; z[j++] = ' '; }
}
if( flags & SBS_NEWLINE ){
z[j++] = '\n';
}
p->n += j;
}
/*
** Append a string to an SbSLine with coding, interpretation, or padding.
*/
static void sbsWrite(SbsLine *p, const char *zIn, int nIn){
memcpy(p->zLine+p->n, zIn, nIn);
p->n += nIn;
}
/*
** Append n spaces to the string.
*/
static void sbsWriteSpace(SbsLine *p, int n){
while( n-- ) p->zLine[p->n++] = ' ';
}
/*
** Append a string to the output only if we are rendering HTML.
*/
static void sbsWriteHtml(SbsLine *p, const char *zIn){
if( p->escHtml ) sbsWrite(p, zIn, strlen(zIn));
}
/*
** Given a diff context in which the aEdit[] array has been filled
** in, compute a side-by-side diff into pOut.
*/
static void sbsDiff(
DContext *p, /* The computed diff */
Blob *pOut, /* Write the results here */
int nContext, /* Number of lines of context around each change */
int width, /* Width of each column of output */
int escHtml /* True to generate HTML output */
){
DLine *A; /* Left side of the diff */
DLine *B; /* Right side of the diff */
int a = 0; /* Index of next line in A[] */
int b = 0; /* Index of next line in B[] */
int *R; /* Array of COPY/DELETE/INSERT triples */
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 */
SbsLine s; /* Output line buffer */
s.zLine = fossil_malloc( 10*width + 100 );
if( s.zLine==0 ) return;
s.width = width;
s.escHtml = escHtml;
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 */
|
| ︙ | ︙ | |||
399 400 401 402 403 404 405 |
nb += R[r+i*3];
}
/*
* 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.
*/
| > > > > > | > > | | | > | | | | | > | < > | > | | | | > | < | < | < | > > | > | | | | | > | | | | | | > | | | | | 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 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 |
nb += R[r+i*3];
}
/*
* 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.
*/
if( r>0 ){
if( escHtml ){
blob_appendf(pOut, "<span class=\"diffhr\">%.*c</span>\n",
width*2+16, '.');
}else{
blob_appendf(pOut, "%.*c\n", width*2+16, '.');
}
}
/* Show the initial common area */
a += skip;
b += skip;
m = R[r] - skip;
for(j=0; j<m; j++){
s.n = 0;
sbsWriteLineno(&s, a+j);
sbsWriteText(&s, &A[a+j], SBS_PAD);
sbsWrite(&s, " ", 3);
sbsWriteLineno(&s, b+j);
sbsWriteText(&s, &B[b+j], SBS_NEWLINE);
blob_append(pOut, s.zLine, s.n);
}
a += m;
b += m;
/* Show the differences */
for(i=0; i<nr; i++){
ma = R[r+i*3+1];
mb = R[r+i*3+2];
m = ma<mb ? ma : mb;
for(j=0; j<m; j++){
s.n = 0;
sbsWriteLineno(&s, a+j);
sbsWriteHtml(&s, "<span class=\"diffchng\">");
sbsWriteText(&s, &A[a+j], SBS_PAD | SBS_ENDSPAN);
sbsWrite(&s, " | ", 3);
sbsWriteLineno(&s, b+j);
sbsWriteHtml(&s, "<span class=\"diffchng\">");
sbsWriteText(&s, &B[b+j], SBS_NEWLINE | SBS_ENDSPAN);
blob_append(pOut, s.zLine, s.n);
}
a += m;
b += m;
ma -= m;
mb -= m;
for(j=0; j<ma; j++){
s.n = 0;
sbsWriteLineno(&s, a+j);
sbsWriteHtml(&s, "<span class=\"diffrm\">");
sbsWriteText(&s, &A[a+j], SBS_PAD | SBS_ENDSPAN);
sbsWrite(&s, " <\n", 3);
blob_append(pOut, s.zLine, s.n);
}
a += ma;
for(j=0; j<mb; j++){
s.n = 0;
sbsWriteSpace(&s, width + 7);
sbsWrite(&s, " > ", 3);
sbsWriteLineno(&s, b+j);
sbsWriteHtml(&s, "<span class=\"diffadd\">");
sbsWriteText(&s, &B[b+j], SBS_NEWLINE | SBS_ENDSPAN);
blob_append(pOut, s.zLine, s.n);
}
b += mb;
if( i<nr-1 ){
m = R[r+i*3+3];
for(j=0; j<m; j++){
s.n = 0;
sbsWriteLineno(&s, a+j);
sbsWriteText(&s, &A[a+j], SBS_PAD);
sbsWrite(&s, " ", 3);
sbsWriteLineno(&s, b+j);
sbsWriteText(&s, &B[b+j], SBS_NEWLINE);
blob_append(pOut, s.zLine, s.n);
}
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++){
s.n = 0;
sbsWriteLineno(&s, a+j);
sbsWriteText(&s, &A[a+j], SBS_PAD);
sbsWrite(&s, " ", 3);
sbsWriteLineno(&s, b+j);
sbsWriteText(&s, &B[b+j], SBS_NEWLINE);
blob_append(pOut, s.zLine, s.n);
}
}
free(s.zLine);
}
/*
** 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.
|
| ︙ | ︙ | |||
787 788 789 790 791 792 793 |
/* Compute the difference */
diff_all(&c);
if( pOut ){
/* Compute a context or side-by-side diff into pOut */
if( diffFlags & DIFF_SIDEBYSIDE ){
int width = diff_width(diffFlags);
| > | | 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 |
/* Compute the difference */
diff_all(&c);
if( pOut ){
/* Compute a context or side-by-side diff into pOut */
if( diffFlags & DIFF_SIDEBYSIDE ){
int width = diff_width(diffFlags);
int escHtml = (diffFlags & DIFF_HTML)!=0;
sbsDiff(&c, pOut, nContext, width, escHtml);
}else{
contextDiff(&c, pOut, nContext);
}
free(c.aFrom);
free(c.aTo);
free(c.aEdit);
return 0;
|
| ︙ | ︙ | |||
849 850 851 852 853 854 855 856 857 858 859 860 861 862 |
diffFlags |= f;
}
if( (z = find_option("width","W",1))!=0 && (f = atoi(z))>0 ){
f *= DIFF_CONTEXT_MASK+1;
if( f > DIFF_WIDTH_MASK ) f = DIFF_CONTEXT_MASK;
diffFlags |= f;
}
return diffFlags;
}
/*
** COMMAND: test-udiff
**
** Print the difference between two files. The usual diff options apply.
| > | 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 |
diffFlags |= f;
}
if( (z = find_option("width","W",1))!=0 && (f = atoi(z))>0 ){
f *= DIFF_CONTEXT_MASK+1;
if( f > DIFF_WIDTH_MASK ) f = DIFF_CONTEXT_MASK;
diffFlags |= f;
}
if( find_option("html",0,0)!=0 ) diffFlags |= DIFF_HTML;
return diffFlags;
}
/*
** COMMAND: test-udiff
**
** Print the difference between two files. The usual diff options apply.
|
| ︙ | ︙ |
Changes to src/info.c.
| ︙ | ︙ | |||
266 267 268 269 270 271 272 |
if( zTo ){
toid = uuid_to_rid(zTo, 0);
content_get(toid, &to);
}else{
blob_zero(&to);
}
blob_zero(&out);
| > > > > > > | | > | 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
if( zTo ){
toid = uuid_to_rid(zTo, 0);
content_get(toid, &to);
}else{
blob_zero(&to);
}
blob_zero(&out);
if( diffFlags & DIFF_SIDEBYSIDE ){
text_diff(&from, &to, &out, diffFlags | DIFF_HTML);
@ <div class="sbsdiff">
@ %s(blob_str(&out))
@ </div>
}else{
text_diff(&from, &to, &out, diffFlags);
@ %h(blob_str(&out))
}
blob_reset(&from);
blob_reset(&to);
blob_reset(&out);
}
/*
|
| ︙ | ︙ |
Changes to src/style.c.
| ︙ | ︙ | |||
749 750 751 752 753 754 755 756 757 758 759 760 761 762 |
@ color: red;
},
{ "ul.filelist",
"List of files in a timeline",
@ margin-top: 3px;
@ line-height: 100%;
},
{ 0,
0,
0
}
};
/*
| > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 |
@ color: red;
},
{ "ul.filelist",
"List of files in a timeline",
@ margin-top: 3px;
@ line-height: 100%;
},
{ "div.sbsdiff",
"side-by-side diff display",
@ font-family: monospace;
@ white-space: pre;
},
{ "div.udiff",
"unified diff display",
@ font-family: monospace;
@ white-space: pre;
},
{ "span.diffchng",
"changes in a diff",
@ background-color: #d8d8d8;
},
{ "span.diffadd",
"added code in a diff",
@ background-color: #d8ffd8;
},
{ "span.diffrm",
"deleted in a diff",
@ background-color: #ffd8d8;
},
{ "span.diffhr",
"suppressed lines in a diff",
@ color: #0000ff;
},
{ 0,
0,
0
}
};
/*
|
| ︙ | ︙ |