Fossil SCM
Enhance the branch command and the branch www page so that they can show all branches. The branch command can now also show closed branches. Ticket [2adfb697fda1b2].
Commit
ebeaf3ae26fdcd87f7dea99114e3da1b2ae144e1
Parent
d86201dce9f0365…
1 file changed
+51
-32
+51
-32
| --- src/branch.c | ||
| +++ src/branch.c | ||
| @@ -176,10 +176,47 @@ | ||
| 176 | 176 | db_end_transaction(0); |
| 177 | 177 | |
| 178 | 178 | /* Do an autosync push, if requested */ |
| 179 | 179 | autosync(AUTOSYNC_PUSH); |
| 180 | 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 | + "SELECT value FROM tagxref" | |
| 192 | + " WHERE tagid=%d" | |
| 193 | + " AND rid IN leaf" | |
| 194 | + " AND NOT %z" | |
| 195 | + " ORDER BY value COLLATE nocase /*sort*/", | |
| 196 | + TAG_BRANCH, TAG_BRANCH, leaf_is_closed_sql("tagxref.rid") | |
| 197 | + ); | |
| 198 | + }else if( showAll ){ | |
| 199 | + db_prepare(pQuery, | |
| 200 | + "SELECT DISTINCT value FROM tagxref" | |
| 201 | + " WHERE tagid=%d AND value NOT NULL" | |
| 202 | + " AND rid IN leaf" | |
| 203 | + " ORDER BY value COLLATE nocase /*sort*/", | |
| 204 | + TAG_BRANCH | |
| 205 | + ); | |
| 206 | + }else{ | |
| 207 | + db_prepare(pQuery, | |
| 208 | + "SELECT DISTINCT value FROM tagxref" | |
| 209 | + " WHERE tagid=%d AND value NOT NULL" | |
| 210 | + " AND rid IN leaf" | |
| 211 | + " AND NOT %z" | |
| 212 | + " ORDER BY value COLLATE nocase /*sort*/", | |
| 213 | + TAG_BRANCH, leaf_is_closed_sql("tagxref.rid") | |
| 214 | + ); | |
| 215 | + } | |
| 216 | +} | |
| 217 | + | |
| 181 | 218 | |
| 182 | 219 | /* |
| 183 | 220 | ** COMMAND: branch |
| 184 | 221 | ** |
| 185 | 222 | ** Usage: %fossil branch SUBCOMMAND ... ?-R|--repository FILE? |
| @@ -194,11 +231,12 @@ | ||
| 194 | 231 | ** --private option makes the branch private. |
| 195 | 232 | ** |
| 196 | 233 | ** %fossil branch list |
| 197 | 234 | ** %fossil branch ls |
| 198 | 235 | ** |
| 199 | -** List all branches | |
| 236 | +** List all branches. Use --all or --closed to list all branches | |
| 237 | +** or closed branches. The default is to show only open branches. | |
| 200 | 238 | ** |
| 201 | 239 | */ |
| 202 | 240 | void branch_cmd(void){ |
| 203 | 241 | int n; |
| 204 | 242 | const char *zCmd = "list"; |
| @@ -212,24 +250,19 @@ | ||
| 212 | 250 | branch_new(); |
| 213 | 251 | }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){ |
| 214 | 252 | Stmt q; |
| 215 | 253 | int vid; |
| 216 | 254 | char *zCurrent = 0; |
| 255 | + int showAll = find_option("all",0,0)!=0; | |
| 256 | + int showClosed = find_option("closed",0,0)!=0; | |
| 217 | 257 | |
| 218 | 258 | if( g.localOpen ){ |
| 219 | 259 | vid = db_lget_int("checkout", 0); |
| 220 | 260 | zCurrent = db_text(0, "SELECT value FROM tagxref" |
| 221 | 261 | " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH); |
| 222 | 262 | } |
| 223 | - db_prepare(&q, | |
| 224 | - "SELECT DISTINCT value FROM tagxref" | |
| 225 | - " WHERE tagid=%d AND value NOT NULL" | |
| 226 | - " AND rid IN leaf" | |
| 227 | - " AND NOT %z" | |
| 228 | - " ORDER BY value /*sort*/", | |
| 229 | - TAG_BRANCH, leaf_is_closed_sql("tagxref.rid") | |
| 230 | - ); | |
| 263 | + prepareBranchQuery(&q, showAll, showClosed); | |
| 231 | 264 | while( db_step(&q)==SQLITE_ROW ){ |
| 232 | 265 | const char *zBr = db_column_text(&q, 0); |
| 233 | 266 | int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; |
| 234 | 267 | fossil_print("%s%s\n", (isCur ? "* " : " "), zBr); |
| 235 | 268 | } |
| @@ -247,19 +280,26 @@ | ||
| 247 | 280 | */ |
| 248 | 281 | void brlist_page(void){ |
| 249 | 282 | Stmt q; |
| 250 | 283 | int cnt; |
| 251 | 284 | int showClosed = P("closed")!=0; |
| 285 | + int showAll = P("all")!=0; | |
| 252 | 286 | |
| 253 | 287 | login_check_credentials(); |
| 254 | 288 | if( !g.okRead ){ login_needed(); return; } |
| 255 | 289 | |
| 256 | - style_header(showClosed ? "Closed Branches" : "Open Branches"); | |
| 290 | + style_header(showClosed ? "Closed Branches" : | |
| 291 | + showAll ? "All Branches" : "Open Branches"); | |
| 257 | 292 | style_submenu_element("Timeline", "Timeline", "brtimeline"); |
| 258 | 293 | if( showClosed ){ |
| 294 | + style_submenu_element("All", "All", "brlist?all"); | |
| 295 | + style_submenu_element("Open","Open","brlist"); | |
| 296 | + }else if( showAll ){ | |
| 297 | + style_submenu_element("Closed", "Closed", "brlist?closed"); | |
| 259 | 298 | style_submenu_element("Open","Open","brlist"); |
| 260 | 299 | }else{ |
| 300 | + style_submenu_element("All", "All", "brlist?all"); | |
| 261 | 301 | style_submenu_element("Closed","Closed","brlist?closed"); |
| 262 | 302 | } |
| 263 | 303 | login_anonymous_available(); |
| 264 | 304 | style_sidebox_begin("Nomenclature:", "33%"); |
| 265 | 305 | @ <ol> |
| @@ -275,33 +315,12 @@ | ||
| 275 | 315 | @ Closed branches are fixed and do not change (unless they are first |
| 276 | 316 | @ reopened)</li> |
| 277 | 317 | @ </ol> |
| 278 | 318 | style_sidebox_end(); |
| 279 | 319 | |
| 320 | + prepareBranchQuery(&q, showAll, showClosed); | |
| 280 | 321 | cnt = 0; |
| 281 | - if( showClosed ){ | |
| 282 | - db_prepare(&q, | |
| 283 | - "SELECT value FROM tagxref" | |
| 284 | - " WHERE tagid=%d AND value NOT NULL " | |
| 285 | - "EXCEPT " | |
| 286 | - "SELECT value FROM tagxref" | |
| 287 | - " WHERE tagid=%d" | |
| 288 | - " AND rid IN leaf" | |
| 289 | - " AND NOT %z" | |
| 290 | - " ORDER BY value /*sort*/", | |
| 291 | - TAG_BRANCH, TAG_BRANCH, leaf_is_closed_sql("tagxref.rid") | |
| 292 | - ); | |
| 293 | - }else{ | |
| 294 | - db_prepare(&q, | |
| 295 | - "SELECT DISTINCT value FROM tagxref" | |
| 296 | - " WHERE tagid=%d AND value NOT NULL" | |
| 297 | - " AND rid IN leaf" | |
| 298 | - " AND NOT %z" | |
| 299 | - " ORDER BY value /*sort*/", | |
| 300 | - TAG_BRANCH, leaf_is_closed_sql("tagxref.rid") | |
| 301 | - ); | |
| 302 | - } | |
| 303 | 322 | while( db_step(&q)==SQLITE_ROW ){ |
| 304 | 323 | const char *zBr = db_column_text(&q, 0); |
| 305 | 324 | if( cnt==0 ){ |
| 306 | 325 | if( showClosed ){ |
| 307 | 326 | @ <h2>Closed Branches:</h2> |
| 308 | 327 |
| --- src/branch.c | |
| +++ src/branch.c | |
| @@ -176,10 +176,47 @@ | |
| 176 | db_end_transaction(0); |
| 177 | |
| 178 | /* Do an autosync push, if requested */ |
| 179 | autosync(AUTOSYNC_PUSH); |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | ** COMMAND: branch |
| 184 | ** |
| 185 | ** Usage: %fossil branch SUBCOMMAND ... ?-R|--repository FILE? |
| @@ -194,11 +231,12 @@ | |
| 194 | ** --private option makes the branch private. |
| 195 | ** |
| 196 | ** %fossil branch list |
| 197 | ** %fossil branch ls |
| 198 | ** |
| 199 | ** List all branches |
| 200 | ** |
| 201 | */ |
| 202 | void branch_cmd(void){ |
| 203 | int n; |
| 204 | const char *zCmd = "list"; |
| @@ -212,24 +250,19 @@ | |
| 212 | branch_new(); |
| 213 | }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){ |
| 214 | Stmt q; |
| 215 | int vid; |
| 216 | char *zCurrent = 0; |
| 217 | |
| 218 | if( g.localOpen ){ |
| 219 | vid = db_lget_int("checkout", 0); |
| 220 | zCurrent = db_text(0, "SELECT value FROM tagxref" |
| 221 | " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH); |
| 222 | } |
| 223 | db_prepare(&q, |
| 224 | "SELECT DISTINCT value FROM tagxref" |
| 225 | " WHERE tagid=%d AND value NOT NULL" |
| 226 | " AND rid IN leaf" |
| 227 | " AND NOT %z" |
| 228 | " ORDER BY value /*sort*/", |
| 229 | TAG_BRANCH, leaf_is_closed_sql("tagxref.rid") |
| 230 | ); |
| 231 | while( db_step(&q)==SQLITE_ROW ){ |
| 232 | const char *zBr = db_column_text(&q, 0); |
| 233 | int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; |
| 234 | fossil_print("%s%s\n", (isCur ? "* " : " "), zBr); |
| 235 | } |
| @@ -247,19 +280,26 @@ | |
| 247 | */ |
| 248 | void brlist_page(void){ |
| 249 | Stmt q; |
| 250 | int cnt; |
| 251 | int showClosed = P("closed")!=0; |
| 252 | |
| 253 | login_check_credentials(); |
| 254 | if( !g.okRead ){ login_needed(); return; } |
| 255 | |
| 256 | style_header(showClosed ? "Closed Branches" : "Open Branches"); |
| 257 | style_submenu_element("Timeline", "Timeline", "brtimeline"); |
| 258 | if( showClosed ){ |
| 259 | style_submenu_element("Open","Open","brlist"); |
| 260 | }else{ |
| 261 | style_submenu_element("Closed","Closed","brlist?closed"); |
| 262 | } |
| 263 | login_anonymous_available(); |
| 264 | style_sidebox_begin("Nomenclature:", "33%"); |
| 265 | @ <ol> |
| @@ -275,33 +315,12 @@ | |
| 275 | @ Closed branches are fixed and do not change (unless they are first |
| 276 | @ reopened)</li> |
| 277 | @ </ol> |
| 278 | style_sidebox_end(); |
| 279 | |
| 280 | cnt = 0; |
| 281 | if( showClosed ){ |
| 282 | db_prepare(&q, |
| 283 | "SELECT value FROM tagxref" |
| 284 | " WHERE tagid=%d AND value NOT NULL " |
| 285 | "EXCEPT " |
| 286 | "SELECT value FROM tagxref" |
| 287 | " WHERE tagid=%d" |
| 288 | " AND rid IN leaf" |
| 289 | " AND NOT %z" |
| 290 | " ORDER BY value /*sort*/", |
| 291 | TAG_BRANCH, TAG_BRANCH, leaf_is_closed_sql("tagxref.rid") |
| 292 | ); |
| 293 | }else{ |
| 294 | db_prepare(&q, |
| 295 | "SELECT DISTINCT value FROM tagxref" |
| 296 | " WHERE tagid=%d AND value NOT NULL" |
| 297 | " AND rid IN leaf" |
| 298 | " AND NOT %z" |
| 299 | " ORDER BY value /*sort*/", |
| 300 | TAG_BRANCH, leaf_is_closed_sql("tagxref.rid") |
| 301 | ); |
| 302 | } |
| 303 | while( db_step(&q)==SQLITE_ROW ){ |
| 304 | const char *zBr = db_column_text(&q, 0); |
| 305 | if( cnt==0 ){ |
| 306 | if( showClosed ){ |
| 307 | @ <h2>Closed Branches:</h2> |
| 308 |
| --- src/branch.c | |
| +++ src/branch.c | |
| @@ -176,10 +176,47 @@ | |
| 176 | db_end_transaction(0); |
| 177 | |
| 178 | /* Do an autosync push, if requested */ |
| 179 | autosync(AUTOSYNC_PUSH); |
| 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 | "SELECT value FROM tagxref" |
| 192 | " WHERE tagid=%d" |
| 193 | " AND rid IN leaf" |
| 194 | " AND NOT %z" |
| 195 | " ORDER BY value COLLATE nocase /*sort*/", |
| 196 | TAG_BRANCH, TAG_BRANCH, leaf_is_closed_sql("tagxref.rid") |
| 197 | ); |
| 198 | }else if( showAll ){ |
| 199 | db_prepare(pQuery, |
| 200 | "SELECT DISTINCT value FROM tagxref" |
| 201 | " WHERE tagid=%d AND value NOT NULL" |
| 202 | " AND rid IN leaf" |
| 203 | " ORDER BY value COLLATE nocase /*sort*/", |
| 204 | TAG_BRANCH |
| 205 | ); |
| 206 | }else{ |
| 207 | db_prepare(pQuery, |
| 208 | "SELECT DISTINCT value FROM tagxref" |
| 209 | " WHERE tagid=%d AND value NOT NULL" |
| 210 | " AND rid IN leaf" |
| 211 | " AND NOT %z" |
| 212 | " ORDER BY value COLLATE nocase /*sort*/", |
| 213 | TAG_BRANCH, leaf_is_closed_sql("tagxref.rid") |
| 214 | ); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | |
| 219 | /* |
| 220 | ** COMMAND: branch |
| 221 | ** |
| 222 | ** Usage: %fossil branch SUBCOMMAND ... ?-R|--repository FILE? |
| @@ -194,11 +231,12 @@ | |
| 231 | ** --private option makes the branch private. |
| 232 | ** |
| 233 | ** %fossil branch list |
| 234 | ** %fossil branch ls |
| 235 | ** |
| 236 | ** List all branches. Use --all or --closed to list all branches |
| 237 | ** or closed branches. The default is to show only open branches. |
| 238 | ** |
| 239 | */ |
| 240 | void branch_cmd(void){ |
| 241 | int n; |
| 242 | const char *zCmd = "list"; |
| @@ -212,24 +250,19 @@ | |
| 250 | branch_new(); |
| 251 | }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){ |
| 252 | Stmt q; |
| 253 | int vid; |
| 254 | char *zCurrent = 0; |
| 255 | int showAll = find_option("all",0,0)!=0; |
| 256 | int showClosed = find_option("closed",0,0)!=0; |
| 257 | |
| 258 | if( g.localOpen ){ |
| 259 | vid = db_lget_int("checkout", 0); |
| 260 | zCurrent = db_text(0, "SELECT value FROM tagxref" |
| 261 | " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH); |
| 262 | } |
| 263 | prepareBranchQuery(&q, showAll, showClosed); |
| 264 | while( db_step(&q)==SQLITE_ROW ){ |
| 265 | const char *zBr = db_column_text(&q, 0); |
| 266 | int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; |
| 267 | fossil_print("%s%s\n", (isCur ? "* " : " "), zBr); |
| 268 | } |
| @@ -247,19 +280,26 @@ | |
| 280 | */ |
| 281 | void brlist_page(void){ |
| 282 | Stmt q; |
| 283 | int cnt; |
| 284 | int showClosed = P("closed")!=0; |
| 285 | int showAll = P("all")!=0; |
| 286 | |
| 287 | login_check_credentials(); |
| 288 | if( !g.okRead ){ login_needed(); return; } |
| 289 | |
| 290 | style_header(showClosed ? "Closed Branches" : |
| 291 | showAll ? "All Branches" : "Open Branches"); |
| 292 | style_submenu_element("Timeline", "Timeline", "brtimeline"); |
| 293 | if( showClosed ){ |
| 294 | style_submenu_element("All", "All", "brlist?all"); |
| 295 | style_submenu_element("Open","Open","brlist"); |
| 296 | }else if( showAll ){ |
| 297 | style_submenu_element("Closed", "Closed", "brlist?closed"); |
| 298 | style_submenu_element("Open","Open","brlist"); |
| 299 | }else{ |
| 300 | style_submenu_element("All", "All", "brlist?all"); |
| 301 | style_submenu_element("Closed","Closed","brlist?closed"); |
| 302 | } |
| 303 | login_anonymous_available(); |
| 304 | style_sidebox_begin("Nomenclature:", "33%"); |
| 305 | @ <ol> |
| @@ -275,33 +315,12 @@ | |
| 315 | @ Closed branches are fixed and do not change (unless they are first |
| 316 | @ reopened)</li> |
| 317 | @ </ol> |
| 318 | style_sidebox_end(); |
| 319 | |
| 320 | prepareBranchQuery(&q, showAll, showClosed); |
| 321 | cnt = 0; |
| 322 | while( db_step(&q)==SQLITE_ROW ){ |
| 323 | const char *zBr = db_column_text(&q, 0); |
| 324 | if( cnt==0 ){ |
| 325 | if( showClosed ){ |
| 326 | @ <h2>Closed Branches:</h2> |
| 327 |