Fossil SCM

Fixed a minor denkfehler in the "bump <1ms runtime to 1ms" logic. Changed g.json.gc to an array (lower memory and better performance for what we use it for).

stephan 2011-10-07 02:58 UTC json-multitag-test
Commit 19276984bde340079137e0ddb8498c449b41de6a
--- ajax/index.html
+++ ajax/index.html
@@ -237,10 +237,14 @@
237237
<input type='button' value='resultCodes' onclick='TheApp.cgi.sendCommand("/json/resultCodes")' />
238238
<input type='button' value='tag/list' onclick='TheApp.cgi.sendCommand("/json/tag/list?includeTickets=false&raw=false")' />
239239
<input type='button' value='tag/list/json' onclick='TheApp.cgi.sendCommand("/json/tag/list/json?raw=false")' />
240240
<input type='button' value='tag/add'
241241
onclick='TheApp.cgi.sendCommand("/json/tag/add",{name:"json-add-tag-test",checkin:"json",value:"tag test",propagate:false,raw:false})' />
242
+<input type='button' value='tag/cancel'
243
+onclick='TheApp.cgi.sendCommand("/json/tag/cancel",{name:"json-add-tag-test",checkin:"json",raw:false})' />
244
+<input type='button' value='tag/find'
245
+onclick='TheApp.cgi.sendCommand("/json/tag/find",{name:"json",type:"*",raw:false,limit:5})' />
242246
<!-- not yet ready...
243247
<input type='button' value='artifact/XYZ' onclick='TheApp.cgi.sendCommand("/json/artifact?uuid=json")' />
244248
-->
245249
246250
<!--
247251
--- ajax/index.html
+++ ajax/index.html
@@ -237,10 +237,14 @@
237 <input type='button' value='resultCodes' onclick='TheApp.cgi.sendCommand("/json/resultCodes")' />
238 <input type='button' value='tag/list' onclick='TheApp.cgi.sendCommand("/json/tag/list?includeTickets=false&raw=false")' />
239 <input type='button' value='tag/list/json' onclick='TheApp.cgi.sendCommand("/json/tag/list/json?raw=false")' />
240 <input type='button' value='tag/add'
241 onclick='TheApp.cgi.sendCommand("/json/tag/add",{name:"json-add-tag-test",checkin:"json",value:"tag test",propagate:false,raw:false})' />
 
 
 
 
242 <!-- not yet ready...
243 <input type='button' value='artifact/XYZ' onclick='TheApp.cgi.sendCommand("/json/artifact?uuid=json")' />
244 -->
245
246 <!--
247
--- ajax/index.html
+++ ajax/index.html
@@ -237,10 +237,14 @@
237 <input type='button' value='resultCodes' onclick='TheApp.cgi.sendCommand("/json/resultCodes")' />
238 <input type='button' value='tag/list' onclick='TheApp.cgi.sendCommand("/json/tag/list?includeTickets=false&raw=false")' />
239 <input type='button' value='tag/list/json' onclick='TheApp.cgi.sendCommand("/json/tag/list/json?raw=false")' />
240 <input type='button' value='tag/add'
241 onclick='TheApp.cgi.sendCommand("/json/tag/add",{name:"json-add-tag-test",checkin:"json",value:"tag test",propagate:false,raw:false})' />
242 <input type='button' value='tag/cancel'
243 onclick='TheApp.cgi.sendCommand("/json/tag/cancel",{name:"json-add-tag-test",checkin:"json",raw:false})' />
244 <input type='button' value='tag/find'
245 onclick='TheApp.cgi.sendCommand("/json/tag/find",{name:"json",type:"*",raw:false,limit:5})' />
246 <!-- not yet ready...
247 <input type='button' value='artifact/XYZ' onclick='TheApp.cgi.sendCommand("/json/artifact?uuid=json")' />
248 -->
249
250 <!--
251
+14 -14
--- src/json.c
+++ src/json.c
@@ -340,34 +340,34 @@
340340
sprintf(buf+7,"%04d", code);
341341
return buf;
342342
}
343343
344344
/*
345
-** Adds v to the API-internal cleanup mechanism. key must be a unique
346
-** key for the given element. Adding another item with that key may
347
-** free the previous one (depending on its reference count). If
348
-** freeOnError is true then v is passed to cson_value_free() if the
349
-** key cannot be inserted, otherweise ownership of v is not changed on
350
-** error. Failure to insert a key may be caused by any of the
351
-** following:
345
+** Adds v to the API-internal cleanup mechanism. key is ingored
346
+** (legacy). If freeOnError is true then v is passed to
347
+** cson_value_free() if the key cannot be inserted, otherweise
348
+** ownership of v is not changed on error. Failure to insert an item
349
+** may be caused by any of the following:
352350
**
353351
** - Allocation error.
354
-** - g.json.gc.o is NULL
352
+** - g.json.gc.a is NULL
355353
** - key is NULL or empty.
356354
**
357355
** Returns 0 on success.
358356
**
359357
** On success, ownership of v is transfered to (or shared with)
360358
** g.json.gc, and v will be valid until that object is cleaned up or
361
-** its key is replaced via another call to this function.
359
+** some internal code incorrectly removes it from the gc (which we
360
+** never do).
362361
*/
363362
int json_gc_add( char const * key, cson_value * v, char freeOnError ){
364
- int const rc = cson_object_set( g.json.gc.o, key, v );
365
- assert( NULL != g.json.gc.o );
363
+ int const rc = cson_array_append( g.json.gc.a, v );
364
+ assert( NULL != g.json.gc.a );
366365
if( (0 != rc) && freeOnError ){
367366
cson_value_free( v );
368367
}
368
+ assert( (0==rc) && "Adding item to GC failed." );
369369
return rc;
370370
}
371371
372372
373373
/*
@@ -781,13 +781,13 @@
781781
782782
/* g.json.gc is our "garbage collector" - where we put JSON values
783783
which need a long lifetime but don't have a logical parent to put
784784
them in.
785785
*/
786
- v = cson_value_new_object();
786
+ v = cson_value_new_array();
787787
g.json.gc.v = v;
788
- g.json.gc.o = cson_value_get_object(v);
788
+ g.json.gc.a = cson_value_get_array(v);
789789
790790
/*
791791
g.json.param holds the JSONized counterpart of fossil's
792792
cgi_parameter_xxx() family of data. We store them as JSON, as
793793
opposed to using fossil's data directly, because we can retain
@@ -1412,11 +1412,11 @@
14121412
double span;
14131413
span = END_TIMER;
14141414
/* i'm actually seeing sub-ms runtimes in some tests, but a time of
14151415
0 is "just wrong", so we'll bump that up to 1ms.
14161416
*/
1417
- cson_object_set(o,"procTimeMs", cson_value_new_integer((cson_int_t)((span>0.0)?span:1)));
1417
+ cson_object_set(o,"procTimeMs", cson_value_new_integer((cson_int_t)((span>1.0)?span:1)));
14181418
}
14191419
if(g.json.warnings.v){
14201420
tmp = g.json.warnings.v;
14211421
SET("warnings");
14221422
}
14231423
--- src/json.c
+++ src/json.c
@@ -340,34 +340,34 @@
340 sprintf(buf+7,"%04d", code);
341 return buf;
342 }
343
344 /*
345 ** Adds v to the API-internal cleanup mechanism. key must be a unique
346 ** key for the given element. Adding another item with that key may
347 ** free the previous one (depending on its reference count). If
348 ** freeOnError is true then v is passed to cson_value_free() if the
349 ** key cannot be inserted, otherweise ownership of v is not changed on
350 ** error. Failure to insert a key may be caused by any of the
351 ** following:
352 **
353 ** - Allocation error.
354 ** - g.json.gc.o is NULL
355 ** - key is NULL or empty.
356 **
357 ** Returns 0 on success.
358 **
359 ** On success, ownership of v is transfered to (or shared with)
360 ** g.json.gc, and v will be valid until that object is cleaned up or
361 ** its key is replaced via another call to this function.
 
362 */
363 int json_gc_add( char const * key, cson_value * v, char freeOnError ){
364 int const rc = cson_object_set( g.json.gc.o, key, v );
365 assert( NULL != g.json.gc.o );
366 if( (0 != rc) && freeOnError ){
367 cson_value_free( v );
368 }
 
369 return rc;
370 }
371
372
373 /*
@@ -781,13 +781,13 @@
781
782 /* g.json.gc is our "garbage collector" - where we put JSON values
783 which need a long lifetime but don't have a logical parent to put
784 them in.
785 */
786 v = cson_value_new_object();
787 g.json.gc.v = v;
788 g.json.gc.o = cson_value_get_object(v);
789
790 /*
791 g.json.param holds the JSONized counterpart of fossil's
792 cgi_parameter_xxx() family of data. We store them as JSON, as
793 opposed to using fossil's data directly, because we can retain
@@ -1412,11 +1412,11 @@
1412 double span;
1413 span = END_TIMER;
1414 /* i'm actually seeing sub-ms runtimes in some tests, but a time of
1415 0 is "just wrong", so we'll bump that up to 1ms.
1416 */
1417 cson_object_set(o,"procTimeMs", cson_value_new_integer((cson_int_t)((span>0.0)?span:1)));
1418 }
1419 if(g.json.warnings.v){
1420 tmp = g.json.warnings.v;
1421 SET("warnings");
1422 }
1423
--- src/json.c
+++ src/json.c
@@ -340,34 +340,34 @@
340 sprintf(buf+7,"%04d", code);
341 return buf;
342 }
343
344 /*
345 ** Adds v to the API-internal cleanup mechanism. key is ingored
346 ** (legacy). If freeOnError is true then v is passed to
347 ** cson_value_free() if the key cannot be inserted, otherweise
348 ** ownership of v is not changed on error. Failure to insert an item
349 ** may be caused by any of the following:
 
 
350 **
351 ** - Allocation error.
352 ** - g.json.gc.a is NULL
353 ** - key is NULL or empty.
354 **
355 ** Returns 0 on success.
356 **
357 ** On success, ownership of v is transfered to (or shared with)
358 ** g.json.gc, and v will be valid until that object is cleaned up or
359 ** some internal code incorrectly removes it from the gc (which we
360 ** never do).
361 */
362 int json_gc_add( char const * key, cson_value * v, char freeOnError ){
363 int const rc = cson_array_append( g.json.gc.a, v );
364 assert( NULL != g.json.gc.a );
365 if( (0 != rc) && freeOnError ){
366 cson_value_free( v );
367 }
368 assert( (0==rc) && "Adding item to GC failed." );
369 return rc;
370 }
371
372
373 /*
@@ -781,13 +781,13 @@
781
782 /* g.json.gc is our "garbage collector" - where we put JSON values
783 which need a long lifetime but don't have a logical parent to put
784 them in.
785 */
786 v = cson_value_new_array();
787 g.json.gc.v = v;
788 g.json.gc.a = cson_value_get_array(v);
789
790 /*
791 g.json.param holds the JSONized counterpart of fossil's
792 cgi_parameter_xxx() family of data. We store them as JSON, as
793 opposed to using fossil's data directly, because we can retain
@@ -1412,11 +1412,11 @@
1412 double span;
1413 span = END_TIMER;
1414 /* i'm actually seeing sub-ms runtimes in some tests, but a time of
1415 0 is "just wrong", so we'll bump that up to 1ms.
1416 */
1417 cson_object_set(o,"procTimeMs", cson_value_new_integer((cson_int_t)((span>1.0)?span:1)));
1418 }
1419 if(g.json.warnings.v){
1420 tmp = g.json.warnings.v;
1421 SET("warnings");
1422 }
1423
+14 -1
--- src/json_tag.c
+++ src/json_tag.c
@@ -173,10 +173,13 @@
173173
json_set_err(FSL_JSON_E_MISSING_ARGS,
174174
"'checkin' parameter is missing.");
175175
return NULL;
176176
}
177177
}
178
+ /* FIXME?: verify that the tag is currently active. We have no real
179
+ error case unless we do that.
180
+ */
178181
db_begin_transaction();
179182
tag_add_artifact(zPrefix, zName, zCheckin, NULL, 0, 0, 0);
180183
db_end_transaction(0);
181184
return NULL;
182185
}
@@ -190,10 +193,11 @@
190193
cson_object * pay = NULL;
191194
cson_value * listV = NULL;
192195
cson_array * list = NULL;
193196
char const * zName = NULL;
194197
char const * zType = NULL;
198
+ char const * zType2 = NULL;
195199
char fRaw = 0;
196200
Stmt q = empty_Stmt;
197201
int limit = 0;
198202
int tagid = 0;
199203
@@ -214,10 +218,18 @@
214218
}
215219
}
216220
zType = json_find_option_cstr("type",NULL,"t");
217221
if(!zType || !*zType){
218222
zType = "*";
223
+ zType2 = zType;
224
+ }else{
225
+ switch(*zType){
226
+ case 'c': zType = "ci"; zType2 = "checkin"; break;
227
+ case 'e': zType = "e"; zType2 = "event"; break;
228
+ case 'w': zType = "w"; zType2 = "wiki"; break;
229
+ case 't': zType = "t"; zType2 = "ticket"; break;
230
+ }
219231
}
220232
221233
limit = json_find_option_int("limit",NULL,"n",0);
222234
fRaw = json_find_option_bool("raw",NULL,NULL,0);
223235
@@ -227,11 +239,11 @@
227239
228240
payV = cson_value_new_object();
229241
pay = cson_value_get_object(payV);
230242
cson_object_set(pay, "name", json_new_string(zName));
231243
cson_object_set(pay, "raw", cson_value_new_bool(fRaw));
232
- cson_object_set(pay, "type", json_new_string(zType));
244
+ cson_object_set(pay, "type", json_new_string(zType2));
233245
cson_object_set(pay, "limit", json_new_int(limit));
234246
235247
#if 1
236248
if( tagid<=0 ){
237249
cson_object_set(pay,"artifacts", cson_value_null());
@@ -361,10 +373,11 @@
361373
json_set_err(FSL_JSON_E_UNRESOLVED_UUID,
362374
"Could not find artifact for checkin [%s].",
363375
zCheckin);
364376
goto error;
365377
}
378
+ cson_object_set(pay, "checkin", json_new_string(zCheckin));
366379
db_prepare(&q,
367380
"SELECT tagname, value FROM tagxref, tag"
368381
" WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
369382
" AND tagtype>%d"
370383
" ORDER BY tagname",
371384
--- src/json_tag.c
+++ src/json_tag.c
@@ -173,10 +173,13 @@
173 json_set_err(FSL_JSON_E_MISSING_ARGS,
174 "'checkin' parameter is missing.");
175 return NULL;
176 }
177 }
 
 
 
178 db_begin_transaction();
179 tag_add_artifact(zPrefix, zName, zCheckin, NULL, 0, 0, 0);
180 db_end_transaction(0);
181 return NULL;
182 }
@@ -190,10 +193,11 @@
190 cson_object * pay = NULL;
191 cson_value * listV = NULL;
192 cson_array * list = NULL;
193 char const * zName = NULL;
194 char const * zType = NULL;
 
195 char fRaw = 0;
196 Stmt q = empty_Stmt;
197 int limit = 0;
198 int tagid = 0;
199
@@ -214,10 +218,18 @@
214 }
215 }
216 zType = json_find_option_cstr("type",NULL,"t");
217 if(!zType || !*zType){
218 zType = "*";
 
 
 
 
 
 
 
 
219 }
220
221 limit = json_find_option_int("limit",NULL,"n",0);
222 fRaw = json_find_option_bool("raw",NULL,NULL,0);
223
@@ -227,11 +239,11 @@
227
228 payV = cson_value_new_object();
229 pay = cson_value_get_object(payV);
230 cson_object_set(pay, "name", json_new_string(zName));
231 cson_object_set(pay, "raw", cson_value_new_bool(fRaw));
232 cson_object_set(pay, "type", json_new_string(zType));
233 cson_object_set(pay, "limit", json_new_int(limit));
234
235 #if 1
236 if( tagid<=0 ){
237 cson_object_set(pay,"artifacts", cson_value_null());
@@ -361,10 +373,11 @@
361 json_set_err(FSL_JSON_E_UNRESOLVED_UUID,
362 "Could not find artifact for checkin [%s].",
363 zCheckin);
364 goto error;
365 }
 
366 db_prepare(&q,
367 "SELECT tagname, value FROM tagxref, tag"
368 " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
369 " AND tagtype>%d"
370 " ORDER BY tagname",
371
--- src/json_tag.c
+++ src/json_tag.c
@@ -173,10 +173,13 @@
173 json_set_err(FSL_JSON_E_MISSING_ARGS,
174 "'checkin' parameter is missing.");
175 return NULL;
176 }
177 }
178 /* FIXME?: verify that the tag is currently active. We have no real
179 error case unless we do that.
180 */
181 db_begin_transaction();
182 tag_add_artifact(zPrefix, zName, zCheckin, NULL, 0, 0, 0);
183 db_end_transaction(0);
184 return NULL;
185 }
@@ -190,10 +193,11 @@
193 cson_object * pay = NULL;
194 cson_value * listV = NULL;
195 cson_array * list = NULL;
196 char const * zName = NULL;
197 char const * zType = NULL;
198 char const * zType2 = NULL;
199 char fRaw = 0;
200 Stmt q = empty_Stmt;
201 int limit = 0;
202 int tagid = 0;
203
@@ -214,10 +218,18 @@
218 }
219 }
220 zType = json_find_option_cstr("type",NULL,"t");
221 if(!zType || !*zType){
222 zType = "*";
223 zType2 = zType;
224 }else{
225 switch(*zType){
226 case 'c': zType = "ci"; zType2 = "checkin"; break;
227 case 'e': zType = "e"; zType2 = "event"; break;
228 case 'w': zType = "w"; zType2 = "wiki"; break;
229 case 't': zType = "t"; zType2 = "ticket"; break;
230 }
231 }
232
233 limit = json_find_option_int("limit",NULL,"n",0);
234 fRaw = json_find_option_bool("raw",NULL,NULL,0);
235
@@ -227,11 +239,11 @@
239
240 payV = cson_value_new_object();
241 pay = cson_value_get_object(payV);
242 cson_object_set(pay, "name", json_new_string(zName));
243 cson_object_set(pay, "raw", cson_value_new_bool(fRaw));
244 cson_object_set(pay, "type", json_new_string(zType2));
245 cson_object_set(pay, "limit", json_new_int(limit));
246
247 #if 1
248 if( tagid<=0 ){
249 cson_object_set(pay,"artifacts", cson_value_null());
@@ -361,10 +373,11 @@
373 json_set_err(FSL_JSON_E_UNRESOLVED_UUID,
374 "Could not find artifact for checkin [%s].",
375 zCheckin);
376 goto error;
377 }
378 cson_object_set(pay, "checkin", json_new_string(zCheckin));
379 db_prepare(&q,
380 "SELECT tagname, value FROM tagxref, tag"
381 " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
382 " AND tagtype>%d"
383 " ORDER BY tagname",
384
+1 -1
--- src/main.c
+++ src/main.c
@@ -190,11 +190,11 @@
190190
working on. For this purpose, arg#0
191191
is the "json" path/CLI arg.
192192
*/;
193193
struct { /* "garbage collector" */
194194
cson_value * v;
195
- cson_object * o;
195
+ cson_array * a;
196196
} gc;
197197
struct { /* JSON POST data. */
198198
cson_value * v;
199199
cson_array * a;
200200
int offset; /* Tells us which PATH_INFO/CLI args
201201
--- src/main.c
+++ src/main.c
@@ -190,11 +190,11 @@
190 working on. For this purpose, arg#0
191 is the "json" path/CLI arg.
192 */;
193 struct { /* "garbage collector" */
194 cson_value * v;
195 cson_object * o;
196 } gc;
197 struct { /* JSON POST data. */
198 cson_value * v;
199 cson_array * a;
200 int offset; /* Tells us which PATH_INFO/CLI args
201
--- src/main.c
+++ src/main.c
@@ -190,11 +190,11 @@
190 working on. For this purpose, arg#0
191 is the "json" path/CLI arg.
192 */;
193 struct { /* "garbage collector" */
194 cson_value * v;
195 cson_array * a;
196 } gc;
197 struct { /* JSON POST data. */
198 cson_value * v;
199 cson_array * a;
200 int offset; /* Tells us which PATH_INFO/CLI args
201

Keyboard Shortcuts

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