Fossil SCM

Minor timeline output cleanups. Added /json/branch/list.

stephan 2011-09-21 18:10 json
Commit f266ebdd3f942b08132ca486d5aca8364fe44c2a
3 files changed +1 -1 +75 -29 +2 -1
+1 -1
--- src/branch.c
+++ src/branch.c
@@ -180,11 +180,11 @@
180180
}
181181
182182
/*
183183
** Prepare a query that will list all branches.
184184
*/
185
-static void prepareBranchQuery(Stmt *pQuery, int showAll, int showClosed){
185
+void prepareBranchQuery(Stmt *pQuery, int showAll, int showClosed){
186186
if( showClosed ){
187187
db_prepare(pQuery,
188188
"SELECT value FROM tagxref"
189189
" WHERE tagid=%d AND value NOT NULL "
190190
"EXCEPT "
191191
--- src/branch.c
+++ src/branch.c
@@ -180,11 +180,11 @@
180 }
181
182 /*
183 ** Prepare a query that will list all branches.
184 */
185 static void prepareBranchQuery(Stmt *pQuery, int showAll, int showClosed){
186 if( showClosed ){
187 db_prepare(pQuery,
188 "SELECT value FROM tagxref"
189 " WHERE tagid=%d AND value NOT NULL "
190 "EXCEPT "
191
--- src/branch.c
+++ src/branch.c
@@ -180,11 +180,11 @@
180 }
181
182 /*
183 ** Prepare a query that will list all branches.
184 */
185 void prepareBranchQuery(Stmt *pQuery, int showAll, int showClosed){
186 if( showClosed ){
187 db_prepare(pQuery,
188 "SELECT value FROM tagxref"
189 " WHERE tagid=%d AND value NOT NULL "
190 "EXCEPT "
191
+75 -29
--- src/json.c
+++ src/json.c
@@ -312,10 +312,35 @@
312312
}
313313
}
314314
return NULL;
315315
}
316316
317
+/*
318
+** Wrapper around json_getenv() which...
319
+**
320
+** If it finds a value and that value is-a JSON number or is a string
321
+** which looks like an integer or is-a JSON bool then it is converted
322
+** to an int. If none of those apply then dflt is returned.
323
+*/
324
+static int json_getenv_int(char const * pKey, int dflt ){
325
+ cson_value const * v = json_getenv(pKey);
326
+ if(!v){
327
+ return dflt;
328
+ }else if( cson_value_is_number(v) ){
329
+ return (int)cson_value_get_integer(v);
330
+ }else if( cson_value_is_string(v) ){
331
+ char const * sv = cson_string_cstr(cson_value_get_string(v));
332
+ assert( (NULL!=sv) && "This is quite unexpected." );
333
+ return sv ? atoi(sv) : dflt;
334
+ }else if( cson_value_is_bool(v) ){
335
+ return cson_value_get_bool(v) ? 1 : 0;
336
+ }else{
337
+ /* we should arguably treat JSON null as 0. */
338
+ return dflt;
339
+ }
340
+}
341
+
317342
318343
/*
319344
** Returns the string form of a json_getenv() value, but ONLY If that
320345
** value is-a String. Non-strings are not converted to strings for
321346
** this purpose. Returned memory is owned by g.json or fossil and is
@@ -1511,10 +1536,59 @@
15111536
db_finalize(&q);
15121537
return listV;
15131538
}
15141539
15151540
1541
+
1542
+static cson_value * json_branch_list(unsigned int depth);
1543
+/*
1544
+** Mapping of /json/branch/XXX commands/paths to callbacks.
1545
+*/
1546
+static const JsonPageDef JsonPageDefs_Branch[] = {
1547
+{"list", json_branch_list, 0},
1548
+{"create", json_page_nyi, 1},
1549
+/* Last entry MUST have a NULL name. */
1550
+{NULL,NULL,0}
1551
+};
1552
+
1553
+/*
1554
+** Implements the /json/branch family of pages/commands. Far from
1555
+** complete.
1556
+**
1557
+*/
1558
+static cson_value * json_page_branch(unsigned int depth){
1559
+ return json_page_dispatch_helper(depth,&JsonPageDefs_Branch[0]);
1560
+}
1561
+
1562
+/*
1563
+** Impl for /json/branch/list
1564
+*/
1565
+static cson_value * json_branch_list(unsigned int depth){
1566
+ cson_value * payV = cson_value_new_object();
1567
+ cson_object * pay = cson_value_get_object(payV);
1568
+ cson_value * listV = cson_value_new_array();
1569
+ cson_array * list = cson_value_get_array(listV);
1570
+ int showAll = json_getenv_int("showAll",0);
1571
+ int showClosed = showAll ? 0 : json_getenv_int("showClosed",0);
1572
+ Stmt q;
1573
+ char const * range = showAll
1574
+ ? "all"
1575
+ : (showClosed?"closed":"open");
1576
+ cson_object_set(pay,"range",cson_value_new_string(range,strlen(range)));
1577
+ prepareBranchQuery(&q, showAll, showClosed);
1578
+ cson_object_set(pay,"branches",listV);
1579
+ while((SQLITE_ROW==db_step(&q))){
1580
+ cson_value * v = cson_sqlite3_column_to_value(q.pStmt,0);
1581
+ if(v){
1582
+ cson_array_append(list,v);
1583
+ }else{
1584
+ json_warn(FSL_JSON_W_COL_TO_JSON_FAILED,NULL);
1585
+ }
1586
+ }
1587
+ return payV;
1588
+}
1589
+
15161590
static cson_value * json_timeline_ci(unsigned int depth);
15171591
/*
15181592
** Mapping of /json/timeline/XXX commands/paths to callbacks.
15191593
*/
15201594
static const JsonPageDef JsonPageDefs_Timeline[] = {
@@ -1530,28 +1604,10 @@
15301604
*/
15311605
static cson_value * json_page_timeline(unsigned int depth){
15321606
return json_page_dispatch_helper(depth,&JsonPageDefs_Timeline[0]);
15331607
}
15341608
1535
-static int json_getenv_int(char const * pKey, int dflt ){
1536
- cson_value const * v = json_getenv(pKey);
1537
- if(!v){
1538
- return dflt;
1539
- }else if( cson_value_is_number(v) ){
1540
- return (int)cson_value_get_integer(v);
1541
- }else if( cson_value_is_string(v) ){
1542
- char const * sv = cson_string_cstr(cson_value_get_string(v));
1543
- assert( (NULL!=sv) && "This is quite unexpected." );
1544
- return sv ? atoi(sv) : dflt;
1545
- }else if( cson_value_is_bool(v) ){
1546
- return cson_value_get_bool(v) ? 1 : 0;
1547
- }else{
1548
- /* we should arguably treat JSON null as 0. */
1549
- return dflt;
1550
- }
1551
-}
1552
-
15531609
/*
15541610
** Create a temporary table suitable for storing timeline data.
15551611
*/
15561612
static void json_timeline_temp_table(void){
15571613
/* Field order MUST match that from json_timeline_query_XXX()!!! */
@@ -1726,11 +1782,11 @@
17261782
** /json (in CGI mode) or a subcommand of the json command in CLI mode
17271783
*/
17281784
static const JsonPageDef JsonPageDefs[] = {
17291785
/* please keep alphabetically sorted (case-insensitive) for maintenance reasons. */
17301786
{"anonymousPassword",json_page_anon_password, 1},
1731
-{"branch", json_page_nyi,0},
1787
+{"branch", json_page_branch,0},
17321788
{"cap", json_page_cap, 0},
17331789
{"dir", json_page_nyi, 0},
17341790
{"HAI",json_page_version,0},
17351791
{"login",json_page_login,1},
17361792
{"logout",json_page_logout,1},
@@ -1762,20 +1818,10 @@
17621818
** Mapping of /json/artifact/XXX commands/paths to callbacks.
17631819
*/
17641820
static const JsonPageDef JsonPageDefs_Artifact[] = {
17651821
{"vinfo", json_page_nyi, 0},
17661822
{"finfo", json_page_nyi, 0},
1767
-/* Last entry MUST have a NULL name. */
1768
-{NULL,NULL,0}
1769
-};
1770
-
1771
-/*
1772
-** Mapping of /json/branch/XXX commands/paths to callbacks.
1773
-*/
1774
-static const JsonPageDef JsonPageDefs_Branch[] = {
1775
-{"list", json_page_nyi, 0},
1776
-{"create", json_page_nyi, 1},
17771823
/* Last entry MUST have a NULL name. */
17781824
{NULL,NULL,0}
17791825
};
17801826
17811827
/*
17821828
--- src/json.c
+++ src/json.c
@@ -312,10 +312,35 @@
312 }
313 }
314 return NULL;
315 }
316
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
318 /*
319 ** Returns the string form of a json_getenv() value, but ONLY If that
320 ** value is-a String. Non-strings are not converted to strings for
321 ** this purpose. Returned memory is owned by g.json or fossil and is
@@ -1511,10 +1536,59 @@
1511 db_finalize(&q);
1512 return listV;
1513 }
1514
1515
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1516 static cson_value * json_timeline_ci(unsigned int depth);
1517 /*
1518 ** Mapping of /json/timeline/XXX commands/paths to callbacks.
1519 */
1520 static const JsonPageDef JsonPageDefs_Timeline[] = {
@@ -1530,28 +1604,10 @@
1530 */
1531 static cson_value * json_page_timeline(unsigned int depth){
1532 return json_page_dispatch_helper(depth,&JsonPageDefs_Timeline[0]);
1533 }
1534
1535 static int json_getenv_int(char const * pKey, int dflt ){
1536 cson_value const * v = json_getenv(pKey);
1537 if(!v){
1538 return dflt;
1539 }else if( cson_value_is_number(v) ){
1540 return (int)cson_value_get_integer(v);
1541 }else if( cson_value_is_string(v) ){
1542 char const * sv = cson_string_cstr(cson_value_get_string(v));
1543 assert( (NULL!=sv) && "This is quite unexpected." );
1544 return sv ? atoi(sv) : dflt;
1545 }else if( cson_value_is_bool(v) ){
1546 return cson_value_get_bool(v) ? 1 : 0;
1547 }else{
1548 /* we should arguably treat JSON null as 0. */
1549 return dflt;
1550 }
1551 }
1552
1553 /*
1554 ** Create a temporary table suitable for storing timeline data.
1555 */
1556 static void json_timeline_temp_table(void){
1557 /* Field order MUST match that from json_timeline_query_XXX()!!! */
@@ -1726,11 +1782,11 @@
1726 ** /json (in CGI mode) or a subcommand of the json command in CLI mode
1727 */
1728 static const JsonPageDef JsonPageDefs[] = {
1729 /* please keep alphabetically sorted (case-insensitive) for maintenance reasons. */
1730 {"anonymousPassword",json_page_anon_password, 1},
1731 {"branch", json_page_nyi,0},
1732 {"cap", json_page_cap, 0},
1733 {"dir", json_page_nyi, 0},
1734 {"HAI",json_page_version,0},
1735 {"login",json_page_login,1},
1736 {"logout",json_page_logout,1},
@@ -1762,20 +1818,10 @@
1762 ** Mapping of /json/artifact/XXX commands/paths to callbacks.
1763 */
1764 static const JsonPageDef JsonPageDefs_Artifact[] = {
1765 {"vinfo", json_page_nyi, 0},
1766 {"finfo", json_page_nyi, 0},
1767 /* Last entry MUST have a NULL name. */
1768 {NULL,NULL,0}
1769 };
1770
1771 /*
1772 ** Mapping of /json/branch/XXX commands/paths to callbacks.
1773 */
1774 static const JsonPageDef JsonPageDefs_Branch[] = {
1775 {"list", json_page_nyi, 0},
1776 {"create", json_page_nyi, 1},
1777 /* Last entry MUST have a NULL name. */
1778 {NULL,NULL,0}
1779 };
1780
1781 /*
1782
--- src/json.c
+++ src/json.c
@@ -312,10 +312,35 @@
312 }
313 }
314 return NULL;
315 }
316
317 /*
318 ** Wrapper around json_getenv() which...
319 **
320 ** If it finds a value and that value is-a JSON number or is a string
321 ** which looks like an integer or is-a JSON bool then it is converted
322 ** to an int. If none of those apply then dflt is returned.
323 */
324 static int json_getenv_int(char const * pKey, int dflt ){
325 cson_value const * v = json_getenv(pKey);
326 if(!v){
327 return dflt;
328 }else if( cson_value_is_number(v) ){
329 return (int)cson_value_get_integer(v);
330 }else if( cson_value_is_string(v) ){
331 char const * sv = cson_string_cstr(cson_value_get_string(v));
332 assert( (NULL!=sv) && "This is quite unexpected." );
333 return sv ? atoi(sv) : dflt;
334 }else if( cson_value_is_bool(v) ){
335 return cson_value_get_bool(v) ? 1 : 0;
336 }else{
337 /* we should arguably treat JSON null as 0. */
338 return dflt;
339 }
340 }
341
342
343 /*
344 ** Returns the string form of a json_getenv() value, but ONLY If that
345 ** value is-a String. Non-strings are not converted to strings for
346 ** this purpose. Returned memory is owned by g.json or fossil and is
@@ -1511,10 +1536,59 @@
1536 db_finalize(&q);
1537 return listV;
1538 }
1539
1540
1541
1542 static cson_value * json_branch_list(unsigned int depth);
1543 /*
1544 ** Mapping of /json/branch/XXX commands/paths to callbacks.
1545 */
1546 static const JsonPageDef JsonPageDefs_Branch[] = {
1547 {"list", json_branch_list, 0},
1548 {"create", json_page_nyi, 1},
1549 /* Last entry MUST have a NULL name. */
1550 {NULL,NULL,0}
1551 };
1552
1553 /*
1554 ** Implements the /json/branch family of pages/commands. Far from
1555 ** complete.
1556 **
1557 */
1558 static cson_value * json_page_branch(unsigned int depth){
1559 return json_page_dispatch_helper(depth,&JsonPageDefs_Branch[0]);
1560 }
1561
1562 /*
1563 ** Impl for /json/branch/list
1564 */
1565 static cson_value * json_branch_list(unsigned int depth){
1566 cson_value * payV = cson_value_new_object();
1567 cson_object * pay = cson_value_get_object(payV);
1568 cson_value * listV = cson_value_new_array();
1569 cson_array * list = cson_value_get_array(listV);
1570 int showAll = json_getenv_int("showAll",0);
1571 int showClosed = showAll ? 0 : json_getenv_int("showClosed",0);
1572 Stmt q;
1573 char const * range = showAll
1574 ? "all"
1575 : (showClosed?"closed":"open");
1576 cson_object_set(pay,"range",cson_value_new_string(range,strlen(range)));
1577 prepareBranchQuery(&q, showAll, showClosed);
1578 cson_object_set(pay,"branches",listV);
1579 while((SQLITE_ROW==db_step(&q))){
1580 cson_value * v = cson_sqlite3_column_to_value(q.pStmt,0);
1581 if(v){
1582 cson_array_append(list,v);
1583 }else{
1584 json_warn(FSL_JSON_W_COL_TO_JSON_FAILED,NULL);
1585 }
1586 }
1587 return payV;
1588 }
1589
1590 static cson_value * json_timeline_ci(unsigned int depth);
1591 /*
1592 ** Mapping of /json/timeline/XXX commands/paths to callbacks.
1593 */
1594 static const JsonPageDef JsonPageDefs_Timeline[] = {
@@ -1530,28 +1604,10 @@
1604 */
1605 static cson_value * json_page_timeline(unsigned int depth){
1606 return json_page_dispatch_helper(depth,&JsonPageDefs_Timeline[0]);
1607 }
1608
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1609 /*
1610 ** Create a temporary table suitable for storing timeline data.
1611 */
1612 static void json_timeline_temp_table(void){
1613 /* Field order MUST match that from json_timeline_query_XXX()!!! */
@@ -1726,11 +1782,11 @@
1782 ** /json (in CGI mode) or a subcommand of the json command in CLI mode
1783 */
1784 static const JsonPageDef JsonPageDefs[] = {
1785 /* please keep alphabetically sorted (case-insensitive) for maintenance reasons. */
1786 {"anonymousPassword",json_page_anon_password, 1},
1787 {"branch", json_page_branch,0},
1788 {"cap", json_page_cap, 0},
1789 {"dir", json_page_nyi, 0},
1790 {"HAI",json_page_version,0},
1791 {"login",json_page_login,1},
1792 {"logout",json_page_logout,1},
@@ -1762,20 +1818,10 @@
1818 ** Mapping of /json/artifact/XXX commands/paths to callbacks.
1819 */
1820 static const JsonPageDef JsonPageDefs_Artifact[] = {
1821 {"vinfo", json_page_nyi, 0},
1822 {"finfo", json_page_nyi, 0},
 
 
 
 
 
 
 
 
 
 
1823 /* Last entry MUST have a NULL name. */
1824 {NULL,NULL,0}
1825 };
1826
1827 /*
1828
--- src/json_detail.h
+++ src/json_detail.h
@@ -17,11 +17,12 @@
1717
**
1818
*/
1919
enum FossilJsonCodes {
2020
FSL_JSON_W_START = 0,
2121
FSL_JSON_W_ROW_TO_JSON_FAILED = FSL_JSON_W_START + 1,
22
-FSL_JSON_W_STRING_TO_ARRAY_FAILED = FSL_JSON_W_START + 2,
22
+FSL_JSON_W_COL_TO_JSON_FAILED = FSL_JSON_W_START + 2,
23
+FSL_JSON_W_STRING_TO_ARRAY_FAILED = FSL_JSON_W_START + 3,
2324
2425
FSL_JSON_W_END = 1000,
2526
FSL_JSON_E_GENERIC = 1000,
2627
FSL_JSON_E_GENERIC_SUB1 = FSL_JSON_E_GENERIC + 100,
2728
FSL_JSON_E_INVALID_REQUEST = FSL_JSON_E_GENERIC_SUB1 + 1,
2829
--- src/json_detail.h
+++ src/json_detail.h
@@ -17,11 +17,12 @@
17 **
18 */
19 enum FossilJsonCodes {
20 FSL_JSON_W_START = 0,
21 FSL_JSON_W_ROW_TO_JSON_FAILED = FSL_JSON_W_START + 1,
22 FSL_JSON_W_STRING_TO_ARRAY_FAILED = FSL_JSON_W_START + 2,
 
23
24 FSL_JSON_W_END = 1000,
25 FSL_JSON_E_GENERIC = 1000,
26 FSL_JSON_E_GENERIC_SUB1 = FSL_JSON_E_GENERIC + 100,
27 FSL_JSON_E_INVALID_REQUEST = FSL_JSON_E_GENERIC_SUB1 + 1,
28
--- src/json_detail.h
+++ src/json_detail.h
@@ -17,11 +17,12 @@
17 **
18 */
19 enum FossilJsonCodes {
20 FSL_JSON_W_START = 0,
21 FSL_JSON_W_ROW_TO_JSON_FAILED = FSL_JSON_W_START + 1,
22 FSL_JSON_W_COL_TO_JSON_FAILED = FSL_JSON_W_START + 2,
23 FSL_JSON_W_STRING_TO_ARRAY_FAILED = FSL_JSON_W_START + 3,
24
25 FSL_JSON_W_END = 1000,
26 FSL_JSON_E_GENERIC = 1000,
27 FSL_JSON_E_GENERIC_SUB1 = FSL_JSON_E_GENERIC + 100,
28 FSL_JSON_E_INVALID_REQUEST = FSL_JSON_E_GENERIC_SUB1 + 1,
29

Keyboard Shortcuts

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