Fossil SCM
Add the ability for 'branch list' to filter the branches that have/have not been merged into the current branch, per [forum:c4a9d9e097|forum request].
Commit
d6ddd5bcfa2cac02987530f6e39ab36a9e6c3d40477ce168f65268a71edf1dad
Parent
ebe81aa11c167cd…
1 file changed
+22
-4
+22
-4
| --- src/branch.c | ||
| +++ src/branch.c | ||
| @@ -276,10 +276,12 @@ | ||
| 276 | 276 | #define BRL_BOTH 0x003 /* Show both open and closed branches */ |
| 277 | 277 | #define BRL_OPEN_CLOSED_MASK 0x003 |
| 278 | 278 | #define BRL_ORDERBY_MTIME 0x004 /* Sort by MTIME. (otherwise sort by name)*/ |
| 279 | 279 | #define BRL_REVERSE 0x008 /* Reverse the sort order */ |
| 280 | 280 | #define BRL_PRIVATE 0x010 /* Show only private branches */ |
| 281 | +#define BRL_MERGED 0x020 /* Show only merged branches */ | |
| 282 | +#define BRL_UNMERGED 0x040 /* Show only unmerged branches */ | |
| 281 | 283 | |
| 282 | 284 | #endif /* INTERFACE */ |
| 283 | 285 | |
| 284 | 286 | /* |
| 285 | 287 | ** Prepare a query that will list branches. |
| @@ -305,32 +307,33 @@ | ||
| 305 | 307 | /* Ignore nLimitMRU if no chronological sort requested. */ |
| 306 | 308 | if( (brFlags & BRL_ORDERBY_MTIME)==0 ) nLimitMRU = 0; |
| 307 | 309 | /* Undocumented: invert negative values for nLimitMRU, so that command-line |
| 308 | 310 | ** arguments similar to `head -5' with "option numbers" are possible. */ |
| 309 | 311 | if( nLimitMRU<0 ) nLimitMRU = -nLimitMRU; |
| 310 | - blob_append_sql(&sql,"SELECT name, isprivate FROM ("); /* OUTER QUERY */ | |
| 312 | + blob_append_sql(&sql,"SELECT name, isprivate, mergeto FROM ("); /* OUTER QUERY */ | |
| 311 | 313 | switch( brFlags & BRL_OPEN_CLOSED_MASK ){ |
| 312 | 314 | case BRL_CLOSED_ONLY: { |
| 313 | 315 | blob_append_sql(&sql, |
| 314 | - "SELECT name, isprivate, mtime FROM tmp_brlist WHERE isclosed" | |
| 316 | + "SELECT name, isprivate, mtime, mergeto FROM tmp_brlist WHERE isclosed" | |
| 315 | 317 | ); |
| 316 | 318 | break; |
| 317 | 319 | } |
| 318 | 320 | case BRL_BOTH: { |
| 319 | 321 | blob_append_sql(&sql, |
| 320 | - "SELECT name, isprivate, mtime FROM tmp_brlist WHERE 1" | |
| 322 | + "SELECT name, isprivate, mtime, mergeto FROM tmp_brlist WHERE 1" | |
| 321 | 323 | ); |
| 322 | 324 | break; |
| 323 | 325 | } |
| 324 | 326 | case BRL_OPEN_ONLY: { |
| 325 | 327 | blob_append_sql(&sql, |
| 326 | - "SELECT name, isprivate, mtime FROM tmp_brlist WHERE NOT isclosed" | |
| 328 | + "SELECT name, isprivate, mtime, mergeto FROM tmp_brlist WHERE NOT isclosed" | |
| 327 | 329 | ); |
| 328 | 330 | break; |
| 329 | 331 | } |
| 330 | 332 | } |
| 331 | 333 | if( brFlags & BRL_PRIVATE ) blob_append_sql(&sql, " AND isprivate"); |
| 334 | + if( brFlags & BRL_MERGED ) blob_append_sql(&sql, " AND mergeto IS NOT NULL"); | |
| 332 | 335 | if(zBrNameGlob) blob_append_sql(&sql, " AND (name GLOB %Q)", zBrNameGlob); |
| 333 | 336 | if( brFlags & BRL_ORDERBY_MTIME ){ |
| 334 | 337 | blob_append_sql(&sql, " ORDER BY -mtime"); |
| 335 | 338 | }else{ |
| 336 | 339 | blob_append_sql(&sql, " ORDER BY name COLLATE nocase"); |
| @@ -613,10 +616,12 @@ | ||
| 613 | 616 | ** List all branches. |
| 614 | 617 | ** |
| 615 | 618 | ** Options: |
| 616 | 619 | ** -a|--all List all branches. Default show only open branches |
| 617 | 620 | ** -c|--closed List closed branches |
| 621 | +** -m|--merged List branches merged into the current branch | |
| 622 | +** -M|--unmerged List branches not merged into the current branch | |
| 618 | 623 | ** -p List only private branches |
| 619 | 624 | ** -r Reverse the sort order |
| 620 | 625 | ** -t Show recently changed branches first |
| 621 | 626 | ** |
| 622 | 627 | ** The current branch is marked with an asterisk. Private branches are |
| @@ -694,11 +699,16 @@ | ||
| 694 | 699 | if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH; |
| 695 | 700 | if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY; |
| 696 | 701 | if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME; |
| 697 | 702 | if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE; |
| 698 | 703 | if( find_option("p",0,0)!=0 ) brFlags |= BRL_PRIVATE; |
| 704 | + if( find_option("merged","m",0)!=0 ) brFlags |= BRL_MERGED; | |
| 705 | + if( find_option("unmerged","M",0)!=0 ) brFlags |= BRL_UNMERGED; | |
| 699 | 706 | |
| 707 | + if ( (brFlags & BRL_MERGED) && (brFlags & BRL_UNMERGED) ){ | |
| 708 | + fossil_fatal("flags --merged and --unmerged are mutually exclusive"); | |
| 709 | + } | |
| 700 | 710 | if( strcmp(zCmd, "lsh")==0 ){ |
| 701 | 711 | nLimit = 5; |
| 702 | 712 | if( g.argc>4 || (g.argc==4 && (nLimit = atoi(g.argv[3]))==0) ){ |
| 703 | 713 | fossil_fatal("the lsh subcommand allows one optional numeric argument"); |
| 704 | 714 | } |
| @@ -714,11 +724,19 @@ | ||
| 714 | 724 | } |
| 715 | 725 | branch_prepare_list_query(&q, brFlags, zBrNameGlob, nLimit); |
| 716 | 726 | while( db_step(&q)==SQLITE_ROW ){ |
| 717 | 727 | const char *zBr = db_column_text(&q, 0); |
| 718 | 728 | int isPriv = zCurrent!=0 && db_column_int(&q, 1)==1; |
| 729 | + const char *zMergeTo = db_column_text(&q, 2); | |
| 719 | 730 | int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; |
| 731 | + if( (brFlags & BRL_MERGED) && fossil_strcmp(zCurrent,zMergeTo)!=0 ){ | |
| 732 | + continue; | |
| 733 | + } | |
| 734 | + if( (brFlags & BRL_UNMERGED) && (fossil_strcmp(zCurrent,zMergeTo)==0 | |
| 735 | + || isCur) ){ | |
| 736 | + continue; | |
| 737 | + } | |
| 720 | 738 | fossil_print("%s%s%s\n", |
| 721 | 739 | ( (brFlags & BRL_PRIVATE) ? " " : ( isPriv ? "#" : " ") ), |
| 722 | 740 | (isCur ? "* " : " "), zBr); |
| 723 | 741 | } |
| 724 | 742 | db_finalize(&q); |
| 725 | 743 |
| --- src/branch.c | |
| +++ src/branch.c | |
| @@ -276,10 +276,12 @@ | |
| 276 | #define BRL_BOTH 0x003 /* Show both open and closed branches */ |
| 277 | #define BRL_OPEN_CLOSED_MASK 0x003 |
| 278 | #define BRL_ORDERBY_MTIME 0x004 /* Sort by MTIME. (otherwise sort by name)*/ |
| 279 | #define BRL_REVERSE 0x008 /* Reverse the sort order */ |
| 280 | #define BRL_PRIVATE 0x010 /* Show only private branches */ |
| 281 | |
| 282 | #endif /* INTERFACE */ |
| 283 | |
| 284 | /* |
| 285 | ** Prepare a query that will list branches. |
| @@ -305,32 +307,33 @@ | |
| 305 | /* Ignore nLimitMRU if no chronological sort requested. */ |
| 306 | if( (brFlags & BRL_ORDERBY_MTIME)==0 ) nLimitMRU = 0; |
| 307 | /* Undocumented: invert negative values for nLimitMRU, so that command-line |
| 308 | ** arguments similar to `head -5' with "option numbers" are possible. */ |
| 309 | if( nLimitMRU<0 ) nLimitMRU = -nLimitMRU; |
| 310 | blob_append_sql(&sql,"SELECT name, isprivate FROM ("); /* OUTER QUERY */ |
| 311 | switch( brFlags & BRL_OPEN_CLOSED_MASK ){ |
| 312 | case BRL_CLOSED_ONLY: { |
| 313 | blob_append_sql(&sql, |
| 314 | "SELECT name, isprivate, mtime FROM tmp_brlist WHERE isclosed" |
| 315 | ); |
| 316 | break; |
| 317 | } |
| 318 | case BRL_BOTH: { |
| 319 | blob_append_sql(&sql, |
| 320 | "SELECT name, isprivate, mtime FROM tmp_brlist WHERE 1" |
| 321 | ); |
| 322 | break; |
| 323 | } |
| 324 | case BRL_OPEN_ONLY: { |
| 325 | blob_append_sql(&sql, |
| 326 | "SELECT name, isprivate, mtime FROM tmp_brlist WHERE NOT isclosed" |
| 327 | ); |
| 328 | break; |
| 329 | } |
| 330 | } |
| 331 | if( brFlags & BRL_PRIVATE ) blob_append_sql(&sql, " AND isprivate"); |
| 332 | if(zBrNameGlob) blob_append_sql(&sql, " AND (name GLOB %Q)", zBrNameGlob); |
| 333 | if( brFlags & BRL_ORDERBY_MTIME ){ |
| 334 | blob_append_sql(&sql, " ORDER BY -mtime"); |
| 335 | }else{ |
| 336 | blob_append_sql(&sql, " ORDER BY name COLLATE nocase"); |
| @@ -613,10 +616,12 @@ | |
| 613 | ** List all branches. |
| 614 | ** |
| 615 | ** Options: |
| 616 | ** -a|--all List all branches. Default show only open branches |
| 617 | ** -c|--closed List closed branches |
| 618 | ** -p List only private branches |
| 619 | ** -r Reverse the sort order |
| 620 | ** -t Show recently changed branches first |
| 621 | ** |
| 622 | ** The current branch is marked with an asterisk. Private branches are |
| @@ -694,11 +699,16 @@ | |
| 694 | if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH; |
| 695 | if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY; |
| 696 | if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME; |
| 697 | if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE; |
| 698 | if( find_option("p",0,0)!=0 ) brFlags |= BRL_PRIVATE; |
| 699 | |
| 700 | if( strcmp(zCmd, "lsh")==0 ){ |
| 701 | nLimit = 5; |
| 702 | if( g.argc>4 || (g.argc==4 && (nLimit = atoi(g.argv[3]))==0) ){ |
| 703 | fossil_fatal("the lsh subcommand allows one optional numeric argument"); |
| 704 | } |
| @@ -714,11 +724,19 @@ | |
| 714 | } |
| 715 | branch_prepare_list_query(&q, brFlags, zBrNameGlob, nLimit); |
| 716 | while( db_step(&q)==SQLITE_ROW ){ |
| 717 | const char *zBr = db_column_text(&q, 0); |
| 718 | int isPriv = zCurrent!=0 && db_column_int(&q, 1)==1; |
| 719 | int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; |
| 720 | fossil_print("%s%s%s\n", |
| 721 | ( (brFlags & BRL_PRIVATE) ? " " : ( isPriv ? "#" : " ") ), |
| 722 | (isCur ? "* " : " "), zBr); |
| 723 | } |
| 724 | db_finalize(&q); |
| 725 |
| --- src/branch.c | |
| +++ src/branch.c | |
| @@ -276,10 +276,12 @@ | |
| 276 | #define BRL_BOTH 0x003 /* Show both open and closed branches */ |
| 277 | #define BRL_OPEN_CLOSED_MASK 0x003 |
| 278 | #define BRL_ORDERBY_MTIME 0x004 /* Sort by MTIME. (otherwise sort by name)*/ |
| 279 | #define BRL_REVERSE 0x008 /* Reverse the sort order */ |
| 280 | #define BRL_PRIVATE 0x010 /* Show only private branches */ |
| 281 | #define BRL_MERGED 0x020 /* Show only merged branches */ |
| 282 | #define BRL_UNMERGED 0x040 /* Show only unmerged branches */ |
| 283 | |
| 284 | #endif /* INTERFACE */ |
| 285 | |
| 286 | /* |
| 287 | ** Prepare a query that will list branches. |
| @@ -305,32 +307,33 @@ | |
| 307 | /* Ignore nLimitMRU if no chronological sort requested. */ |
| 308 | if( (brFlags & BRL_ORDERBY_MTIME)==0 ) nLimitMRU = 0; |
| 309 | /* Undocumented: invert negative values for nLimitMRU, so that command-line |
| 310 | ** arguments similar to `head -5' with "option numbers" are possible. */ |
| 311 | if( nLimitMRU<0 ) nLimitMRU = -nLimitMRU; |
| 312 | blob_append_sql(&sql,"SELECT name, isprivate, mergeto FROM ("); /* OUTER QUERY */ |
| 313 | switch( brFlags & BRL_OPEN_CLOSED_MASK ){ |
| 314 | case BRL_CLOSED_ONLY: { |
| 315 | blob_append_sql(&sql, |
| 316 | "SELECT name, isprivate, mtime, mergeto FROM tmp_brlist WHERE isclosed" |
| 317 | ); |
| 318 | break; |
| 319 | } |
| 320 | case BRL_BOTH: { |
| 321 | blob_append_sql(&sql, |
| 322 | "SELECT name, isprivate, mtime, mergeto FROM tmp_brlist WHERE 1" |
| 323 | ); |
| 324 | break; |
| 325 | } |
| 326 | case BRL_OPEN_ONLY: { |
| 327 | blob_append_sql(&sql, |
| 328 | "SELECT name, isprivate, mtime, mergeto FROM tmp_brlist WHERE NOT isclosed" |
| 329 | ); |
| 330 | break; |
| 331 | } |
| 332 | } |
| 333 | if( brFlags & BRL_PRIVATE ) blob_append_sql(&sql, " AND isprivate"); |
| 334 | if( brFlags & BRL_MERGED ) blob_append_sql(&sql, " AND mergeto IS NOT NULL"); |
| 335 | if(zBrNameGlob) blob_append_sql(&sql, " AND (name GLOB %Q)", zBrNameGlob); |
| 336 | if( brFlags & BRL_ORDERBY_MTIME ){ |
| 337 | blob_append_sql(&sql, " ORDER BY -mtime"); |
| 338 | }else{ |
| 339 | blob_append_sql(&sql, " ORDER BY name COLLATE nocase"); |
| @@ -613,10 +616,12 @@ | |
| 616 | ** List all branches. |
| 617 | ** |
| 618 | ** Options: |
| 619 | ** -a|--all List all branches. Default show only open branches |
| 620 | ** -c|--closed List closed branches |
| 621 | ** -m|--merged List branches merged into the current branch |
| 622 | ** -M|--unmerged List branches not merged into the current branch |
| 623 | ** -p List only private branches |
| 624 | ** -r Reverse the sort order |
| 625 | ** -t Show recently changed branches first |
| 626 | ** |
| 627 | ** The current branch is marked with an asterisk. Private branches are |
| @@ -694,11 +699,16 @@ | |
| 699 | if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH; |
| 700 | if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY; |
| 701 | if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME; |
| 702 | if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE; |
| 703 | if( find_option("p",0,0)!=0 ) brFlags |= BRL_PRIVATE; |
| 704 | if( find_option("merged","m",0)!=0 ) brFlags |= BRL_MERGED; |
| 705 | if( find_option("unmerged","M",0)!=0 ) brFlags |= BRL_UNMERGED; |
| 706 | |
| 707 | if ( (brFlags & BRL_MERGED) && (brFlags & BRL_UNMERGED) ){ |
| 708 | fossil_fatal("flags --merged and --unmerged are mutually exclusive"); |
| 709 | } |
| 710 | if( strcmp(zCmd, "lsh")==0 ){ |
| 711 | nLimit = 5; |
| 712 | if( g.argc>4 || (g.argc==4 && (nLimit = atoi(g.argv[3]))==0) ){ |
| 713 | fossil_fatal("the lsh subcommand allows one optional numeric argument"); |
| 714 | } |
| @@ -714,11 +724,19 @@ | |
| 724 | } |
| 725 | branch_prepare_list_query(&q, brFlags, zBrNameGlob, nLimit); |
| 726 | while( db_step(&q)==SQLITE_ROW ){ |
| 727 | const char *zBr = db_column_text(&q, 0); |
| 728 | int isPriv = zCurrent!=0 && db_column_int(&q, 1)==1; |
| 729 | const char *zMergeTo = db_column_text(&q, 2); |
| 730 | int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; |
| 731 | if( (brFlags & BRL_MERGED) && fossil_strcmp(zCurrent,zMergeTo)!=0 ){ |
| 732 | continue; |
| 733 | } |
| 734 | if( (brFlags & BRL_UNMERGED) && (fossil_strcmp(zCurrent,zMergeTo)==0 |
| 735 | || isCur) ){ |
| 736 | continue; |
| 737 | } |
| 738 | fossil_print("%s%s%s\n", |
| 739 | ( (brFlags & BRL_PRIVATE) ? " " : ( isPriv ? "#" : " ") ), |
| 740 | (isCur ? "* " : " "), zBr); |
| 741 | } |
| 742 | db_finalize(&q); |
| 743 |