Fossil SCM

Making the side-by-side diffs autocalculate the width, by default.

viriketo 2012-03-18 14:53 annotate_links
Commit 16397d86259278cb419a668389c59369e0876f72
3 files changed +15 -2 +9 -2 +3 -2
+15 -2
--- src/diff.c
+++ src/diff.c
@@ -351,10 +351,12 @@
351351
appendDiffLine(pOut, ' ', &B[b+j], html);
352352
}
353353
}
354354
}
355355
356
+static int maxwidth;
357
+
356358
/*
357359
** Status of a single output line
358360
*/
359361
typedef struct SbsLine SbsLine;
360362
struct SbsLine {
@@ -388,10 +390,14 @@
388390
int k; /* Cursor position */
389391
int needEndSpan = 0;
390392
const char *zIn = pLine->z;
391393
char *z = &p->zLine[p->n];
392394
int w = p->width;
395
+
396
+ if (n > maxwidth)
397
+ maxwidth = n;
398
+
393399
for(i=j=k=0; k<w && i<n; i++, k++){
394400
char c = zIn[i];
395401
if( p->escHtml ){
396402
if( i==p->iStart ){
397403
int x = strlen(p->zStart);
@@ -863,11 +869,11 @@
863869
static void sbsDiff(
864870
DContext *p, /* The computed diff */
865871
Blob *pOut, /* Write the results here */
866872
int nContext, /* Number of lines of context around each change */
867873
int width, /* Width of each column of output */
868
- int escHtml /* True to generate HTML output */
874
+ int escHtml /* True to generate HTML output */
869875
){
870876
DLine *A; /* Left side of the diff */
871877
DLine *B; /* Right side of the diff */
872878
int a = 0; /* Index of next line in A[] */
873879
int b = 0; /* Index of next line in B[] */
@@ -1432,11 +1438,10 @@
14321438
** Extract the width of columns for side-by-side diff. Supply an
14331439
** appropriate default if no width is given.
14341440
*/
14351441
int diff_width(int diffFlags){
14361442
int w = (diffFlags & DIFF_WIDTH_MASK)/(DIFF_CONTEXT_MASK+1);
1437
- if( w==0 ) w = 80;
14381443
return w;
14391444
}
14401445
14411446
/*
14421447
** Generate a report of the differences between files pA and pB.
@@ -1492,10 +1497,18 @@
14921497
if( pOut ){
14931498
/* Compute a context or side-by-side diff into pOut */
14941499
int escHtml = (diffFlags & DIFF_HTML)!=0;
14951500
if( diffFlags & DIFF_SIDEBYSIDE ){
14961501
int width = diff_width(diffFlags);
1502
+ if (width == 0){ /* Autocalculate */
1503
+ Blob dump;
1504
+ /* Webserver */
1505
+ maxwidth = 0;
1506
+ blob_zero(&dump);
1507
+ sbsDiff(&c, &dump, nContext, width, escHtml);
1508
+ width = maxwidth;
1509
+ }
14971510
sbsDiff(&c, pOut, nContext, width, escHtml);
14981511
}else{
14991512
int showLn = (diffFlags & DIFF_LINENO)!=0;
15001513
contextDiff(&c, pOut, nContext, showLn, escHtml);
15011514
}
15021515
--- src/diff.c
+++ src/diff.c
@@ -351,10 +351,12 @@
351 appendDiffLine(pOut, ' ', &B[b+j], html);
352 }
353 }
354 }
355
 
 
356 /*
357 ** Status of a single output line
358 */
359 typedef struct SbsLine SbsLine;
360 struct SbsLine {
@@ -388,10 +390,14 @@
388 int k; /* Cursor position */
389 int needEndSpan = 0;
390 const char *zIn = pLine->z;
391 char *z = &p->zLine[p->n];
392 int w = p->width;
 
 
 
 
393 for(i=j=k=0; k<w && i<n; i++, k++){
394 char c = zIn[i];
395 if( p->escHtml ){
396 if( i==p->iStart ){
397 int x = strlen(p->zStart);
@@ -863,11 +869,11 @@
863 static void sbsDiff(
864 DContext *p, /* The computed diff */
865 Blob *pOut, /* Write the results here */
866 int nContext, /* Number of lines of context around each change */
867 int width, /* Width of each column of output */
868 int escHtml /* True to generate HTML output */
869 ){
870 DLine *A; /* Left side of the diff */
871 DLine *B; /* Right side of the diff */
872 int a = 0; /* Index of next line in A[] */
873 int b = 0; /* Index of next line in B[] */
@@ -1432,11 +1438,10 @@
1432 ** Extract the width of columns for side-by-side diff. Supply an
1433 ** appropriate default if no width is given.
1434 */
1435 int diff_width(int diffFlags){
1436 int w = (diffFlags & DIFF_WIDTH_MASK)/(DIFF_CONTEXT_MASK+1);
1437 if( w==0 ) w = 80;
1438 return w;
1439 }
1440
1441 /*
1442 ** Generate a report of the differences between files pA and pB.
@@ -1492,10 +1497,18 @@
1492 if( pOut ){
1493 /* Compute a context or side-by-side diff into pOut */
1494 int escHtml = (diffFlags & DIFF_HTML)!=0;
1495 if( diffFlags & DIFF_SIDEBYSIDE ){
1496 int width = diff_width(diffFlags);
 
 
 
 
 
 
 
 
1497 sbsDiff(&c, pOut, nContext, width, escHtml);
1498 }else{
1499 int showLn = (diffFlags & DIFF_LINENO)!=0;
1500 contextDiff(&c, pOut, nContext, showLn, escHtml);
1501 }
1502
--- src/diff.c
+++ src/diff.c
@@ -351,10 +351,12 @@
351 appendDiffLine(pOut, ' ', &B[b+j], html);
352 }
353 }
354 }
355
356 static int maxwidth;
357
358 /*
359 ** Status of a single output line
360 */
361 typedef struct SbsLine SbsLine;
362 struct SbsLine {
@@ -388,10 +390,14 @@
390 int k; /* Cursor position */
391 int needEndSpan = 0;
392 const char *zIn = pLine->z;
393 char *z = &p->zLine[p->n];
394 int w = p->width;
395
396 if (n > maxwidth)
397 maxwidth = n;
398
399 for(i=j=k=0; k<w && i<n; i++, k++){
400 char c = zIn[i];
401 if( p->escHtml ){
402 if( i==p->iStart ){
403 int x = strlen(p->zStart);
@@ -863,11 +869,11 @@
869 static void sbsDiff(
870 DContext *p, /* The computed diff */
871 Blob *pOut, /* Write the results here */
872 int nContext, /* Number of lines of context around each change */
873 int width, /* Width of each column of output */
874 int escHtml /* True to generate HTML output */
875 ){
876 DLine *A; /* Left side of the diff */
877 DLine *B; /* Right side of the diff */
878 int a = 0; /* Index of next line in A[] */
879 int b = 0; /* Index of next line in B[] */
@@ -1432,11 +1438,10 @@
1438 ** Extract the width of columns for side-by-side diff. Supply an
1439 ** appropriate default if no width is given.
1440 */
1441 int diff_width(int diffFlags){
1442 int w = (diffFlags & DIFF_WIDTH_MASK)/(DIFF_CONTEXT_MASK+1);
 
1443 return w;
1444 }
1445
1446 /*
1447 ** Generate a report of the differences between files pA and pB.
@@ -1492,10 +1497,18 @@
1497 if( pOut ){
1498 /* Compute a context or side-by-side diff into pOut */
1499 int escHtml = (diffFlags & DIFF_HTML)!=0;
1500 if( diffFlags & DIFF_SIDEBYSIDE ){
1501 int width = diff_width(diffFlags);
1502 if (width == 0){ /* Autocalculate */
1503 Blob dump;
1504 /* Webserver */
1505 maxwidth = 0;
1506 blob_zero(&dump);
1507 sbsDiff(&c, &dump, nContext, width, escHtml);
1508 width = maxwidth;
1509 }
1510 sbsDiff(&c, pOut, nContext, width, escHtml);
1511 }else{
1512 int showLn = (diffFlags & DIFF_LINENO)!=0;
1513 contextDiff(&c, pOut, nContext, showLn, escHtml);
1514 }
1515
+9 -2
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -41,12 +41,19 @@
4141
/* no-op */
4242
}else if( diffFlags & DIFF_SIDEBYSIDE ){
4343
int w = diff_width(diffFlags);
4444
int n1 = strlen(zLeft);
4545
int x;
46
- if( n1>w*2 ) n1 = w*2;
47
- x = w*2+17 - (n1+2);
46
+ if (w > 0) {
47
+ if( n1>w*2 ) n1 = w*2;
48
+ x = w*2+17 - (n1+2);
49
+ }else{
50
+ /* Autocalculate width
51
+ * We can't know the width in advance, so we'll make it
52
+ * output three = around the name */
53
+ x = 6;
54
+ }
4855
z = mprintf("%.*c %.*s %.*c\n",
4956
x/2, '=', n1, zLeft, (x+1)/2, '=');
5057
}else{
5158
z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
5259
}
5360
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -41,12 +41,19 @@
41 /* no-op */
42 }else if( diffFlags & DIFF_SIDEBYSIDE ){
43 int w = diff_width(diffFlags);
44 int n1 = strlen(zLeft);
45 int x;
46 if( n1>w*2 ) n1 = w*2;
47 x = w*2+17 - (n1+2);
 
 
 
 
 
 
 
48 z = mprintf("%.*c %.*s %.*c\n",
49 x/2, '=', n1, zLeft, (x+1)/2, '=');
50 }else{
51 z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
52 }
53
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -41,12 +41,19 @@
41 /* no-op */
42 }else if( diffFlags & DIFF_SIDEBYSIDE ){
43 int w = diff_width(diffFlags);
44 int n1 = strlen(zLeft);
45 int x;
46 if (w > 0) {
47 if( n1>w*2 ) n1 = w*2;
48 x = w*2+17 - (n1+2);
49 }else{
50 /* Autocalculate width
51 * We can't know the width in advance, so we'll make it
52 * output three = around the name */
53 x = 6;
54 }
55 z = mprintf("%.*c %.*s %.*c\n",
56 x/2, '=', n1, zLeft, (x+1)/2, '=');
57 }else{
58 z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
59 }
60
+3 -2
--- src/info.c
+++ src/info.c
@@ -363,12 +363,13 @@
363363
}else{
364364
int x;
365365
if( sideBySide ){
366366
diffFlags = DIFF_SIDEBYSIDE | DIFF_IGNORE_EOLWS;
367367
368
- /* "dw" query parameter determines width of each column */
369
- x = atoi(PD("dw","80"))*(DIFF_CONTEXT_MASK+1);
368
+ /* "dw" query parameter determines width of each column
369
+ * 0 means autocalculate. */
370
+ x = atoi(PD("dw","0"))*(DIFF_CONTEXT_MASK+1);
370371
if( x<0 || x>DIFF_WIDTH_MASK ) x = DIFF_WIDTH_MASK;
371372
diffFlags += x;
372373
}else{
373374
diffFlags = DIFF_INLINE | DIFF_IGNORE_EOLWS;
374375
}
375376
--- src/info.c
+++ src/info.c
@@ -363,12 +363,13 @@
363 }else{
364 int x;
365 if( sideBySide ){
366 diffFlags = DIFF_SIDEBYSIDE | DIFF_IGNORE_EOLWS;
367
368 /* "dw" query parameter determines width of each column */
369 x = atoi(PD("dw","80"))*(DIFF_CONTEXT_MASK+1);
 
370 if( x<0 || x>DIFF_WIDTH_MASK ) x = DIFF_WIDTH_MASK;
371 diffFlags += x;
372 }else{
373 diffFlags = DIFF_INLINE | DIFF_IGNORE_EOLWS;
374 }
375
--- src/info.c
+++ src/info.c
@@ -363,12 +363,13 @@
363 }else{
364 int x;
365 if( sideBySide ){
366 diffFlags = DIFF_SIDEBYSIDE | DIFF_IGNORE_EOLWS;
367
368 /* "dw" query parameter determines width of each column
369 * 0 means autocalculate. */
370 x = atoi(PD("dw","0"))*(DIFF_CONTEXT_MASK+1);
371 if( x<0 || x>DIFF_WIDTH_MASK ) x = DIFF_WIDTH_MASK;
372 diffFlags += x;
373 }else{
374 diffFlags = DIFF_INLINE | DIFF_IGNORE_EOLWS;
375 }
376

Keyboard Shortcuts

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