Fossil SCM
Add a new `-h' option to `fossil branch ls' to list the "hot" (first few recently modified) branches.
Commit
fe299ee400d06551774b874e158819d0973897a0c10ca87471cd405ea3e6413f
Parent
769a7651e46a642…
1 file changed
+26
-5
+26
-5
| --- src/branch.c | ||
| +++ src/branch.c | ||
| @@ -280,10 +280,11 @@ | ||
| 280 | 280 | #define BRL_BOTH 0x003 /* Show both open and closed branches */ |
| 281 | 281 | #define BRL_OPEN_CLOSED_MASK 0x003 |
| 282 | 282 | #define BRL_ORDERBY_MTIME 0x004 /* Sort by MTIME. (otherwise sort by name)*/ |
| 283 | 283 | #define BRL_REVERSE 0x008 /* Reverse the sort order */ |
| 284 | 284 | #define BRL_PRIVATE 0x010 /* Show only private branches */ |
| 285 | +#define BRL_LIMIT 0x020 /* Limit entries to specified number */ | |
| 285 | 286 | |
| 286 | 287 | #endif /* INTERFACE */ |
| 287 | 288 | |
| 288 | 289 | /* |
| 289 | 290 | ** Prepare a query that will list branches. |
| @@ -290,11 +291,16 @@ | ||
| 290 | 291 | ** |
| 291 | 292 | ** If (which<0) then the query pulls only closed branches. If |
| 292 | 293 | ** (which>0) then the query pulls all (closed and opened) |
| 293 | 294 | ** branches. Else the query pulls currently-opened branches. |
| 294 | 295 | */ |
| 295 | -void branch_prepare_list_query(Stmt *pQuery, int brFlags, const char *zBrNameGlob){ | |
| 296 | +void branch_prepare_list_query( | |
| 297 | + Stmt *pQuery, | |
| 298 | + int brFlags, | |
| 299 | + const char *zBrNameGlob, | |
| 300 | + int nLimit | |
| 301 | +){ | |
| 296 | 302 | Blob sql; |
| 297 | 303 | blob_init(&sql, 0, 0); |
| 298 | 304 | brlist_create_temp_table(); |
| 299 | 305 | switch( brFlags & BRL_OPEN_CLOSED_MASK ){ |
| 300 | 306 | case BRL_CLOSED_ONLY: { |
| @@ -324,10 +330,13 @@ | ||
| 324 | 330 | blob_append_sql(&sql, " ORDER BY name COLLATE nocase"); |
| 325 | 331 | } |
| 326 | 332 | if( brFlags & BRL_REVERSE ){ |
| 327 | 333 | blob_append_sql(&sql," DESC"); |
| 328 | 334 | } |
| 335 | + if( brFlags & BRL_LIMIT && nLimit>0 ){ | |
| 336 | + blob_append_sql(&sql," LIMIT %d",nLimit); | |
| 337 | + } | |
| 329 | 338 | db_prepare_blob(pQuery, &sql); |
| 330 | 339 | blob_reset(&sql); |
| 331 | 340 | } |
| 332 | 341 | |
| 333 | 342 | /* |
| @@ -592,15 +601,18 @@ | ||
| 592 | 601 | ** -a|--all List all branches. Default show only open branches |
| 593 | 602 | ** -c|--closed List closed branches. |
| 594 | 603 | ** -p List only private branches. |
| 595 | 604 | ** -r Reverse the sort order |
| 596 | 605 | ** -t Show recently changed branches first |
| 606 | +** -h ?N? Show N recently changed branches (or 5 if N omitted) | |
| 597 | 607 | ** |
| 598 | 608 | ** The current branch is marked with an asterisk. Private branches are |
| 599 | 609 | ** marked with a hash sign. |
| 600 | 610 | ** |
| 601 | -** If GLOB is given, show only branches matching the pattern. | |
| 611 | +** If GLOB is given, show only branches matching the pattern. With the | |
| 612 | +** -h option set, no GLOB argument is allowed, but an (optional) number | |
| 613 | +** of entries to output. | |
| 602 | 614 | ** |
| 603 | 615 | ** > fossil branch new BRANCH-NAME BASIS ?OPTIONS? |
| 604 | 616 | ** |
| 605 | 617 | ** Create a new branch BRANCH-NAME off of check-in BASIS. |
| 606 | 618 | ** Supported options for this subcommand include: |
| @@ -656,24 +668,33 @@ | ||
| 656 | 668 | }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){ |
| 657 | 669 | Stmt q; |
| 658 | 670 | int vid; |
| 659 | 671 | char *zCurrent = 0; |
| 660 | 672 | const char *zBrNameGlob = 0; |
| 673 | + int nLimit = 5; | |
| 661 | 674 | int brFlags = BRL_OPEN_ONLY; |
| 662 | 675 | if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH; |
| 663 | 676 | if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY; |
| 664 | 677 | if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME; |
| 665 | 678 | if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE; |
| 666 | 679 | if( find_option("p",0,0)!=0 ) brFlags |= BRL_PRIVATE; |
| 667 | - if( g.argc >= 4 ) zBrNameGlob = g.argv[3]; | |
| 680 | + if( find_option("h",0,0)!=0 ) brFlags |= BRL_LIMIT; | |
| 681 | + if( (brFlags & BRL_LIMIT)==0 ){ | |
| 682 | + if( g.argc >= 4 ) zBrNameGlob = g.argv[3]; | |
| 683 | + }else{ | |
| 684 | + if( g.argc>4 || g.argc==4 && (nLimit = atoi(g.argv[3]))==0 ){ | |
| 685 | + fossil_fatal("only one numeric or no argument allowed following -h"); | |
| 686 | + } | |
| 687 | + brFlags |= BRL_ORDERBY_MTIME; | |
| 688 | + } | |
| 668 | 689 | |
| 669 | 690 | if( g.localOpen ){ |
| 670 | 691 | vid = db_lget_int("checkout", 0); |
| 671 | 692 | zCurrent = db_text(0, "SELECT value FROM tagxref" |
| 672 | 693 | " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH); |
| 673 | 694 | } |
| 674 | - branch_prepare_list_query(&q, brFlags, zBrNameGlob); | |
| 695 | + branch_prepare_list_query(&q, brFlags, zBrNameGlob, nLimit); | |
| 675 | 696 | while( db_step(&q)==SQLITE_ROW ){ |
| 676 | 697 | const char *zBr = db_column_text(&q, 0); |
| 677 | 698 | int isPriv = zCurrent!=0 && db_column_int(&q, 1)==1; |
| 678 | 699 | int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; |
| 679 | 700 | fossil_print("%s%s%s\n", |
| @@ -862,11 +883,11 @@ | ||
| 862 | 883 | @ reopened).</li> |
| 863 | 884 | @ </ol> |
| 864 | 885 | style_sidebox_end(); |
| 865 | 886 | #endif |
| 866 | 887 | |
| 867 | - branch_prepare_list_query(&q, brFlags, 0); | |
| 888 | + branch_prepare_list_query(&q, brFlags, 0, 0); | |
| 868 | 889 | cnt = 0; |
| 869 | 890 | while( db_step(&q)==SQLITE_ROW ){ |
| 870 | 891 | const char *zBr = db_column_text(&q, 0); |
| 871 | 892 | if( cnt==0 ){ |
| 872 | 893 | if( colorTest ){ |
| 873 | 894 |
| --- src/branch.c | |
| +++ src/branch.c | |
| @@ -280,10 +280,11 @@ | |
| 280 | #define BRL_BOTH 0x003 /* Show both open and closed branches */ |
| 281 | #define BRL_OPEN_CLOSED_MASK 0x003 |
| 282 | #define BRL_ORDERBY_MTIME 0x004 /* Sort by MTIME. (otherwise sort by name)*/ |
| 283 | #define BRL_REVERSE 0x008 /* Reverse the sort order */ |
| 284 | #define BRL_PRIVATE 0x010 /* Show only private branches */ |
| 285 | |
| 286 | #endif /* INTERFACE */ |
| 287 | |
| 288 | /* |
| 289 | ** Prepare a query that will list branches. |
| @@ -290,11 +291,16 @@ | |
| 290 | ** |
| 291 | ** If (which<0) then the query pulls only closed branches. If |
| 292 | ** (which>0) then the query pulls all (closed and opened) |
| 293 | ** branches. Else the query pulls currently-opened branches. |
| 294 | */ |
| 295 | void branch_prepare_list_query(Stmt *pQuery, int brFlags, const char *zBrNameGlob){ |
| 296 | Blob sql; |
| 297 | blob_init(&sql, 0, 0); |
| 298 | brlist_create_temp_table(); |
| 299 | switch( brFlags & BRL_OPEN_CLOSED_MASK ){ |
| 300 | case BRL_CLOSED_ONLY: { |
| @@ -324,10 +330,13 @@ | |
| 324 | blob_append_sql(&sql, " ORDER BY name COLLATE nocase"); |
| 325 | } |
| 326 | if( brFlags & BRL_REVERSE ){ |
| 327 | blob_append_sql(&sql," DESC"); |
| 328 | } |
| 329 | db_prepare_blob(pQuery, &sql); |
| 330 | blob_reset(&sql); |
| 331 | } |
| 332 | |
| 333 | /* |
| @@ -592,15 +601,18 @@ | |
| 592 | ** -a|--all List all branches. Default show only open branches |
| 593 | ** -c|--closed List closed branches. |
| 594 | ** -p List only private branches. |
| 595 | ** -r Reverse the sort order |
| 596 | ** -t Show recently changed branches first |
| 597 | ** |
| 598 | ** The current branch is marked with an asterisk. Private branches are |
| 599 | ** marked with a hash sign. |
| 600 | ** |
| 601 | ** If GLOB is given, show only branches matching the pattern. |
| 602 | ** |
| 603 | ** > fossil branch new BRANCH-NAME BASIS ?OPTIONS? |
| 604 | ** |
| 605 | ** Create a new branch BRANCH-NAME off of check-in BASIS. |
| 606 | ** Supported options for this subcommand include: |
| @@ -656,24 +668,33 @@ | |
| 656 | }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){ |
| 657 | Stmt q; |
| 658 | int vid; |
| 659 | char *zCurrent = 0; |
| 660 | const char *zBrNameGlob = 0; |
| 661 | int brFlags = BRL_OPEN_ONLY; |
| 662 | if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH; |
| 663 | if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY; |
| 664 | if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME; |
| 665 | if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE; |
| 666 | if( find_option("p",0,0)!=0 ) brFlags |= BRL_PRIVATE; |
| 667 | if( g.argc >= 4 ) zBrNameGlob = g.argv[3]; |
| 668 | |
| 669 | if( g.localOpen ){ |
| 670 | vid = db_lget_int("checkout", 0); |
| 671 | zCurrent = db_text(0, "SELECT value FROM tagxref" |
| 672 | " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH); |
| 673 | } |
| 674 | branch_prepare_list_query(&q, brFlags, zBrNameGlob); |
| 675 | while( db_step(&q)==SQLITE_ROW ){ |
| 676 | const char *zBr = db_column_text(&q, 0); |
| 677 | int isPriv = zCurrent!=0 && db_column_int(&q, 1)==1; |
| 678 | int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; |
| 679 | fossil_print("%s%s%s\n", |
| @@ -862,11 +883,11 @@ | |
| 862 | @ reopened).</li> |
| 863 | @ </ol> |
| 864 | style_sidebox_end(); |
| 865 | #endif |
| 866 | |
| 867 | branch_prepare_list_query(&q, brFlags, 0); |
| 868 | cnt = 0; |
| 869 | while( db_step(&q)==SQLITE_ROW ){ |
| 870 | const char *zBr = db_column_text(&q, 0); |
| 871 | if( cnt==0 ){ |
| 872 | if( colorTest ){ |
| 873 |
| --- src/branch.c | |
| +++ src/branch.c | |
| @@ -280,10 +280,11 @@ | |
| 280 | #define BRL_BOTH 0x003 /* Show both open and closed branches */ |
| 281 | #define BRL_OPEN_CLOSED_MASK 0x003 |
| 282 | #define BRL_ORDERBY_MTIME 0x004 /* Sort by MTIME. (otherwise sort by name)*/ |
| 283 | #define BRL_REVERSE 0x008 /* Reverse the sort order */ |
| 284 | #define BRL_PRIVATE 0x010 /* Show only private branches */ |
| 285 | #define BRL_LIMIT 0x020 /* Limit entries to specified number */ |
| 286 | |
| 287 | #endif /* INTERFACE */ |
| 288 | |
| 289 | /* |
| 290 | ** Prepare a query that will list branches. |
| @@ -290,11 +291,16 @@ | |
| 291 | ** |
| 292 | ** If (which<0) then the query pulls only closed branches. If |
| 293 | ** (which>0) then the query pulls all (closed and opened) |
| 294 | ** branches. Else the query pulls currently-opened branches. |
| 295 | */ |
| 296 | void branch_prepare_list_query( |
| 297 | Stmt *pQuery, |
| 298 | int brFlags, |
| 299 | const char *zBrNameGlob, |
| 300 | int nLimit |
| 301 | ){ |
| 302 | Blob sql; |
| 303 | blob_init(&sql, 0, 0); |
| 304 | brlist_create_temp_table(); |
| 305 | switch( brFlags & BRL_OPEN_CLOSED_MASK ){ |
| 306 | case BRL_CLOSED_ONLY: { |
| @@ -324,10 +330,13 @@ | |
| 330 | blob_append_sql(&sql, " ORDER BY name COLLATE nocase"); |
| 331 | } |
| 332 | if( brFlags & BRL_REVERSE ){ |
| 333 | blob_append_sql(&sql," DESC"); |
| 334 | } |
| 335 | if( brFlags & BRL_LIMIT && nLimit>0 ){ |
| 336 | blob_append_sql(&sql," LIMIT %d",nLimit); |
| 337 | } |
| 338 | db_prepare_blob(pQuery, &sql); |
| 339 | blob_reset(&sql); |
| 340 | } |
| 341 | |
| 342 | /* |
| @@ -592,15 +601,18 @@ | |
| 601 | ** -a|--all List all branches. Default show only open branches |
| 602 | ** -c|--closed List closed branches. |
| 603 | ** -p List only private branches. |
| 604 | ** -r Reverse the sort order |
| 605 | ** -t Show recently changed branches first |
| 606 | ** -h ?N? Show N recently changed branches (or 5 if N omitted) |
| 607 | ** |
| 608 | ** The current branch is marked with an asterisk. Private branches are |
| 609 | ** marked with a hash sign. |
| 610 | ** |
| 611 | ** If GLOB is given, show only branches matching the pattern. With the |
| 612 | ** -h option set, no GLOB argument is allowed, but an (optional) number |
| 613 | ** of entries to output. |
| 614 | ** |
| 615 | ** > fossil branch new BRANCH-NAME BASIS ?OPTIONS? |
| 616 | ** |
| 617 | ** Create a new branch BRANCH-NAME off of check-in BASIS. |
| 618 | ** Supported options for this subcommand include: |
| @@ -656,24 +668,33 @@ | |
| 668 | }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){ |
| 669 | Stmt q; |
| 670 | int vid; |
| 671 | char *zCurrent = 0; |
| 672 | const char *zBrNameGlob = 0; |
| 673 | int nLimit = 5; |
| 674 | int brFlags = BRL_OPEN_ONLY; |
| 675 | if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH; |
| 676 | if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY; |
| 677 | if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME; |
| 678 | if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE; |
| 679 | if( find_option("p",0,0)!=0 ) brFlags |= BRL_PRIVATE; |
| 680 | if( find_option("h",0,0)!=0 ) brFlags |= BRL_LIMIT; |
| 681 | if( (brFlags & BRL_LIMIT)==0 ){ |
| 682 | if( g.argc >= 4 ) zBrNameGlob = g.argv[3]; |
| 683 | }else{ |
| 684 | if( g.argc>4 || g.argc==4 && (nLimit = atoi(g.argv[3]))==0 ){ |
| 685 | fossil_fatal("only one numeric or no argument allowed following -h"); |
| 686 | } |
| 687 | brFlags |= BRL_ORDERBY_MTIME; |
| 688 | } |
| 689 | |
| 690 | if( g.localOpen ){ |
| 691 | vid = db_lget_int("checkout", 0); |
| 692 | zCurrent = db_text(0, "SELECT value FROM tagxref" |
| 693 | " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH); |
| 694 | } |
| 695 | branch_prepare_list_query(&q, brFlags, zBrNameGlob, nLimit); |
| 696 | while( db_step(&q)==SQLITE_ROW ){ |
| 697 | const char *zBr = db_column_text(&q, 0); |
| 698 | int isPriv = zCurrent!=0 && db_column_int(&q, 1)==1; |
| 699 | int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; |
| 700 | fossil_print("%s%s%s\n", |
| @@ -862,11 +883,11 @@ | |
| 883 | @ reopened).</li> |
| 884 | @ </ol> |
| 885 | style_sidebox_end(); |
| 886 | #endif |
| 887 | |
| 888 | branch_prepare_list_query(&q, brFlags, 0, 0); |
| 889 | cnt = 0; |
| 890 | while( db_step(&q)==SQLITE_ROW ){ |
| 891 | const char *zBr = db_column_text(&q, 0); |
| 892 | if( cnt==0 ){ |
| 893 | if( colorTest ){ |
| 894 |