Fossil SCM

branch close: minor doc and style cleanups. Delay output of control artifact in dry-run mode until after Z-card is calculated. Only show new dry-run artifact in --verbose mode.

stephan 2021-07-22 06:25 branch-close-subcommand
Commit 25197505b1f0fbef05840023b149169cc42ae39fd04cb7212d693873e685e99f
1 file changed +17 -19
+17 -19
--- src/branch.c
+++ src/branch.c
@@ -349,23 +349,23 @@
349349
/*
350350
** Implementation of (branch close) subcommand. nStartAtArg is the
351351
** g.argv index to start reading branch names. If fDryRun is true then
352352
** the change is run in dry-run mode. Fails fatally on error.
353353
*/
354
-static void branch_cmd_close(int nStartAtArg, int fVerbose, int fDryRun){
355
- int argPos = nStartAtArg;
354
+static void branch_cmd_close(int nStartAtArg, int fVerbose,
355
+ int fDryRun){
356
+ int argPos = nStartAtArg; /* g.argv pos with first branch name */
356357
Blob manifest = empty_blob; /* Control artifact */
357358
Stmt q = empty_Stmt;
358359
int nQueued = 0; /* # of branches queued for closing */
359
- char * zUuid = 0;
360
- int doRollback = fDryRun!=0;
360
+ char * zUuid = 0; /* Resolved branch UUID. */
361
+ int doRollback = fDryRun!=0; /* Roll back transaction if true */
361362
db_begin_transaction();
362
- db_multi_exec("create temp table brclose("
363
+ db_multi_exec("CREATE TEMP TABLE brclose("
363364
"rid INTEGER UNIQUE ON CONFLICT IGNORE"
364365
")");
365
- db_prepare(&q, "INSERT INTO brclose(rid) "
366
- "VALUES(:rid)");
366
+ db_prepare(&q, "INSERT INTO brclose(rid) VALUES(:rid)");
367367
for( ; argPos < g.argc; fossil_free(zUuid), ++argPos ){
368368
const char * zBranch = g.argv[argPos];
369369
const int rid = name_to_uuid2(zBranch, "ci", &zUuid);
370370
if(0==rid){
371371
fossil_fatal("Cannot resolve branch name: %s", zBranch);
@@ -391,33 +391,31 @@
391391
fossil_warning("No branches queued for closing. Nothing to do.");
392392
doRollback = 1;
393393
goto br_close_end;
394394
}
395395
blob_appendf(&manifest, "D %z\n", date_in_standard_format("now"));
396
- db_prepare(&q, "SELECT b.uuid "
397
- "FROM brclose c, blob b "
398
- "WHERE c.rid=b.rid "
399
- "ORDER BY b.uuid");
396
+ db_prepare(&q, "SELECT uuid FROM blob WHERE rid IN brclose");
400397
while(SQLITE_ROW==db_step(&q)){
401398
const char * zHash = db_column_text(&q, 0);
402399
blob_appendf(&manifest, "T +closed %s\n", zHash);
403400
}
401
+ db_finalize(&q);
404402
user_select();
405403
blob_appendf(&manifest, "U %F\n", login_name());
406
- db_finalize(&q);
407
- if(fDryRun){
408
- fossil_print("Dry-run mode: will roll back new artifact:\n%b",
409
- &manifest);
410
- /* Run through the saving steps, though, noting that doing so
411
- ** will clear out &manifest. */
412
- }
413
- {
404
+ { /* Z-card and save artifact */
414405
int newRid;
415406
Blob cksum = empty_blob;
416407
md5sum_blob(&manifest, &cksum);
417408
blob_appendf(&manifest, "Z %b\n", &cksum);
418409
blob_reset(&cksum);
410
+ if(fDryRun && fVerbose){
411
+ fossil_print("Dry-run mode: will roll back new artifact:\n%b",
412
+ &manifest);
413
+ /* Run through the saving steps, though, noting that doing so
414
+ ** will clear out &manifest, which is why we output it here
415
+ ** instead of after saving. */
416
+ }
419417
newRid = content_put(&manifest);
420418
if(0==newRid){
421419
fossil_fatal("Problem saving new artifact: %s\n%b",
422420
g.zErrMsg, &manifest);
423421
}else if(manifest_crosslink(newRid, &manifest, 0)==0){
424422
--- src/branch.c
+++ src/branch.c
@@ -349,23 +349,23 @@
349 /*
350 ** Implementation of (branch close) subcommand. nStartAtArg is the
351 ** g.argv index to start reading branch names. If fDryRun is true then
352 ** the change is run in dry-run mode. Fails fatally on error.
353 */
354 static void branch_cmd_close(int nStartAtArg, int fVerbose, int fDryRun){
355 int argPos = nStartAtArg;
 
356 Blob manifest = empty_blob; /* Control artifact */
357 Stmt q = empty_Stmt;
358 int nQueued = 0; /* # of branches queued for closing */
359 char * zUuid = 0;
360 int doRollback = fDryRun!=0;
361 db_begin_transaction();
362 db_multi_exec("create temp table brclose("
363 "rid INTEGER UNIQUE ON CONFLICT IGNORE"
364 ")");
365 db_prepare(&q, "INSERT INTO brclose(rid) "
366 "VALUES(:rid)");
367 for( ; argPos < g.argc; fossil_free(zUuid), ++argPos ){
368 const char * zBranch = g.argv[argPos];
369 const int rid = name_to_uuid2(zBranch, "ci", &zUuid);
370 if(0==rid){
371 fossil_fatal("Cannot resolve branch name: %s", zBranch);
@@ -391,33 +391,31 @@
391 fossil_warning("No branches queued for closing. Nothing to do.");
392 doRollback = 1;
393 goto br_close_end;
394 }
395 blob_appendf(&manifest, "D %z\n", date_in_standard_format("now"));
396 db_prepare(&q, "SELECT b.uuid "
397 "FROM brclose c, blob b "
398 "WHERE c.rid=b.rid "
399 "ORDER BY b.uuid");
400 while(SQLITE_ROW==db_step(&q)){
401 const char * zHash = db_column_text(&q, 0);
402 blob_appendf(&manifest, "T +closed %s\n", zHash);
403 }
 
404 user_select();
405 blob_appendf(&manifest, "U %F\n", login_name());
406 db_finalize(&q);
407 if(fDryRun){
408 fossil_print("Dry-run mode: will roll back new artifact:\n%b",
409 &manifest);
410 /* Run through the saving steps, though, noting that doing so
411 ** will clear out &manifest. */
412 }
413 {
414 int newRid;
415 Blob cksum = empty_blob;
416 md5sum_blob(&manifest, &cksum);
417 blob_appendf(&manifest, "Z %b\n", &cksum);
418 blob_reset(&cksum);
 
 
 
 
 
 
 
419 newRid = content_put(&manifest);
420 if(0==newRid){
421 fossil_fatal("Problem saving new artifact: %s\n%b",
422 g.zErrMsg, &manifest);
423 }else if(manifest_crosslink(newRid, &manifest, 0)==0){
424
--- src/branch.c
+++ src/branch.c
@@ -349,23 +349,23 @@
349 /*
350 ** Implementation of (branch close) subcommand. nStartAtArg is the
351 ** g.argv index to start reading branch names. If fDryRun is true then
352 ** the change is run in dry-run mode. Fails fatally on error.
353 */
354 static void branch_cmd_close(int nStartAtArg, int fVerbose,
355 int fDryRun){
356 int argPos = nStartAtArg; /* g.argv pos with first branch name */
357 Blob manifest = empty_blob; /* Control artifact */
358 Stmt q = empty_Stmt;
359 int nQueued = 0; /* # of branches queued for closing */
360 char * zUuid = 0; /* Resolved branch UUID. */
361 int doRollback = fDryRun!=0; /* Roll back transaction if true */
362 db_begin_transaction();
363 db_multi_exec("CREATE TEMP TABLE brclose("
364 "rid INTEGER UNIQUE ON CONFLICT IGNORE"
365 ")");
366 db_prepare(&q, "INSERT INTO brclose(rid) VALUES(:rid)");
 
367 for( ; argPos < g.argc; fossil_free(zUuid), ++argPos ){
368 const char * zBranch = g.argv[argPos];
369 const int rid = name_to_uuid2(zBranch, "ci", &zUuid);
370 if(0==rid){
371 fossil_fatal("Cannot resolve branch name: %s", zBranch);
@@ -391,33 +391,31 @@
391 fossil_warning("No branches queued for closing. Nothing to do.");
392 doRollback = 1;
393 goto br_close_end;
394 }
395 blob_appendf(&manifest, "D %z\n", date_in_standard_format("now"));
396 db_prepare(&q, "SELECT uuid FROM blob WHERE rid IN brclose");
 
 
 
397 while(SQLITE_ROW==db_step(&q)){
398 const char * zHash = db_column_text(&q, 0);
399 blob_appendf(&manifest, "T +closed %s\n", zHash);
400 }
401 db_finalize(&q);
402 user_select();
403 blob_appendf(&manifest, "U %F\n", login_name());
404 { /* Z-card and save artifact */
 
 
 
 
 
 
 
405 int newRid;
406 Blob cksum = empty_blob;
407 md5sum_blob(&manifest, &cksum);
408 blob_appendf(&manifest, "Z %b\n", &cksum);
409 blob_reset(&cksum);
410 if(fDryRun && fVerbose){
411 fossil_print("Dry-run mode: will roll back new artifact:\n%b",
412 &manifest);
413 /* Run through the saving steps, though, noting that doing so
414 ** will clear out &manifest, which is why we output it here
415 ** instead of after saving. */
416 }
417 newRid = content_put(&manifest);
418 if(0==newRid){
419 fossil_fatal("Problem saving new artifact: %s\n%b",
420 g.zErrMsg, &manifest);
421 }else if(manifest_crosslink(newRid, &manifest, 0)==0){
422

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button