Fossil SCM

Fix off-by-one line numbers in the context-diff display. Improvements to the formatting of context-diff displays.

drh 2012-02-04 20:13 UTC retro-sbsdiff
Commit 56ad4ac7aecf1de5c0799b0905acb7abe55bad0b
1 file changed +19 -9
+19 -9
--- src/diff.c
+++ src/diff.c
@@ -295,44 +295,54 @@
295295
/*
296296
* If the patch changes an empty file or results in an empty file,
297297
* the block header must use 0,0 as position indicator and not 1,0.
298298
* Otherwise, patch would be confused and may reject the diff.
299299
*/
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
+ }
304314
305315
/* Show the initial common area */
306316
a += skip;
307317
b += skip;
308318
m = R[r] - skip;
309319
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);
311321
appendDiffLine(pOut, ' ', &A[a+j], html);
312322
}
313323
a += m;
314324
b += m;
315325
316326
/* Show the differences */
317327
for(i=0; i<nr; i++){
318328
m = R[r+i*3+1];
319329
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);
321331
appendDiffLine(pOut, '-', &A[a+j], html);
322332
}
323333
a += m;
324334
m = R[r+i*3+2];
325335
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);
327337
appendDiffLine(pOut, '+', &B[b+j], html);
328338
}
329339
b += m;
330340
if( i<nr-1 ){
331341
m = R[r+i*3+3];
332342
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);
334344
appendDiffLine(pOut, ' ', &B[b+j], html);
335345
}
336346
b += m;
337347
a += m;
338348
}
@@ -341,11 +351,11 @@
341351
/* Show the final common area */
342352
assert( nr==i );
343353
m = R[r+nr*3];
344354
if( m>nContext ) m = nContext;
345355
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);
347357
appendDiffLine(pOut, ' ', &B[b+j], html);
348358
}
349359
}
350360
}
351361
352362
--- 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

Keyboard Shortcuts

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