Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Refactor the `-h' option to its own `lsh' subcommand sibling to `list|ls' to reuse their infrastructure and flags. To produce useful output with the `-r' option, the SQL query to generate the branch list is LIMIT'ed in an inner query, and then ORDER'ed again in an outer query. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | ls-hot-branches |
| Files: | files | file ages | folders |
| SHA3-256: |
dbd6efe2d89be79bade5e1eb358b5efa |
| User & Date: | florian 2022-08-02 10:27:00.000 |
Context
|
2022-08-10
| ||
| 05:56 | Fix a compiler warning. ... (Closed-Leaf check-in: 877b237ba2 user: florian tags: ls-hot-branches) | |
|
2022-08-02
| ||
| 10:27 | Refactor the `-h' option to its own `lsh' subcommand sibling to `list|ls' to reuse their infrastructure and flags. To produce useful output with the `-r' option, the SQL query to generate the branch list is LIMIT'ed in an inner query, and then ORDER'ed again in an outer query. ... (check-in: dbd6efe2d8 user: florian tags: ls-hot-branches) | |
|
2022-07-31
| ||
| 10:47 | Add a new `-h' option to `fossil branch ls' to list the "hot" (first few recently modified) branches. ... (check-in: fe299ee400 user: florian tags: ls-hot-branches) | |
Changes
Changes to src/branch.c.
| ︙ | ︙ | |||
278 279 280 281 282 283 284 | #define BRL_CLOSED_ONLY 0x001 /* Show only closed branches */ #define BRL_OPEN_ONLY 0x002 /* Show only open branches */ #define BRL_BOTH 0x003 /* Show both open and closed branches */ #define BRL_OPEN_CLOSED_MASK 0x003 #define BRL_ORDERBY_MTIME 0x004 /* Sort by MTIME. (otherwise sort by name)*/ #define BRL_REVERSE 0x008 /* Reverse the sort order */ #define BRL_PRIVATE 0x010 /* Show only private branches */ | < > > > > > > > > > | > > > > > > | | | | | | > > > > | 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
#define BRL_CLOSED_ONLY 0x001 /* Show only closed branches */
#define BRL_OPEN_ONLY 0x002 /* Show only open branches */
#define BRL_BOTH 0x003 /* Show both open and closed branches */
#define BRL_OPEN_CLOSED_MASK 0x003
#define BRL_ORDERBY_MTIME 0x004 /* Sort by MTIME. (otherwise sort by name)*/
#define BRL_REVERSE 0x008 /* Reverse the sort order */
#define BRL_PRIVATE 0x010 /* Show only private branches */
#endif /* INTERFACE */
/*
** 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.
**
** If the BRL_ORDERBY_MTIME flag is set and nLimitMRU ("Limit Most Recently Used
** style") is a non-zero number, the result is limited to nLimitMRU entries, and
** the BRL_REVERSE flag is applied in an outer query after processing the limit,
** so that it's possible to generate short lists with the most recently modified
** branches sorted chronologically in either direction, as does the "branch lsh"
** command.
** For other cases, the outer query is also generated, but works as a no-op. The
** code to build the outer query is marked with *//* OUTER QUERY *//* comments.
*/
void branch_prepare_list_query(
Stmt *pQuery,
int brFlags,
const char *zBrNameGlob,
int nLimitMRU
){
Blob sql;
blob_init(&sql, 0, 0);
brlist_create_temp_table();
/* Ignore nLimitMRU if no chronological sort requested. */
if( (brFlags & BRL_ORDERBY_MTIME)==0 ) nLimitMRU = 0;
/* Undocumented: invert negative values for nLimitMRU, so that command-line
** arguments similar to `head -5' with "option numbers" are possible. */
if( nLimitMRU<0 ) nLimitMRU = -nLimitMRU;
blob_append_sql(&sql,"SELECT name, isprivate FROM ("); /* OUTER QUERY */
switch( brFlags & BRL_OPEN_CLOSED_MASK ){
case BRL_CLOSED_ONLY: {
blob_append_sql(&sql,
"SELECT name, isprivate, mtime FROM tmp_brlist WHERE isclosed"
);
break;
}
case BRL_BOTH: {
blob_append_sql(&sql,
"SELECT name, isprivate, mtime FROM tmp_brlist WHERE 1"
);
break;
}
case BRL_OPEN_ONLY: {
blob_append_sql(&sql,
"SELECT name, isprivate, mtime FROM tmp_brlist WHERE NOT isclosed"
);
break;
}
}
if( brFlags & BRL_PRIVATE ) blob_append_sql(&sql, " AND isprivate");
if(zBrNameGlob) blob_append_sql(&sql, " AND (name GLOB %Q)", zBrNameGlob);
if( brFlags & BRL_ORDERBY_MTIME ){
blob_append_sql(&sql, " ORDER BY -mtime");
}else{
blob_append_sql(&sql, " ORDER BY name COLLATE nocase");
}
if( brFlags & BRL_REVERSE && !nLimitMRU ){
blob_append_sql(&sql," DESC");
}
if( nLimitMRU ){
blob_append_sql(&sql," LIMIT %d",nLimitMRU);
}
blob_append_sql(&sql,")"); /* OUTER QUERY */
if( brFlags & BRL_REVERSE && nLimitMRU ){
blob_append_sql(&sql," ORDER BY mtime"); /* OUTER QUERY */
}
db_prepare_blob(pQuery, &sql);
blob_reset(&sql);
}
/*
** If the branch named in the argument is open, return a RID for one of
|
| ︙ | ︙ | |||
592 593 594 595 596 597 598 599 600 601 602 603 604 605 | ** subcommand. ** ** > fossil branch info BRANCH-NAME ** ** Print information about a branch ** ** > fossil branch list|ls ?OPTIONS? ?GLOB? ** ** List all branches. Options: ** -a|--all List all branches. Default show only open branches ** -c|--closed List closed branches. ** -p List only private branches. ** -r Reverse the sort order ** -t Show recently changed branches first | > < | > > > | | | 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | ** subcommand. ** ** > fossil branch info BRANCH-NAME ** ** Print information about a branch ** ** > fossil branch list|ls ?OPTIONS? ?GLOB? ** > fossil branch lsh ?OPTIONS? ?LIMIT? ** ** List all branches. Options: ** -a|--all List all branches. Default show only open branches ** -c|--closed List closed branches. ** -p List only private branches. ** -r Reverse the sort order ** -t Show recently changed branches first ** ** The current branch is marked with an asterisk. Private branches are ** marked with a hash sign. ** ** If GLOB is given, show only branches matching the pattern. ** ** The "lsh" variant of this subcommand shows recently changed branches, ** and accepts an optional LIMIT argument (defaults to 5) to cap output, ** but no GLOB argument. All other options are supported, with -t being ** an implied no-op. ** ** > fossil branch new BRANCH-NAME BASIS ?OPTIONS? ** ** Create a new branch BRANCH-NAME off of check-in BASIS. ** Supported options for this subcommand include: ** --private branch is private (i.e., remains local) ** --bgcolor COLOR use COLOR instead of automatic background |
| ︙ | ︙ | |||
661 662 663 664 665 666 667 |
const char *zUuid = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid);
const char *zDate = db_text(0,
"SELECT datetime(mtime,toLocal()) FROM event"
" WHERE objid=%d", rid);
fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid);
}
}
| > | > | | | | < | > > | 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 |
const char *zUuid = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid);
const char *zDate = db_text(0,
"SELECT datetime(mtime,toLocal()) FROM event"
" WHERE objid=%d", rid);
fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid);
}
}
}else if( strncmp(zCmd,"list",n)==0 ||
strncmp(zCmd, "ls", n)==0 ||
strcmp(zCmd, "lsh")==0 ){
Stmt q;
int vid;
char *zCurrent = 0;
const char *zBrNameGlob = 0;
int nLimit = 0;
int brFlags = BRL_OPEN_ONLY;
if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH;
if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY;
if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME;
if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE;
if( find_option("p",0,0)!=0 ) brFlags |= BRL_PRIVATE;
if( strcmp(zCmd, "lsh")==0 ){
nLimit = 5;
if( g.argc>4 || g.argc==4 && (nLimit = atoi(g.argv[3]))==0 ){
fossil_fatal("the lsh subcommand allows one optional numeric argument");
}
brFlags |= BRL_ORDERBY_MTIME;
}else{
if( g.argc >= 4 ) zBrNameGlob = g.argv[3];
}
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);
}
|
| ︙ | ︙ | |||
722 723 724 725 726 727 728 |
}else if( strncmp(zCmd,"unhide",6)==0 ){
if(g.argc<4){
usage("branch unhide branch-name(s)...");
}
branch_cmd_hide(3,0);
}else{
fossil_fatal("branch subcommand should be one of: "
| | | 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 |
}else if( strncmp(zCmd,"unhide",6)==0 ){
if(g.argc<4){
usage("branch unhide branch-name(s)...");
}
branch_cmd_hide(3,0);
}else{
fossil_fatal("branch subcommand should be one of: "
"close current hide info list ls lsh new reopen unhide");
}
}
/*
** This is the new-style branch-list page that shows the branch names
** together with their ages (time of last check-in) and whether or not
** they are closed or merged to another branch.
|
| ︙ | ︙ |