Fossil SCM
Improvements to the side-by-side diff display for indentation changes with minor edits.
Commit
c4bbc4a9afcc35dcf43087b552732748215922c1
Parent
4cf8c16cd82f160…
1 file changed
+45
-20
+45
-20
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -797,10 +797,41 @@ | ||
| 797 | 797 | } |
| 798 | 798 | } |
| 799 | 799 | } |
| 800 | 800 | return rc; |
| 801 | 801 | } |
| 802 | + | |
| 803 | +/* | |
| 804 | +** Try to shift iStart as far as possible to the left. | |
| 805 | +*/ | |
| 806 | +static void sbsShiftLeft(SbsLine *p, const char *z){ | |
| 807 | + int i, j; | |
| 808 | + while( (i=p->iStart)>0 && z[i-1]==z[i] ){ | |
| 809 | + for(j=i+1; j<p->iEnd && z[j-1]==z[j]; j++){} | |
| 810 | + if( j<p->iEnd ) break; | |
| 811 | + p->iStart--; | |
| 812 | + p->iEnd--; | |
| 813 | + } | |
| 814 | +} | |
| 815 | + | |
| 816 | +/* | |
| 817 | +** Simplify iStart and iStart2: | |
| 818 | +** | |
| 819 | +** * If iStart is a null-change then move iStart2 into iStart | |
| 820 | +** * Make sure any null-changes are in canonoical form. | |
| 821 | +*/ | |
| 822 | +static void sbsSimplifyLine(SbsLine *p){ | |
| 823 | + if( p->iStart2==p->iEnd2 ) p->iStart2 = p->iEnd2 = 0; | |
| 824 | + if( p->iStart==p->iEnd ){ | |
| 825 | + p->iStart = p->iStart2; | |
| 826 | + p->iEnd = p->iEnd2; | |
| 827 | + p->zStart = p->zStart2; | |
| 828 | + p->iStart2 = 0; | |
| 829 | + p->iEnd2 = 0; | |
| 830 | + } | |
| 831 | + if( p->iStart==p->iEnd ) p->iStart = p->iEnd = -1; | |
| 832 | +} | |
| 802 | 833 | |
| 803 | 834 | /* |
| 804 | 835 | ** Write out lines that have been edited. Adjust the highlight to cover |
| 805 | 836 | ** only those parts of the line that actually changed. |
| 806 | 837 | */ |
| @@ -891,41 +922,35 @@ | ||
| 891 | 922 | && textLCS(&zLeft[nPrefix], nLeftDiff, &zRight[nPrefix], nRightDiff, aLCS) |
| 892 | 923 | ){ |
| 893 | 924 | sbsWriteLineno(p, lnLeft); |
| 894 | 925 | p->iStart = nPrefix; |
| 895 | 926 | p->iEnd = nPrefix + aLCS[0]; |
| 896 | - p->zStart = aLCS[2]==0 ? zClassRm : zClassChng; | |
| 927 | + if( aLCS[2]==0 ){ | |
| 928 | + sbsShiftLeft(p, pLeft->z); | |
| 929 | + p->zStart = zClassRm; | |
| 930 | + }else{ | |
| 931 | + p->zStart = zClassChng; | |
| 932 | + } | |
| 897 | 933 | p->iStart2 = nPrefix + aLCS[1]; |
| 898 | 934 | p->iEnd2 = nLeft - nSuffix; |
| 899 | 935 | p->zStart2 = aLCS[3]==nRightDiff ? zClassRm : zClassChng; |
| 900 | - if( p->iStart2==p->iEnd2 ) p->iStart2 = p->iEnd2 = 0; | |
| 901 | - if( p->iStart==p->iEnd ){ | |
| 902 | - p->iStart = p->iStart2; | |
| 903 | - p->iEnd = p->iEnd2; | |
| 904 | - p->zStart = p->zStart2; | |
| 905 | - p->iStart2 = 0; | |
| 906 | - p->iEnd2 = 0; | |
| 907 | - } | |
| 908 | - if( p->iStart==p->iEnd ) p->iStart = p->iEnd = -1; | |
| 936 | + sbsSimplifyLine(p); | |
| 909 | 937 | sbsWriteText(p, pLeft, SBS_PAD); |
| 910 | 938 | sbsWrite(p, " | ", 3); |
| 911 | 939 | sbsWriteLineno(p, lnRight); |
| 912 | 940 | p->iStart = nPrefix; |
| 913 | 941 | p->iEnd = nPrefix + aLCS[2]; |
| 914 | - p->zStart = aLCS[0]==0 ? zClassAdd : zClassChng; | |
| 942 | + if( aLCS[0]==0 ){ | |
| 943 | + sbsShiftLeft(p, pRight->z); | |
| 944 | + p->zStart = zClassAdd; | |
| 945 | + }else{ | |
| 946 | + p->zStart = zClassChng; | |
| 947 | + } | |
| 915 | 948 | p->iStart2 = nPrefix + aLCS[3]; |
| 916 | 949 | p->iEnd2 = nRight - nSuffix; |
| 917 | 950 | p->zStart2 = aLCS[1]==nLeftDiff ? zClassAdd : zClassChng; |
| 918 | - if( p->iStart2==p->iEnd2 ) p->iStart2 = p->iEnd2 = 0; | |
| 919 | - if( p->iStart==p->iEnd ){ | |
| 920 | - p->iStart = p->iStart2; | |
| 921 | - p->iEnd = p->iEnd2; | |
| 922 | - p->zStart = p->zStart2; | |
| 923 | - p->iStart2 = 0; | |
| 924 | - p->iEnd2 = 0; | |
| 925 | - } | |
| 926 | - if( p->iStart==p->iEnd ) p->iStart = p->iEnd = -1; | |
| 951 | + sbsSimplifyLine(p); | |
| 927 | 952 | sbsWriteText(p, pRight, SBS_NEWLINE); |
| 928 | 953 | return; |
| 929 | 954 | } |
| 930 | 955 | |
| 931 | 956 | /* If all else fails, show a single big change between left and right */ |
| 932 | 957 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -797,10 +797,41 @@ | |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | return rc; |
| 801 | } |
| 802 | |
| 803 | /* |
| 804 | ** Write out lines that have been edited. Adjust the highlight to cover |
| 805 | ** only those parts of the line that actually changed. |
| 806 | */ |
| @@ -891,41 +922,35 @@ | |
| 891 | && textLCS(&zLeft[nPrefix], nLeftDiff, &zRight[nPrefix], nRightDiff, aLCS) |
| 892 | ){ |
| 893 | sbsWriteLineno(p, lnLeft); |
| 894 | p->iStart = nPrefix; |
| 895 | p->iEnd = nPrefix + aLCS[0]; |
| 896 | p->zStart = aLCS[2]==0 ? zClassRm : zClassChng; |
| 897 | p->iStart2 = nPrefix + aLCS[1]; |
| 898 | p->iEnd2 = nLeft - nSuffix; |
| 899 | p->zStart2 = aLCS[3]==nRightDiff ? zClassRm : zClassChng; |
| 900 | if( p->iStart2==p->iEnd2 ) p->iStart2 = p->iEnd2 = 0; |
| 901 | if( p->iStart==p->iEnd ){ |
| 902 | p->iStart = p->iStart2; |
| 903 | p->iEnd = p->iEnd2; |
| 904 | p->zStart = p->zStart2; |
| 905 | p->iStart2 = 0; |
| 906 | p->iEnd2 = 0; |
| 907 | } |
| 908 | if( p->iStart==p->iEnd ) p->iStart = p->iEnd = -1; |
| 909 | sbsWriteText(p, pLeft, SBS_PAD); |
| 910 | sbsWrite(p, " | ", 3); |
| 911 | sbsWriteLineno(p, lnRight); |
| 912 | p->iStart = nPrefix; |
| 913 | p->iEnd = nPrefix + aLCS[2]; |
| 914 | p->zStart = aLCS[0]==0 ? zClassAdd : zClassChng; |
| 915 | p->iStart2 = nPrefix + aLCS[3]; |
| 916 | p->iEnd2 = nRight - nSuffix; |
| 917 | p->zStart2 = aLCS[1]==nLeftDiff ? zClassAdd : zClassChng; |
| 918 | if( p->iStart2==p->iEnd2 ) p->iStart2 = p->iEnd2 = 0; |
| 919 | if( p->iStart==p->iEnd ){ |
| 920 | p->iStart = p->iStart2; |
| 921 | p->iEnd = p->iEnd2; |
| 922 | p->zStart = p->zStart2; |
| 923 | p->iStart2 = 0; |
| 924 | p->iEnd2 = 0; |
| 925 | } |
| 926 | if( p->iStart==p->iEnd ) p->iStart = p->iEnd = -1; |
| 927 | sbsWriteText(p, pRight, SBS_NEWLINE); |
| 928 | return; |
| 929 | } |
| 930 | |
| 931 | /* If all else fails, show a single big change between left and right */ |
| 932 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -797,10 +797,41 @@ | |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | return rc; |
| 801 | } |
| 802 | |
| 803 | /* |
| 804 | ** Try to shift iStart as far as possible to the left. |
| 805 | */ |
| 806 | static void sbsShiftLeft(SbsLine *p, const char *z){ |
| 807 | int i, j; |
| 808 | while( (i=p->iStart)>0 && z[i-1]==z[i] ){ |
| 809 | for(j=i+1; j<p->iEnd && z[j-1]==z[j]; j++){} |
| 810 | if( j<p->iEnd ) break; |
| 811 | p->iStart--; |
| 812 | p->iEnd--; |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | /* |
| 817 | ** Simplify iStart and iStart2: |
| 818 | ** |
| 819 | ** * If iStart is a null-change then move iStart2 into iStart |
| 820 | ** * Make sure any null-changes are in canonoical form. |
| 821 | */ |
| 822 | static void sbsSimplifyLine(SbsLine *p){ |
| 823 | if( p->iStart2==p->iEnd2 ) p->iStart2 = p->iEnd2 = 0; |
| 824 | if( p->iStart==p->iEnd ){ |
| 825 | p->iStart = p->iStart2; |
| 826 | p->iEnd = p->iEnd2; |
| 827 | p->zStart = p->zStart2; |
| 828 | p->iStart2 = 0; |
| 829 | p->iEnd2 = 0; |
| 830 | } |
| 831 | if( p->iStart==p->iEnd ) p->iStart = p->iEnd = -1; |
| 832 | } |
| 833 | |
| 834 | /* |
| 835 | ** Write out lines that have been edited. Adjust the highlight to cover |
| 836 | ** only those parts of the line that actually changed. |
| 837 | */ |
| @@ -891,41 +922,35 @@ | |
| 922 | && textLCS(&zLeft[nPrefix], nLeftDiff, &zRight[nPrefix], nRightDiff, aLCS) |
| 923 | ){ |
| 924 | sbsWriteLineno(p, lnLeft); |
| 925 | p->iStart = nPrefix; |
| 926 | p->iEnd = nPrefix + aLCS[0]; |
| 927 | if( aLCS[2]==0 ){ |
| 928 | sbsShiftLeft(p, pLeft->z); |
| 929 | p->zStart = zClassRm; |
| 930 | }else{ |
| 931 | p->zStart = zClassChng; |
| 932 | } |
| 933 | p->iStart2 = nPrefix + aLCS[1]; |
| 934 | p->iEnd2 = nLeft - nSuffix; |
| 935 | p->zStart2 = aLCS[3]==nRightDiff ? zClassRm : zClassChng; |
| 936 | sbsSimplifyLine(p); |
| 937 | sbsWriteText(p, pLeft, SBS_PAD); |
| 938 | sbsWrite(p, " | ", 3); |
| 939 | sbsWriteLineno(p, lnRight); |
| 940 | p->iStart = nPrefix; |
| 941 | p->iEnd = nPrefix + aLCS[2]; |
| 942 | if( aLCS[0]==0 ){ |
| 943 | sbsShiftLeft(p, pRight->z); |
| 944 | p->zStart = zClassAdd; |
| 945 | }else{ |
| 946 | p->zStart = zClassChng; |
| 947 | } |
| 948 | p->iStart2 = nPrefix + aLCS[3]; |
| 949 | p->iEnd2 = nRight - nSuffix; |
| 950 | p->zStart2 = aLCS[1]==nLeftDiff ? zClassAdd : zClassChng; |
| 951 | sbsSimplifyLine(p); |
| 952 | sbsWriteText(p, pRight, SBS_NEWLINE); |
| 953 | return; |
| 954 | } |
| 955 | |
| 956 | /* If all else fails, show a single big change between left and right */ |
| 957 |