Fossil SCM
Improvements to the diff algorithm. See [forum:/forumpost/515e0d43425d7164|forum thread 515e0d43425d7164] for discussion.
Commit
a45c7f0a560a90541967f790c4b5e03db754e511299312f842b95a67f1db3f25
Parent
a8b6fdc83e8b539…
2 files changed
+2
-2
+18
+2
-2
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -422,11 +422,11 @@ | ||
| 422 | 422 | R = p->aEdit; |
| 423 | 423 | mxr = p->nEdit; |
| 424 | 424 | while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; } |
| 425 | 425 | for(r=0; r<mxr; r += 3*nr){ |
| 426 | 426 | /* Figure out how many triples to show in a single block */ |
| 427 | - for(nr=1; R[r+nr*3]>0 && R[r+nr*3]<nContext*2; nr++){} | |
| 427 | + for(nr=1; 3*nr<mxr && R[r+nr*3]>0 && R[r+nr*3]<(int)nContext*2; nr++){} | |
| 428 | 428 | /* printf("r=%d nr=%d\n", r, nr); */ |
| 429 | 429 | |
| 430 | 430 | /* For the current block comprising nr triples, figure out |
| 431 | 431 | ** how many lines of A and B are to be displayed |
| 432 | 432 | */ |
| @@ -2223,11 +2223,11 @@ | ||
| 2223 | 2223 | mxr = p->nEdit; |
| 2224 | 2224 | while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; } |
| 2225 | 2225 | |
| 2226 | 2226 | for(r=0; r<mxr; r += 3*nr){ |
| 2227 | 2227 | /* Figure out how many triples to show in a single block */ |
| 2228 | - for(nr=1; R[r+nr*3]>0 && R[r+nr*3]<(int)nContext*2; nr++){} | |
| 2228 | + for(nr=1; 3*nr<mxr && R[r+nr*3]>0 && R[r+nr*3]<(int)nContext*2; nr++){} | |
| 2229 | 2229 | |
| 2230 | 2230 | /* If there is a regex, skip this block (generate no diff output) |
| 2231 | 2231 | ** if the regex matches or does not match both insert and delete. |
| 2232 | 2232 | ** Only display the block if one side matches but the other side does |
| 2233 | 2233 | ** not. |
| 2234 | 2234 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -422,11 +422,11 @@ | |
| 422 | R = p->aEdit; |
| 423 | mxr = p->nEdit; |
| 424 | while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; } |
| 425 | for(r=0; r<mxr; r += 3*nr){ |
| 426 | /* Figure out how many triples to show in a single block */ |
| 427 | for(nr=1; R[r+nr*3]>0 && R[r+nr*3]<nContext*2; nr++){} |
| 428 | /* printf("r=%d nr=%d\n", r, nr); */ |
| 429 | |
| 430 | /* For the current block comprising nr triples, figure out |
| 431 | ** how many lines of A and B are to be displayed |
| 432 | */ |
| @@ -2223,11 +2223,11 @@ | |
| 2223 | mxr = p->nEdit; |
| 2224 | while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; } |
| 2225 | |
| 2226 | for(r=0; r<mxr; r += 3*nr){ |
| 2227 | /* Figure out how many triples to show in a single block */ |
| 2228 | for(nr=1; R[r+nr*3]>0 && R[r+nr*3]<(int)nContext*2; nr++){} |
| 2229 | |
| 2230 | /* If there is a regex, skip this block (generate no diff output) |
| 2231 | ** if the regex matches or does not match both insert and delete. |
| 2232 | ** Only display the block if one side matches but the other side does |
| 2233 | ** not. |
| 2234 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -422,11 +422,11 @@ | |
| 422 | R = p->aEdit; |
| 423 | mxr = p->nEdit; |
| 424 | while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; } |
| 425 | for(r=0; r<mxr; r += 3*nr){ |
| 426 | /* Figure out how many triples to show in a single block */ |
| 427 | for(nr=1; 3*nr<mxr && R[r+nr*3]>0 && R[r+nr*3]<(int)nContext*2; nr++){} |
| 428 | /* printf("r=%d nr=%d\n", r, nr); */ |
| 429 | |
| 430 | /* For the current block comprising nr triples, figure out |
| 431 | ** how many lines of A and B are to be displayed |
| 432 | */ |
| @@ -2223,11 +2223,11 @@ | |
| 2223 | mxr = p->nEdit; |
| 2224 | while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; } |
| 2225 | |
| 2226 | for(r=0; r<mxr; r += 3*nr){ |
| 2227 | /* Figure out how many triples to show in a single block */ |
| 2228 | for(nr=1; 3*nr<mxr && R[r+nr*3]>0 && R[r+nr*3]<(int)nContext*2; nr++){} |
| 2229 | |
| 2230 | /* If there is a regex, skip this block (generate no diff output) |
| 2231 | ** if the regex matches or does not match both insert and delete. |
| 2232 | ** Only display the block if one side matches but the other side does |
| 2233 | ** not. |
| 2234 |
+18
| --- test/diff.test | ||
| +++ test/diff.test | ||
| @@ -108,9 +108,27 @@ | ||
| 108 | 108 | test diff-file5-1 {[normalize_result] eq {Index: file5.dat |
| 109 | 109 | ================================================================== |
| 110 | 110 | --- file5.dat |
| 111 | 111 | +++ file5.dat |
| 112 | 112 | cannot compute difference between binary files}} |
| 113 | + | |
| 114 | +############################################################################### | |
| 115 | + | |
| 116 | +write_file file6a.dat "{\n \"abc\": {\n \"def\": false,\n \"ghi\": false\n }\n}\n" | |
| 117 | +write_file file6b.dat "{\n \"abc\": {\n \"def\": false,\n \"ghi\": false\n },\n \"jkl\": {\n \"mno\": {\n \"pqr\": false\n }\n }\n}\n" | |
| 118 | +fossil xdiff -y -W 16 file6a.dat file6b.dat | |
| 119 | +test diff-file-6-1 {[normalize_result] eq {========== file6a.dat ===== versus ===== file6b.dat ===== | |
| 120 | + 1 { 1 { | |
| 121 | + 2 "abc": { 2 "abc": { | |
| 122 | + 3 "def": false, 3 "def": false, | |
| 123 | + 4 "ghi": false 4 "ghi": false | |
| 124 | + > 5 }, | |
| 125 | + > 6 "jkl": { | |
| 126 | + > 7 "mno": { | |
| 127 | + > 8 "pqr": false | |
| 128 | + > 9 } | |
| 129 | + 5 } 10 } | |
| 130 | + 6 } 11 }}} | |
| 113 | 131 | |
| 114 | 132 | ############################################################################### |
| 115 | 133 | |
| 116 | 134 | test_cleanup |
| 117 | 135 |
| --- test/diff.test | |
| +++ test/diff.test | |
| @@ -108,9 +108,27 @@ | |
| 108 | test diff-file5-1 {[normalize_result] eq {Index: file5.dat |
| 109 | ================================================================== |
| 110 | --- file5.dat |
| 111 | +++ file5.dat |
| 112 | cannot compute difference between binary files}} |
| 113 | |
| 114 | ############################################################################### |
| 115 | |
| 116 | test_cleanup |
| 117 |
| --- test/diff.test | |
| +++ test/diff.test | |
| @@ -108,9 +108,27 @@ | |
| 108 | test diff-file5-1 {[normalize_result] eq {Index: file5.dat |
| 109 | ================================================================== |
| 110 | --- file5.dat |
| 111 | +++ file5.dat |
| 112 | cannot compute difference between binary files}} |
| 113 | |
| 114 | ############################################################################### |
| 115 | |
| 116 | write_file file6a.dat "{\n \"abc\": {\n \"def\": false,\n \"ghi\": false\n }\n}\n" |
| 117 | write_file file6b.dat "{\n \"abc\": {\n \"def\": false,\n \"ghi\": false\n },\n \"jkl\": {\n \"mno\": {\n \"pqr\": false\n }\n }\n}\n" |
| 118 | fossil xdiff -y -W 16 file6a.dat file6b.dat |
| 119 | test diff-file-6-1 {[normalize_result] eq {========== file6a.dat ===== versus ===== file6b.dat ===== |
| 120 | 1 { 1 { |
| 121 | 2 "abc": { 2 "abc": { |
| 122 | 3 "def": false, 3 "def": false, |
| 123 | 4 "ghi": false 4 "ghi": false |
| 124 | > 5 }, |
| 125 | > 6 "jkl": { |
| 126 | > 7 "mno": { |
| 127 | > 8 "pqr": false |
| 128 | > 9 } |
| 129 | 5 } 10 } |
| 130 | 6 } 11 }}} |
| 131 | |
| 132 | ############################################################################### |
| 133 | |
| 134 | test_cleanup |
| 135 |