Fossil SCM
Add the "fossil branch current" command. Also rearrange the code and the help text for the "fossil branch" command so that the various subcommands are in alphabetical order.
Commit
3b0a1f4e1e4e9a4eaa41ae132e2ef66ebae9489a1676f7a22aacc727608574ed
Parent
079431525d13a14…
1 file changed
+48
-28
+48
-28
| --- src/branch.c | ||
| +++ src/branch.c | ||
| @@ -268,10 +268,24 @@ | ||
| 268 | 268 | ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS? |
| 269 | 269 | ** |
| 270 | 270 | ** Run various subcommands to manage branches of the open repository or |
| 271 | 271 | ** of the repository identified by the -R or --repository option. |
| 272 | 272 | ** |
| 273 | +** fossil branch current | |
| 274 | +** | |
| 275 | +** Print the name of the branch for the current check-out | |
| 276 | +** | |
| 277 | +** fossil branch info BRANCH-NAME | |
| 278 | +** | |
| 279 | +** Print information about a branch | |
| 280 | +** | |
| 281 | +** fossil branch list|ls ?-a|--all|-c|--closed? | |
| 282 | +** | |
| 283 | +** List all branches. Use -a or --all to list all branches and | |
| 284 | +** -c or --closed to list all closed branches. The default is to | |
| 285 | +** show only open branches. | |
| 286 | +** | |
| 273 | 287 | ** fossil branch new BRANCH-NAME BASIS ?OPTIONS? |
| 274 | 288 | ** |
| 275 | 289 | ** Create a new branch BRANCH-NAME off of check-in BASIS. |
| 276 | 290 | ** Supported options for this subcommand include: |
| 277 | 291 | ** --private branch is private (i.e., remains local) |
| @@ -284,31 +298,50 @@ | ||
| 284 | 298 | ** year-month-day form, it may be truncated, the "T" may be |
| 285 | 299 | ** replaced by a space, and it may also name a timezone offset |
| 286 | 300 | ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward). |
| 287 | 301 | ** Either no timezone suffix or "Z" means UTC. |
| 288 | 302 | ** |
| 289 | -** fossil branch list|ls ?-a|--all|-c|--closed? | |
| 290 | -** | |
| 291 | -** List all branches. Use -a or --all to list all branches and | |
| 292 | -** -c or --closed to list all closed branches. The default is to | |
| 293 | -** show only open branches. | |
| 294 | -** | |
| 295 | -** fossil branch info BRANCH-NAME | |
| 296 | -** | |
| 297 | -** Print information about a branch | |
| 298 | -** | |
| 299 | 303 | ** Options: |
| 300 | 304 | ** -R|--repository FILE Run commands on repository FILE |
| 305 | +** | |
| 306 | +** Summary: | |
| 307 | +** fossil branch current | |
| 308 | +** fossil branch info BRANCHNAME | |
| 309 | +** fossil branch [list|ls] | |
| 310 | +** fossil branch new | |
| 301 | 311 | */ |
| 302 | 312 | void branch_cmd(void){ |
| 303 | 313 | int n; |
| 304 | 314 | const char *zCmd = "list"; |
| 305 | 315 | db_find_and_open_repository(0, 0); |
| 306 | 316 | if( g.argc>=3 ) zCmd = g.argv[2]; |
| 307 | 317 | n = strlen(zCmd); |
| 308 | - if( strncmp(zCmd,"new",n)==0 ){ | |
| 309 | - branch_new(); | |
| 318 | + if( strncmp(zCmd,"current",n)==0 ){ | |
| 319 | + if( !g.localOpen ){ | |
| 320 | + fossil_fatal("not within an open checkout"); | |
| 321 | + }else{ | |
| 322 | + int vid = db_lget_int("checkout", 0); | |
| 323 | + char *zCurrent = db_text(0, "SELECT value FROM tagxref" | |
| 324 | + " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH); | |
| 325 | + fossil_print("%s\n", zCurrent); | |
| 326 | + fossil_free(zCurrent); | |
| 327 | + } | |
| 328 | + }else if( strncmp(zCmd,"info",n)==0 ){ | |
| 329 | + int i; | |
| 330 | + for(i=3; i<g.argc; i++){ | |
| 331 | + const char *zBrName = g.argv[i]; | |
| 332 | + int rid = branch_is_open(zBrName); | |
| 333 | + if( rid==0 ){ | |
| 334 | + fossil_print("%s: not an open branch\n", zBrName); | |
| 335 | + }else{ | |
| 336 | + const char *zUuid = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid); | |
| 337 | + const char *zDate = db_text(0, | |
| 338 | + "SELECT datetime(mtime,toLocal()) FROM event" | |
| 339 | + " WHERE objid=%d", rid); | |
| 340 | + fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid); | |
| 341 | + } | |
| 342 | + } | |
| 310 | 343 | }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){ |
| 311 | 344 | Stmt q; |
| 312 | 345 | int vid; |
| 313 | 346 | char *zCurrent = 0; |
| 314 | 347 | int brFlags = BRL_OPEN_ONLY; |
| @@ -325,28 +358,15 @@ | ||
| 325 | 358 | const char *zBr = db_column_text(&q, 0); |
| 326 | 359 | int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; |
| 327 | 360 | fossil_print("%s%s\n", (isCur ? "* " : " "), zBr); |
| 328 | 361 | } |
| 329 | 362 | db_finalize(&q); |
| 330 | - }else if( strncmp(zCmd,"info",n)==0 ){ | |
| 331 | - int i; | |
| 332 | - for(i=3; i<g.argc; i++){ | |
| 333 | - const char *zBrName = g.argv[i]; | |
| 334 | - int rid = branch_is_open(zBrName); | |
| 335 | - if( rid==0 ){ | |
| 336 | - fossil_print("%s: not an open branch\n", zBrName); | |
| 337 | - }else{ | |
| 338 | - const char *zUuid = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid); | |
| 339 | - const char *zDate = db_text(0, | |
| 340 | - "SELECT datetime(mtime,toLocal()) FROM event" | |
| 341 | - " WHERE objid=%d", rid); | |
| 342 | - fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid); | |
| 343 | - } | |
| 344 | - } | |
| 363 | + }else if( strncmp(zCmd,"new",n)==0 ){ | |
| 364 | + branch_new(); | |
| 345 | 365 | }else{ |
| 346 | 366 | fossil_fatal("branch subcommand should be one of: " |
| 347 | - "info list ls new"); | |
| 367 | + "current info list ls new"); | |
| 348 | 368 | } |
| 349 | 369 | } |
| 350 | 370 | |
| 351 | 371 | static const char brlistQuery[] = |
| 352 | 372 | @ SELECT |
| 353 | 373 |
| --- src/branch.c | |
| +++ src/branch.c | |
| @@ -268,10 +268,24 @@ | |
| 268 | ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS? |
| 269 | ** |
| 270 | ** Run various subcommands to manage branches of the open repository or |
| 271 | ** of the repository identified by the -R or --repository option. |
| 272 | ** |
| 273 | ** fossil branch new BRANCH-NAME BASIS ?OPTIONS? |
| 274 | ** |
| 275 | ** Create a new branch BRANCH-NAME off of check-in BASIS. |
| 276 | ** Supported options for this subcommand include: |
| 277 | ** --private branch is private (i.e., remains local) |
| @@ -284,31 +298,50 @@ | |
| 284 | ** year-month-day form, it may be truncated, the "T" may be |
| 285 | ** replaced by a space, and it may also name a timezone offset |
| 286 | ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward). |
| 287 | ** Either no timezone suffix or "Z" means UTC. |
| 288 | ** |
| 289 | ** fossil branch list|ls ?-a|--all|-c|--closed? |
| 290 | ** |
| 291 | ** List all branches. Use -a or --all to list all branches and |
| 292 | ** -c or --closed to list all closed branches. The default is to |
| 293 | ** show only open branches. |
| 294 | ** |
| 295 | ** fossil branch info BRANCH-NAME |
| 296 | ** |
| 297 | ** Print information about a branch |
| 298 | ** |
| 299 | ** Options: |
| 300 | ** -R|--repository FILE Run commands on repository FILE |
| 301 | */ |
| 302 | void branch_cmd(void){ |
| 303 | int n; |
| 304 | const char *zCmd = "list"; |
| 305 | db_find_and_open_repository(0, 0); |
| 306 | if( g.argc>=3 ) zCmd = g.argv[2]; |
| 307 | n = strlen(zCmd); |
| 308 | if( strncmp(zCmd,"new",n)==0 ){ |
| 309 | branch_new(); |
| 310 | }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){ |
| 311 | Stmt q; |
| 312 | int vid; |
| 313 | char *zCurrent = 0; |
| 314 | int brFlags = BRL_OPEN_ONLY; |
| @@ -325,28 +358,15 @@ | |
| 325 | const char *zBr = db_column_text(&q, 0); |
| 326 | int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; |
| 327 | fossil_print("%s%s\n", (isCur ? "* " : " "), zBr); |
| 328 | } |
| 329 | db_finalize(&q); |
| 330 | }else if( strncmp(zCmd,"info",n)==0 ){ |
| 331 | int i; |
| 332 | for(i=3; i<g.argc; i++){ |
| 333 | const char *zBrName = g.argv[i]; |
| 334 | int rid = branch_is_open(zBrName); |
| 335 | if( rid==0 ){ |
| 336 | fossil_print("%s: not an open branch\n", zBrName); |
| 337 | }else{ |
| 338 | const char *zUuid = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid); |
| 339 | const char *zDate = db_text(0, |
| 340 | "SELECT datetime(mtime,toLocal()) FROM event" |
| 341 | " WHERE objid=%d", rid); |
| 342 | fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid); |
| 343 | } |
| 344 | } |
| 345 | }else{ |
| 346 | fossil_fatal("branch subcommand should be one of: " |
| 347 | "info list ls new"); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | static const char brlistQuery[] = |
| 352 | @ SELECT |
| 353 |
| --- src/branch.c | |
| +++ src/branch.c | |
| @@ -268,10 +268,24 @@ | |
| 268 | ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS? |
| 269 | ** |
| 270 | ** Run various subcommands to manage branches of the open repository or |
| 271 | ** of the repository identified by the -R or --repository option. |
| 272 | ** |
| 273 | ** fossil branch current |
| 274 | ** |
| 275 | ** Print the name of the branch for the current check-out |
| 276 | ** |
| 277 | ** fossil branch info BRANCH-NAME |
| 278 | ** |
| 279 | ** Print information about a branch |
| 280 | ** |
| 281 | ** fossil branch list|ls ?-a|--all|-c|--closed? |
| 282 | ** |
| 283 | ** List all branches. Use -a or --all to list all branches and |
| 284 | ** -c or --closed to list all closed branches. The default is to |
| 285 | ** show only open branches. |
| 286 | ** |
| 287 | ** fossil branch new BRANCH-NAME BASIS ?OPTIONS? |
| 288 | ** |
| 289 | ** Create a new branch BRANCH-NAME off of check-in BASIS. |
| 290 | ** Supported options for this subcommand include: |
| 291 | ** --private branch is private (i.e., remains local) |
| @@ -284,31 +298,50 @@ | |
| 298 | ** year-month-day form, it may be truncated, the "T" may be |
| 299 | ** replaced by a space, and it may also name a timezone offset |
| 300 | ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward). |
| 301 | ** Either no timezone suffix or "Z" means UTC. |
| 302 | ** |
| 303 | ** Options: |
| 304 | ** -R|--repository FILE Run commands on repository FILE |
| 305 | ** |
| 306 | ** Summary: |
| 307 | ** fossil branch current |
| 308 | ** fossil branch info BRANCHNAME |
| 309 | ** fossil branch [list|ls] |
| 310 | ** fossil branch new |
| 311 | */ |
| 312 | void branch_cmd(void){ |
| 313 | int n; |
| 314 | const char *zCmd = "list"; |
| 315 | db_find_and_open_repository(0, 0); |
| 316 | if( g.argc>=3 ) zCmd = g.argv[2]; |
| 317 | n = strlen(zCmd); |
| 318 | if( strncmp(zCmd,"current",n)==0 ){ |
| 319 | if( !g.localOpen ){ |
| 320 | fossil_fatal("not within an open checkout"); |
| 321 | }else{ |
| 322 | int vid = db_lget_int("checkout", 0); |
| 323 | char *zCurrent = db_text(0, "SELECT value FROM tagxref" |
| 324 | " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH); |
| 325 | fossil_print("%s\n", zCurrent); |
| 326 | fossil_free(zCurrent); |
| 327 | } |
| 328 | }else if( strncmp(zCmd,"info",n)==0 ){ |
| 329 | int i; |
| 330 | for(i=3; i<g.argc; i++){ |
| 331 | const char *zBrName = g.argv[i]; |
| 332 | int rid = branch_is_open(zBrName); |
| 333 | if( rid==0 ){ |
| 334 | fossil_print("%s: not an open branch\n", zBrName); |
| 335 | }else{ |
| 336 | const char *zUuid = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid); |
| 337 | const char *zDate = db_text(0, |
| 338 | "SELECT datetime(mtime,toLocal()) FROM event" |
| 339 | " WHERE objid=%d", rid); |
| 340 | fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid); |
| 341 | } |
| 342 | } |
| 343 | }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){ |
| 344 | Stmt q; |
| 345 | int vid; |
| 346 | char *zCurrent = 0; |
| 347 | int brFlags = BRL_OPEN_ONLY; |
| @@ -325,28 +358,15 @@ | |
| 358 | const char *zBr = db_column_text(&q, 0); |
| 359 | int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; |
| 360 | fossil_print("%s%s\n", (isCur ? "* " : " "), zBr); |
| 361 | } |
| 362 | db_finalize(&q); |
| 363 | }else if( strncmp(zCmd,"new",n)==0 ){ |
| 364 | branch_new(); |
| 365 | }else{ |
| 366 | fossil_fatal("branch subcommand should be one of: " |
| 367 | "current info list ls new"); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | static const char brlistQuery[] = |
| 372 | @ SELECT |
| 373 |