Fossil SCM

removed some dead code, minor internal cleanups in /json/timeline.

stephan 2012-03-02 14:23 trunk
Commit 6420654c806b93b6fed4341c748ae8da1317a96f
1 file changed +12 -26
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -135,11 +135,11 @@
135135
** to.
136136
**
137137
** Returns a positive value if it modifies pSql, 0 if it
138138
** does not. It returns a negative value if the tag
139139
** provided to the request was not found (pSql is not modified
140
-** in that case.
140
+** in that case).
141141
**
142142
** If payload is not NULL then on success its "tag" or "branch"
143143
** property is set to the tag/branch name found in the request.
144144
**
145145
** Only one of "tag" or "branch" modes will work at a time, and if
@@ -233,12 +233,11 @@
233233
** environment parameters. If it can it returns that value,
234234
** else it returns some statically defined default value.
235235
**
236236
** Never returns a negative value. 0 means no limit.
237237
*/
238
-static int json_timeline_limit(){
239
- static const int defaultLimit = 20;
238
+static int json_timeline_limit(int defaultLimit){
240239
int limit = -1;
241240
if(!g.isHTTP){/* CLI mode */
242241
char const * arg = find_option("limit","n",1);
243242
if(arg && *arg){
244243
limit = atoi(arg);
@@ -275,12 +274,12 @@
275274
blob_appendf(pSql, " AND event.type IN(%Q) ", zEventType);
276275
if( json_timeline_add_tag_branch_clause(pSql, pPayload) < 0 ){
277276
return FSL_JSON_E_INVALID_ARGS;
278277
}
279278
json_timeline_add_time_clause(pSql);
280
- limit = json_timeline_limit();
281
- if(limit>=0){
279
+ limit = json_timeline_limit(20);
280
+ if(limit>0){
282281
blob_appendf(pSql,"LIMIT %d ",limit);
283282
}
284283
if(pPayload){
285284
cson_object_set(pPayload, "limit", json_new_int(limit));
286285
}
@@ -353,10 +352,11 @@
353352
354353
static cson_value * json_timeline_branch(){
355354
cson_value * pay = NULL;
356355
Blob sql = empty_blob;
357356
Stmt q = empty_Stmt;
357
+ int limit = 0;
358358
if(!g.perm.Read){
359359
json_set_err(FSL_JSON_E_DENIED,
360360
"Requires 'o' permissions.");
361361
return NULL;
362362
}
@@ -378,10 +378,14 @@
378378
" AND event.type='ci'"
379379
" AND blob.rid IN (SELECT rid FROM tagxref"
380380
" WHERE tagtype>0 AND tagid=%d AND srcid!=0)"
381381
" ORDER BY event.mtime DESC",
382382
TAG_BRANCH);
383
+ limit = json_timeline_limit(20);
384
+ if(limit>0){
385
+ blob_appendf(&sql," LIMIT %d ",limit);
386
+ }
383387
db_prepare(&q,"%s", blob_str(&sql));
384388
blob_reset(&sql);
385389
pay = json_stmt_to_array_of_obj(&q, NULL);
386390
db_finalize(&q);
387391
assert(NULL != pay);
@@ -395,14 +399,13 @@
395399
unsigned int i = 0;
396400
unsigned int len = cson_array_length_get(ar);
397401
for( ; i < len; ++i ){
398402
cson_object * row = cson_value_get_object(cson_array_get(ar,i));
399403
int rid = cson_value_get_integer(cson_object_get(row,"rid"));
400
- if(row>0) {
401
- cson_object_set_s(row, tags, json_tags_for_checkin_rid(rid,0));
402
- cson_object_set_s(row, isLeaf, json_value_to_bool(cson_object_get(row,"isLeaf")));
403
- }
404
+ assert( rid > 0 );
405
+ cson_object_set_s(row, tags, json_tags_for_checkin_rid(rid,0));
406
+ cson_object_set_s(row, isLeaf, json_value_to_bool(cson_object_get(row,"isLeaf")));
404407
}
405408
cson_value_free( cson_string_value(tags) );
406409
cson_value_free( cson_string_value(isLeaf) );
407410
}
408411
return pay;
@@ -454,27 +457,10 @@
454457
#endif
455458
db_multi_exec(blob_buffer(&sql));
456459
blob_reset(&sql);
457460
db_prepare(&q, "SELECT "
458461
" rid AS rid"
459
-#if 0
460
- " uuid AS uuid,"
461
- " mtime AS timestamp,"
462
-# if 0
463
- " timestampString AS timestampString,"
464
-# endif
465
- " comment AS comment, "
466
- " user AS user,"
467
- " isLeaf AS isLeaf," /*FIXME: convert to JSON bool */
468
- " bgColor AS bgColor," /* why always null? */
469
- " eventType AS eventType"
470
-# if 0
471
- " tags AS tags"
472
- /*tagId is always null?*/
473
- " tagId AS tagId"
474
-# endif
475
-#endif
476462
" FROM json_timeline"
477463
" ORDER BY rowid");
478464
listV = cson_value_new_array();
479465
list = cson_value_get_array(listV);
480466
tmp = listV;
481467
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -135,11 +135,11 @@
135 ** to.
136 **
137 ** Returns a positive value if it modifies pSql, 0 if it
138 ** does not. It returns a negative value if the tag
139 ** provided to the request was not found (pSql is not modified
140 ** in that case.
141 **
142 ** If payload is not NULL then on success its "tag" or "branch"
143 ** property is set to the tag/branch name found in the request.
144 **
145 ** Only one of "tag" or "branch" modes will work at a time, and if
@@ -233,12 +233,11 @@
233 ** environment parameters. If it can it returns that value,
234 ** else it returns some statically defined default value.
235 **
236 ** Never returns a negative value. 0 means no limit.
237 */
238 static int json_timeline_limit(){
239 static const int defaultLimit = 20;
240 int limit = -1;
241 if(!g.isHTTP){/* CLI mode */
242 char const * arg = find_option("limit","n",1);
243 if(arg && *arg){
244 limit = atoi(arg);
@@ -275,12 +274,12 @@
275 blob_appendf(pSql, " AND event.type IN(%Q) ", zEventType);
276 if( json_timeline_add_tag_branch_clause(pSql, pPayload) < 0 ){
277 return FSL_JSON_E_INVALID_ARGS;
278 }
279 json_timeline_add_time_clause(pSql);
280 limit = json_timeline_limit();
281 if(limit>=0){
282 blob_appendf(pSql,"LIMIT %d ",limit);
283 }
284 if(pPayload){
285 cson_object_set(pPayload, "limit", json_new_int(limit));
286 }
@@ -353,10 +352,11 @@
353
354 static cson_value * json_timeline_branch(){
355 cson_value * pay = NULL;
356 Blob sql = empty_blob;
357 Stmt q = empty_Stmt;
 
358 if(!g.perm.Read){
359 json_set_err(FSL_JSON_E_DENIED,
360 "Requires 'o' permissions.");
361 return NULL;
362 }
@@ -378,10 +378,14 @@
378 " AND event.type='ci'"
379 " AND blob.rid IN (SELECT rid FROM tagxref"
380 " WHERE tagtype>0 AND tagid=%d AND srcid!=0)"
381 " ORDER BY event.mtime DESC",
382 TAG_BRANCH);
 
 
 
 
383 db_prepare(&q,"%s", blob_str(&sql));
384 blob_reset(&sql);
385 pay = json_stmt_to_array_of_obj(&q, NULL);
386 db_finalize(&q);
387 assert(NULL != pay);
@@ -395,14 +399,13 @@
395 unsigned int i = 0;
396 unsigned int len = cson_array_length_get(ar);
397 for( ; i < len; ++i ){
398 cson_object * row = cson_value_get_object(cson_array_get(ar,i));
399 int rid = cson_value_get_integer(cson_object_get(row,"rid"));
400 if(row>0) {
401 cson_object_set_s(row, tags, json_tags_for_checkin_rid(rid,0));
402 cson_object_set_s(row, isLeaf, json_value_to_bool(cson_object_get(row,"isLeaf")));
403 }
404 }
405 cson_value_free( cson_string_value(tags) );
406 cson_value_free( cson_string_value(isLeaf) );
407 }
408 return pay;
@@ -454,27 +457,10 @@
454 #endif
455 db_multi_exec(blob_buffer(&sql));
456 blob_reset(&sql);
457 db_prepare(&q, "SELECT "
458 " rid AS rid"
459 #if 0
460 " uuid AS uuid,"
461 " mtime AS timestamp,"
462 # if 0
463 " timestampString AS timestampString,"
464 # endif
465 " comment AS comment, "
466 " user AS user,"
467 " isLeaf AS isLeaf," /*FIXME: convert to JSON bool */
468 " bgColor AS bgColor," /* why always null? */
469 " eventType AS eventType"
470 # if 0
471 " tags AS tags"
472 /*tagId is always null?*/
473 " tagId AS tagId"
474 # endif
475 #endif
476 " FROM json_timeline"
477 " ORDER BY rowid");
478 listV = cson_value_new_array();
479 list = cson_value_get_array(listV);
480 tmp = listV;
481
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -135,11 +135,11 @@
135 ** to.
136 **
137 ** Returns a positive value if it modifies pSql, 0 if it
138 ** does not. It returns a negative value if the tag
139 ** provided to the request was not found (pSql is not modified
140 ** in that case).
141 **
142 ** If payload is not NULL then on success its "tag" or "branch"
143 ** property is set to the tag/branch name found in the request.
144 **
145 ** Only one of "tag" or "branch" modes will work at a time, and if
@@ -233,12 +233,11 @@
233 ** environment parameters. If it can it returns that value,
234 ** else it returns some statically defined default value.
235 **
236 ** Never returns a negative value. 0 means no limit.
237 */
238 static int json_timeline_limit(int defaultLimit){
 
239 int limit = -1;
240 if(!g.isHTTP){/* CLI mode */
241 char const * arg = find_option("limit","n",1);
242 if(arg && *arg){
243 limit = atoi(arg);
@@ -275,12 +274,12 @@
274 blob_appendf(pSql, " AND event.type IN(%Q) ", zEventType);
275 if( json_timeline_add_tag_branch_clause(pSql, pPayload) < 0 ){
276 return FSL_JSON_E_INVALID_ARGS;
277 }
278 json_timeline_add_time_clause(pSql);
279 limit = json_timeline_limit(20);
280 if(limit>0){
281 blob_appendf(pSql,"LIMIT %d ",limit);
282 }
283 if(pPayload){
284 cson_object_set(pPayload, "limit", json_new_int(limit));
285 }
@@ -353,10 +352,11 @@
352
353 static cson_value * json_timeline_branch(){
354 cson_value * pay = NULL;
355 Blob sql = empty_blob;
356 Stmt q = empty_Stmt;
357 int limit = 0;
358 if(!g.perm.Read){
359 json_set_err(FSL_JSON_E_DENIED,
360 "Requires 'o' permissions.");
361 return NULL;
362 }
@@ -378,10 +378,14 @@
378 " AND event.type='ci'"
379 " AND blob.rid IN (SELECT rid FROM tagxref"
380 " WHERE tagtype>0 AND tagid=%d AND srcid!=0)"
381 " ORDER BY event.mtime DESC",
382 TAG_BRANCH);
383 limit = json_timeline_limit(20);
384 if(limit>0){
385 blob_appendf(&sql," LIMIT %d ",limit);
386 }
387 db_prepare(&q,"%s", blob_str(&sql));
388 blob_reset(&sql);
389 pay = json_stmt_to_array_of_obj(&q, NULL);
390 db_finalize(&q);
391 assert(NULL != pay);
@@ -395,14 +399,13 @@
399 unsigned int i = 0;
400 unsigned int len = cson_array_length_get(ar);
401 for( ; i < len; ++i ){
402 cson_object * row = cson_value_get_object(cson_array_get(ar,i));
403 int rid = cson_value_get_integer(cson_object_get(row,"rid"));
404 assert( rid > 0 );
405 cson_object_set_s(row, tags, json_tags_for_checkin_rid(rid,0));
406 cson_object_set_s(row, isLeaf, json_value_to_bool(cson_object_get(row,"isLeaf")));
 
407 }
408 cson_value_free( cson_string_value(tags) );
409 cson_value_free( cson_string_value(isLeaf) );
410 }
411 return pay;
@@ -454,27 +457,10 @@
457 #endif
458 db_multi_exec(blob_buffer(&sql));
459 blob_reset(&sql);
460 db_prepare(&q, "SELECT "
461 " rid AS rid"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
462 " FROM json_timeline"
463 " ORDER BY rowid");
464 listV = cson_value_new_array();
465 list = cson_value_get_array(listV);
466 tmp = listV;
467

Keyboard Shortcuts

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