Fossil

Check-in [3b0a1f4e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3b0a1f4e1e4e9a4eaa41ae132e2ef66ebae9489a1676f7a22aacc727608574ed
User & Date: drh 2018-09-18 15:50:30
Context
2018-09-18
15:53
Add the "fossil branch current" command to the 2.7 change log. check-in: fc977f14 user: drh tags: trunk
15:50
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. check-in: 3b0a1f4e user: drh tags: trunk
2018-09-17
09:47
Wiki markup fixes in the recent edits to the www/forum.wiki doc check-in: 07943152 user: wyoung tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/branch.c.

   266    266   ** COMMAND: branch
   267    267   **
   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)
   278    292   **        --bgcolor COLOR       use COLOR instead of automatic background
   279    293   **        --nosign              do not sign contents on this branch
................................................................................
   282    296   **
   283    297   **        DATE may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
   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;
   315    348       if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH;
   316    349       if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY;
................................................................................
   323    356       branch_prepare_list_query(&q, brFlags);
   324    357       while( db_step(&q)==SQLITE_ROW ){
   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   @   tagxref.value,
   354    374   @   max(event.mtime),