Fossil SCM

Minor C-side fossil JS API simplification to ease upcoming changes.

stephan 2020-09-18 05:07 trunk
Commit 58d86b16bf2c233e03f34ab9960ce75336d345a4e7a2e5613fc3915495690e2c
+37 -3
--- src/builtin.c
+++ src/builtin.c
@@ -700,19 +700,52 @@
700700
builtin_emit_script_fossil_bootstrap(1);
701701
}
702702
zName = mprintf("fossil.%s.js", zApi);
703703
builtin_request_js(zName);
704704
fossil_free(zName);
705
+ va_start(vargs,zApi);
706
+ while( (zArg = va_arg (vargs, const char *))!=0 ){
707
+ zName = mprintf("fossil.%s.js", zArg);
708
+ builtin_request_js(zName);
709
+ fossil_free(zName);
710
+ }
711
+ va_end(vargs);
712
+}
713
+
714
+/*
715
+** This is a variant of builtin_emit_fossil_js_apis() which is
716
+** equivalent to:
717
+**
718
+** if(!builtin_bundle_all_fossil_js_apis()){
719
+** builtin_emit_fossil_js_apis(zApi, ...args);
720
+** }
721
+**
722
+*/
723
+void builtin_fossil_js_bundle_or( const char * zApi, ... ) {
724
+ const char *zArg;
725
+ char * zName;
726
+ va_list vargs;
727
+ static int once = 0;
705728
729
+ if(builtin_bundle_all_fossil_js_apis()){
730
+ return;
731
+ }
732
+ if(0==once++){
733
+ builtin_emit_script_fossil_bootstrap(1);
734
+ }
735
+ zName = mprintf("fossil.%s.js", zApi);
736
+ builtin_request_js(zName);
737
+ fossil_free(zName);
706738
va_start(vargs,zApi);
707739
while( (zArg = va_arg (vargs, const char *))!=0 ){
708740
zName = mprintf("fossil.%s.js", zArg);
709741
builtin_request_js(zName);
710742
fossil_free(zName);
711743
}
712744
va_end(vargs);
713745
}
746
+
714747
715748
/*
716749
** If builtin_get_js_delivery_mode() returns JS_BUNDLED then this
717750
** function emits, via builtin_request_js(), all JS fossil.XYZ APIs
718751
** which are not strictly specific to a single page, and then calls
@@ -724,11 +757,11 @@
724757
**
725758
** If the current JS delivery mode is *not* JS_BUNDLED then this
726759
** function is a no-op and returns false. The reason is simply because
727760
** bundled mode is the only mode in which this API improves aggregate
728761
** over-the-wire and HTTP request costs. For other modes, reducing the
729
-** inclusion of fossil.XYZ APIs to their bare minimum, provides the
762
+** inclusion of fossil.XYZ APIs to their bare minimum provides the
730763
** lowest aggregate costs. For debate and details, see the discussion
731764
** at:
732765
**
733766
** https://fossil-scm.org/forum/forumpost/3fa2633f3e
734767
**
@@ -759,12 +792,13 @@
759792
if(!bundled){
760793
bundled = 1;
761794
builtin_emit_fossil_js_apis(
762795
/* The order of the following arguments is important: any
763796
which have dependencies must be listed after their
764
- dependencies. ALL of them depend on the core
765
- window.fossil bootstrapping bits. */
797
+ dependencies. ALL of them depend on the core window.fossil
798
+ bootstrapping bits, and those are initialize by this
799
+ call. */
766800
"dom", "fetch", "storage", "tabs",
767801
"confirmer", "popupwidget",
768802
"copybutton", "numbered-lines",
769803
"pikchr",
770804
0);
771805
--- src/builtin.c
+++ src/builtin.c
@@ -700,19 +700,52 @@
700 builtin_emit_script_fossil_bootstrap(1);
701 }
702 zName = mprintf("fossil.%s.js", zApi);
703 builtin_request_js(zName);
704 fossil_free(zName);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
705
 
 
 
 
 
 
 
 
 
706 va_start(vargs,zApi);
707 while( (zArg = va_arg (vargs, const char *))!=0 ){
708 zName = mprintf("fossil.%s.js", zArg);
709 builtin_request_js(zName);
710 fossil_free(zName);
711 }
712 va_end(vargs);
713 }
 
714
715 /*
716 ** If builtin_get_js_delivery_mode() returns JS_BUNDLED then this
717 ** function emits, via builtin_request_js(), all JS fossil.XYZ APIs
718 ** which are not strictly specific to a single page, and then calls
@@ -724,11 +757,11 @@
724 **
725 ** If the current JS delivery mode is *not* JS_BUNDLED then this
726 ** function is a no-op and returns false. The reason is simply because
727 ** bundled mode is the only mode in which this API improves aggregate
728 ** over-the-wire and HTTP request costs. For other modes, reducing the
729 ** inclusion of fossil.XYZ APIs to their bare minimum, provides the
730 ** lowest aggregate costs. For debate and details, see the discussion
731 ** at:
732 **
733 ** https://fossil-scm.org/forum/forumpost/3fa2633f3e
734 **
@@ -759,12 +792,13 @@
759 if(!bundled){
760 bundled = 1;
761 builtin_emit_fossil_js_apis(
762 /* The order of the following arguments is important: any
763 which have dependencies must be listed after their
764 dependencies. ALL of them depend on the core
765 window.fossil bootstrapping bits. */
 
766 "dom", "fetch", "storage", "tabs",
767 "confirmer", "popupwidget",
768 "copybutton", "numbered-lines",
769 "pikchr",
770 0);
771
--- src/builtin.c
+++ src/builtin.c
@@ -700,19 +700,52 @@
700 builtin_emit_script_fossil_bootstrap(1);
701 }
702 zName = mprintf("fossil.%s.js", zApi);
703 builtin_request_js(zName);
704 fossil_free(zName);
705 va_start(vargs,zApi);
706 while( (zArg = va_arg (vargs, const char *))!=0 ){
707 zName = mprintf("fossil.%s.js", zArg);
708 builtin_request_js(zName);
709 fossil_free(zName);
710 }
711 va_end(vargs);
712 }
713
714 /*
715 ** This is a variant of builtin_emit_fossil_js_apis() which is
716 ** equivalent to:
717 **
718 ** if(!builtin_bundle_all_fossil_js_apis()){
719 ** builtin_emit_fossil_js_apis(zApi, ...args);
720 ** }
721 **
722 */
723 void builtin_fossil_js_bundle_or( const char * zApi, ... ) {
724 const char *zArg;
725 char * zName;
726 va_list vargs;
727 static int once = 0;
728
729 if(builtin_bundle_all_fossil_js_apis()){
730 return;
731 }
732 if(0==once++){
733 builtin_emit_script_fossil_bootstrap(1);
734 }
735 zName = mprintf("fossil.%s.js", zApi);
736 builtin_request_js(zName);
737 fossil_free(zName);
738 va_start(vargs,zApi);
739 while( (zArg = va_arg (vargs, const char *))!=0 ){
740 zName = mprintf("fossil.%s.js", zArg);
741 builtin_request_js(zName);
742 fossil_free(zName);
743 }
744 va_end(vargs);
745 }
746
747
748 /*
749 ** If builtin_get_js_delivery_mode() returns JS_BUNDLED then this
750 ** function emits, via builtin_request_js(), all JS fossil.XYZ APIs
751 ** which are not strictly specific to a single page, and then calls
@@ -724,11 +757,11 @@
757 **
758 ** If the current JS delivery mode is *not* JS_BUNDLED then this
759 ** function is a no-op and returns false. The reason is simply because
760 ** bundled mode is the only mode in which this API improves aggregate
761 ** over-the-wire and HTTP request costs. For other modes, reducing the
762 ** inclusion of fossil.XYZ APIs to their bare minimum provides the
763 ** lowest aggregate costs. For debate and details, see the discussion
764 ** at:
765 **
766 ** https://fossil-scm.org/forum/forumpost/3fa2633f3e
767 **
@@ -759,12 +792,13 @@
792 if(!bundled){
793 bundled = 1;
794 builtin_emit_fossil_js_apis(
795 /* The order of the following arguments is important: any
796 which have dependencies must be listed after their
797 dependencies. ALL of them depend on the core window.fossil
798 bootstrapping bits, and those are initialize by this
799 call. */
800 "dom", "fetch", "storage", "tabs",
801 "confirmer", "popupwidget",
802 "copybutton", "numbered-lines",
803 "pikchr",
804 0);
805
+1 -4
--- src/doc.c
+++ src/doc.c
@@ -404,14 +404,11 @@
404404
** Emit Javascript which applies (or optionally can apply) to both the
405405
** /doc and /wiki pages. None of this implements required
406406
** functionality, just nice-to-haves. Only call this once per page.
407407
*/
408408
void document_emit_js(void){
409
- if(!builtin_bundle_all_fossil_js_apis()){
410
- builtin_emit_fossil_js_apis("dom", "copybutton",
411
- "pikchr", 0);
412
- }
409
+ builtin_fossil_js_bundle_or("dom", "copybutton", "pikchr", 0);
413410
style_script_begin(__FILE__,__LINE__);
414411
CX("window.addEventListener('load', "
415412
"()=>window.fossil.pikchr.addSrcView(), "
416413
"false);\n");
417414
style_script_end();
418415
--- src/doc.c
+++ src/doc.c
@@ -404,14 +404,11 @@
404 ** Emit Javascript which applies (or optionally can apply) to both the
405 ** /doc and /wiki pages. None of this implements required
406 ** functionality, just nice-to-haves. Only call this once per page.
407 */
408 void document_emit_js(void){
409 if(!builtin_bundle_all_fossil_js_apis()){
410 builtin_emit_fossil_js_apis("dom", "copybutton",
411 "pikchr", 0);
412 }
413 style_script_begin(__FILE__,__LINE__);
414 CX("window.addEventListener('load', "
415 "()=>window.fossil.pikchr.addSrcView(), "
416 "false);\n");
417 style_script_end();
418
--- src/doc.c
+++ src/doc.c
@@ -404,14 +404,11 @@
404 ** Emit Javascript which applies (or optionally can apply) to both the
405 ** /doc and /wiki pages. None of this implements required
406 ** functionality, just nice-to-haves. Only call this once per page.
407 */
408 void document_emit_js(void){
409 builtin_fossil_js_bundle_or("dom", "copybutton", "pikchr", 0);
 
 
 
410 style_script_begin(__FILE__,__LINE__);
411 CX("window.addEventListener('load', "
412 "()=>window.fossil.pikchr.addSrcView(), "
413 "false);\n");
414 style_script_end();
415
+3 -5
--- src/fileedit.c
+++ src/fileedit.c
@@ -1987,15 +1987,13 @@
19871987
"file/check-in combination are discarded.</li>");
19881988
CX("</ul>");
19891989
}
19901990
CX("</div>"/*#fileedit-tab-help*/);
19911991
1992
- if(!builtin_bundle_all_fossil_js_apis()){
1993
- builtin_emit_fossil_js_apis("fetch", "dom", "tabs", "confirmer",
1994
- "storage", "popupwidget", "copybutton",
1995
- "pikchr", 0);
1996
- }
1992
+ builtin_fossil_js_bundle_or("fetch", "dom", "tabs", "confirmer",
1993
+ "storage", "popupwidget", "copybutton",
1994
+ "pikchr", 0);
19971995
/*
19981996
** Set up a JS-side mapping of the AJAX_RENDER_xyz values. This is
19991997
** used for dynamically toggling certain UI components on and off.
20001998
** Must come after window.fossil has been intialized and before
20011999
** fossil.page.fileedit.js. Potential TODO: move this into the
20022000
--- src/fileedit.c
+++ src/fileedit.c
@@ -1987,15 +1987,13 @@
1987 "file/check-in combination are discarded.</li>");
1988 CX("</ul>");
1989 }
1990 CX("</div>"/*#fileedit-tab-help*/);
1991
1992 if(!builtin_bundle_all_fossil_js_apis()){
1993 builtin_emit_fossil_js_apis("fetch", "dom", "tabs", "confirmer",
1994 "storage", "popupwidget", "copybutton",
1995 "pikchr", 0);
1996 }
1997 /*
1998 ** Set up a JS-side mapping of the AJAX_RENDER_xyz values. This is
1999 ** used for dynamically toggling certain UI components on and off.
2000 ** Must come after window.fossil has been intialized and before
2001 ** fossil.page.fileedit.js. Potential TODO: move this into the
2002
--- src/fileedit.c
+++ src/fileedit.c
@@ -1987,15 +1987,13 @@
1987 "file/check-in combination are discarded.</li>");
1988 CX("</ul>");
1989 }
1990 CX("</div>"/*#fileedit-tab-help*/);
1991
1992 builtin_fossil_js_bundle_or("fetch", "dom", "tabs", "confirmer",
1993 "storage", "popupwidget", "copybutton",
1994 "pikchr", 0);
 
 
1995 /*
1996 ** Set up a JS-side mapping of the AJAX_RENDER_xyz values. This is
1997 ** used for dynamically toggling certain UI components on and off.
1998 ** Must come after window.fossil has been intialized and before
1999 ** fossil.page.fileedit.js. Potential TODO: move this into the
2000
+1 -4
--- src/forum.c
+++ src/forum.c
@@ -742,14 +742,11 @@
742742
** Emit Forum Javascript which applies (or optionally can apply)
743743
** to all forum-related pages. It does not include page-specific
744744
** code (e.g. "forum.js").
745745
*/
746746
static void forum_emit_js(void){
747
- if(!builtin_bundle_all_fossil_js_apis()){
748
- builtin_emit_fossil_js_apis("dom", "copybutton",
749
- "pikchr", 0);
750
- }
747
+ builtin_fossil_js_bundle_or("dom", "copybutton", "pikchr", 0);
751748
builtin_emit_fossil_js_apis("page.forumpost", 0);
752749
}
753750
754751
/*
755752
** WEBPAGE: forumpost
756753
--- src/forum.c
+++ src/forum.c
@@ -742,14 +742,11 @@
742 ** Emit Forum Javascript which applies (or optionally can apply)
743 ** to all forum-related pages. It does not include page-specific
744 ** code (e.g. "forum.js").
745 */
746 static void forum_emit_js(void){
747 if(!builtin_bundle_all_fossil_js_apis()){
748 builtin_emit_fossil_js_apis("dom", "copybutton",
749 "pikchr", 0);
750 }
751 builtin_emit_fossil_js_apis("page.forumpost", 0);
752 }
753
754 /*
755 ** WEBPAGE: forumpost
756
--- src/forum.c
+++ src/forum.c
@@ -742,14 +742,11 @@
742 ** Emit Forum Javascript which applies (or optionally can apply)
743 ** to all forum-related pages. It does not include page-specific
744 ** code (e.g. "forum.js").
745 */
746 static void forum_emit_js(void){
747 builtin_fossil_js_bundle_or("dom", "copybutton", "pikchr", 0);
 
 
 
748 builtin_emit_fossil_js_apis("page.forumpost", 0);
749 }
750
751 /*
752 ** WEBPAGE: forumpost
753
+2 -4
--- src/info.c
+++ src/info.c
@@ -2129,14 +2129,12 @@
21292129
if(includeJS && !emittedJS){
21302130
emittedJS = 1;
21312131
if( db_int(0, "SELECT EXISTS(SELECT 1 FROM lnos)") ){
21322132
builtin_request_js("scroll.js");
21332133
}
2134
- if(!builtin_bundle_all_fossil_js_apis()){
2135
- builtin_emit_fossil_js_apis("dom", "copybutton", "popupwidget",
2136
- "numbered-lines", 0);
2137
- }
2134
+ builtin_fossil_js_bundle_or("dom", "copybutton", "popupwidget",
2135
+ "numbered-lines", 0);
21382136
}
21392137
}
21402138
21412139
/*
21422140
** COMMAND: test-line-numbers
21432141
--- src/info.c
+++ src/info.c
@@ -2129,14 +2129,12 @@
2129 if(includeJS && !emittedJS){
2130 emittedJS = 1;
2131 if( db_int(0, "SELECT EXISTS(SELECT 1 FROM lnos)") ){
2132 builtin_request_js("scroll.js");
2133 }
2134 if(!builtin_bundle_all_fossil_js_apis()){
2135 builtin_emit_fossil_js_apis("dom", "copybutton", "popupwidget",
2136 "numbered-lines", 0);
2137 }
2138 }
2139 }
2140
2141 /*
2142 ** COMMAND: test-line-numbers
2143
--- src/info.c
+++ src/info.c
@@ -2129,14 +2129,12 @@
2129 if(includeJS && !emittedJS){
2130 emittedJS = 1;
2131 if( db_int(0, "SELECT EXISTS(SELECT 1 FROM lnos)") ){
2132 builtin_request_js("scroll.js");
2133 }
2134 builtin_fossil_js_bundle_or("dom", "copybutton", "popupwidget",
2135 "numbered-lines", 0);
 
 
2136 }
2137 }
2138
2139 /*
2140 ** COMMAND: test-line-numbers
2141
--- src/pikchrshow.c
+++ src/pikchrshow.c
@@ -357,15 +357,12 @@
357357
CX("%b", &out);
358358
blob_reset(&out);
359359
} CX("</div>"/*#pikchrshow-output*/);
360360
} CX("</fieldset>"/*#pikchrshow-output-wrapper*/);
361361
} CX("</div>"/*sbs-wrapper*/);
362
- if(!builtin_bundle_all_fossil_js_apis()){
363
- builtin_emit_fossil_js_apis("dom", "fetch", "copybutton",
364
- "popupwidget", "storage",
365
- "pikchr", 0);
366
- }
362
+ builtin_fossil_js_bundle_or("dom", "fetch", "copybutton",
363
+ "popupwidget", "storage", "pikchr", 0);
367364
builtin_emit_fossil_js_apis("page.pikchrshow", 0);
368365
builtin_fulfill_js_requests();
369366
style_footer();
370367
}
371368
372369
--- src/pikchrshow.c
+++ src/pikchrshow.c
@@ -357,15 +357,12 @@
357 CX("%b", &out);
358 blob_reset(&out);
359 } CX("</div>"/*#pikchrshow-output*/);
360 } CX("</fieldset>"/*#pikchrshow-output-wrapper*/);
361 } CX("</div>"/*sbs-wrapper*/);
362 if(!builtin_bundle_all_fossil_js_apis()){
363 builtin_emit_fossil_js_apis("dom", "fetch", "copybutton",
364 "popupwidget", "storage",
365 "pikchr", 0);
366 }
367 builtin_emit_fossil_js_apis("page.pikchrshow", 0);
368 builtin_fulfill_js_requests();
369 style_footer();
370 }
371
372
--- src/pikchrshow.c
+++ src/pikchrshow.c
@@ -357,15 +357,12 @@
357 CX("%b", &out);
358 blob_reset(&out);
359 } CX("</div>"/*#pikchrshow-output*/);
360 } CX("</fieldset>"/*#pikchrshow-output-wrapper*/);
361 } CX("</div>"/*sbs-wrapper*/);
362 builtin_fossil_js_bundle_or("dom", "fetch", "copybutton",
363 "popupwidget", "storage", "pikchr", 0);
 
 
 
364 builtin_emit_fossil_js_apis("page.pikchrshow", 0);
365 builtin_fulfill_js_requests();
366 style_footer();
367 }
368
369
+3 -5
--- src/wiki.c
+++ src/wiki.c
@@ -1282,15 +1282,13 @@
12821282
"sandbox page will fail.</p>");
12831283
CX("<h2>Wiki Name Rules</h2>");
12841284
well_formed_wiki_name_rules();
12851285
CX("</div>"/*#wikiedit-tab-save*/);
12861286
}
1287
- if(!builtin_bundle_all_fossil_js_apis()){
1288
- builtin_emit_fossil_js_apis("fetch", "dom", "tabs", "confirmer",
1289
- "storage", "popupwidget", "copybutton",
1290
- "pikchr", 0);
1291
- }
1287
+ builtin_fossil_js_bundle_or("fetch", "dom", "tabs", "confirmer",
1288
+ "storage", "popupwidget", "copybutton",
1289
+ "pikchr", 0);
12921290
builtin_request_js("sbsdiff.js");
12931291
builtin_request_js("fossil.page.wikiedit.js");
12941292
builtin_fulfill_js_requests();
12951293
/* Dynamically populate the editor... */
12961294
style_script_begin(__FILE__,__LINE__);
12971295
--- src/wiki.c
+++ src/wiki.c
@@ -1282,15 +1282,13 @@
1282 "sandbox page will fail.</p>");
1283 CX("<h2>Wiki Name Rules</h2>");
1284 well_formed_wiki_name_rules();
1285 CX("</div>"/*#wikiedit-tab-save*/);
1286 }
1287 if(!builtin_bundle_all_fossil_js_apis()){
1288 builtin_emit_fossil_js_apis("fetch", "dom", "tabs", "confirmer",
1289 "storage", "popupwidget", "copybutton",
1290 "pikchr", 0);
1291 }
1292 builtin_request_js("sbsdiff.js");
1293 builtin_request_js("fossil.page.wikiedit.js");
1294 builtin_fulfill_js_requests();
1295 /* Dynamically populate the editor... */
1296 style_script_begin(__FILE__,__LINE__);
1297
--- src/wiki.c
+++ src/wiki.c
@@ -1282,15 +1282,13 @@
1282 "sandbox page will fail.</p>");
1283 CX("<h2>Wiki Name Rules</h2>");
1284 well_formed_wiki_name_rules();
1285 CX("</div>"/*#wikiedit-tab-save*/);
1286 }
1287 builtin_fossil_js_bundle_or("fetch", "dom", "tabs", "confirmer",
1288 "storage", "popupwidget", "copybutton",
1289 "pikchr", 0);
 
 
1290 builtin_request_js("sbsdiff.js");
1291 builtin_request_js("fossil.page.wikiedit.js");
1292 builtin_fulfill_js_requests();
1293 /* Dynamically populate the editor... */
1294 style_script_begin(__FILE__,__LINE__);
1295

Keyboard Shortcuts

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