Fossil SCM
Delete unused legacy context-diff logic for HTML.
Commit
1fb022ff98d56e6e6d6ca1dbd495c579e9eebd1e81302d2fd75651f952b7c3d4
Parent
d29ddba32115d21…
1 file changed
+18
-73
+18
-73
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -302,41 +302,23 @@ | ||
| 302 | 302 | ** Append a single line of context-diff output to pOut. |
| 303 | 303 | */ |
| 304 | 304 | static void appendDiffLine( |
| 305 | 305 | Blob *pOut, /* Where to write the line of output */ |
| 306 | 306 | char cPrefix, /* One of " ", "+", or "-" */ |
| 307 | - DLine *pLine, /* The line to be output */ | |
| 308 | - int html, /* True if generating HTML. False for plain text */ | |
| 309 | - ReCompiled *pRe /* Colorize only if line matches this Regex */ | |
| 307 | + DLine *pLine /* The line to be output */ | |
| 310 | 308 | ){ |
| 311 | - blob_append(pOut, &cPrefix, 1); | |
| 312 | - if( html ){ | |
| 313 | - if( pRe && re_dline_match(pRe, pLine, 1)==0 ){ | |
| 314 | - cPrefix = ' '; | |
| 315 | - }else if( cPrefix=='+' ){ | |
| 316 | - blob_append(pOut, zClassAdd, -1); | |
| 317 | - }else if( cPrefix=='-' ){ | |
| 318 | - blob_append(pOut, zClassRm, -1); | |
| 319 | - } | |
| 320 | - htmlize_to_blob(pOut, pLine->z, pLine->n); | |
| 321 | - if( cPrefix!=' ' ){ | |
| 322 | - blob_append(pOut, "</span>", -1); | |
| 323 | - } | |
| 324 | - }else{ | |
| 325 | - blob_append(pOut, pLine->z, pLine->n); | |
| 326 | - } | |
| 327 | - blob_append(pOut, "\n", 1); | |
| 309 | + blob_append_char(pOut, cPrefix); | |
| 310 | + blob_append(pOut, pLine->z, pLine->n); | |
| 311 | + blob_append_char(pOut, '\n'); | |
| 328 | 312 | } |
| 329 | 313 | |
| 330 | 314 | /* |
| 331 | 315 | ** Add two line numbers to the beginning of an output line for a context |
| 332 | 316 | ** diff. One or the other of the two numbers might be zero, which means |
| 333 | -** to leave that number field blank. The "html" parameter means to format | |
| 334 | -** the output for HTML. | |
| 317 | +** to leave that number field blank. | |
| 335 | 318 | */ |
| 336 | -static void appendDiffLineno(Blob *pOut, int lnA, int lnB, int html){ | |
| 337 | - if( html ) blob_append(pOut, "<span class=\"diffln\">", -1); | |
| 319 | +static void appendDiffLineno(Blob *pOut, int lnA, int lnB){ | |
| 338 | 320 | if( lnA>0 ){ |
| 339 | 321 | blob_appendf(pOut, "%6d ", lnA); |
| 340 | 322 | }else{ |
| 341 | 323 | blob_append(pOut, " ", 7); |
| 342 | 324 | } |
| @@ -343,21 +325,18 @@ | ||
| 343 | 325 | if( lnB>0 ){ |
| 344 | 326 | blob_appendf(pOut, "%6d ", lnB); |
| 345 | 327 | }else{ |
| 346 | 328 | blob_append(pOut, " ", 8); |
| 347 | 329 | } |
| 348 | - if( html ) blob_append(pOut, "</span>", -1); | |
| 349 | 330 | } |
| 350 | 331 | |
| 351 | 332 | /* |
| 352 | -** Given a raw diff p[] in which the p->aEdit[] array has been filled | |
| 353 | -** in, compute a context diff into pOut. | |
| 333 | +** Output a patch-style text diff. | |
| 354 | 334 | */ |
| 355 | 335 | static void contextDiff( |
| 356 | 336 | DContext *p, /* The difference */ |
| 357 | 337 | Blob *pOut, /* Output a context diff to here */ |
| 358 | - ReCompiled *pRe, /* Only show changes that match this regex */ | |
| 359 | 338 | u64 diffFlags /* Flags controlling the diff format */ |
| 360 | 339 | ){ |
| 361 | 340 | DLine *A; /* Left side of the diff */ |
| 362 | 341 | DLine *B; /* Right side of the diff */ |
| 363 | 342 | int a = 0; /* Index of next line in A[] */ |
| @@ -371,17 +350,14 @@ | ||
| 371 | 350 | int m; /* Number of lines to output */ |
| 372 | 351 | int skip; /* Number of lines to skip */ |
| 373 | 352 | static int nChunk = 0; /* Number of diff chunks seen so far */ |
| 374 | 353 | int nContext; /* Number of lines of context */ |
| 375 | 354 | int showLn; /* Show line numbers */ |
| 376 | - int html; /* Render as HTML */ | |
| 377 | 355 | int showDivider = 0; /* True to show the divider between diff blocks */ |
| 378 | 356 | |
| 379 | 357 | nContext = diff_context_lines(diffFlags); |
| 380 | 358 | showLn = (diffFlags & DIFF_LINENO)!=0; |
| 381 | - html = (diffFlags & DIFF_HTML)!=0; | |
| 382 | - if( html ) blob_append(pOut, "<pre class=\"udiff\">\n", -1); | |
| 383 | 359 | A = p->aFrom; |
| 384 | 360 | B = p->aTo; |
| 385 | 361 | R = p->aEdit; |
| 386 | 362 | mxr = p->nEdit; |
| 387 | 363 | while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; } |
| @@ -388,35 +364,10 @@ | ||
| 388 | 364 | for(r=0; r<mxr; r += 3*nr){ |
| 389 | 365 | /* Figure out how many triples to show in a single block */ |
| 390 | 366 | for(nr=1; R[r+nr*3]>0 && R[r+nr*3]<nContext*2; nr++){} |
| 391 | 367 | /* printf("r=%d nr=%d\n", r, nr); */ |
| 392 | 368 | |
| 393 | - /* If there is a regex, skip this block (generate no diff output) | |
| 394 | - ** if the regex matches or does not match both insert and delete. | |
| 395 | - ** Only display the block if one side matches but the other side does | |
| 396 | - ** not. | |
| 397 | - */ | |
| 398 | - if( pRe ){ | |
| 399 | - int hideBlock = 1; | |
| 400 | - int xa = a, xb = b; | |
| 401 | - for(i=0; hideBlock && i<nr; i++){ | |
| 402 | - int c1, c2; | |
| 403 | - xa += R[r+i*3]; | |
| 404 | - xb += R[r+i*3]; | |
| 405 | - c1 = re_dline_match(pRe, &A[xa], R[r+i*3+1]); | |
| 406 | - c2 = re_dline_match(pRe, &B[xb], R[r+i*3+2]); | |
| 407 | - hideBlock = c1==c2; | |
| 408 | - xa += R[r+i*3+1]; | |
| 409 | - xb += R[r+i*3+2]; | |
| 410 | - } | |
| 411 | - if( hideBlock ){ | |
| 412 | - a = xa; | |
| 413 | - b = xb; | |
| 414 | - continue; | |
| 415 | - } | |
| 416 | - } | |
| 417 | - | |
| 418 | 369 | /* For the current block comprising nr triples, figure out |
| 419 | 370 | ** how many lines of A and B are to be displayed |
| 420 | 371 | */ |
| 421 | 372 | if( R[r]>nContext ){ |
| 422 | 373 | na = nb = nContext; |
| @@ -448,60 +399,55 @@ | ||
| 448 | 399 | nChunk++; |
| 449 | 400 | if( showLn ){ |
| 450 | 401 | if( !showDivider ){ |
| 451 | 402 | /* Do not show a top divider */ |
| 452 | 403 | showDivider = 1; |
| 453 | - }else if( html ){ | |
| 454 | - blob_appendf(pOut, "<span class=\"diffhr\">%.80c</span>\n", '.'); | |
| 455 | 404 | }else{ |
| 456 | 405 | blob_appendf(pOut, "%.80c\n", '.'); |
| 457 | 406 | } |
| 458 | - if( html ) blob_appendf(pOut, "<span id=\"chunk%d\"></span>", nChunk); | |
| 459 | 407 | }else{ |
| 460 | - if( html ) blob_appendf(pOut, "<span class=\"diffln\">"); | |
| 461 | 408 | /* |
| 462 | 409 | * If the patch changes an empty file or results in an empty file, |
| 463 | 410 | * the block header must use 0,0 as position indicator and not 1,0. |
| 464 | 411 | * Otherwise, patch would be confused and may reject the diff. |
| 465 | 412 | */ |
| 466 | 413 | blob_appendf(pOut,"@@ -%d,%d +%d,%d @@", |
| 467 | 414 | na ? a+skip+1 : a+skip, na, |
| 468 | 415 | nb ? b+skip+1 : b+skip, nb); |
| 469 | - if( html ) blob_appendf(pOut, "</span>"); | |
| 470 | 416 | blob_append(pOut, "\n", 1); |
| 471 | 417 | } |
| 472 | 418 | |
| 473 | 419 | /* Show the initial common area */ |
| 474 | 420 | a += skip; |
| 475 | 421 | b += skip; |
| 476 | 422 | m = R[r] - skip; |
| 477 | 423 | for(j=0; j<m; j++){ |
| 478 | - if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html); | |
| 479 | - appendDiffLine(pOut, ' ', &A[a+j], html, 0); | |
| 424 | + if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1); | |
| 425 | + appendDiffLine(pOut, ' ', &A[a+j]); | |
| 480 | 426 | } |
| 481 | 427 | a += m; |
| 482 | 428 | b += m; |
| 483 | 429 | |
| 484 | 430 | /* Show the differences */ |
| 485 | 431 | for(i=0; i<nr; i++){ |
| 486 | 432 | m = R[r+i*3+1]; |
| 487 | 433 | for(j=0; j<m; j++){ |
| 488 | - if( showLn ) appendDiffLineno(pOut, a+j+1, 0, html); | |
| 489 | - appendDiffLine(pOut, '-', &A[a+j], html, pRe); | |
| 434 | + if( showLn ) appendDiffLineno(pOut, a+j+1, 0); | |
| 435 | + appendDiffLine(pOut, '-', &A[a+j]); | |
| 490 | 436 | } |
| 491 | 437 | a += m; |
| 492 | 438 | m = R[r+i*3+2]; |
| 493 | 439 | for(j=0; j<m; j++){ |
| 494 | - if( showLn ) appendDiffLineno(pOut, 0, b+j+1, html); | |
| 495 | - appendDiffLine(pOut, '+', &B[b+j], html, pRe); | |
| 440 | + if( showLn ) appendDiffLineno(pOut, 0, b+j+1); | |
| 441 | + appendDiffLine(pOut, '+', &B[b+j]); | |
| 496 | 442 | } |
| 497 | 443 | b += m; |
| 498 | 444 | if( i<nr-1 ){ |
| 499 | 445 | m = R[r+i*3+3]; |
| 500 | 446 | for(j=0; j<m; j++){ |
| 501 | - if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html); | |
| 502 | - appendDiffLine(pOut, ' ', &A[a+j], html, 0); | |
| 447 | + if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1); | |
| 448 | + appendDiffLine(pOut, ' ', &A[a+j]); | |
| 503 | 449 | } |
| 504 | 450 | b += m; |
| 505 | 451 | a += m; |
| 506 | 452 | } |
| 507 | 453 | } |
| @@ -509,15 +455,14 @@ | ||
| 509 | 455 | /* Show the final common area */ |
| 510 | 456 | assert( nr==i ); |
| 511 | 457 | m = R[r+nr*3]; |
| 512 | 458 | if( m>nContext ) m = nContext; |
| 513 | 459 | for(j=0; j<m; j++){ |
| 514 | - if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html); | |
| 515 | - appendDiffLine(pOut, ' ', &A[a+j], html, 0); | |
| 460 | + if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1); | |
| 461 | + appendDiffLine(pOut, ' ', &A[a+j]); | |
| 516 | 462 | } |
| 517 | 463 | } |
| 518 | - if( html ) blob_append(pOut, "</pre>\n", -1); | |
| 519 | 464 | } |
| 520 | 465 | |
| 521 | 466 | /* |
| 522 | 467 | ** Limits for the intra-line diffing. |
| 523 | 468 | */ |
| @@ -3083,11 +3028,11 @@ | ||
| 3083 | 3028 | formatDiff(&c, pRe, diffFlags, pBuilder); |
| 3084 | 3029 | }else if( diffFlags & DIFF_HTML ){ |
| 3085 | 3030 | DiffBuilder *pBuilder = dfunifiedNew(pOut); |
| 3086 | 3031 | formatDiff(&c, pRe, diffFlags, pBuilder); |
| 3087 | 3032 | }else{ |
| 3088 | - contextDiff(&c, pOut, pRe, diffFlags); | |
| 3033 | + contextDiff(&c, pOut, diffFlags); | |
| 3089 | 3034 | } |
| 3090 | 3035 | fossil_free(c.aFrom); |
| 3091 | 3036 | fossil_free(c.aTo); |
| 3092 | 3037 | fossil_free(c.aEdit); |
| 3093 | 3038 | return 0; |
| 3094 | 3039 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -302,41 +302,23 @@ | |
| 302 | ** Append a single line of context-diff output to pOut. |
| 303 | */ |
| 304 | static void appendDiffLine( |
| 305 | Blob *pOut, /* Where to write the line of output */ |
| 306 | char cPrefix, /* One of " ", "+", or "-" */ |
| 307 | DLine *pLine, /* The line to be output */ |
| 308 | int html, /* True if generating HTML. False for plain text */ |
| 309 | ReCompiled *pRe /* Colorize only if line matches this Regex */ |
| 310 | ){ |
| 311 | blob_append(pOut, &cPrefix, 1); |
| 312 | if( html ){ |
| 313 | if( pRe && re_dline_match(pRe, pLine, 1)==0 ){ |
| 314 | cPrefix = ' '; |
| 315 | }else if( cPrefix=='+' ){ |
| 316 | blob_append(pOut, zClassAdd, -1); |
| 317 | }else if( cPrefix=='-' ){ |
| 318 | blob_append(pOut, zClassRm, -1); |
| 319 | } |
| 320 | htmlize_to_blob(pOut, pLine->z, pLine->n); |
| 321 | if( cPrefix!=' ' ){ |
| 322 | blob_append(pOut, "</span>", -1); |
| 323 | } |
| 324 | }else{ |
| 325 | blob_append(pOut, pLine->z, pLine->n); |
| 326 | } |
| 327 | blob_append(pOut, "\n", 1); |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | ** Add two line numbers to the beginning of an output line for a context |
| 332 | ** diff. One or the other of the two numbers might be zero, which means |
| 333 | ** to leave that number field blank. The "html" parameter means to format |
| 334 | ** the output for HTML. |
| 335 | */ |
| 336 | static void appendDiffLineno(Blob *pOut, int lnA, int lnB, int html){ |
| 337 | if( html ) blob_append(pOut, "<span class=\"diffln\">", -1); |
| 338 | if( lnA>0 ){ |
| 339 | blob_appendf(pOut, "%6d ", lnA); |
| 340 | }else{ |
| 341 | blob_append(pOut, " ", 7); |
| 342 | } |
| @@ -343,21 +325,18 @@ | |
| 343 | if( lnB>0 ){ |
| 344 | blob_appendf(pOut, "%6d ", lnB); |
| 345 | }else{ |
| 346 | blob_append(pOut, " ", 8); |
| 347 | } |
| 348 | if( html ) blob_append(pOut, "</span>", -1); |
| 349 | } |
| 350 | |
| 351 | /* |
| 352 | ** Given a raw diff p[] in which the p->aEdit[] array has been filled |
| 353 | ** in, compute a context diff into pOut. |
| 354 | */ |
| 355 | static void contextDiff( |
| 356 | DContext *p, /* The difference */ |
| 357 | Blob *pOut, /* Output a context diff to here */ |
| 358 | ReCompiled *pRe, /* Only show changes that match this regex */ |
| 359 | u64 diffFlags /* Flags controlling the diff format */ |
| 360 | ){ |
| 361 | DLine *A; /* Left side of the diff */ |
| 362 | DLine *B; /* Right side of the diff */ |
| 363 | int a = 0; /* Index of next line in A[] */ |
| @@ -371,17 +350,14 @@ | |
| 371 | int m; /* Number of lines to output */ |
| 372 | int skip; /* Number of lines to skip */ |
| 373 | static int nChunk = 0; /* Number of diff chunks seen so far */ |
| 374 | int nContext; /* Number of lines of context */ |
| 375 | int showLn; /* Show line numbers */ |
| 376 | int html; /* Render as HTML */ |
| 377 | int showDivider = 0; /* True to show the divider between diff blocks */ |
| 378 | |
| 379 | nContext = diff_context_lines(diffFlags); |
| 380 | showLn = (diffFlags & DIFF_LINENO)!=0; |
| 381 | html = (diffFlags & DIFF_HTML)!=0; |
| 382 | if( html ) blob_append(pOut, "<pre class=\"udiff\">\n", -1); |
| 383 | A = p->aFrom; |
| 384 | B = p->aTo; |
| 385 | R = p->aEdit; |
| 386 | mxr = p->nEdit; |
| 387 | while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; } |
| @@ -388,35 +364,10 @@ | |
| 388 | for(r=0; r<mxr; r += 3*nr){ |
| 389 | /* Figure out how many triples to show in a single block */ |
| 390 | for(nr=1; R[r+nr*3]>0 && R[r+nr*3]<nContext*2; nr++){} |
| 391 | /* printf("r=%d nr=%d\n", r, nr); */ |
| 392 | |
| 393 | /* If there is a regex, skip this block (generate no diff output) |
| 394 | ** if the regex matches or does not match both insert and delete. |
| 395 | ** Only display the block if one side matches but the other side does |
| 396 | ** not. |
| 397 | */ |
| 398 | if( pRe ){ |
| 399 | int hideBlock = 1; |
| 400 | int xa = a, xb = b; |
| 401 | for(i=0; hideBlock && i<nr; i++){ |
| 402 | int c1, c2; |
| 403 | xa += R[r+i*3]; |
| 404 | xb += R[r+i*3]; |
| 405 | c1 = re_dline_match(pRe, &A[xa], R[r+i*3+1]); |
| 406 | c2 = re_dline_match(pRe, &B[xb], R[r+i*3+2]); |
| 407 | hideBlock = c1==c2; |
| 408 | xa += R[r+i*3+1]; |
| 409 | xb += R[r+i*3+2]; |
| 410 | } |
| 411 | if( hideBlock ){ |
| 412 | a = xa; |
| 413 | b = xb; |
| 414 | continue; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | /* For the current block comprising nr triples, figure out |
| 419 | ** how many lines of A and B are to be displayed |
| 420 | */ |
| 421 | if( R[r]>nContext ){ |
| 422 | na = nb = nContext; |
| @@ -448,60 +399,55 @@ | |
| 448 | nChunk++; |
| 449 | if( showLn ){ |
| 450 | if( !showDivider ){ |
| 451 | /* Do not show a top divider */ |
| 452 | showDivider = 1; |
| 453 | }else if( html ){ |
| 454 | blob_appendf(pOut, "<span class=\"diffhr\">%.80c</span>\n", '.'); |
| 455 | }else{ |
| 456 | blob_appendf(pOut, "%.80c\n", '.'); |
| 457 | } |
| 458 | if( html ) blob_appendf(pOut, "<span id=\"chunk%d\"></span>", nChunk); |
| 459 | }else{ |
| 460 | if( html ) blob_appendf(pOut, "<span class=\"diffln\">"); |
| 461 | /* |
| 462 | * If the patch changes an empty file or results in an empty file, |
| 463 | * the block header must use 0,0 as position indicator and not 1,0. |
| 464 | * Otherwise, patch would be confused and may reject the diff. |
| 465 | */ |
| 466 | blob_appendf(pOut,"@@ -%d,%d +%d,%d @@", |
| 467 | na ? a+skip+1 : a+skip, na, |
| 468 | nb ? b+skip+1 : b+skip, nb); |
| 469 | if( html ) blob_appendf(pOut, "</span>"); |
| 470 | blob_append(pOut, "\n", 1); |
| 471 | } |
| 472 | |
| 473 | /* Show the initial common area */ |
| 474 | a += skip; |
| 475 | b += skip; |
| 476 | m = R[r] - skip; |
| 477 | for(j=0; j<m; j++){ |
| 478 | if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html); |
| 479 | appendDiffLine(pOut, ' ', &A[a+j], html, 0); |
| 480 | } |
| 481 | a += m; |
| 482 | b += m; |
| 483 | |
| 484 | /* Show the differences */ |
| 485 | for(i=0; i<nr; i++){ |
| 486 | m = R[r+i*3+1]; |
| 487 | for(j=0; j<m; j++){ |
| 488 | if( showLn ) appendDiffLineno(pOut, a+j+1, 0, html); |
| 489 | appendDiffLine(pOut, '-', &A[a+j], html, pRe); |
| 490 | } |
| 491 | a += m; |
| 492 | m = R[r+i*3+2]; |
| 493 | for(j=0; j<m; j++){ |
| 494 | if( showLn ) appendDiffLineno(pOut, 0, b+j+1, html); |
| 495 | appendDiffLine(pOut, '+', &B[b+j], html, pRe); |
| 496 | } |
| 497 | b += m; |
| 498 | if( i<nr-1 ){ |
| 499 | m = R[r+i*3+3]; |
| 500 | for(j=0; j<m; j++){ |
| 501 | if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html); |
| 502 | appendDiffLine(pOut, ' ', &A[a+j], html, 0); |
| 503 | } |
| 504 | b += m; |
| 505 | a += m; |
| 506 | } |
| 507 | } |
| @@ -509,15 +455,14 @@ | |
| 509 | /* Show the final common area */ |
| 510 | assert( nr==i ); |
| 511 | m = R[r+nr*3]; |
| 512 | if( m>nContext ) m = nContext; |
| 513 | for(j=0; j<m; j++){ |
| 514 | if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html); |
| 515 | appendDiffLine(pOut, ' ', &A[a+j], html, 0); |
| 516 | } |
| 517 | } |
| 518 | if( html ) blob_append(pOut, "</pre>\n", -1); |
| 519 | } |
| 520 | |
| 521 | /* |
| 522 | ** Limits for the intra-line diffing. |
| 523 | */ |
| @@ -3083,11 +3028,11 @@ | |
| 3083 | formatDiff(&c, pRe, diffFlags, pBuilder); |
| 3084 | }else if( diffFlags & DIFF_HTML ){ |
| 3085 | DiffBuilder *pBuilder = dfunifiedNew(pOut); |
| 3086 | formatDiff(&c, pRe, diffFlags, pBuilder); |
| 3087 | }else{ |
| 3088 | contextDiff(&c, pOut, pRe, diffFlags); |
| 3089 | } |
| 3090 | fossil_free(c.aFrom); |
| 3091 | fossil_free(c.aTo); |
| 3092 | fossil_free(c.aEdit); |
| 3093 | return 0; |
| 3094 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -302,41 +302,23 @@ | |
| 302 | ** Append a single line of context-diff output to pOut. |
| 303 | */ |
| 304 | static void appendDiffLine( |
| 305 | Blob *pOut, /* Where to write the line of output */ |
| 306 | char cPrefix, /* One of " ", "+", or "-" */ |
| 307 | DLine *pLine /* The line to be output */ |
| 308 | ){ |
| 309 | blob_append_char(pOut, cPrefix); |
| 310 | blob_append(pOut, pLine->z, pLine->n); |
| 311 | blob_append_char(pOut, '\n'); |
| 312 | } |
| 313 | |
| 314 | /* |
| 315 | ** Add two line numbers to the beginning of an output line for a context |
| 316 | ** diff. One or the other of the two numbers might be zero, which means |
| 317 | ** to leave that number field blank. |
| 318 | */ |
| 319 | static void appendDiffLineno(Blob *pOut, int lnA, int lnB){ |
| 320 | if( lnA>0 ){ |
| 321 | blob_appendf(pOut, "%6d ", lnA); |
| 322 | }else{ |
| 323 | blob_append(pOut, " ", 7); |
| 324 | } |
| @@ -343,21 +325,18 @@ | |
| 325 | if( lnB>0 ){ |
| 326 | blob_appendf(pOut, "%6d ", lnB); |
| 327 | }else{ |
| 328 | blob_append(pOut, " ", 8); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | /* |
| 333 | ** Output a patch-style text diff. |
| 334 | */ |
| 335 | static void contextDiff( |
| 336 | DContext *p, /* The difference */ |
| 337 | Blob *pOut, /* Output a context diff to here */ |
| 338 | u64 diffFlags /* Flags controlling the diff format */ |
| 339 | ){ |
| 340 | DLine *A; /* Left side of the diff */ |
| 341 | DLine *B; /* Right side of the diff */ |
| 342 | int a = 0; /* Index of next line in A[] */ |
| @@ -371,17 +350,14 @@ | |
| 350 | int m; /* Number of lines to output */ |
| 351 | int skip; /* Number of lines to skip */ |
| 352 | static int nChunk = 0; /* Number of diff chunks seen so far */ |
| 353 | int nContext; /* Number of lines of context */ |
| 354 | int showLn; /* Show line numbers */ |
| 355 | int showDivider = 0; /* True to show the divider between diff blocks */ |
| 356 | |
| 357 | nContext = diff_context_lines(diffFlags); |
| 358 | showLn = (diffFlags & DIFF_LINENO)!=0; |
| 359 | A = p->aFrom; |
| 360 | B = p->aTo; |
| 361 | R = p->aEdit; |
| 362 | mxr = p->nEdit; |
| 363 | while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; } |
| @@ -388,35 +364,10 @@ | |
| 364 | for(r=0; r<mxr; r += 3*nr){ |
| 365 | /* Figure out how many triples to show in a single block */ |
| 366 | for(nr=1; R[r+nr*3]>0 && R[r+nr*3]<nContext*2; nr++){} |
| 367 | /* printf("r=%d nr=%d\n", r, nr); */ |
| 368 | |
| 369 | /* For the current block comprising nr triples, figure out |
| 370 | ** how many lines of A and B are to be displayed |
| 371 | */ |
| 372 | if( R[r]>nContext ){ |
| 373 | na = nb = nContext; |
| @@ -448,60 +399,55 @@ | |
| 399 | nChunk++; |
| 400 | if( showLn ){ |
| 401 | if( !showDivider ){ |
| 402 | /* Do not show a top divider */ |
| 403 | showDivider = 1; |
| 404 | }else{ |
| 405 | blob_appendf(pOut, "%.80c\n", '.'); |
| 406 | } |
| 407 | }else{ |
| 408 | /* |
| 409 | * If the patch changes an empty file or results in an empty file, |
| 410 | * the block header must use 0,0 as position indicator and not 1,0. |
| 411 | * Otherwise, patch would be confused and may reject the diff. |
| 412 | */ |
| 413 | blob_appendf(pOut,"@@ -%d,%d +%d,%d @@", |
| 414 | na ? a+skip+1 : a+skip, na, |
| 415 | nb ? b+skip+1 : b+skip, nb); |
| 416 | blob_append(pOut, "\n", 1); |
| 417 | } |
| 418 | |
| 419 | /* Show the initial common area */ |
| 420 | a += skip; |
| 421 | b += skip; |
| 422 | m = R[r] - skip; |
| 423 | for(j=0; j<m; j++){ |
| 424 | if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1); |
| 425 | appendDiffLine(pOut, ' ', &A[a+j]); |
| 426 | } |
| 427 | a += m; |
| 428 | b += m; |
| 429 | |
| 430 | /* Show the differences */ |
| 431 | for(i=0; i<nr; i++){ |
| 432 | m = R[r+i*3+1]; |
| 433 | for(j=0; j<m; j++){ |
| 434 | if( showLn ) appendDiffLineno(pOut, a+j+1, 0); |
| 435 | appendDiffLine(pOut, '-', &A[a+j]); |
| 436 | } |
| 437 | a += m; |
| 438 | m = R[r+i*3+2]; |
| 439 | for(j=0; j<m; j++){ |
| 440 | if( showLn ) appendDiffLineno(pOut, 0, b+j+1); |
| 441 | appendDiffLine(pOut, '+', &B[b+j]); |
| 442 | } |
| 443 | b += m; |
| 444 | if( i<nr-1 ){ |
| 445 | m = R[r+i*3+3]; |
| 446 | for(j=0; j<m; j++){ |
| 447 | if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1); |
| 448 | appendDiffLine(pOut, ' ', &A[a+j]); |
| 449 | } |
| 450 | b += m; |
| 451 | a += m; |
| 452 | } |
| 453 | } |
| @@ -509,15 +455,14 @@ | |
| 455 | /* Show the final common area */ |
| 456 | assert( nr==i ); |
| 457 | m = R[r+nr*3]; |
| 458 | if( m>nContext ) m = nContext; |
| 459 | for(j=0; j<m; j++){ |
| 460 | if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1); |
| 461 | appendDiffLine(pOut, ' ', &A[a+j]); |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | /* |
| 467 | ** Limits for the intra-line diffing. |
| 468 | */ |
| @@ -3083,11 +3028,11 @@ | |
| 3028 | formatDiff(&c, pRe, diffFlags, pBuilder); |
| 3029 | }else if( diffFlags & DIFF_HTML ){ |
| 3030 | DiffBuilder *pBuilder = dfunifiedNew(pOut); |
| 3031 | formatDiff(&c, pRe, diffFlags, pBuilder); |
| 3032 | }else{ |
| 3033 | contextDiff(&c, pOut, diffFlags); |
| 3034 | } |
| 3035 | fossil_free(c.aFrom); |
| 3036 | fossil_free(c.aTo); |
| 3037 | fossil_free(c.aEdit); |
| 3038 | return 0; |
| 3039 |