Fossil SCM

Identical lines in diff output should never use the "|" comparison mark.

drh 2021-09-05 22:58 trunk
Commit 99f93d9231c604434446f7b617c70b45ebb357cd2d26fdc2c6f79a4364c8fdde
1 file changed +20 -16
+20 -16
--- src/diff.c
+++ src/diff.c
@@ -253,11 +253,11 @@
253253
}
254254
255255
/*
256256
** Return zero if two DLine elements are identical.
257257
*/
258
-static int same_dline(const DLine *pA, const DLine *pB){
258
+static int compare_dline(const DLine *pA, const DLine *pB){
259259
if( pA->h!=pB->h ) return 1;
260260
return memcmp(pA->z,pB->z, pA->h&LENGTH_MASK);
261261
}
262262
263263
/*
@@ -264,11 +264,11 @@
264264
** Return zero if two DLine elements are identical, ignoring
265265
** all whitespace. The indent field of pA/pB already points
266266
** to the first non-space character in the string.
267267
*/
268268
269
-static int same_dline_ignore_allws(const DLine *pA, const DLine *pB){
269
+static int compare_dline_ignore_allws(const DLine *pA, const DLine *pB){
270270
int a = pA->indent, b = pB->indent;
271271
if( pA->h==pB->h ){
272272
while( a<pA->n || b<pB->n ){
273273
if( a<pA->n && b<pB->n && pA->z[a++] != pB->z[b++] ) return 1;
274274
while( a<pA->n && fossil_isspace(pA->z[a])) ++a;
@@ -890,11 +890,11 @@
890890
blob_appendf(p->pOut, "INSERT %8d %.*s\n",
891891
p->lnRight, (int)pLine->n, pLine->z);
892892
}
893893
static void dfdebugDelete(DiffBuilder *p, const DLine *pLine){
894894
p->lnLeft++;
895
- blob_appendf(p->pOut, "DELETE %8u %.*s\n",
895
+ blob_appendf(p->pOut, "DELETE %8u %.*s\n",
896896
p->lnLeft, (int)pLine->n, pLine->z);
897897
}
898898
static void dfdebugReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
899899
p->lnLeft++;
900900
p->lnRight++;
@@ -907,41 +907,43 @@
907907
int i, j;
908908
int x;
909909
LineChange chng;
910910
p->lnLeft++;
911911
p->lnRight++;
912
- blob_appendf(p->pOut, "EDIT %8u %.*s\n",
912
+ blob_appendf(p->pOut, "EDIT %8u %.*s\n",
913913
p->lnLeft, (int)pX->n, pX->z);
914914
oneLineChange(pX, pY, &chng);
915915
for(i=x=0; i<chng.n; i++){
916916
int ofst = chng.a[i].iStart1;
917917
int len = chng.a[i].iLen1;
918918
if( len ){
919
- if( x==0 ){ blob_appendf(p->pOut, "%*s", 25, ""); }
919
+ char c = '0' + i;
920
+ if( x==0 ){ blob_appendf(p->pOut, "%*s", 26, ""); }
920921
while( ofst > x ){
921922
if( (pX->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, ' ');
922923
x++;
923924
}
924925
for(j=0; j<len; j++, x++){
925
- if( (pX->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, '^');
926
+ if( (pX->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, c);
926927
}
927928
}
928929
}
929930
if( x ) blob_append_char(p->pOut, '\n');
930
- blob_appendf(p->pOut, " %8u %.*s\n",
931
+ blob_appendf(p->pOut, " %8u %.*s\n",
931932
p->lnRight, (int)pY->n, pY->z);
932933
for(i=x=0; i<chng.n; i++){
933934
int ofst = chng.a[i].iStart2;
934935
int len = chng.a[i].iLen2;
935936
if( len ){
936
- if( x==0 ){ blob_appendf(p->pOut, "%*s", 25, ""); }
937
+ char c = '0' + i;
938
+ if( x==0 ){ blob_appendf(p->pOut, "%*s", 26, ""); }
937939
while( ofst > x ){
938940
if( (pY->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, ' ');
939941
x++;
940942
}
941943
for(j=0; j<len; j++, x++){
942
- if( (pY->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, '^');
944
+ if( (pY->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, c);
943945
}
944946
}
945947
}
946948
if( x ) blob_append_char(p->pOut, '\n');
947949
}
@@ -1210,12 +1212,10 @@
12101212
}
12111213
static void dfunifiedStartRow(DiffBuilder *p){
12121214
if( blob_size(&p->aCol[0])>0 ) return;
12131215
blob_appendf(p->pOut,"<tr id=\"chunk%d\">"
12141216
"<td class=\"diffln difflnl\"><pre>\n", ++nChunk);
1215
- p->eState = 0;
1216
- p->nPending = 0;
12171217
}
12181218
static void dfunifiedSkip(DiffBuilder *p, unsigned int n, int isFinal){
12191219
dfunifiedFinishRow(p);
12201220
blob_append(p->pOut, "<tr><td class=\"diffln difflne\">"
12211221
"&#xfe19;</td><td></td><td></td></tr>\n", -1);
@@ -2072,11 +2072,15 @@
20722072
b++;
20732073
break;
20742074
}
20752075
case 3: {
20762076
/* The left line is changed into the right line */
2077
- pBuilder->xEdit(pBuilder, &A[a], &B[b]);
2077
+ if( compare_dline(&A[a], &B[b])==0 ){
2078
+ pBuilder->xCommon(pBuilder, &A[a]);
2079
+ }else{
2080
+ pBuilder->xEdit(pBuilder, &A[a], &B[b]);
2081
+ }
20782082
assert( ma>0 && mb>0 );
20792083
ma--;
20802084
mb--;
20812085
a++;
20822086
b++;
@@ -2603,13 +2607,13 @@
26032607
blob_to_utf8_no_bom(pB_Blob, 0);
26042608
26052609
/* Prepare the input files */
26062610
memset(&c, 0, sizeof(c));
26072611
if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
2608
- c.xDiffer = same_dline_ignore_allws;
2612
+ c.xDiffer = compare_dline_ignore_allws;
26092613
}else{
2610
- c.xDiffer = same_dline;
2614
+ c.xDiffer = compare_dline;
26112615
}
26122616
c.aFrom = break_into_lines(blob_str(pA_Blob), blob_size(pA_Blob),
26132617
&c.nFrom, diffFlags);
26142618
c.aTo = break_into_lines(blob_str(pB_Blob), blob_size(pB_Blob),
26152619
&c.nTo, diffFlags);
@@ -2870,13 +2874,13 @@
28702874
static int annotation_start(Annotator *p, Blob *pInput, u64 diffFlags){
28712875
int i;
28722876
28732877
memset(p, 0, sizeof(*p));
28742878
if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
2875
- p->c.xDiffer = same_dline_ignore_allws;
2879
+ p->c.xDiffer = compare_dline_ignore_allws;
28762880
}else{
2877
- p->c.xDiffer = same_dline;
2881
+ p->c.xDiffer = compare_dline;
28782882
}
28792883
p->c.aTo = break_into_lines(blob_str(pInput), blob_size(pInput),&p->c.nTo,
28802884
diffFlags);
28812885
if( p->c.aTo==0 ){
28822886
return 1;
28832887
--- src/diff.c
+++ src/diff.c
@@ -253,11 +253,11 @@
253 }
254
255 /*
256 ** Return zero if two DLine elements are identical.
257 */
258 static int same_dline(const DLine *pA, const DLine *pB){
259 if( pA->h!=pB->h ) return 1;
260 return memcmp(pA->z,pB->z, pA->h&LENGTH_MASK);
261 }
262
263 /*
@@ -264,11 +264,11 @@
264 ** Return zero if two DLine elements are identical, ignoring
265 ** all whitespace. The indent field of pA/pB already points
266 ** to the first non-space character in the string.
267 */
268
269 static int same_dline_ignore_allws(const DLine *pA, const DLine *pB){
270 int a = pA->indent, b = pB->indent;
271 if( pA->h==pB->h ){
272 while( a<pA->n || b<pB->n ){
273 if( a<pA->n && b<pB->n && pA->z[a++] != pB->z[b++] ) return 1;
274 while( a<pA->n && fossil_isspace(pA->z[a])) ++a;
@@ -890,11 +890,11 @@
890 blob_appendf(p->pOut, "INSERT %8d %.*s\n",
891 p->lnRight, (int)pLine->n, pLine->z);
892 }
893 static void dfdebugDelete(DiffBuilder *p, const DLine *pLine){
894 p->lnLeft++;
895 blob_appendf(p->pOut, "DELETE %8u %.*s\n",
896 p->lnLeft, (int)pLine->n, pLine->z);
897 }
898 static void dfdebugReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
899 p->lnLeft++;
900 p->lnRight++;
@@ -907,41 +907,43 @@
907 int i, j;
908 int x;
909 LineChange chng;
910 p->lnLeft++;
911 p->lnRight++;
912 blob_appendf(p->pOut, "EDIT %8u %.*s\n",
913 p->lnLeft, (int)pX->n, pX->z);
914 oneLineChange(pX, pY, &chng);
915 for(i=x=0; i<chng.n; i++){
916 int ofst = chng.a[i].iStart1;
917 int len = chng.a[i].iLen1;
918 if( len ){
919 if( x==0 ){ blob_appendf(p->pOut, "%*s", 25, ""); }
 
920 while( ofst > x ){
921 if( (pX->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, ' ');
922 x++;
923 }
924 for(j=0; j<len; j++, x++){
925 if( (pX->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, '^');
926 }
927 }
928 }
929 if( x ) blob_append_char(p->pOut, '\n');
930 blob_appendf(p->pOut, " %8u %.*s\n",
931 p->lnRight, (int)pY->n, pY->z);
932 for(i=x=0; i<chng.n; i++){
933 int ofst = chng.a[i].iStart2;
934 int len = chng.a[i].iLen2;
935 if( len ){
936 if( x==0 ){ blob_appendf(p->pOut, "%*s", 25, ""); }
 
937 while( ofst > x ){
938 if( (pY->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, ' ');
939 x++;
940 }
941 for(j=0; j<len; j++, x++){
942 if( (pY->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, '^');
943 }
944 }
945 }
946 if( x ) blob_append_char(p->pOut, '\n');
947 }
@@ -1210,12 +1212,10 @@
1210 }
1211 static void dfunifiedStartRow(DiffBuilder *p){
1212 if( blob_size(&p->aCol[0])>0 ) return;
1213 blob_appendf(p->pOut,"<tr id=\"chunk%d\">"
1214 "<td class=\"diffln difflnl\"><pre>\n", ++nChunk);
1215 p->eState = 0;
1216 p->nPending = 0;
1217 }
1218 static void dfunifiedSkip(DiffBuilder *p, unsigned int n, int isFinal){
1219 dfunifiedFinishRow(p);
1220 blob_append(p->pOut, "<tr><td class=\"diffln difflne\">"
1221 "&#xfe19;</td><td></td><td></td></tr>\n", -1);
@@ -2072,11 +2072,15 @@
2072 b++;
2073 break;
2074 }
2075 case 3: {
2076 /* The left line is changed into the right line */
2077 pBuilder->xEdit(pBuilder, &A[a], &B[b]);
 
 
 
 
2078 assert( ma>0 && mb>0 );
2079 ma--;
2080 mb--;
2081 a++;
2082 b++;
@@ -2603,13 +2607,13 @@
2603 blob_to_utf8_no_bom(pB_Blob, 0);
2604
2605 /* Prepare the input files */
2606 memset(&c, 0, sizeof(c));
2607 if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
2608 c.xDiffer = same_dline_ignore_allws;
2609 }else{
2610 c.xDiffer = same_dline;
2611 }
2612 c.aFrom = break_into_lines(blob_str(pA_Blob), blob_size(pA_Blob),
2613 &c.nFrom, diffFlags);
2614 c.aTo = break_into_lines(blob_str(pB_Blob), blob_size(pB_Blob),
2615 &c.nTo, diffFlags);
@@ -2870,13 +2874,13 @@
2870 static int annotation_start(Annotator *p, Blob *pInput, u64 diffFlags){
2871 int i;
2872
2873 memset(p, 0, sizeof(*p));
2874 if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
2875 p->c.xDiffer = same_dline_ignore_allws;
2876 }else{
2877 p->c.xDiffer = same_dline;
2878 }
2879 p->c.aTo = break_into_lines(blob_str(pInput), blob_size(pInput),&p->c.nTo,
2880 diffFlags);
2881 if( p->c.aTo==0 ){
2882 return 1;
2883
--- src/diff.c
+++ src/diff.c
@@ -253,11 +253,11 @@
253 }
254
255 /*
256 ** Return zero if two DLine elements are identical.
257 */
258 static int compare_dline(const DLine *pA, const DLine *pB){
259 if( pA->h!=pB->h ) return 1;
260 return memcmp(pA->z,pB->z, pA->h&LENGTH_MASK);
261 }
262
263 /*
@@ -264,11 +264,11 @@
264 ** Return zero if two DLine elements are identical, ignoring
265 ** all whitespace. The indent field of pA/pB already points
266 ** to the first non-space character in the string.
267 */
268
269 static int compare_dline_ignore_allws(const DLine *pA, const DLine *pB){
270 int a = pA->indent, b = pB->indent;
271 if( pA->h==pB->h ){
272 while( a<pA->n || b<pB->n ){
273 if( a<pA->n && b<pB->n && pA->z[a++] != pB->z[b++] ) return 1;
274 while( a<pA->n && fossil_isspace(pA->z[a])) ++a;
@@ -890,11 +890,11 @@
890 blob_appendf(p->pOut, "INSERT %8d %.*s\n",
891 p->lnRight, (int)pLine->n, pLine->z);
892 }
893 static void dfdebugDelete(DiffBuilder *p, const DLine *pLine){
894 p->lnLeft++;
895 blob_appendf(p->pOut, "DELETE %8u %.*s\n",
896 p->lnLeft, (int)pLine->n, pLine->z);
897 }
898 static void dfdebugReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
899 p->lnLeft++;
900 p->lnRight++;
@@ -907,41 +907,43 @@
907 int i, j;
908 int x;
909 LineChange chng;
910 p->lnLeft++;
911 p->lnRight++;
912 blob_appendf(p->pOut, "EDIT %8u %.*s\n",
913 p->lnLeft, (int)pX->n, pX->z);
914 oneLineChange(pX, pY, &chng);
915 for(i=x=0; i<chng.n; i++){
916 int ofst = chng.a[i].iStart1;
917 int len = chng.a[i].iLen1;
918 if( len ){
919 char c = '0' + i;
920 if( x==0 ){ blob_appendf(p->pOut, "%*s", 26, ""); }
921 while( ofst > x ){
922 if( (pX->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, ' ');
923 x++;
924 }
925 for(j=0; j<len; j++, x++){
926 if( (pX->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, c);
927 }
928 }
929 }
930 if( x ) blob_append_char(p->pOut, '\n');
931 blob_appendf(p->pOut, " %8u %.*s\n",
932 p->lnRight, (int)pY->n, pY->z);
933 for(i=x=0; i<chng.n; i++){
934 int ofst = chng.a[i].iStart2;
935 int len = chng.a[i].iLen2;
936 if( len ){
937 char c = '0' + i;
938 if( x==0 ){ blob_appendf(p->pOut, "%*s", 26, ""); }
939 while( ofst > x ){
940 if( (pY->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, ' ');
941 x++;
942 }
943 for(j=0; j<len; j++, x++){
944 if( (pY->z[x]&0xc0)!=0x80 ) blob_append_char(p->pOut, c);
945 }
946 }
947 }
948 if( x ) blob_append_char(p->pOut, '\n');
949 }
@@ -1210,12 +1212,10 @@
1212 }
1213 static void dfunifiedStartRow(DiffBuilder *p){
1214 if( blob_size(&p->aCol[0])>0 ) return;
1215 blob_appendf(p->pOut,"<tr id=\"chunk%d\">"
1216 "<td class=\"diffln difflnl\"><pre>\n", ++nChunk);
 
 
1217 }
1218 static void dfunifiedSkip(DiffBuilder *p, unsigned int n, int isFinal){
1219 dfunifiedFinishRow(p);
1220 blob_append(p->pOut, "<tr><td class=\"diffln difflne\">"
1221 "&#xfe19;</td><td></td><td></td></tr>\n", -1);
@@ -2072,11 +2072,15 @@
2072 b++;
2073 break;
2074 }
2075 case 3: {
2076 /* The left line is changed into the right line */
2077 if( compare_dline(&A[a], &B[b])==0 ){
2078 pBuilder->xCommon(pBuilder, &A[a]);
2079 }else{
2080 pBuilder->xEdit(pBuilder, &A[a], &B[b]);
2081 }
2082 assert( ma>0 && mb>0 );
2083 ma--;
2084 mb--;
2085 a++;
2086 b++;
@@ -2603,13 +2607,13 @@
2607 blob_to_utf8_no_bom(pB_Blob, 0);
2608
2609 /* Prepare the input files */
2610 memset(&c, 0, sizeof(c));
2611 if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
2612 c.xDiffer = compare_dline_ignore_allws;
2613 }else{
2614 c.xDiffer = compare_dline;
2615 }
2616 c.aFrom = break_into_lines(blob_str(pA_Blob), blob_size(pA_Blob),
2617 &c.nFrom, diffFlags);
2618 c.aTo = break_into_lines(blob_str(pB_Blob), blob_size(pB_Blob),
2619 &c.nTo, diffFlags);
@@ -2870,13 +2874,13 @@
2874 static int annotation_start(Annotator *p, Blob *pInput, u64 diffFlags){
2875 int i;
2876
2877 memset(p, 0, sizeof(*p));
2878 if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
2879 p->c.xDiffer = compare_dline_ignore_allws;
2880 }else{
2881 p->c.xDiffer = compare_dline;
2882 }
2883 p->c.aTo = break_into_lines(blob_str(pInput), blob_size(pInput),&p->c.nTo,
2884 diffFlags);
2885 if( p->c.aTo==0 ){
2886 return 1;
2887

Keyboard Shortcuts

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