Fossil SCM

Fix the --webpage option so that it correctly generates the HTML closing tags for the "fossil test-diff" command.

drh 2021-08-25 17:18 trunk
Commit 7e37ae9549c1a1764a215fbd198a646d499164d7558aae8d85171d463c9549fd
+4 -4
--- src/diff.c
+++ src/diff.c
@@ -2100,17 +2100,17 @@
21002100
if( zErr ) fossil_fatal("regex error: %s", zErr);
21012101
}
21022102
diffFlag = diff_options();
21032103
verify_all_options();
21042104
if( g.argc!=4 ) usage("FILE1 FILE2");
2105
- diff_header(diffFlag);
2106
- diff_print_filenames(g.argv[2], g.argv[3], diffFlag, 0);
2105
+ blob_zero(&out);
2106
+ diff_header(diffFlag, &out);
2107
+ diff_print_filenames(g.argv[2], g.argv[3], diffFlag, &out);
21072108
blob_read_from_file(&a, g.argv[2], ExtFILE);
21082109
blob_read_from_file(&b, g.argv[3], ExtFILE);
2109
- blob_zero(&out);
21102110
text_diff(&a, &b, &out, pRe, diffFlag);
2111
- diff_footer(diffFlag);
2111
+ diff_footer(diffFlag, &out);
21122112
blob_write_to_file(&out, "-");
21132113
re_free(pRe);
21142114
}
21152115
21162116
/**************************************************************************
21172117
--- src/diff.c
+++ src/diff.c
@@ -2100,17 +2100,17 @@
2100 if( zErr ) fossil_fatal("regex error: %s", zErr);
2101 }
2102 diffFlag = diff_options();
2103 verify_all_options();
2104 if( g.argc!=4 ) usage("FILE1 FILE2");
2105 diff_header(diffFlag);
2106 diff_print_filenames(g.argv[2], g.argv[3], diffFlag, 0);
 
2107 blob_read_from_file(&a, g.argv[2], ExtFILE);
2108 blob_read_from_file(&b, g.argv[3], ExtFILE);
2109 blob_zero(&out);
2110 text_diff(&a, &b, &out, pRe, diffFlag);
2111 diff_footer(diffFlag);
2112 blob_write_to_file(&out, "-");
2113 re_free(pRe);
2114 }
2115
2116 /**************************************************************************
2117
--- src/diff.c
+++ src/diff.c
@@ -2100,17 +2100,17 @@
2100 if( zErr ) fossil_fatal("regex error: %s", zErr);
2101 }
2102 diffFlag = diff_options();
2103 verify_all_options();
2104 if( g.argc!=4 ) usage("FILE1 FILE2");
2105 blob_zero(&out);
2106 diff_header(diffFlag, &out);
2107 diff_print_filenames(g.argv[2], g.argv[3], diffFlag, &out);
2108 blob_read_from_file(&a, g.argv[2], ExtFILE);
2109 blob_read_from_file(&b, g.argv[3], ExtFILE);
 
2110 text_diff(&a, &b, &out, pRe, diffFlag);
2111 diff_footer(diffFlag, &out);
2112 blob_write_to_file(&out, "-");
2113 re_free(pRe);
2114 }
2115
2116 /**************************************************************************
2117
+22 -10
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -219,26 +219,38 @@
219219
@ }
220220
@ </style>
221221
@ </head>
222222
@ <body>
223223
;
224
+const char zWebpageEnd[] =
225
+@ </body>
226
+@ </html>
227
+;
224228
225229
/*
226230
** Print a header or footer on the overall diff output.
227231
**
228232
** This is only a factor for --webpage, in which case the header
229233
** is the HTML header CSS definitions and the footer is the HTML
230234
** close tags.
231235
*/
232
-void diff_header(u64 diffFlags){
233
- if( (diffFlags & DIFF_WEBPAGE)!=0 ){
234
- fossil_print("%s", zWebpageHdr);
235
- }
236
-}
237
-void diff_footer(u64 diffFlags){
238
- if( (diffFlags & DIFF_WEBPAGE)!=0 ){
239
- fossil_print("</body></html>\n");
236
+void diff_header(u64 diffFlags, Blob *pOut){
237
+ if( (diffFlags & DIFF_WEBPAGE)!=0 ){
238
+ if( pOut ){
239
+ blob_append(pOut, zWebpageHdr, -1);
240
+ }else{
241
+ fossil_print("%s", zWebpageHdr);
242
+ }
243
+ }
244
+}
245
+void diff_footer(u64 diffFlags, Blob *pOut){
246
+ if( (diffFlags & DIFF_WEBPAGE)!=0 ){
247
+ if( pOut ){
248
+ blob_append(pOut, zWebpageEnd, -1);
249
+ }else{
250
+ fossil_print("%s", zWebpageEnd);
251
+ }
240252
}
241253
}
242254
243255
/*
244256
** Show the difference between two files, one in memory and one on disk.
@@ -1037,11 +1049,11 @@
10371049
ridTo);
10381050
if( zFrom==0 ){
10391051
fossil_fatal("check-in %s has no parent", zTo);
10401052
}
10411053
}
1042
- diff_header(diffFlags);
1054
+ diff_header(diffFlags, 0);
10431055
if( againstUndo ){
10441056
if( db_lget_int("undo_available",0)==0 ){
10451057
fossil_print("No undo or redo is available\n");
10461058
return;
10471059
}
@@ -1065,11 +1077,11 @@
10651077
}
10661078
fossil_free(pFileDir[i].zName);
10671079
}
10681080
fossil_free(pFileDir);
10691081
}
1070
- diff_footer(diffFlags);
1082
+ diff_footer(diffFlags, 0);
10711083
if ( diffFlags & DIFF_NUMSTAT ){
10721084
fossil_print("%10d %10d TOTAL over %d changed files\n",
10731085
g.diffCnt[1], g.diffCnt[2], g.diffCnt[0]);
10741086
}
10751087
}
10761088
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -219,26 +219,38 @@
219 @ }
220 @ </style>
221 @ </head>
222 @ <body>
223 ;
 
 
 
 
224
225 /*
226 ** Print a header or footer on the overall diff output.
227 **
228 ** This is only a factor for --webpage, in which case the header
229 ** is the HTML header CSS definitions and the footer is the HTML
230 ** close tags.
231 */
232 void diff_header(u64 diffFlags){
233 if( (diffFlags & DIFF_WEBPAGE)!=0 ){
234 fossil_print("%s", zWebpageHdr);
235 }
236 }
237 void diff_footer(u64 diffFlags){
238 if( (diffFlags & DIFF_WEBPAGE)!=0 ){
239 fossil_print("</body></html>\n");
 
 
 
 
 
 
 
 
240 }
241 }
242
243 /*
244 ** Show the difference between two files, one in memory and one on disk.
@@ -1037,11 +1049,11 @@
1037 ridTo);
1038 if( zFrom==0 ){
1039 fossil_fatal("check-in %s has no parent", zTo);
1040 }
1041 }
1042 diff_header(diffFlags);
1043 if( againstUndo ){
1044 if( db_lget_int("undo_available",0)==0 ){
1045 fossil_print("No undo or redo is available\n");
1046 return;
1047 }
@@ -1065,11 +1077,11 @@
1065 }
1066 fossil_free(pFileDir[i].zName);
1067 }
1068 fossil_free(pFileDir);
1069 }
1070 diff_footer(diffFlags);
1071 if ( diffFlags & DIFF_NUMSTAT ){
1072 fossil_print("%10d %10d TOTAL over %d changed files\n",
1073 g.diffCnt[1], g.diffCnt[2], g.diffCnt[0]);
1074 }
1075 }
1076
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -219,26 +219,38 @@
219 @ }
220 @ </style>
221 @ </head>
222 @ <body>
223 ;
224 const char zWebpageEnd[] =
225 @ </body>
226 @ </html>
227 ;
228
229 /*
230 ** Print a header or footer on the overall diff output.
231 **
232 ** This is only a factor for --webpage, in which case the header
233 ** is the HTML header CSS definitions and the footer is the HTML
234 ** close tags.
235 */
236 void diff_header(u64 diffFlags, Blob *pOut){
237 if( (diffFlags & DIFF_WEBPAGE)!=0 ){
238 if( pOut ){
239 blob_append(pOut, zWebpageHdr, -1);
240 }else{
241 fossil_print("%s", zWebpageHdr);
242 }
243 }
244 }
245 void diff_footer(u64 diffFlags, Blob *pOut){
246 if( (diffFlags & DIFF_WEBPAGE)!=0 ){
247 if( pOut ){
248 blob_append(pOut, zWebpageEnd, -1);
249 }else{
250 fossil_print("%s", zWebpageEnd);
251 }
252 }
253 }
254
255 /*
256 ** Show the difference between two files, one in memory and one on disk.
@@ -1037,11 +1049,11 @@
1049 ridTo);
1050 if( zFrom==0 ){
1051 fossil_fatal("check-in %s has no parent", zTo);
1052 }
1053 }
1054 diff_header(diffFlags, 0);
1055 if( againstUndo ){
1056 if( db_lget_int("undo_available",0)==0 ){
1057 fossil_print("No undo or redo is available\n");
1058 return;
1059 }
@@ -1065,11 +1077,11 @@
1077 }
1078 fossil_free(pFileDir[i].zName);
1079 }
1080 fossil_free(pFileDir);
1081 }
1082 diff_footer(diffFlags, 0);
1083 if ( diffFlags & DIFF_NUMSTAT ){
1084 fossil_print("%10d %10d TOTAL over %d changed files\n",
1085 g.diffCnt[1], g.diffCnt[2], g.diffCnt[0]);
1086 }
1087 }
1088
+2 -2
--- src/patch.c
+++ src/patch.c
@@ -764,11 +764,11 @@
764764
"in the %s repository", zBaseline, g.zRepositoryName);
765765
}
766766
}
767767
}
768768
769
- diff_header(diffFlags);
769
+ diff_header(diffFlags, 0);
770770
db_prepare(&q,
771771
"SELECT"
772772
" (SELECT blob.rid FROM blob WHERE blob.uuid=chng.hash),"
773773
" pathname," /* 1: new pathname */
774774
" origname," /* 2: original pathname. Null if not renamed */
@@ -836,11 +836,11 @@
836836
blob_reset(&b);
837837
blob_reset(&delta);
838838
}
839839
}
840840
db_finalize(&q);
841
- diff_footer(diffFlags);
841
+ diff_footer(diffFlags, 0);
842842
if( nErr ) fossil_fatal("abort due to prior errors");
843843
}
844844
845845
846846
/*
847847
--- src/patch.c
+++ src/patch.c
@@ -764,11 +764,11 @@
764 "in the %s repository", zBaseline, g.zRepositoryName);
765 }
766 }
767 }
768
769 diff_header(diffFlags);
770 db_prepare(&q,
771 "SELECT"
772 " (SELECT blob.rid FROM blob WHERE blob.uuid=chng.hash),"
773 " pathname," /* 1: new pathname */
774 " origname," /* 2: original pathname. Null if not renamed */
@@ -836,11 +836,11 @@
836 blob_reset(&b);
837 blob_reset(&delta);
838 }
839 }
840 db_finalize(&q);
841 diff_footer(diffFlags);
842 if( nErr ) fossil_fatal("abort due to prior errors");
843 }
844
845
846 /*
847
--- src/patch.c
+++ src/patch.c
@@ -764,11 +764,11 @@
764 "in the %s repository", zBaseline, g.zRepositoryName);
765 }
766 }
767 }
768
769 diff_header(diffFlags, 0);
770 db_prepare(&q,
771 "SELECT"
772 " (SELECT blob.rid FROM blob WHERE blob.uuid=chng.hash),"
773 " pathname," /* 1: new pathname */
774 " origname," /* 2: original pathname. Null if not renamed */
@@ -836,11 +836,11 @@
836 blob_reset(&b);
837 blob_reset(&delta);
838 }
839 }
840 db_finalize(&q);
841 diff_footer(diffFlags, 0);
842 if( nErr ) fossil_fatal("abort due to prior errors");
843 }
844
845
846 /*
847
+2 -2
--- src/stash.c
+++ src/stash.c
@@ -412,11 +412,11 @@
412412
){
413413
Stmt q;
414414
Blob empty;
415415
int bWebpage = (diffFlags & DIFF_WEBPAGE)!=0;
416416
blob_zero(&empty);
417
- diff_header(diffFlags);
417
+ diff_header(diffFlags, 0);
418418
db_prepare(&q,
419419
"SELECT blob.rid, isRemoved, isExec, isLink, origname, newname, delta"
420420
" FROM stashfile, blob WHERE stashid=%d AND blob.uuid=stashfile.hash",
421421
stashid
422422
);
@@ -475,11 +475,11 @@
475475
}
476476
blob_reset(&delta);
477477
}
478478
}
479479
db_finalize(&q);
480
- diff_footer(diffFlags);
480
+ diff_footer(diffFlags, 0);
481481
}
482482
483483
/*
484484
** Drop the indicated stash
485485
*/
486486
--- src/stash.c
+++ src/stash.c
@@ -412,11 +412,11 @@
412 ){
413 Stmt q;
414 Blob empty;
415 int bWebpage = (diffFlags & DIFF_WEBPAGE)!=0;
416 blob_zero(&empty);
417 diff_header(diffFlags);
418 db_prepare(&q,
419 "SELECT blob.rid, isRemoved, isExec, isLink, origname, newname, delta"
420 " FROM stashfile, blob WHERE stashid=%d AND blob.uuid=stashfile.hash",
421 stashid
422 );
@@ -475,11 +475,11 @@
475 }
476 blob_reset(&delta);
477 }
478 }
479 db_finalize(&q);
480 diff_footer(diffFlags);
481 }
482
483 /*
484 ** Drop the indicated stash
485 */
486
--- src/stash.c
+++ src/stash.c
@@ -412,11 +412,11 @@
412 ){
413 Stmt q;
414 Blob empty;
415 int bWebpage = (diffFlags & DIFF_WEBPAGE)!=0;
416 blob_zero(&empty);
417 diff_header(diffFlags, 0);
418 db_prepare(&q,
419 "SELECT blob.rid, isRemoved, isExec, isLink, origname, newname, delta"
420 " FROM stashfile, blob WHERE stashid=%d AND blob.uuid=stashfile.hash",
421 stashid
422 );
@@ -475,11 +475,11 @@
475 }
476 blob_reset(&delta);
477 }
478 }
479 db_finalize(&q);
480 diff_footer(diffFlags, 0);
481 }
482
483 /*
484 ** Drop the indicated stash
485 */
486

Keyboard Shortcuts

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