Fossil SCM
Fix off-by-one line numbers in the context-diff display. Improvements to the formatting of context-diff displays.
Commit
56ad4ac7aecf1de5c0799b0905acb7abe55bad0b
Parent
ecf30837d417c03…
1 file changed
+19
-9
+19
-9
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -295,44 +295,54 @@ | ||
| 295 | 295 | /* |
| 296 | 296 | * If the patch changes an empty file or results in an empty file, |
| 297 | 297 | * the block header must use 0,0 as position indicator and not 1,0. |
| 298 | 298 | * Otherwise, patch would be confused and may reject the diff. |
| 299 | 299 | */ |
| 300 | - if( showLn ) blob_appendf(pOut, "%*s", 15, ""); | |
| 301 | - blob_appendf(pOut,"@@ -%d,%d +%d,%d @@\n", | |
| 302 | - na ? a+skip+1 : 0, na, | |
| 303 | - nb ? b+skip+1 : 0, nb); | |
| 300 | + if( showLn ){ | |
| 301 | + if( html ){ | |
| 302 | + blob_appendf(pOut, "<span class=\"diffhr\">%.80c</span>\n", '.'); | |
| 303 | + }else{ | |
| 304 | + blob_appendf(pOut, "%.80c\n", '.'); | |
| 305 | + } | |
| 306 | + }else{ | |
| 307 | + if( html ) blob_appendf(pOut, "<span class=\"diffln\">"); | |
| 308 | + blob_appendf(pOut,"@@ -%d,%d +%d,%d @@", | |
| 309 | + na ? a+skip+1 : 0, na, | |
| 310 | + nb ? b+skip+1 : 0, nb); | |
| 311 | + if( html ) blob_appendf(pOut, "</span>"); | |
| 312 | + blob_append(pOut, "\n", 1); | |
| 313 | + } | |
| 304 | 314 | |
| 305 | 315 | /* Show the initial common area */ |
| 306 | 316 | a += skip; |
| 307 | 317 | b += skip; |
| 308 | 318 | m = R[r] - skip; |
| 309 | 319 | for(j=0; j<m; j++){ |
| 310 | - if( showLn ) appendDiffLineno(pOut, a+j, b+j, html); | |
| 320 | + if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html); | |
| 311 | 321 | appendDiffLine(pOut, ' ', &A[a+j], html); |
| 312 | 322 | } |
| 313 | 323 | a += m; |
| 314 | 324 | b += m; |
| 315 | 325 | |
| 316 | 326 | /* Show the differences */ |
| 317 | 327 | for(i=0; i<nr; i++){ |
| 318 | 328 | m = R[r+i*3+1]; |
| 319 | 329 | for(j=0; j<m; j++){ |
| 320 | - if( showLn ) appendDiffLineno(pOut, a+j, 0, html); | |
| 330 | + if( showLn ) appendDiffLineno(pOut, a+j+1, 0, html); | |
| 321 | 331 | appendDiffLine(pOut, '-', &A[a+j], html); |
| 322 | 332 | } |
| 323 | 333 | a += m; |
| 324 | 334 | m = R[r+i*3+2]; |
| 325 | 335 | for(j=0; j<m; j++){ |
| 326 | - if( showLn ) appendDiffLineno(pOut, 0, b+j, html); | |
| 336 | + if( showLn ) appendDiffLineno(pOut, 0, b+j+1, html); | |
| 327 | 337 | appendDiffLine(pOut, '+', &B[b+j], html); |
| 328 | 338 | } |
| 329 | 339 | b += m; |
| 330 | 340 | if( i<nr-1 ){ |
| 331 | 341 | m = R[r+i*3+3]; |
| 332 | 342 | for(j=0; j<m; j++){ |
| 333 | - if( showLn ) appendDiffLineno(pOut, a+j, b+j, html); | |
| 343 | + if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html); | |
| 334 | 344 | appendDiffLine(pOut, ' ', &B[b+j], html); |
| 335 | 345 | } |
| 336 | 346 | b += m; |
| 337 | 347 | a += m; |
| 338 | 348 | } |
| @@ -341,11 +351,11 @@ | ||
| 341 | 351 | /* Show the final common area */ |
| 342 | 352 | assert( nr==i ); |
| 343 | 353 | m = R[r+nr*3]; |
| 344 | 354 | if( m>nContext ) m = nContext; |
| 345 | 355 | for(j=0; j<m; j++){ |
| 346 | - if( showLn ) appendDiffLineno(pOut, a+j, b+j, html); | |
| 356 | + if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html); | |
| 347 | 357 | appendDiffLine(pOut, ' ', &B[b+j], html); |
| 348 | 358 | } |
| 349 | 359 | } |
| 350 | 360 | } |
| 351 | 361 | |
| 352 | 362 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -295,44 +295,54 @@ | |
| 295 | /* |
| 296 | * If the patch changes an empty file or results in an empty file, |
| 297 | * the block header must use 0,0 as position indicator and not 1,0. |
| 298 | * Otherwise, patch would be confused and may reject the diff. |
| 299 | */ |
| 300 | if( showLn ) blob_appendf(pOut, "%*s", 15, ""); |
| 301 | blob_appendf(pOut,"@@ -%d,%d +%d,%d @@\n", |
| 302 | na ? a+skip+1 : 0, na, |
| 303 | nb ? b+skip+1 : 0, nb); |
| 304 | |
| 305 | /* Show the initial common area */ |
| 306 | a += skip; |
| 307 | b += skip; |
| 308 | m = R[r] - skip; |
| 309 | for(j=0; j<m; j++){ |
| 310 | if( showLn ) appendDiffLineno(pOut, a+j, b+j, html); |
| 311 | appendDiffLine(pOut, ' ', &A[a+j], html); |
| 312 | } |
| 313 | a += m; |
| 314 | b += m; |
| 315 | |
| 316 | /* Show the differences */ |
| 317 | for(i=0; i<nr; i++){ |
| 318 | m = R[r+i*3+1]; |
| 319 | for(j=0; j<m; j++){ |
| 320 | if( showLn ) appendDiffLineno(pOut, a+j, 0, html); |
| 321 | appendDiffLine(pOut, '-', &A[a+j], html); |
| 322 | } |
| 323 | a += m; |
| 324 | m = R[r+i*3+2]; |
| 325 | for(j=0; j<m; j++){ |
| 326 | if( showLn ) appendDiffLineno(pOut, 0, b+j, html); |
| 327 | appendDiffLine(pOut, '+', &B[b+j], html); |
| 328 | } |
| 329 | b += m; |
| 330 | if( i<nr-1 ){ |
| 331 | m = R[r+i*3+3]; |
| 332 | for(j=0; j<m; j++){ |
| 333 | if( showLn ) appendDiffLineno(pOut, a+j, b+j, html); |
| 334 | appendDiffLine(pOut, ' ', &B[b+j], html); |
| 335 | } |
| 336 | b += m; |
| 337 | a += m; |
| 338 | } |
| @@ -341,11 +351,11 @@ | |
| 341 | /* Show the final common area */ |
| 342 | assert( nr==i ); |
| 343 | m = R[r+nr*3]; |
| 344 | if( m>nContext ) m = nContext; |
| 345 | for(j=0; j<m; j++){ |
| 346 | if( showLn ) appendDiffLineno(pOut, a+j, b+j, html); |
| 347 | appendDiffLine(pOut, ' ', &B[b+j], html); |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -295,44 +295,54 @@ | |
| 295 | /* |
| 296 | * If the patch changes an empty file or results in an empty file, |
| 297 | * the block header must use 0,0 as position indicator and not 1,0. |
| 298 | * Otherwise, patch would be confused and may reject the diff. |
| 299 | */ |
| 300 | if( showLn ){ |
| 301 | if( html ){ |
| 302 | blob_appendf(pOut, "<span class=\"diffhr\">%.80c</span>\n", '.'); |
| 303 | }else{ |
| 304 | blob_appendf(pOut, "%.80c\n", '.'); |
| 305 | } |
| 306 | }else{ |
| 307 | if( html ) blob_appendf(pOut, "<span class=\"diffln\">"); |
| 308 | blob_appendf(pOut,"@@ -%d,%d +%d,%d @@", |
| 309 | na ? a+skip+1 : 0, na, |
| 310 | nb ? b+skip+1 : 0, nb); |
| 311 | if( html ) blob_appendf(pOut, "</span>"); |
| 312 | blob_append(pOut, "\n", 1); |
| 313 | } |
| 314 | |
| 315 | /* Show the initial common area */ |
| 316 | a += skip; |
| 317 | b += skip; |
| 318 | m = R[r] - skip; |
| 319 | for(j=0; j<m; j++){ |
| 320 | if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html); |
| 321 | appendDiffLine(pOut, ' ', &A[a+j], html); |
| 322 | } |
| 323 | a += m; |
| 324 | b += m; |
| 325 | |
| 326 | /* Show the differences */ |
| 327 | for(i=0; i<nr; i++){ |
| 328 | m = R[r+i*3+1]; |
| 329 | for(j=0; j<m; j++){ |
| 330 | if( showLn ) appendDiffLineno(pOut, a+j+1, 0, html); |
| 331 | appendDiffLine(pOut, '-', &A[a+j], html); |
| 332 | } |
| 333 | a += m; |
| 334 | m = R[r+i*3+2]; |
| 335 | for(j=0; j<m; j++){ |
| 336 | if( showLn ) appendDiffLineno(pOut, 0, b+j+1, html); |
| 337 | appendDiffLine(pOut, '+', &B[b+j], html); |
| 338 | } |
| 339 | b += m; |
| 340 | if( i<nr-1 ){ |
| 341 | m = R[r+i*3+3]; |
| 342 | for(j=0; j<m; j++){ |
| 343 | if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html); |
| 344 | appendDiffLine(pOut, ' ', &B[b+j], html); |
| 345 | } |
| 346 | b += m; |
| 347 | a += m; |
| 348 | } |
| @@ -341,11 +351,11 @@ | |
| 351 | /* Show the final common area */ |
| 352 | assert( nr==i ); |
| 353 | m = R[r+nr*3]; |
| 354 | if( m>nContext ) m = nContext; |
| 355 | for(j=0; j<m; j++){ |
| 356 | if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html); |
| 357 | appendDiffLine(pOut, ' ', &B[b+j], html); |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 |