Fossil SCM
Simplify the interface to the internal diff_file() routine.
Commit
db034a5a6c799031f5864f37e3f000c2fd0547ea6c319a93e850a5d4c9c8dd44
Parent
4ef3ba374cb0749…
2 files changed
+4
-19
+3
-3
+4
-19
| --- src/diffcmd.c | ||
| +++ src/diffcmd.c | ||
| @@ -399,27 +399,16 @@ | ||
| 399 | 399 | /* |
| 400 | 400 | ** Show the difference between two files, one in memory and one on disk. |
| 401 | 401 | ** |
| 402 | 402 | ** The difference is the set of edits needed to transform pFile1 into |
| 403 | 403 | ** zFile2. The content of pFile1 is in memory. zFile2 exists on disk. |
| 404 | -** | |
| 405 | -** If fSwapDiff is 1, show the set of edits to transform zFile2 into pFile1 | |
| 406 | -** instead of the opposite. | |
| 407 | -** | |
| 408 | -** Use the internal diff logic if zDiffCmd is NULL. Otherwise call the | |
| 409 | -** command zDiffCmd to do the diffing. | |
| 410 | -** | |
| 411 | -** When using an external diff program, zBinGlob contains the GLOB patterns | |
| 412 | -** for file names to treat as binary. If fIncludeBinary is zero, these files | |
| 413 | -** will be skipped in addition to files that may contain binary content. | |
| 414 | 404 | */ |
| 415 | 405 | void diff_file( |
| 416 | 406 | Blob *pFile1, /* In memory content to compare from */ |
| 417 | 407 | const char *zFile2, /* On disk content to compare to */ |
| 418 | 408 | const char *zName, /* Display name of the file */ |
| 419 | 409 | DiffConfig *pCfg, /* Flags to control the diff */ |
| 420 | - int fSwapDiff, /* Diff from Zfile2 to Pfile1 */ | |
| 421 | 410 | Blob *diffBlob /* Blob to store diff output */ |
| 422 | 411 | ){ |
| 423 | 412 | if( pCfg->zDiffCmd==0 ){ |
| 424 | 413 | Blob out; /* Diff output text */ |
| 425 | 414 | Blob file2; /* Content of zFile2 */ |
| @@ -439,15 +428,11 @@ | ||
| 439 | 428 | if( blob_compare(pFile1, &file2) ){ |
| 440 | 429 | fossil_print("CHANGED %s\n", zName); |
| 441 | 430 | } |
| 442 | 431 | }else{ |
| 443 | 432 | blob_zero(&out); |
| 444 | - if( fSwapDiff ){ | |
| 445 | - text_diff(&file2, pFile1, &out, pCfg); | |
| 446 | - }else{ | |
| 447 | - text_diff(pFile1, &file2, &out, pCfg); | |
| 448 | - } | |
| 433 | + text_diff(pFile1, &file2, &out, pCfg); | |
| 449 | 434 | if( blob_size(&out) ){ |
| 450 | 435 | if( pCfg->diffFlags & DIFF_NUMSTAT ){ |
| 451 | 436 | if( !diffBlob ){ |
| 452 | 437 | fossil_print("%s %s\n", blob_str(&out), zName); |
| 453 | 438 | }else{ |
| @@ -504,11 +489,11 @@ | ||
| 504 | 489 | blob_write_to_file(pFile1, blob_str(&nameFile1)); |
| 505 | 490 | |
| 506 | 491 | /* Construct the external diff command */ |
| 507 | 492 | blob_zero(&cmd); |
| 508 | 493 | blob_append(&cmd, pCfg->zDiffCmd, -1); |
| 509 | - if( fSwapDiff ){ | |
| 494 | + if( pCfg->diffFlags & DIFF_INVERT ){ | |
| 510 | 495 | blob_append_escaped_arg(&cmd, zFile2, 1); |
| 511 | 496 | blob_append_escaped_arg(&cmd, blob_str(&nameFile1), 1); |
| 512 | 497 | }else{ |
| 513 | 498 | blob_append_escaped_arg(&cmd, blob_str(&nameFile1), 1); |
| 514 | 499 | blob_append_escaped_arg(&cmd, zFile2, 1); |
| @@ -723,11 +708,11 @@ | ||
| 723 | 708 | content_get(srcid, &content); |
| 724 | 709 | }else{ |
| 725 | 710 | blob_zero(&content); |
| 726 | 711 | } |
| 727 | 712 | diff_print_index(zPathname, pCfg, diffBlob); |
| 728 | - diff_file(&content, zFullName, zPathname, pCfg, 0, diffBlob); | |
| 713 | + diff_file(&content, zFullName, zPathname, pCfg, diffBlob); | |
| 729 | 714 | blob_reset(&content); |
| 730 | 715 | } |
| 731 | 716 | blob_reset(&fname); |
| 732 | 717 | } |
| 733 | 718 | db_finalize(&q); |
| @@ -756,11 +741,11 @@ | ||
| 756 | 741 | char *zFullName; |
| 757 | 742 | const char *zFile = (const char*)db_column_text(&q, 0); |
| 758 | 743 | if( !file_dir_match(pFileDir, zFile) ) continue; |
| 759 | 744 | zFullName = mprintf("%s%s", g.zLocalRoot, zFile); |
| 760 | 745 | db_column_blob(&q, 1, &content); |
| 761 | - diff_file(&content, zFullName, zFile, pCfg, 0, 0); | |
| 746 | + diff_file(&content, zFullName, zFile, pCfg, 0); | |
| 762 | 747 | fossil_free(zFullName); |
| 763 | 748 | blob_reset(&content); |
| 764 | 749 | } |
| 765 | 750 | db_finalize(&q); |
| 766 | 751 | } |
| 767 | 752 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -399,27 +399,16 @@ | |
| 399 | /* |
| 400 | ** Show the difference between two files, one in memory and one on disk. |
| 401 | ** |
| 402 | ** The difference is the set of edits needed to transform pFile1 into |
| 403 | ** zFile2. The content of pFile1 is in memory. zFile2 exists on disk. |
| 404 | ** |
| 405 | ** If fSwapDiff is 1, show the set of edits to transform zFile2 into pFile1 |
| 406 | ** instead of the opposite. |
| 407 | ** |
| 408 | ** Use the internal diff logic if zDiffCmd is NULL. Otherwise call the |
| 409 | ** command zDiffCmd to do the diffing. |
| 410 | ** |
| 411 | ** When using an external diff program, zBinGlob contains the GLOB patterns |
| 412 | ** for file names to treat as binary. If fIncludeBinary is zero, these files |
| 413 | ** will be skipped in addition to files that may contain binary content. |
| 414 | */ |
| 415 | void diff_file( |
| 416 | Blob *pFile1, /* In memory content to compare from */ |
| 417 | const char *zFile2, /* On disk content to compare to */ |
| 418 | const char *zName, /* Display name of the file */ |
| 419 | DiffConfig *pCfg, /* Flags to control the diff */ |
| 420 | int fSwapDiff, /* Diff from Zfile2 to Pfile1 */ |
| 421 | Blob *diffBlob /* Blob to store diff output */ |
| 422 | ){ |
| 423 | if( pCfg->zDiffCmd==0 ){ |
| 424 | Blob out; /* Diff output text */ |
| 425 | Blob file2; /* Content of zFile2 */ |
| @@ -439,15 +428,11 @@ | |
| 439 | if( blob_compare(pFile1, &file2) ){ |
| 440 | fossil_print("CHANGED %s\n", zName); |
| 441 | } |
| 442 | }else{ |
| 443 | blob_zero(&out); |
| 444 | if( fSwapDiff ){ |
| 445 | text_diff(&file2, pFile1, &out, pCfg); |
| 446 | }else{ |
| 447 | text_diff(pFile1, &file2, &out, pCfg); |
| 448 | } |
| 449 | if( blob_size(&out) ){ |
| 450 | if( pCfg->diffFlags & DIFF_NUMSTAT ){ |
| 451 | if( !diffBlob ){ |
| 452 | fossil_print("%s %s\n", blob_str(&out), zName); |
| 453 | }else{ |
| @@ -504,11 +489,11 @@ | |
| 504 | blob_write_to_file(pFile1, blob_str(&nameFile1)); |
| 505 | |
| 506 | /* Construct the external diff command */ |
| 507 | blob_zero(&cmd); |
| 508 | blob_append(&cmd, pCfg->zDiffCmd, -1); |
| 509 | if( fSwapDiff ){ |
| 510 | blob_append_escaped_arg(&cmd, zFile2, 1); |
| 511 | blob_append_escaped_arg(&cmd, blob_str(&nameFile1), 1); |
| 512 | }else{ |
| 513 | blob_append_escaped_arg(&cmd, blob_str(&nameFile1), 1); |
| 514 | blob_append_escaped_arg(&cmd, zFile2, 1); |
| @@ -723,11 +708,11 @@ | |
| 723 | content_get(srcid, &content); |
| 724 | }else{ |
| 725 | blob_zero(&content); |
| 726 | } |
| 727 | diff_print_index(zPathname, pCfg, diffBlob); |
| 728 | diff_file(&content, zFullName, zPathname, pCfg, 0, diffBlob); |
| 729 | blob_reset(&content); |
| 730 | } |
| 731 | blob_reset(&fname); |
| 732 | } |
| 733 | db_finalize(&q); |
| @@ -756,11 +741,11 @@ | |
| 756 | char *zFullName; |
| 757 | const char *zFile = (const char*)db_column_text(&q, 0); |
| 758 | if( !file_dir_match(pFileDir, zFile) ) continue; |
| 759 | zFullName = mprintf("%s%s", g.zLocalRoot, zFile); |
| 760 | db_column_blob(&q, 1, &content); |
| 761 | diff_file(&content, zFullName, zFile, pCfg, 0, 0); |
| 762 | fossil_free(zFullName); |
| 763 | blob_reset(&content); |
| 764 | } |
| 765 | db_finalize(&q); |
| 766 | } |
| 767 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -399,27 +399,16 @@ | |
| 399 | /* |
| 400 | ** Show the difference between two files, one in memory and one on disk. |
| 401 | ** |
| 402 | ** The difference is the set of edits needed to transform pFile1 into |
| 403 | ** zFile2. The content of pFile1 is in memory. zFile2 exists on disk. |
| 404 | */ |
| 405 | void diff_file( |
| 406 | Blob *pFile1, /* In memory content to compare from */ |
| 407 | const char *zFile2, /* On disk content to compare to */ |
| 408 | const char *zName, /* Display name of the file */ |
| 409 | DiffConfig *pCfg, /* Flags to control the diff */ |
| 410 | Blob *diffBlob /* Blob to store diff output */ |
| 411 | ){ |
| 412 | if( pCfg->zDiffCmd==0 ){ |
| 413 | Blob out; /* Diff output text */ |
| 414 | Blob file2; /* Content of zFile2 */ |
| @@ -439,15 +428,11 @@ | |
| 428 | if( blob_compare(pFile1, &file2) ){ |
| 429 | fossil_print("CHANGED %s\n", zName); |
| 430 | } |
| 431 | }else{ |
| 432 | blob_zero(&out); |
| 433 | text_diff(pFile1, &file2, &out, pCfg); |
| 434 | if( blob_size(&out) ){ |
| 435 | if( pCfg->diffFlags & DIFF_NUMSTAT ){ |
| 436 | if( !diffBlob ){ |
| 437 | fossil_print("%s %s\n", blob_str(&out), zName); |
| 438 | }else{ |
| @@ -504,11 +489,11 @@ | |
| 489 | blob_write_to_file(pFile1, blob_str(&nameFile1)); |
| 490 | |
| 491 | /* Construct the external diff command */ |
| 492 | blob_zero(&cmd); |
| 493 | blob_append(&cmd, pCfg->zDiffCmd, -1); |
| 494 | if( pCfg->diffFlags & DIFF_INVERT ){ |
| 495 | blob_append_escaped_arg(&cmd, zFile2, 1); |
| 496 | blob_append_escaped_arg(&cmd, blob_str(&nameFile1), 1); |
| 497 | }else{ |
| 498 | blob_append_escaped_arg(&cmd, blob_str(&nameFile1), 1); |
| 499 | blob_append_escaped_arg(&cmd, zFile2, 1); |
| @@ -723,11 +708,11 @@ | |
| 708 | content_get(srcid, &content); |
| 709 | }else{ |
| 710 | blob_zero(&content); |
| 711 | } |
| 712 | diff_print_index(zPathname, pCfg, diffBlob); |
| 713 | diff_file(&content, zFullName, zPathname, pCfg, diffBlob); |
| 714 | blob_reset(&content); |
| 715 | } |
| 716 | blob_reset(&fname); |
| 717 | } |
| 718 | db_finalize(&q); |
| @@ -756,11 +741,11 @@ | |
| 741 | char *zFullName; |
| 742 | const char *zFile = (const char*)db_column_text(&q, 0); |
| 743 | if( !file_dir_match(pFileDir, zFile) ) continue; |
| 744 | zFullName = mprintf("%s%s", g.zLocalRoot, zFile); |
| 745 | db_column_blob(&q, 1, &content); |
| 746 | diff_file(&content, zFullName, zFile, pCfg, 0); |
| 747 | fossil_free(zFullName); |
| 748 | blob_reset(&content); |
| 749 | } |
| 750 | db_finalize(&q); |
| 751 | } |
| 752 |
+3
-3
| --- src/stash.c | ||
| +++ src/stash.c | ||
| @@ -450,13 +450,13 @@ | ||
| 450 | 450 | content_get(rid, &a); |
| 451 | 451 | blob_delta_apply(&a, &delta, &b); |
| 452 | 452 | if( fBaseline ){ |
| 453 | 453 | diff_file_mem(&a, &b, zNew, pCfg); |
| 454 | 454 | }else{ |
| 455 | - /*Diff with file on disk using fSwapDiff=1 to show the diff in the | |
| 456 | - same direction as if fBaseline=1.*/ | |
| 457 | - diff_file(&b, zOPath, zNew, pCfg, 1, 0); | |
| 455 | + pCfg->diffFlags ^= DIFF_INVERT; | |
| 456 | + diff_file(&b, zOPath, zNew, pCfg, 0); | |
| 457 | + pCfg->diffFlags ^= DIFF_INVERT; | |
| 458 | 458 | } |
| 459 | 459 | blob_reset(&a); |
| 460 | 460 | blob_reset(&b); |
| 461 | 461 | } |
| 462 | 462 | blob_reset(&delta); |
| 463 | 463 |
| --- src/stash.c | |
| +++ src/stash.c | |
| @@ -450,13 +450,13 @@ | |
| 450 | content_get(rid, &a); |
| 451 | blob_delta_apply(&a, &delta, &b); |
| 452 | if( fBaseline ){ |
| 453 | diff_file_mem(&a, &b, zNew, pCfg); |
| 454 | }else{ |
| 455 | /*Diff with file on disk using fSwapDiff=1 to show the diff in the |
| 456 | same direction as if fBaseline=1.*/ |
| 457 | diff_file(&b, zOPath, zNew, pCfg, 1, 0); |
| 458 | } |
| 459 | blob_reset(&a); |
| 460 | blob_reset(&b); |
| 461 | } |
| 462 | blob_reset(&delta); |
| 463 |
| --- src/stash.c | |
| +++ src/stash.c | |
| @@ -450,13 +450,13 @@ | |
| 450 | content_get(rid, &a); |
| 451 | blob_delta_apply(&a, &delta, &b); |
| 452 | if( fBaseline ){ |
| 453 | diff_file_mem(&a, &b, zNew, pCfg); |
| 454 | }else{ |
| 455 | pCfg->diffFlags ^= DIFF_INVERT; |
| 456 | diff_file(&b, zOPath, zNew, pCfg, 0); |
| 457 | pCfg->diffFlags ^= DIFF_INVERT; |
| 458 | } |
| 459 | blob_reset(&a); |
| 460 | blob_reset(&b); |
| 461 | } |
| 462 | blob_reset(&delta); |
| 463 |