Fossil

Check-in [0bdb19f3d3]
Login

Check-in [0bdb19f3d3]

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

Overview
Comment:Initial impl of (branch close) subcommand.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | branch-close-subcommand
Files: files | file ages | folders
SHA3-256: 0bdb19f3d333268866bab9a30e221b6489df70fedc5d38be909bdd56c9a61660
User & Date: stephan 2021-07-22 05:59:06.612
Context
2021-07-22
06:16
branch close: dry-run mode no longer skips the saving steps. ... (check-in: a6a1a3cf0c user: stephan tags: branch-close-subcommand)
05:59
Initial impl of (branch close) subcommand. ... (check-in: 0bdb19f3d3 user: stephan tags: branch-close-subcommand)
2021-07-21
18:48
Cleanup for the "fossil help" command implementation. ... (check-in: 8a231a7990 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/branch.c.
342
343
344
345
346
347
348


















































































349
350
351
352
353
354
355
                      " WHERE tagid=%d"
                      "   AND tagtype=1"
                      "   AND ox.rid=ix.rid)",
    TAG_BRANCH, zBrName, TAG_CLOSED
  );
}




















































































/*
** COMMAND: branch
**
** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
**
** Run various subcommands to manage branches of the open repository or







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
                      " WHERE tagid=%d"
                      "   AND tagtype=1"
                      "   AND ox.rid=ix.rid)",
    TAG_BRANCH, zBrName, TAG_CLOSED
  );
}

/*
** Implementation of (branch close) subcommand. nStartAtArg is the
** g.argv index to start reading branch names. If fDryRun is true then
** the change is run in dry-run mode. Fails fatally on error.
*/
static void branch_cmd_close(int nStartAtArg, int fVerbose, int fDryRun){
  int argPos = nStartAtArg; 
  Blob manifest = empty_blob;  /* Control artifact */
  Stmt q = empty_Stmt;
  int nQueued = 0;             /* # of branches queued for closing */
  char * zUuid = 0;
  int doRollback = fDryRun!=0;
  db_begin_transaction();
  db_multi_exec("create temp table brclose("
                "rid INTEGER UNIQUE ON CONFLICT IGNORE"
                ")");
  db_prepare(&q, "INSERT INTO brclose(rid) "
             "VALUES(:rid)");
  for( ; argPos < g.argc; fossil_free(zUuid), ++argPos ){
    const char * zBranch = g.argv[argPos];
    const int rid = name_to_uuid2(zBranch, "ci", &zUuid);
    if(0==rid){
      fossil_fatal("Cannot resolve branch name: %s", zBranch);
    }else if(rid<0){
      fossil_fatal("Ambiguous branch name: %s", zBranch);
    }else if(!is_a_leaf(rid)){
      fossil_warning("Skipping non-leaf [%s] %s", zBranch, zUuid);
      continue;
    }else if(leaf_is_closed(rid)){
      fossil_warning("Skipping closed [%s] %s", zBranch, zUuid);
      continue;
    }
    ++nQueued;
    db_bind_int(&q, ":rid", rid);
    db_step(&q);
    db_reset(&q);
    if(fVerbose!=0){
      fossil_print("Closing branch [%s] %s\n", zBranch, zUuid);
    }
  }
  db_finalize(&q);
  if(!nQueued){
    fossil_warning("No branches queued for closing. Nothing to do.");
    doRollback = 1;
    goto br_close_end;
  }
  blob_appendf(&manifest, "D %z\n", date_in_standard_format("now"));
  db_prepare(&q, "SELECT b.uuid "
             "FROM brclose c, blob b "
             "WHERE c.rid=b.rid "
             "ORDER BY b.uuid");
  while(SQLITE_ROW==db_step(&q)){
    const char * zHash = db_column_text(&q, 0);
    blob_appendf(&manifest, "T +closed %s\n", zHash);
  }
  user_select();
  blob_appendf(&manifest, "U %F\n", login_name());
  db_finalize(&q);
  {
    Blob cksum = empty_blob;
    md5sum_blob(&manifest, &cksum);
    blob_appendf(&manifest, "Z %b\n", &cksum);
    blob_reset(&cksum);
  }
  if(fDryRun){
    fossil_print("Dry-run mode. Not saving control artifact:\n%b",
                 &manifest);
  }else{
    const int newRid = content_put(&manifest);
    if(0==newRid){
      fossil_fatal("Problem saving new manifest: %s\n%b",
                   g.zErrMsg, &manifest);
    }else if(manifest_crosslink(newRid, &manifest, 0)==0){
      fossil_fatal("Crosslinking error: %s", g.zErrMsg);
    }
    fossil_print("Saved new control artifact (RID %d)\n", newRid);
  }
  blob_reset(&manifest);
  br_close_end:
  db_multi_exec("DROP TABLE brclose");
  db_end_transaction(doRollback);
}

/*
** COMMAND: branch
**
** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
**
** Run various subcommands to manage branches of the open repository or
388
389
390
391
392
393
394










395
396
397
398
399
400
401
**        --user-override USER  USER to use instead of the current default
**
**        DATE may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
**        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.










**
** Options valid for all subcommands:
**
**    -R|--repository REPO       Run commands on repository REPO
*/
void branch_cmd(void){
  int n;







>
>
>
>
>
>
>
>
>
>







470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
**        --user-override USER  USER to use instead of the current default
**
**        DATE may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
**        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 close ?OPTIONS? BRANCH-NAME ?...BRANCH-NAMES?
**
**       Close one or more branches by adding the "closed" tag
**       to them. It accepts arbitrary unambiguous symbolic names but
**       will only resolve checkin names and skips any which resolve
**       to non-leaf or closed checkins. Options:
**       -n|--dry-run          do not commit changes and dump artifact
**                             to stdout
**       -v|--verbose          output more information
**
** Options valid for all subcommands:
**
**    -R|--repository REPO       Run commands on repository REPO
*/
void branch_cmd(void){
  int n;
450
451
452
453
454
455
456








457
458
459
460
461
462
463
464
465
466
      const char *zBr = db_column_text(&q, 0);
      int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
      fossil_print("%s%s\n", (isCur ? "* " : "  "), zBr);
    }
    db_finalize(&q);
  }else if( strncmp(zCmd,"new",n)==0 ){
    branch_new();








  }else{
    fossil_fatal("branch subcommand should be one of: "
                 "current info list ls new");
  }
}

/*
** 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.







>
>
>
>
>
>
>
>


|







542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
      const char *zBr = db_column_text(&q, 0);
      int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
      fossil_print("%s%s\n", (isCur ? "* " : "  "), zBr);
    }
    db_finalize(&q);
  }else if( strncmp(zCmd,"new",n)==0 ){
    branch_new();
  }else if( strncmp(zCmd,"close",5)==0 ){
    const int fDryRun = find_option("dry-run","n",0)!=0;
    const int fVerbose = find_option("verbose","v",0)!=0;
    verify_all_options();
    if(g.argc<4){
      usage("branch close branch-name(s)...");
    }
    branch_cmd_close(3, fVerbose, fDryRun);
  }else{
    fossil_fatal("branch subcommand should be one of: "
                 "close current info list ls new");
  }
}

/*
** 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.