Fossil SCM

Improvement to TH_RETURN handling needed for TH1 hooks. Update and correct TH1 hook tests. Add draft documentation for TH1 hooks.

mistachkin 2017-10-04 05:35 trunk
Commit 36f0e47b3275937da8b73a7376c9eec417066e6f84cc4ffb68304fd5ce31d5a9
+2 -2
--- src/main.c
+++ src/main.c
@@ -735,11 +735,11 @@
735735
/*
736736
** The TH1 return codes from the hook will be handled as follows:
737737
**
738738
** TH_OK: The xFunc() and the TH1 notification will both be executed.
739739
**
740
- ** TH_ERROR: The xFunc() will be executed, the TH1 notification will be
740
+ ** TH_ERROR: The xFunc() will be skipped, the TH1 notification will be
741741
** skipped. If the xFunc() is being hooked, the error message
742742
** will be emitted.
743743
**
744744
** TH_BREAK: The xFunc() and the TH1 notification will both be skipped.
745745
**
@@ -1664,11 +1664,11 @@
16641664
/*
16651665
** The TH1 return codes from the hook will be handled as follows:
16661666
**
16671667
** TH_OK: The xFunc() and the TH1 notification will both be executed.
16681668
**
1669
- ** TH_ERROR: The xFunc() will be executed, the TH1 notification will be
1669
+ ** TH_ERROR: The xFunc() will be skipped, the TH1 notification will be
16701670
** skipped. If the xFunc() is being hooked, the error message
16711671
** will be emitted.
16721672
**
16731673
** TH_BREAK: The xFunc() and the TH1 notification will both be skipped.
16741674
**
16751675
--- src/main.c
+++ src/main.c
@@ -735,11 +735,11 @@
735 /*
736 ** The TH1 return codes from the hook will be handled as follows:
737 **
738 ** TH_OK: The xFunc() and the TH1 notification will both be executed.
739 **
740 ** TH_ERROR: The xFunc() will be executed, the TH1 notification will be
741 ** skipped. If the xFunc() is being hooked, the error message
742 ** will be emitted.
743 **
744 ** TH_BREAK: The xFunc() and the TH1 notification will both be skipped.
745 **
@@ -1664,11 +1664,11 @@
1664 /*
1665 ** The TH1 return codes from the hook will be handled as follows:
1666 **
1667 ** TH_OK: The xFunc() and the TH1 notification will both be executed.
1668 **
1669 ** TH_ERROR: The xFunc() will be executed, the TH1 notification will be
1670 ** skipped. If the xFunc() is being hooked, the error message
1671 ** will be emitted.
1672 **
1673 ** TH_BREAK: The xFunc() and the TH1 notification will both be skipped.
1674 **
1675
--- src/main.c
+++ src/main.c
@@ -735,11 +735,11 @@
735 /*
736 ** The TH1 return codes from the hook will be handled as follows:
737 **
738 ** TH_OK: The xFunc() and the TH1 notification will both be executed.
739 **
740 ** TH_ERROR: The xFunc() will be skipped, the TH1 notification will be
741 ** skipped. If the xFunc() is being hooked, the error message
742 ** will be emitted.
743 **
744 ** TH_BREAK: The xFunc() and the TH1 notification will both be skipped.
745 **
@@ -1664,11 +1664,11 @@
1664 /*
1665 ** The TH1 return codes from the hook will be handled as follows:
1666 **
1667 ** TH_OK: The xFunc() and the TH1 notification will both be executed.
1668 **
1669 ** TH_ERROR: The xFunc() will be skipped, the TH1 notification will be
1670 ** skipped. If the xFunc() is being hooked, the error message
1671 ** will be emitted.
1672 **
1673 ** TH_BREAK: The xFunc() and the TH1 notification will both be skipped.
1674 **
1675
+1
--- src/th.h
+++ src/th.h
@@ -102,10 +102,11 @@
102102
#define TH_OK 0
103103
#define TH_ERROR 1
104104
#define TH_BREAK 2
105105
#define TH_RETURN 3
106106
#define TH_CONTINUE 4
107
+#define TH_RETURN2 5
107108
108109
/*
109110
** Set and get the interpreter result.
110111
*/
111112
int Th_SetResult(Th_Interp *, const char *, int);
112113
--- src/th.h
+++ src/th.h
@@ -102,10 +102,11 @@
102 #define TH_OK 0
103 #define TH_ERROR 1
104 #define TH_BREAK 2
105 #define TH_RETURN 3
106 #define TH_CONTINUE 4
 
107
108 /*
109 ** Set and get the interpreter result.
110 */
111 int Th_SetResult(Th_Interp *, const char *, int);
112
--- src/th.h
+++ src/th.h
@@ -102,10 +102,11 @@
102 #define TH_OK 0
103 #define TH_ERROR 1
104 #define TH_BREAK 2
105 #define TH_RETURN 3
106 #define TH_CONTINUE 4
107 #define TH_RETURN2 5
108
109 /*
110 ** Set and get the interpreter result.
111 */
112 int Th_SetResult(Th_Interp *, const char *, int);
113
--- src/th_lang.c
+++ src/th_lang.c
@@ -432,10 +432,13 @@
432432
procargs.argl = argl;
433433
rc = Th_InFrame(interp, proc_call2, (void *)p, (void *)&procargs);
434434
435435
if( rc==TH_RETURN ){
436436
rc = TH_OK;
437
+ }
438
+ if( rc==TH_RETURN2 ){
439
+ rc = TH_RETURN;
437440
}
438441
return rc;
439442
}
440443
441444
/*
442445
--- src/th_lang.c
+++ src/th_lang.c
@@ -432,10 +432,13 @@
432 procargs.argl = argl;
433 rc = Th_InFrame(interp, proc_call2, (void *)p, (void *)&procargs);
434
435 if( rc==TH_RETURN ){
436 rc = TH_OK;
 
 
 
437 }
438 return rc;
439 }
440
441 /*
442
--- src/th_lang.c
+++ src/th_lang.c
@@ -432,10 +432,13 @@
432 procargs.argl = argl;
433 rc = Th_InFrame(interp, proc_call2, (void *)p, (void *)&procargs);
434
435 if( rc==TH_RETURN ){
436 rc = TH_OK;
437 }
438 if( rc==TH_RETURN2 ){
439 rc = TH_RETURN;
440 }
441 return rc;
442 }
443
444 /*
445
--- src/th_main.c
+++ src/th_main.c
@@ -299,10 +299,11 @@
299299
case TH_OK: return nullIfOk ? 0 : "TH_OK";
300300
case TH_ERROR: return "TH_ERROR";
301301
case TH_BREAK: return "TH_BREAK";
302302
case TH_RETURN: return "TH_RETURN";
303303
case TH_CONTINUE: return "TH_CONTINUE";
304
+ case TH_RETURN2: return "TH_RETURN2";
304305
default: {
305306
sqlite3_snprintf(sizeof(zRc), zRc, "TH1 return code %d", rc);
306307
}
307308
}
308309
return zRc;
309310
--- src/th_main.c
+++ src/th_main.c
@@ -299,10 +299,11 @@
299 case TH_OK: return nullIfOk ? 0 : "TH_OK";
300 case TH_ERROR: return "TH_ERROR";
301 case TH_BREAK: return "TH_BREAK";
302 case TH_RETURN: return "TH_RETURN";
303 case TH_CONTINUE: return "TH_CONTINUE";
 
304 default: {
305 sqlite3_snprintf(sizeof(zRc), zRc, "TH1 return code %d", rc);
306 }
307 }
308 return zRc;
309
--- src/th_main.c
+++ src/th_main.c
@@ -299,10 +299,11 @@
299 case TH_OK: return nullIfOk ? 0 : "TH_OK";
300 case TH_ERROR: return "TH_ERROR";
301 case TH_BREAK: return "TH_BREAK";
302 case TH_RETURN: return "TH_RETURN";
303 case TH_CONTINUE: return "TH_CONTINUE";
304 case TH_RETURN2: return "TH_RETURN2";
305 default: {
306 sqlite3_snprintf(sizeof(zRc), zRc, "TH1 return code %d", rc);
307 }
308 }
309 return zRc;
310
--- test/th1-hooks.test
+++ test/th1-hooks.test
@@ -70,11 +70,11 @@
7070
} elseif {$::cmd_name eq "test3"} {
7171
emit_hook_log
7272
break "TH_BREAK return code"
7373
} elseif {$::cmd_name eq "test4"} {
7474
emit_hook_log
75
- return -code 2 "TH_RETURN return code"
75
+ return -code 5 "TH_RETURN return code"
7676
} elseif {$::cmd_name eq "timeline"} {
7777
set length [llength $::cmd_args]
7878
set length [expr {$length - 1}]
7979
if {[lindex $::cmd_args $length] eq "custom"} {
8080
append_hook_log "CUSTOM TIMELINE"
@@ -82,10 +82,13 @@
8282
return "custom timeline"
8383
} elseif {[lindex $::cmd_args $length] eq "custom2"} {
8484
emit_hook_log
8585
puts "+++ some stuff here +++"
8686
continue "custom2 timeline"
87
+ } elseif {[lindex $::cmd_args $length] eq "custom3"} {
88
+ emit_hook_log
89
+ return -code 5 "TH_RETURN return code"
8790
} elseif {[lindex $::cmd_args $length] eq "now"} {
8891
emit_hook_log
8992
return "now timeline"
9093
} else {
9194
emit_hook_log
@@ -142,10 +145,18 @@
142145
+++ some stuff here +++
143146
<h1><b>command_hook timeline command_notify timeline</b></h1>}}
144147
145148
###############################################################################
146149
150
+fossil timeline custom3; # NOTE: Bad "WHEN" argument.
151
+
152
+test th1-cmd-hooks-1c {[normalize_result] eq \
153
+{<h1><b>command_hook timeline</b></h1>
154
+unknown check-in or invalid date: custom3}}
155
+
156
+###############################################################################
157
+
147158
fossil timeline
148159
test th1-cmd-hooks-2a {[first_data_line] eq \
149160
{<h1><b>command_hook timeline</b></h1>}}
150161
151162
test th1-cmd-hooks-2b {[second_data_line] eq {ERROR: unsupported timeline}}
@@ -185,13 +196,20 @@
185196
{<h1><b>command_hook test3</b></h1>}}
186197
187198
###############################################################################
188199
189200
fossil test4
190
-test th1-custom-cmd-4a {[string trim $RESULT] eq \
201
+
202
+test th1-custom-cmd-4a {[first_data_line] eq \
191203
{<h1><b>command_hook test4</b></h1>}}
192204
205
+test th1-custom-cmd-4b {[regexp -- \
206
+ {: unknown command: test4$} [second_data_line]]}
207
+
208
+test th1-custom-cmd-4d {[regexp -- \
209
+ {: use "help" for more information$} [third_data_line]]}
210
+
193211
###############################################################################
194212
195213
set RESULT [test_fossil_http $repository $dataFileName /timeline]
196214
197215
test th1-web-hooks-1a {[regexp \
198216
--- test/th1-hooks.test
+++ test/th1-hooks.test
@@ -70,11 +70,11 @@
70 } elseif {$::cmd_name eq "test3"} {
71 emit_hook_log
72 break "TH_BREAK return code"
73 } elseif {$::cmd_name eq "test4"} {
74 emit_hook_log
75 return -code 2 "TH_RETURN return code"
76 } elseif {$::cmd_name eq "timeline"} {
77 set length [llength $::cmd_args]
78 set length [expr {$length - 1}]
79 if {[lindex $::cmd_args $length] eq "custom"} {
80 append_hook_log "CUSTOM TIMELINE"
@@ -82,10 +82,13 @@
82 return "custom timeline"
83 } elseif {[lindex $::cmd_args $length] eq "custom2"} {
84 emit_hook_log
85 puts "+++ some stuff here +++"
86 continue "custom2 timeline"
 
 
 
87 } elseif {[lindex $::cmd_args $length] eq "now"} {
88 emit_hook_log
89 return "now timeline"
90 } else {
91 emit_hook_log
@@ -142,10 +145,18 @@
142 +++ some stuff here +++
143 <h1><b>command_hook timeline command_notify timeline</b></h1>}}
144
145 ###############################################################################
146
 
 
 
 
 
 
 
 
147 fossil timeline
148 test th1-cmd-hooks-2a {[first_data_line] eq \
149 {<h1><b>command_hook timeline</b></h1>}}
150
151 test th1-cmd-hooks-2b {[second_data_line] eq {ERROR: unsupported timeline}}
@@ -185,13 +196,20 @@
185 {<h1><b>command_hook test3</b></h1>}}
186
187 ###############################################################################
188
189 fossil test4
190 test th1-custom-cmd-4a {[string trim $RESULT] eq \
 
191 {<h1><b>command_hook test4</b></h1>}}
192
 
 
 
 
 
 
193 ###############################################################################
194
195 set RESULT [test_fossil_http $repository $dataFileName /timeline]
196
197 test th1-web-hooks-1a {[regexp \
198
--- test/th1-hooks.test
+++ test/th1-hooks.test
@@ -70,11 +70,11 @@
70 } elseif {$::cmd_name eq "test3"} {
71 emit_hook_log
72 break "TH_BREAK return code"
73 } elseif {$::cmd_name eq "test4"} {
74 emit_hook_log
75 return -code 5 "TH_RETURN return code"
76 } elseif {$::cmd_name eq "timeline"} {
77 set length [llength $::cmd_args]
78 set length [expr {$length - 1}]
79 if {[lindex $::cmd_args $length] eq "custom"} {
80 append_hook_log "CUSTOM TIMELINE"
@@ -82,10 +82,13 @@
82 return "custom timeline"
83 } elseif {[lindex $::cmd_args $length] eq "custom2"} {
84 emit_hook_log
85 puts "+++ some stuff here +++"
86 continue "custom2 timeline"
87 } elseif {[lindex $::cmd_args $length] eq "custom3"} {
88 emit_hook_log
89 return -code 5 "TH_RETURN return code"
90 } elseif {[lindex $::cmd_args $length] eq "now"} {
91 emit_hook_log
92 return "now timeline"
93 } else {
94 emit_hook_log
@@ -142,10 +145,18 @@
145 +++ some stuff here +++
146 <h1><b>command_hook timeline command_notify timeline</b></h1>}}
147
148 ###############################################################################
149
150 fossil timeline custom3; # NOTE: Bad "WHEN" argument.
151
152 test th1-cmd-hooks-1c {[normalize_result] eq \
153 {<h1><b>command_hook timeline</b></h1>
154 unknown check-in or invalid date: custom3}}
155
156 ###############################################################################
157
158 fossil timeline
159 test th1-cmd-hooks-2a {[first_data_line] eq \
160 {<h1><b>command_hook timeline</b></h1>}}
161
162 test th1-cmd-hooks-2b {[second_data_line] eq {ERROR: unsupported timeline}}
@@ -185,13 +196,20 @@
196 {<h1><b>command_hook test3</b></h1>}}
197
198 ###############################################################################
199
200 fossil test4
201
202 test th1-custom-cmd-4a {[first_data_line] eq \
203 {<h1><b>command_hook test4</b></h1>}}
204
205 test th1-custom-cmd-4b {[regexp -- \
206 {: unknown command: test4$} [second_data_line]]}
207
208 test th1-custom-cmd-4d {[regexp -- \
209 {: use "help" for more information$} [third_data_line]]}
210
211 ###############################################################################
212
213 set RESULT [test_fossil_http $repository $dataFileName /timeline]
214
215 test th1-web-hooks-1a {[regexp \
216
--- www/index.wiki
+++ www/index.wiki
@@ -127,10 +127,12 @@
127127
[http://www.sqliteconcepts.org/THManual.pdf | TH1 scripting language],
128128
used to customize [./custom_ticket.wiki | ticketing], and several other
129129
subsystems, including [./customskin.md | theming].
130130
* List of [./th1.md | TH1 commands provided by Fossil itself] that expose
131131
its key functionality to TH1 scripts.
132
+ * List of [./th1-hooks.md | TH1 hooks exposed by Fossil] that enable
133
+ customization of commands and web pages.
132134
* A free hosting server for Fossil repositories is available at
133135
[http://chiselapp.com/].
134136
* How to [./server.wiki | set up a server] for your repository.
135137
* Customizing the [./custom_ticket.wiki | ticket system].
136138
* Methods to [./checkin_names.wiki | identify a specific check-in].
137139
138140
ADDED www/th1-hooks.md
--- www/index.wiki
+++ www/index.wiki
@@ -127,10 +127,12 @@
127 [http://www.sqliteconcepts.org/THManual.pdf | TH1 scripting language],
128 used to customize [./custom_ticket.wiki | ticketing], and several other
129 subsystems, including [./customskin.md | theming].
130 * List of [./th1.md | TH1 commands provided by Fossil itself] that expose
131 its key functionality to TH1 scripts.
 
 
132 * A free hosting server for Fossil repositories is available at
133 [http://chiselapp.com/].
134 * How to [./server.wiki | set up a server] for your repository.
135 * Customizing the [./custom_ticket.wiki | ticket system].
136 * Methods to [./checkin_names.wiki | identify a specific check-in].
137
138 DDED www/th1-hooks.md
--- www/index.wiki
+++ www/index.wiki
@@ -127,10 +127,12 @@
127 [http://www.sqliteconcepts.org/THManual.pdf | TH1 scripting language],
128 used to customize [./custom_ticket.wiki | ticketing], and several other
129 subsystems, including [./customskin.md | theming].
130 * List of [./th1.md | TH1 commands provided by Fossil itself] that expose
131 its key functionality to TH1 scripts.
132 * List of [./th1-hooks.md | TH1 hooks exposed by Fossil] that enable
133 customization of commands and web pages.
134 * A free hosting server for Fossil repositories is available at
135 [http://chiselapp.com/].
136 * How to [./server.wiki | set up a server] for your repository.
137 * Customizing the [./custom_ticket.wiki | ticket system].
138 * Methods to [./checkin_names.wiki | identify a specific check-in].
139
140 DDED www/th1-hooks.md
--- a/www/th1-hooks.md
+++ b/www/th1-hooks.md
@@ -0,0 +1,6 @@
1
+TH1 Hooks
2
+=========
3
+
4
+<big><big><big><font color="red">** DRAFT **</font></big></big></big>
5
+
6
+The **
--- a/www/th1-hooks.md
+++ b/www/th1-hooks.md
@@ -0,0 +1,6 @@
 
 
 
 
 
 
--- a/www/th1-hooks.md
+++ b/www/th1-hooks.md
@@ -0,0 +1,6 @@
1 TH1 Hooks
2 =========
3
4 <big><big><big><font color="red">** DRAFT **</font></big></big></big>
5
6 The **

Keyboard Shortcuts

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