Hello everybody, Amount of branches may be quite important (in Fossil code itself, there are now about 100 branches). In this case, executing "fossil branch" to get the current branch is not very convenient to me.
please find an attached patch which implements a new "current" subcommand for "branch". This is now the default subcommand if one executes "fossil branch" without any subcommand. All other subcommands (info, list|ls, info) are left unmodified.
Index: src/branch.c ================================================================== --- src/branch.c +++ src/branch.c @@ -186,13 +186,14 @@ ** Allows bits in the mBplqFlags parameter to branch_prepare_list_query(). */ #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_MTIME 0x004 /* Include lastest check-in time */ -#define BRL_ORDERBY_MTIME 0x008 /* Sort by MTIME. (otherwise sort by name)*/ +#define BRL_CURRENT_ONLY 0x004 /* Show only current branch */ +#define BRL_MASK 0x007 +#define BRL_MTIME 0x008 /* Include lastest check-in time */ +#define BRL_ORDERBY_MTIME 0x009 /* Sort by MTIME. (otherwise sort by name)*/ #endif /* INTERFACE */ /* ** Prepare a query that will list branches. @@ -200,11 +201,11 @@ ** 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. */ void branch_prepare_list_query(Stmt *pQuery, int brFlags){ - switch( brFlags & BRL_OPEN_CLOSED_MASK ){ + switch( brFlags & BRL_MASK ){ case BRL_CLOSED_ONLY: { db_prepare(pQuery, "SELECT value FROM tagxref" " WHERE tagid=%d AND value NOT NULL " "EXCEPT " @@ -235,10 +236,20 @@ " AND NOT %z" " ORDER BY value COLLATE nocase /*sort*/", TAG_BRANCH, leaf_is_closed_sql("tagxref.rid") ); break; + } + case BRL_CURRENT_ONLY: { + db_prepare(pQuery, + "SELECT DISTINCT value FROM tagxref" + " WHERE tagid=%d AND rid=%d" + " AND rid IN leaf" + " ORDER BY value COLLATE nocase /*sort*/", + TAG_BRANCH, db_lget_int("checkout", 0) + ); + break; } } } /* @@ -284,10 +295,14 @@ ** year-month-day form, it may be truncated, the "T" may be ** replaced by a space, and it may also name a timezone offset ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward). ** Either no timezone suffix or "Z" means UTC. ** +** fossil branch current +** +** Display current branch. +** ** fossil branch list|ls ?-a|--all|-c|--closed? ** ** List all branches. Use -a or --all to list all branches and ** -c or --closed to list all closed branches. The default is to ** show only open branches. @@ -299,23 +314,31 @@ ** Options: ** -R|--repository FILE Run commands on repository FILE */ void branch_cmd(void){ int n; - const char *zCmd = "list"; + const char *zCmd = "current"; db_find_and_open_repository(0, 0); if( g.argc>=3 ) zCmd = g.argv[2]; n = strlen(zCmd); if( strncmp(zCmd,"new",n)==0 ){ branch_new(); - }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){ + }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0)|| + (strncmp(zCmd,"current", n)==0) ){ Stmt q; int vid; char *zCurrent = 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( strncmp(zCmd,"current", n)==0 ){ + brFlags = BRL_CURRENT_ONLY; + if( !g.localOpen ){ + fossil_fatal("must be within a local checkout to use 'current'"); + } + }else{ + if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH; + if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY; + } 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); @@ -342,11 +365,11 @@ fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid); } } }else{ fossil_fatal("branch subcommand should be one of: " - "info list ls new"); + "current info list ls new"); } } static const char brlistQuery[] = @ SELECT
_______________________________________________ fossil-users mailing list fossil-users@lists.fossil-scm.org http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users