Fossil

Check-in [5a81a5ea]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Refactored prepareBranchStatement() to simplify its usage, get rid of ambiguous arg handling, and allow the caller to specify the priority of the all-vs-closed-vs-opened decision. Made it non-static and renamed to branch_prepare_statement() for re-use in /json/branch/list.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | json
Files: files | file ages | folders
SHA1: 5a81a5ead600ac8a3ae7e1e1ca696e889bba909d
User & Date: stephan 2011-09-21 18:20:14.068
Context
2011-09-21
18:53
changed how /json/branch/list selects whether to look at open/all/closed branches. ... (check-in: 14423f32 user: stephan tags: json)
18:20
Refactored prepareBranchStatement() to simplify its usage, get rid of ambiguous arg handling, and allow the caller to specify the priority of the all-vs-closed-vs-opened decision. Made it non-static and renamed to branch_prepare_statement() for re-use in /json/branch/list. ... (check-in: 5a81a5ea user: stephan tags: json)
18:10
Minor timeline output cleanups. Added /json/branch/list. ... (check-in: f266ebdd user: stephan tags: json)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/branch.c.
176
177
178
179
180
181
182
183




184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
  db_end_transaction(0);
  
  /* Do an autosync push, if requested */
  if( !isPrivate ) autosync(AUTOSYNC_PUSH);
}

/*
** Prepare a query that will list all branches.




*/
void prepareBranchQuery(Stmt *pQuery, int showAll, int showClosed){
  if( showClosed ){
    db_prepare(pQuery,
      "SELECT value FROM tagxref"
      " WHERE tagid=%d AND value NOT NULL "
      "EXCEPT "
      "SELECT value FROM tagxref"
      " WHERE tagid=%d"
      "   AND rid IN leaf"
      "   AND NOT %z"
      " ORDER BY value COLLATE nocase /*sort*/",
      TAG_BRANCH, TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
    );
  }else if( showAll ){
    db_prepare(pQuery,
      "SELECT DISTINCT value FROM tagxref"
      " WHERE tagid=%d AND value NOT NULL"
      "   AND rid IN leaf"
      " ORDER BY value COLLATE nocase /*sort*/",
      TAG_BRANCH
    );







|
>
>
>
>

|
|











|







176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  db_end_transaction(0);
  
  /* Do an autosync push, if requested */
  if( !isPrivate ) autosync(AUTOSYNC_PUSH);
}

/*
** Prepare a query that will list branches.
**
** If (which<0) then the query pulls only closed branches. If
** (which>0) then the query pulls all (closed and opened)
** branches. Else the query pulls currently-opened branches.
*/
void branch_prepare_query(Stmt *pQuery, int which ){
  if( which < 0 ){
    db_prepare(pQuery,
      "SELECT value FROM tagxref"
      " WHERE tagid=%d AND value NOT NULL "
      "EXCEPT "
      "SELECT value FROM tagxref"
      " WHERE tagid=%d"
      "   AND rid IN leaf"
      "   AND NOT %z"
      " ORDER BY value COLLATE nocase /*sort*/",
      TAG_BRANCH, TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
    );
  }else if( which>0 ){
    db_prepare(pQuery,
      "SELECT DISTINCT value FROM tagxref"
      " WHERE tagid=%d AND value NOT NULL"
      "   AND rid IN leaf"
      " ORDER BY value COLLATE nocase /*sort*/",
      TAG_BRANCH
    );
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
    int showClosed = find_option("closed",0,0)!=0;

    if( g.localOpen ){
      vid = db_lget_int("checkout", 0);
      zCurrent = db_text(0, "SELECT value FROM tagxref"
                            " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
    }
    prepareBranchQuery(&q, showAll, showClosed);
    while( db_step(&q)==SQLITE_ROW ){
      const char *zBr = db_column_text(&q, 0);
      int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
      fossil_print("%s%s\n", (isCur ? "* " : "  "), zBr);
    }
    db_finalize(&q);
  }else{







|







262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
    int showClosed = find_option("closed",0,0)!=0;

    if( g.localOpen ){
      vid = db_lget_int("checkout", 0);
      zCurrent = db_text(0, "SELECT value FROM tagxref"
                            " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
    }
    branch_prepare_query(&q, showAll?1:(showClosed?-1:0));
    while( db_step(&q)==SQLITE_ROW ){
      const char *zBr = db_column_text(&q, 0);
      int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
      fossil_print("%s%s\n", (isCur ? "* " : "  "), zBr);
    }
    db_finalize(&q);
  }else{
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
  @ <div class="sideboxDescribed"><a href="leaves?closed">
  @ closed leaves</a></div>.
  @ Closed branches are fixed and do not change (unless they are first
  @ reopened)</li>
  @ </ol>
  style_sidebox_end();

  prepareBranchQuery(&q, showAll, showClosed);
  cnt = 0;
  while( db_step(&q)==SQLITE_ROW ){
    const char *zBr = db_column_text(&q, 0);
    if( cnt==0 ){
      if( colorTest ){
        @ <h2>Default background colors for all branches:</h2>
      }else if( showAll ){







|







329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
  @ <div class="sideboxDescribed"><a href="leaves?closed">
  @ closed leaves</a></div>.
  @ Closed branches are fixed and do not change (unless they are first
  @ reopened)</li>
  @ </ol>
  style_sidebox_end();

  branch_prepare_query(&q, showAll?1:(showClosed?-1:0));
  cnt = 0;
  while( db_step(&q)==SQLITE_ROW ){
    const char *zBr = db_column_text(&q, 0);
    if( cnt==0 ){
      if( colorTest ){
        @ <h2>Default background colors for all branches:</h2>
      }else if( showAll ){
Changes to src/json.c.
1557
1558
1559
1560
1561
1562
1563




1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
*/
static cson_value * json_page_branch(unsigned int depth){
  return json_page_dispatch_helper(depth,&JsonPageDefs_Branch[0]);
}

/*
** Impl for /json/branch/list




*/
static cson_value * json_branch_list(unsigned int depth){
  cson_value * payV = cson_value_new_object();
  cson_object * pay = cson_value_get_object(payV);
  cson_value * listV = cson_value_new_array();
  cson_array * list = cson_value_get_array(listV);
  int showAll = json_getenv_int("showAll",0);
  int showClosed = showAll ? 0 : json_getenv_int("showClosed",0);
  Stmt q;
  char const * range = showAll
    ? "all"
    : (showClosed?"closed":"open");
  cson_object_set(pay,"range",cson_value_new_string(range,strlen(range)));
  prepareBranchQuery(&q, showAll, showClosed);
  cson_object_set(pay,"branches",listV);
  while((SQLITE_ROW==db_step(&q))){
    cson_value * v = cson_sqlite3_column_to_value(q.pStmt,0);
    if(v){
      cson_array_append(list,v);
    }else{
      json_warn(FSL_JSON_W_COL_TO_JSON_FAILED,NULL);







>
>
>
>






|
|





|







1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
*/
static cson_value * json_page_branch(unsigned int depth){
  return json_page_dispatch_helper(depth,&JsonPageDefs_Branch[0]);
}

/*
** Impl for /json/branch/list
**
** TODO: change how the "range" of branches is specified.
** Take a string arg in the form ("open","all","closed")
** and decide based off of that.
*/
static cson_value * json_branch_list(unsigned int depth){
  cson_value * payV = cson_value_new_object();
  cson_object * pay = cson_value_get_object(payV);
  cson_value * listV = cson_value_new_array();
  cson_array * list = cson_value_get_array(listV);
  int showAll = json_getenv_int("all",0);
  int showClosed = showAll ? 0 : json_getenv_int("closed",0);
  Stmt q;
  char const * range = showAll
    ? "all"
    : (showClosed?"closed":"open");
  cson_object_set(pay,"range",cson_value_new_string(range,strlen(range)));
  branch_prepare_query(&q, showAll?1:(showClosed?-1:0));
  cson_object_set(pay,"branches",listV);
  while((SQLITE_ROW==db_step(&q))){
    cson_value * v = cson_sqlite3_column_to_value(q.pStmt,0);
    if(v){
      cson_array_append(list,v);
    }else{
      json_warn(FSL_JSON_W_COL_TO_JSON_FAILED,NULL);