Fossil SCM

Better fix for the case of doing a "fossil diff" on a checkout that includes a merge and specifying a --from clause that is the branch that was merged from.

drh 2021-10-19 19:25 trunk
Commit 960c9e8bd69531ebca9664afadd49326b1d336c877bdd7253eae000e6d5203c6
1 file changed +23 -2
+23 -2
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -551,10 +551,29 @@
551551
blob_reset(&temp1);
552552
blob_reset(&temp2);
553553
blob_reset(&cmd);
554554
}
555555
}
556
+
557
+/*
558
+** Return true the disk file is identical to the Blob. Return zero
559
+** if the files differ in any way.
560
+*/
561
+static int file_same_as_blob(Blob *blob, const char *zDiskFile){
562
+ Blob file;
563
+ int rc = 0;
564
+ if( blob_size(blob)!=file_size(zDiskFile, ExtFILE) ) return 0;
565
+ blob_zero(&file);
566
+ blob_read_from_file(&file, zDiskFile, ExtFILE);
567
+ if( blob_size(&file)!=blob_size(blob) ){
568
+ rc = 0;
569
+ }else{
570
+ rc = memcmp(blob_buffer(&file), blob_buffer(blob), blob_size(&file))==0;
571
+ }
572
+ blob_reset(&file);
573
+ return rc;
574
+}
556575
557576
/*
558577
** Run a diff between the version zFrom and files on disk. zFrom might
559578
** be NULL which means to simply show the difference between the edited
560579
** files on disk and the check-out on which they are based.
@@ -672,12 +691,14 @@
672691
if( srcid>0 ){
673692
content_get(srcid, &content);
674693
}else{
675694
blob_zero(&content);
676695
}
677
- diff_print_index(zPathname, pCfg, pOut);
678
- diff_file(&content, zFullName, zPathname, pCfg, pOut);
696
+ if( isChnged==0 || !file_same_as_blob(&content, zFullName) ){
697
+ diff_print_index(zPathname, pCfg, pOut);
698
+ diff_file(&content, zFullName, zPathname, pCfg, pOut);
699
+ }
679700
blob_reset(&content);
680701
}
681702
blob_reset(&fname);
682703
}
683704
db_finalize(&q);
684705
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -551,10 +551,29 @@
551 blob_reset(&temp1);
552 blob_reset(&temp2);
553 blob_reset(&cmd);
554 }
555 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
556
557 /*
558 ** Run a diff between the version zFrom and files on disk. zFrom might
559 ** be NULL which means to simply show the difference between the edited
560 ** files on disk and the check-out on which they are based.
@@ -672,12 +691,14 @@
672 if( srcid>0 ){
673 content_get(srcid, &content);
674 }else{
675 blob_zero(&content);
676 }
677 diff_print_index(zPathname, pCfg, pOut);
678 diff_file(&content, zFullName, zPathname, pCfg, pOut);
 
 
679 blob_reset(&content);
680 }
681 blob_reset(&fname);
682 }
683 db_finalize(&q);
684
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -551,10 +551,29 @@
551 blob_reset(&temp1);
552 blob_reset(&temp2);
553 blob_reset(&cmd);
554 }
555 }
556
557 /*
558 ** Return true the disk file is identical to the Blob. Return zero
559 ** if the files differ in any way.
560 */
561 static int file_same_as_blob(Blob *blob, const char *zDiskFile){
562 Blob file;
563 int rc = 0;
564 if( blob_size(blob)!=file_size(zDiskFile, ExtFILE) ) return 0;
565 blob_zero(&file);
566 blob_read_from_file(&file, zDiskFile, ExtFILE);
567 if( blob_size(&file)!=blob_size(blob) ){
568 rc = 0;
569 }else{
570 rc = memcmp(blob_buffer(&file), blob_buffer(blob), blob_size(&file))==0;
571 }
572 blob_reset(&file);
573 return rc;
574 }
575
576 /*
577 ** Run a diff between the version zFrom and files on disk. zFrom might
578 ** be NULL which means to simply show the difference between the edited
579 ** files on disk and the check-out on which they are based.
@@ -672,12 +691,14 @@
691 if( srcid>0 ){
692 content_get(srcid, &content);
693 }else{
694 blob_zero(&content);
695 }
696 if( isChnged==0 || !file_same_as_blob(&content, zFullName) ){
697 diff_print_index(zPathname, pCfg, pOut);
698 diff_file(&content, zFullName, zPathname, pCfg, pOut);
699 }
700 blob_reset(&content);
701 }
702 blob_reset(&fname);
703 }
704 db_finalize(&q);
705

Keyboard Shortcuts

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