Fossil SCM

Simplify the interface to the internal diff_file() routine.

drh 2021-09-07 12:18 trunk
Commit db034a5a6c799031f5864f37e3f000c2fd0547ea6c319a93e850a5d4c9c8dd44
2 files changed +4 -19 +3 -3
+4 -19
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -399,27 +399,16 @@
399399
/*
400400
** Show the difference between two files, one in memory and one on disk.
401401
**
402402
** The difference is the set of edits needed to transform pFile1 into
403403
** 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.
414404
*/
415405
void diff_file(
416406
Blob *pFile1, /* In memory content to compare from */
417407
const char *zFile2, /* On disk content to compare to */
418408
const char *zName, /* Display name of the file */
419409
DiffConfig *pCfg, /* Flags to control the diff */
420
- int fSwapDiff, /* Diff from Zfile2 to Pfile1 */
421410
Blob *diffBlob /* Blob to store diff output */
422411
){
423412
if( pCfg->zDiffCmd==0 ){
424413
Blob out; /* Diff output text */
425414
Blob file2; /* Content of zFile2 */
@@ -439,15 +428,11 @@
439428
if( blob_compare(pFile1, &file2) ){
440429
fossil_print("CHANGED %s\n", zName);
441430
}
442431
}else{
443432
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);
449434
if( blob_size(&out) ){
450435
if( pCfg->diffFlags & DIFF_NUMSTAT ){
451436
if( !diffBlob ){
452437
fossil_print("%s %s\n", blob_str(&out), zName);
453438
}else{
@@ -504,11 +489,11 @@
504489
blob_write_to_file(pFile1, blob_str(&nameFile1));
505490
506491
/* Construct the external diff command */
507492
blob_zero(&cmd);
508493
blob_append(&cmd, pCfg->zDiffCmd, -1);
509
- if( fSwapDiff ){
494
+ if( pCfg->diffFlags & DIFF_INVERT ){
510495
blob_append_escaped_arg(&cmd, zFile2, 1);
511496
blob_append_escaped_arg(&cmd, blob_str(&nameFile1), 1);
512497
}else{
513498
blob_append_escaped_arg(&cmd, blob_str(&nameFile1), 1);
514499
blob_append_escaped_arg(&cmd, zFile2, 1);
@@ -723,11 +708,11 @@
723708
content_get(srcid, &content);
724709
}else{
725710
blob_zero(&content);
726711
}
727712
diff_print_index(zPathname, pCfg, diffBlob);
728
- diff_file(&content, zFullName, zPathname, pCfg, 0, diffBlob);
713
+ diff_file(&content, zFullName, zPathname, pCfg, diffBlob);
729714
blob_reset(&content);
730715
}
731716
blob_reset(&fname);
732717
}
733718
db_finalize(&q);
@@ -756,11 +741,11 @@
756741
char *zFullName;
757742
const char *zFile = (const char*)db_column_text(&q, 0);
758743
if( !file_dir_match(pFileDir, zFile) ) continue;
759744
zFullName = mprintf("%s%s", g.zLocalRoot, zFile);
760745
db_column_blob(&q, 1, &content);
761
- diff_file(&content, zFullName, zFile, pCfg, 0, 0);
746
+ diff_file(&content, zFullName, zFile, pCfg, 0);
762747
fossil_free(zFullName);
763748
blob_reset(&content);
764749
}
765750
db_finalize(&q);
766751
}
767752
--- 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 @@
450450
content_get(rid, &a);
451451
blob_delta_apply(&a, &delta, &b);
452452
if( fBaseline ){
453453
diff_file_mem(&a, &b, zNew, pCfg);
454454
}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;
458458
}
459459
blob_reset(&a);
460460
blob_reset(&b);
461461
}
462462
blob_reset(&delta);
463463
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button