Fossil SCM

Improved highlighting of changes in the color-coded side-by-side diff.

drh 2015-11-04 17:51 trunk
Commit 81cae7feac47eeca65905e23ed1acad29acc33c1
1 file changed +34 -1
+34 -1
--- src/diff.c
+++ src/diff.c
@@ -789,11 +789,44 @@
789789
if( nSuffix<nShort ){
790790
while( nSuffix>0 && (zLeft[nLeft-nSuffix]&0xc0)==0x80 ) nSuffix--;
791791
}
792792
if( nSuffix==nLeft || nSuffix==nRight ) nPrefix = 0;
793793
}
794
- if( nPrefix+nSuffix > nShort ) nPrefix = nShort - nSuffix;
794
+
795
+ /* If the prefix and suffix overlap, that means that we are dealing with
796
+ ** a pure insertion or deletion of text that can have multiple alignments.
797
+ ** Try to find an alignment to begins and ends on whitespace, or on
798
+ ** punctuation, rather than in the middle of a name or number.
799
+ */
800
+ if( nPrefix+nSuffix > nShort ){
801
+ int iBest = -1;
802
+ int iBestVal = -1;
803
+ int i;
804
+ int nLong = nLeft<nRight ? nRight : nLeft;
805
+ int nGap = nLong - nShort;
806
+ for(i=nShort-nSuffix; i<=nPrefix; i++){
807
+ int iVal = 0;
808
+ char c = zLeft[i];
809
+ if( fossil_isspace(c) ){
810
+ iVal += 5;
811
+ }else if( !fossil_isalnum(c) ){
812
+ iVal += 2;
813
+ }
814
+ c = zLeft[i+nGap-1];
815
+ if( fossil_isspace(c) ){
816
+ iVal += 5;
817
+ }else if( !fossil_isalnum(c) ){
818
+ iVal += 2;
819
+ }
820
+ if( iVal>iBestVal ){
821
+ iBestVal = iVal;
822
+ iBest = i;
823
+ }
824
+ }
825
+ nPrefix = iBest;
826
+ nSuffix = nShort - nPrefix;
827
+ }
795828
796829
/* A single chunk of text inserted on the right */
797830
if( nPrefix+nSuffix==nLeft ){
798831
sbsWriteLineno(p, lnLeft, SBS_LNA);
799832
p->iStart2 = p->iEnd2 = 0;
800833
--- src/diff.c
+++ src/diff.c
@@ -789,11 +789,44 @@
789 if( nSuffix<nShort ){
790 while( nSuffix>0 && (zLeft[nLeft-nSuffix]&0xc0)==0x80 ) nSuffix--;
791 }
792 if( nSuffix==nLeft || nSuffix==nRight ) nPrefix = 0;
793 }
794 if( nPrefix+nSuffix > nShort ) nPrefix = nShort - nSuffix;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
795
796 /* A single chunk of text inserted on the right */
797 if( nPrefix+nSuffix==nLeft ){
798 sbsWriteLineno(p, lnLeft, SBS_LNA);
799 p->iStart2 = p->iEnd2 = 0;
800
--- src/diff.c
+++ src/diff.c
@@ -789,11 +789,44 @@
789 if( nSuffix<nShort ){
790 while( nSuffix>0 && (zLeft[nLeft-nSuffix]&0xc0)==0x80 ) nSuffix--;
791 }
792 if( nSuffix==nLeft || nSuffix==nRight ) nPrefix = 0;
793 }
794
795 /* If the prefix and suffix overlap, that means that we are dealing with
796 ** a pure insertion or deletion of text that can have multiple alignments.
797 ** Try to find an alignment to begins and ends on whitespace, or on
798 ** punctuation, rather than in the middle of a name or number.
799 */
800 if( nPrefix+nSuffix > nShort ){
801 int iBest = -1;
802 int iBestVal = -1;
803 int i;
804 int nLong = nLeft<nRight ? nRight : nLeft;
805 int nGap = nLong - nShort;
806 for(i=nShort-nSuffix; i<=nPrefix; i++){
807 int iVal = 0;
808 char c = zLeft[i];
809 if( fossil_isspace(c) ){
810 iVal += 5;
811 }else if( !fossil_isalnum(c) ){
812 iVal += 2;
813 }
814 c = zLeft[i+nGap-1];
815 if( fossil_isspace(c) ){
816 iVal += 5;
817 }else if( !fossil_isalnum(c) ){
818 iVal += 2;
819 }
820 if( iVal>iBestVal ){
821 iBestVal = iVal;
822 iBest = i;
823 }
824 }
825 nPrefix = iBest;
826 nSuffix = nShort - nPrefix;
827 }
828
829 /* A single chunk of text inserted on the right */
830 if( nPrefix+nSuffix==nLeft ){
831 sbsWriteLineno(p, lnLeft, SBS_LNA);
832 p->iStart2 = p->iEnd2 = 0;
833

Keyboard Shortcuts

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