Fossil SCM

Delete unused legacy context-diff logic for HTML.

drh 2021-09-02 22:44 diff-color-enhancements
Commit 1fb022ff98d56e6e6d6ca1dbd495c579e9eebd1e81302d2fd75651f952b7c3d4
1 file changed +18 -73
+18 -73
--- src/diff.c
+++ src/diff.c
@@ -302,41 +302,23 @@
302302
** Append a single line of context-diff output to pOut.
303303
*/
304304
static void appendDiffLine(
305305
Blob *pOut, /* Where to write the line of output */
306306
char cPrefix, /* One of " ", "+", or "-" */
307
- DLine *pLine, /* The line to be output */
308
- int html, /* True if generating HTML. False for plain text */
309
- ReCompiled *pRe /* Colorize only if line matches this Regex */
307
+ DLine *pLine /* The line to be output */
310308
){
311
- blob_append(pOut, &cPrefix, 1);
312
- if( html ){
313
- if( pRe && re_dline_match(pRe, pLine, 1)==0 ){
314
- cPrefix = ' ';
315
- }else if( cPrefix=='+' ){
316
- blob_append(pOut, zClassAdd, -1);
317
- }else if( cPrefix=='-' ){
318
- blob_append(pOut, zClassRm, -1);
319
- }
320
- htmlize_to_blob(pOut, pLine->z, pLine->n);
321
- if( cPrefix!=' ' ){
322
- blob_append(pOut, "</span>", -1);
323
- }
324
- }else{
325
- blob_append(pOut, pLine->z, pLine->n);
326
- }
327
- blob_append(pOut, "\n", 1);
309
+ blob_append_char(pOut, cPrefix);
310
+ blob_append(pOut, pLine->z, pLine->n);
311
+ blob_append_char(pOut, '\n');
328312
}
329313
330314
/*
331315
** Add two line numbers to the beginning of an output line for a context
332316
** diff. One or the other of the two numbers might be zero, which means
333
-** to leave that number field blank. The "html" parameter means to format
334
-** the output for HTML.
317
+** to leave that number field blank.
335318
*/
336
-static void appendDiffLineno(Blob *pOut, int lnA, int lnB, int html){
337
- if( html ) blob_append(pOut, "<span class=\"diffln\">", -1);
319
+static void appendDiffLineno(Blob *pOut, int lnA, int lnB){
338320
if( lnA>0 ){
339321
blob_appendf(pOut, "%6d ", lnA);
340322
}else{
341323
blob_append(pOut, " ", 7);
342324
}
@@ -343,21 +325,18 @@
343325
if( lnB>0 ){
344326
blob_appendf(pOut, "%6d ", lnB);
345327
}else{
346328
blob_append(pOut, " ", 8);
347329
}
348
- if( html ) blob_append(pOut, "</span>", -1);
349330
}
350331
351332
/*
352
-** Given a raw diff p[] in which the p->aEdit[] array has been filled
353
-** in, compute a context diff into pOut.
333
+** Output a patch-style text diff.
354334
*/
355335
static void contextDiff(
356336
DContext *p, /* The difference */
357337
Blob *pOut, /* Output a context diff to here */
358
- ReCompiled *pRe, /* Only show changes that match this regex */
359338
u64 diffFlags /* Flags controlling the diff format */
360339
){
361340
DLine *A; /* Left side of the diff */
362341
DLine *B; /* Right side of the diff */
363342
int a = 0; /* Index of next line in A[] */
@@ -371,17 +350,14 @@
371350
int m; /* Number of lines to output */
372351
int skip; /* Number of lines to skip */
373352
static int nChunk = 0; /* Number of diff chunks seen so far */
374353
int nContext; /* Number of lines of context */
375354
int showLn; /* Show line numbers */
376
- int html; /* Render as HTML */
377355
int showDivider = 0; /* True to show the divider between diff blocks */
378356
379357
nContext = diff_context_lines(diffFlags);
380358
showLn = (diffFlags & DIFF_LINENO)!=0;
381
- html = (diffFlags & DIFF_HTML)!=0;
382
- if( html ) blob_append(pOut, "<pre class=\"udiff\">\n", -1);
383359
A = p->aFrom;
384360
B = p->aTo;
385361
R = p->aEdit;
386362
mxr = p->nEdit;
387363
while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; }
@@ -388,35 +364,10 @@
388364
for(r=0; r<mxr; r += 3*nr){
389365
/* Figure out how many triples to show in a single block */
390366
for(nr=1; R[r+nr*3]>0 && R[r+nr*3]<nContext*2; nr++){}
391367
/* printf("r=%d nr=%d\n", r, nr); */
392368
393
- /* If there is a regex, skip this block (generate no diff output)
394
- ** if the regex matches or does not match both insert and delete.
395
- ** Only display the block if one side matches but the other side does
396
- ** not.
397
- */
398
- if( pRe ){
399
- int hideBlock = 1;
400
- int xa = a, xb = b;
401
- for(i=0; hideBlock && i<nr; i++){
402
- int c1, c2;
403
- xa += R[r+i*3];
404
- xb += R[r+i*3];
405
- c1 = re_dline_match(pRe, &A[xa], R[r+i*3+1]);
406
- c2 = re_dline_match(pRe, &B[xb], R[r+i*3+2]);
407
- hideBlock = c1==c2;
408
- xa += R[r+i*3+1];
409
- xb += R[r+i*3+2];
410
- }
411
- if( hideBlock ){
412
- a = xa;
413
- b = xb;
414
- continue;
415
- }
416
- }
417
-
418369
/* For the current block comprising nr triples, figure out
419370
** how many lines of A and B are to be displayed
420371
*/
421372
if( R[r]>nContext ){
422373
na = nb = nContext;
@@ -448,60 +399,55 @@
448399
nChunk++;
449400
if( showLn ){
450401
if( !showDivider ){
451402
/* Do not show a top divider */
452403
showDivider = 1;
453
- }else if( html ){
454
- blob_appendf(pOut, "<span class=\"diffhr\">%.80c</span>\n", '.');
455404
}else{
456405
blob_appendf(pOut, "%.80c\n", '.');
457406
}
458
- if( html ) blob_appendf(pOut, "<span id=\"chunk%d\"></span>", nChunk);
459407
}else{
460
- if( html ) blob_appendf(pOut, "<span class=\"diffln\">");
461408
/*
462409
* If the patch changes an empty file or results in an empty file,
463410
* the block header must use 0,0 as position indicator and not 1,0.
464411
* Otherwise, patch would be confused and may reject the diff.
465412
*/
466413
blob_appendf(pOut,"@@ -%d,%d +%d,%d @@",
467414
na ? a+skip+1 : a+skip, na,
468415
nb ? b+skip+1 : b+skip, nb);
469
- if( html ) blob_appendf(pOut, "</span>");
470416
blob_append(pOut, "\n", 1);
471417
}
472418
473419
/* Show the initial common area */
474420
a += skip;
475421
b += skip;
476422
m = R[r] - skip;
477423
for(j=0; j<m; j++){
478
- if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html);
479
- appendDiffLine(pOut, ' ', &A[a+j], html, 0);
424
+ if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1);
425
+ appendDiffLine(pOut, ' ', &A[a+j]);
480426
}
481427
a += m;
482428
b += m;
483429
484430
/* Show the differences */
485431
for(i=0; i<nr; i++){
486432
m = R[r+i*3+1];
487433
for(j=0; j<m; j++){
488
- if( showLn ) appendDiffLineno(pOut, a+j+1, 0, html);
489
- appendDiffLine(pOut, '-', &A[a+j], html, pRe);
434
+ if( showLn ) appendDiffLineno(pOut, a+j+1, 0);
435
+ appendDiffLine(pOut, '-', &A[a+j]);
490436
}
491437
a += m;
492438
m = R[r+i*3+2];
493439
for(j=0; j<m; j++){
494
- if( showLn ) appendDiffLineno(pOut, 0, b+j+1, html);
495
- appendDiffLine(pOut, '+', &B[b+j], html, pRe);
440
+ if( showLn ) appendDiffLineno(pOut, 0, b+j+1);
441
+ appendDiffLine(pOut, '+', &B[b+j]);
496442
}
497443
b += m;
498444
if( i<nr-1 ){
499445
m = R[r+i*3+3];
500446
for(j=0; j<m; j++){
501
- if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html);
502
- appendDiffLine(pOut, ' ', &A[a+j], html, 0);
447
+ if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1);
448
+ appendDiffLine(pOut, ' ', &A[a+j]);
503449
}
504450
b += m;
505451
a += m;
506452
}
507453
}
@@ -509,15 +455,14 @@
509455
/* Show the final common area */
510456
assert( nr==i );
511457
m = R[r+nr*3];
512458
if( m>nContext ) m = nContext;
513459
for(j=0; j<m; j++){
514
- if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html);
515
- appendDiffLine(pOut, ' ', &A[a+j], html, 0);
460
+ if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1);
461
+ appendDiffLine(pOut, ' ', &A[a+j]);
516462
}
517463
}
518
- if( html ) blob_append(pOut, "</pre>\n", -1);
519464
}
520465
521466
/*
522467
** Limits for the intra-line diffing.
523468
*/
@@ -3083,11 +3028,11 @@
30833028
formatDiff(&c, pRe, diffFlags, pBuilder);
30843029
}else if( diffFlags & DIFF_HTML ){
30853030
DiffBuilder *pBuilder = dfunifiedNew(pOut);
30863031
formatDiff(&c, pRe, diffFlags, pBuilder);
30873032
}else{
3088
- contextDiff(&c, pOut, pRe, diffFlags);
3033
+ contextDiff(&c, pOut, diffFlags);
30893034
}
30903035
fossil_free(c.aFrom);
30913036
fossil_free(c.aTo);
30923037
fossil_free(c.aEdit);
30933038
return 0;
30943039
--- src/diff.c
+++ src/diff.c
@@ -302,41 +302,23 @@
302 ** Append a single line of context-diff output to pOut.
303 */
304 static void appendDiffLine(
305 Blob *pOut, /* Where to write the line of output */
306 char cPrefix, /* One of " ", "+", or "-" */
307 DLine *pLine, /* The line to be output */
308 int html, /* True if generating HTML. False for plain text */
309 ReCompiled *pRe /* Colorize only if line matches this Regex */
310 ){
311 blob_append(pOut, &cPrefix, 1);
312 if( html ){
313 if( pRe && re_dline_match(pRe, pLine, 1)==0 ){
314 cPrefix = ' ';
315 }else if( cPrefix=='+' ){
316 blob_append(pOut, zClassAdd, -1);
317 }else if( cPrefix=='-' ){
318 blob_append(pOut, zClassRm, -1);
319 }
320 htmlize_to_blob(pOut, pLine->z, pLine->n);
321 if( cPrefix!=' ' ){
322 blob_append(pOut, "</span>", -1);
323 }
324 }else{
325 blob_append(pOut, pLine->z, pLine->n);
326 }
327 blob_append(pOut, "\n", 1);
328 }
329
330 /*
331 ** Add two line numbers to the beginning of an output line for a context
332 ** diff. One or the other of the two numbers might be zero, which means
333 ** to leave that number field blank. The "html" parameter means to format
334 ** the output for HTML.
335 */
336 static void appendDiffLineno(Blob *pOut, int lnA, int lnB, int html){
337 if( html ) blob_append(pOut, "<span class=\"diffln\">", -1);
338 if( lnA>0 ){
339 blob_appendf(pOut, "%6d ", lnA);
340 }else{
341 blob_append(pOut, " ", 7);
342 }
@@ -343,21 +325,18 @@
343 if( lnB>0 ){
344 blob_appendf(pOut, "%6d ", lnB);
345 }else{
346 blob_append(pOut, " ", 8);
347 }
348 if( html ) blob_append(pOut, "</span>", -1);
349 }
350
351 /*
352 ** Given a raw diff p[] in which the p->aEdit[] array has been filled
353 ** in, compute a context diff into pOut.
354 */
355 static void contextDiff(
356 DContext *p, /* The difference */
357 Blob *pOut, /* Output a context diff to here */
358 ReCompiled *pRe, /* Only show changes that match this regex */
359 u64 diffFlags /* Flags controlling the diff format */
360 ){
361 DLine *A; /* Left side of the diff */
362 DLine *B; /* Right side of the diff */
363 int a = 0; /* Index of next line in A[] */
@@ -371,17 +350,14 @@
371 int m; /* Number of lines to output */
372 int skip; /* Number of lines to skip */
373 static int nChunk = 0; /* Number of diff chunks seen so far */
374 int nContext; /* Number of lines of context */
375 int showLn; /* Show line numbers */
376 int html; /* Render as HTML */
377 int showDivider = 0; /* True to show the divider between diff blocks */
378
379 nContext = diff_context_lines(diffFlags);
380 showLn = (diffFlags & DIFF_LINENO)!=0;
381 html = (diffFlags & DIFF_HTML)!=0;
382 if( html ) blob_append(pOut, "<pre class=\"udiff\">\n", -1);
383 A = p->aFrom;
384 B = p->aTo;
385 R = p->aEdit;
386 mxr = p->nEdit;
387 while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; }
@@ -388,35 +364,10 @@
388 for(r=0; r<mxr; r += 3*nr){
389 /* Figure out how many triples to show in a single block */
390 for(nr=1; R[r+nr*3]>0 && R[r+nr*3]<nContext*2; nr++){}
391 /* printf("r=%d nr=%d\n", r, nr); */
392
393 /* If there is a regex, skip this block (generate no diff output)
394 ** if the regex matches or does not match both insert and delete.
395 ** Only display the block if one side matches but the other side does
396 ** not.
397 */
398 if( pRe ){
399 int hideBlock = 1;
400 int xa = a, xb = b;
401 for(i=0; hideBlock && i<nr; i++){
402 int c1, c2;
403 xa += R[r+i*3];
404 xb += R[r+i*3];
405 c1 = re_dline_match(pRe, &A[xa], R[r+i*3+1]);
406 c2 = re_dline_match(pRe, &B[xb], R[r+i*3+2]);
407 hideBlock = c1==c2;
408 xa += R[r+i*3+1];
409 xb += R[r+i*3+2];
410 }
411 if( hideBlock ){
412 a = xa;
413 b = xb;
414 continue;
415 }
416 }
417
418 /* For the current block comprising nr triples, figure out
419 ** how many lines of A and B are to be displayed
420 */
421 if( R[r]>nContext ){
422 na = nb = nContext;
@@ -448,60 +399,55 @@
448 nChunk++;
449 if( showLn ){
450 if( !showDivider ){
451 /* Do not show a top divider */
452 showDivider = 1;
453 }else if( html ){
454 blob_appendf(pOut, "<span class=\"diffhr\">%.80c</span>\n", '.');
455 }else{
456 blob_appendf(pOut, "%.80c\n", '.');
457 }
458 if( html ) blob_appendf(pOut, "<span id=\"chunk%d\"></span>", nChunk);
459 }else{
460 if( html ) blob_appendf(pOut, "<span class=\"diffln\">");
461 /*
462 * If the patch changes an empty file or results in an empty file,
463 * the block header must use 0,0 as position indicator and not 1,0.
464 * Otherwise, patch would be confused and may reject the diff.
465 */
466 blob_appendf(pOut,"@@ -%d,%d +%d,%d @@",
467 na ? a+skip+1 : a+skip, na,
468 nb ? b+skip+1 : b+skip, nb);
469 if( html ) blob_appendf(pOut, "</span>");
470 blob_append(pOut, "\n", 1);
471 }
472
473 /* Show the initial common area */
474 a += skip;
475 b += skip;
476 m = R[r] - skip;
477 for(j=0; j<m; j++){
478 if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html);
479 appendDiffLine(pOut, ' ', &A[a+j], html, 0);
480 }
481 a += m;
482 b += m;
483
484 /* Show the differences */
485 for(i=0; i<nr; i++){
486 m = R[r+i*3+1];
487 for(j=0; j<m; j++){
488 if( showLn ) appendDiffLineno(pOut, a+j+1, 0, html);
489 appendDiffLine(pOut, '-', &A[a+j], html, pRe);
490 }
491 a += m;
492 m = R[r+i*3+2];
493 for(j=0; j<m; j++){
494 if( showLn ) appendDiffLineno(pOut, 0, b+j+1, html);
495 appendDiffLine(pOut, '+', &B[b+j], html, pRe);
496 }
497 b += m;
498 if( i<nr-1 ){
499 m = R[r+i*3+3];
500 for(j=0; j<m; j++){
501 if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html);
502 appendDiffLine(pOut, ' ', &A[a+j], html, 0);
503 }
504 b += m;
505 a += m;
506 }
507 }
@@ -509,15 +455,14 @@
509 /* Show the final common area */
510 assert( nr==i );
511 m = R[r+nr*3];
512 if( m>nContext ) m = nContext;
513 for(j=0; j<m; j++){
514 if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1, html);
515 appendDiffLine(pOut, ' ', &A[a+j], html, 0);
516 }
517 }
518 if( html ) blob_append(pOut, "</pre>\n", -1);
519 }
520
521 /*
522 ** Limits for the intra-line diffing.
523 */
@@ -3083,11 +3028,11 @@
3083 formatDiff(&c, pRe, diffFlags, pBuilder);
3084 }else if( diffFlags & DIFF_HTML ){
3085 DiffBuilder *pBuilder = dfunifiedNew(pOut);
3086 formatDiff(&c, pRe, diffFlags, pBuilder);
3087 }else{
3088 contextDiff(&c, pOut, pRe, diffFlags);
3089 }
3090 fossil_free(c.aFrom);
3091 fossil_free(c.aTo);
3092 fossil_free(c.aEdit);
3093 return 0;
3094
--- src/diff.c
+++ src/diff.c
@@ -302,41 +302,23 @@
302 ** Append a single line of context-diff output to pOut.
303 */
304 static void appendDiffLine(
305 Blob *pOut, /* Where to write the line of output */
306 char cPrefix, /* One of " ", "+", or "-" */
307 DLine *pLine /* The line to be output */
 
 
308 ){
309 blob_append_char(pOut, cPrefix);
310 blob_append(pOut, pLine->z, pLine->n);
311 blob_append_char(pOut, '\n');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
312 }
313
314 /*
315 ** Add two line numbers to the beginning of an output line for a context
316 ** diff. One or the other of the two numbers might be zero, which means
317 ** to leave that number field blank.
 
318 */
319 static void appendDiffLineno(Blob *pOut, int lnA, int lnB){
 
320 if( lnA>0 ){
321 blob_appendf(pOut, "%6d ", lnA);
322 }else{
323 blob_append(pOut, " ", 7);
324 }
@@ -343,21 +325,18 @@
325 if( lnB>0 ){
326 blob_appendf(pOut, "%6d ", lnB);
327 }else{
328 blob_append(pOut, " ", 8);
329 }
 
330 }
331
332 /*
333 ** Output a patch-style text diff.
 
334 */
335 static void contextDiff(
336 DContext *p, /* The difference */
337 Blob *pOut, /* Output a context diff to here */
 
338 u64 diffFlags /* Flags controlling the diff format */
339 ){
340 DLine *A; /* Left side of the diff */
341 DLine *B; /* Right side of the diff */
342 int a = 0; /* Index of next line in A[] */
@@ -371,17 +350,14 @@
350 int m; /* Number of lines to output */
351 int skip; /* Number of lines to skip */
352 static int nChunk = 0; /* Number of diff chunks seen so far */
353 int nContext; /* Number of lines of context */
354 int showLn; /* Show line numbers */
 
355 int showDivider = 0; /* True to show the divider between diff blocks */
356
357 nContext = diff_context_lines(diffFlags);
358 showLn = (diffFlags & DIFF_LINENO)!=0;
 
 
359 A = p->aFrom;
360 B = p->aTo;
361 R = p->aEdit;
362 mxr = p->nEdit;
363 while( mxr>2 && R[mxr-1]==0 && R[mxr-2]==0 ){ mxr -= 3; }
@@ -388,35 +364,10 @@
364 for(r=0; r<mxr; r += 3*nr){
365 /* Figure out how many triples to show in a single block */
366 for(nr=1; R[r+nr*3]>0 && R[r+nr*3]<nContext*2; nr++){}
367 /* printf("r=%d nr=%d\n", r, nr); */
368
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
369 /* For the current block comprising nr triples, figure out
370 ** how many lines of A and B are to be displayed
371 */
372 if( R[r]>nContext ){
373 na = nb = nContext;
@@ -448,60 +399,55 @@
399 nChunk++;
400 if( showLn ){
401 if( !showDivider ){
402 /* Do not show a top divider */
403 showDivider = 1;
 
 
404 }else{
405 blob_appendf(pOut, "%.80c\n", '.');
406 }
 
407 }else{
 
408 /*
409 * If the patch changes an empty file or results in an empty file,
410 * the block header must use 0,0 as position indicator and not 1,0.
411 * Otherwise, patch would be confused and may reject the diff.
412 */
413 blob_appendf(pOut,"@@ -%d,%d +%d,%d @@",
414 na ? a+skip+1 : a+skip, na,
415 nb ? b+skip+1 : b+skip, nb);
 
416 blob_append(pOut, "\n", 1);
417 }
418
419 /* Show the initial common area */
420 a += skip;
421 b += skip;
422 m = R[r] - skip;
423 for(j=0; j<m; j++){
424 if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1);
425 appendDiffLine(pOut, ' ', &A[a+j]);
426 }
427 a += m;
428 b += m;
429
430 /* Show the differences */
431 for(i=0; i<nr; i++){
432 m = R[r+i*3+1];
433 for(j=0; j<m; j++){
434 if( showLn ) appendDiffLineno(pOut, a+j+1, 0);
435 appendDiffLine(pOut, '-', &A[a+j]);
436 }
437 a += m;
438 m = R[r+i*3+2];
439 for(j=0; j<m; j++){
440 if( showLn ) appendDiffLineno(pOut, 0, b+j+1);
441 appendDiffLine(pOut, '+', &B[b+j]);
442 }
443 b += m;
444 if( i<nr-1 ){
445 m = R[r+i*3+3];
446 for(j=0; j<m; j++){
447 if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1);
448 appendDiffLine(pOut, ' ', &A[a+j]);
449 }
450 b += m;
451 a += m;
452 }
453 }
@@ -509,15 +455,14 @@
455 /* Show the final common area */
456 assert( nr==i );
457 m = R[r+nr*3];
458 if( m>nContext ) m = nContext;
459 for(j=0; j<m; j++){
460 if( showLn ) appendDiffLineno(pOut, a+j+1, b+j+1);
461 appendDiffLine(pOut, ' ', &A[a+j]);
462 }
463 }
 
464 }
465
466 /*
467 ** Limits for the intra-line diffing.
468 */
@@ -3083,11 +3028,11 @@
3028 formatDiff(&c, pRe, diffFlags, pBuilder);
3029 }else if( diffFlags & DIFF_HTML ){
3030 DiffBuilder *pBuilder = dfunifiedNew(pOut);
3031 formatDiff(&c, pRe, diffFlags, pBuilder);
3032 }else{
3033 contextDiff(&c, pOut, diffFlags);
3034 }
3035 fossil_free(c.aFrom);
3036 fossil_free(c.aTo);
3037 fossil_free(c.aEdit);
3038 return 0;
3039

Keyboard Shortcuts

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