Fossil SCM

Add the --dryrun option to "reparent" and "tag add" and "tag cancel". Fix a typo in the command-line help for "reparent".

drh 2016-06-10 14:40 UTC reparent
Commit 9cf12e655fdb03f3d583097182817c22adacd1cd
1 file changed +51 -17
+51 -17
--- src/tag.c
+++ src/tag.c
@@ -279,13 +279,26 @@
279279
db_begin_transaction();
280280
tag_insert(zTag, tagtype, zValue, -1, 0.0, rid);
281281
db_end_transaction(0);
282282
}
283283
284
+/*
285
+** OR this value into the tagtype argument to tag_add_artifact to
286
+** cause the tag to be displayed on standard output rather than be
287
+** inserted. Used for --dryrun options and debugging.
288
+*/
289
+#if INTERFACE
290
+#define TAG_ADD_DRYRUN 0x04
291
+#endif
292
+
284293
/*
285294
** Add a control record to the repository that either creates
286295
** or cancels a tag.
296
+**
297
+** tagtype should normally be 0, 1, or 2. But if the TAG_ADD_DRYRUN bit
298
+** is also set, then simply print the text of the tag on standard output
299
+** (for testing purposes) rather than create the tag.
287300
*/
288301
void tag_add_artifact(
289302
const char *zPrefix, /* Prefix to prepend to tag name */
290303
const char *zTagname, /* The tag to add or cancel */
291304
const char *zObjName, /* Name of object attached to */
@@ -299,11 +312,16 @@
299312
char *zDate;
300313
Blob uuid;
301314
Blob ctrl;
302315
Blob cksum;
303316
static const char zTagtype[] = { '-', '+', '*' };
317
+ int dryRun = 0;
304318
319
+ if( tagtype & TAG_ADD_DRYRUN ){
320
+ tagtype &= ~TAG_ADD_DRYRUN;
321
+ dryRun = 1;
322
+ }
305323
assert( tagtype>=0 && tagtype<=2 );
306324
user_select();
307325
blob_zero(&uuid);
308326
blob_append(&uuid, zObjName, -1);
309327
if( name_to_uuid(&uuid, 9, "*") ){
@@ -333,12 +351,17 @@
333351
blob_appendf(&ctrl, "\n");
334352
}
335353
blob_appendf(&ctrl, "U %F\n", zUserOvrd ? zUserOvrd : login_name());
336354
md5sum_blob(&ctrl, &cksum);
337355
blob_appendf(&ctrl, "Z %b\n", &cksum);
338
- nrid = content_put(&ctrl);
339
- manifest_crosslink(nrid, &ctrl, MC_PERMIT_HOOKS);
356
+ if( dryRun ){
357
+ fossil_print("%s", blob_str(&ctrl));
358
+ blob_reset(&ctrl);
359
+ }else{
360
+ nrid = content_put(&ctrl);
361
+ manifest_crosslink(nrid, &ctrl, MC_PERMIT_HOOKS);
362
+ }
340363
assert( blob_is_reset(&ctrl) );
341364
}
342365
343366
/*
344367
** COMMAND: tag
@@ -353,23 +376,26 @@
353376
** be usable instead of a CHECK-IN in commands such as
354377
** update and merge. If the --propagate flag is present,
355378
** the tag value propagates to all descendants of CHECK-IN
356379
**
357380
** Options:
358
-** --raw Raw tag name.
359
-** --propagate Propagating tag.
360
-** --date-override DATETIME Set date and time added.
361
-** --user-override USER Name USER when adding the tag.
381
+** --raw Raw tag name.
382
+** --propagate Propagating tag.
383
+** --date-override DATETIME Set date and time added.
384
+** --user-override USER Name USER when adding the tag.
385
+** --dryrun|-n Display the tag text, but to not
386
+** actually insert it into the database.
362387
**
363388
** The --date-override and --user-override options support
364389
** importing history from other SCM systems. DATETIME has
365390
** the form 'YYYY-MMM-DD HH:MM:SS'.
366391
**
367392
** %fossil tag cancel ?--raw? TAGNAME CHECK-IN
368393
**
369394
** Remove the tag TAGNAME from CHECK-IN, and also remove
370
-** the propagation of the tag to any descendants.
395
+** the propagation of the tag to any descendants. Use the
396
+** the --dryrun or -n options to see what would have happened.
371397
**
372398
** %fossil tag find ?OPTIONS? TAGNAME
373399
**
374400
** List all objects that use TAGNAME. TYPE can be "ci" for
375401
** check-ins or "e" for events. The limit option limits the number
@@ -422,33 +448,37 @@
422448
goto tag_cmd_usage;
423449
}
424450
425451
if( strncmp(g.argv[2],"add",n)==0 ){
426452
char *zValue;
453
+ int dryRun = 0;
427454
const char *zDateOvrd = find_option("date-override",0,1);
428455
const char *zUserOvrd = find_option("user-override",0,1);
456
+ if( find_option("dryrun","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN;
429457
if( g.argc!=5 && g.argc!=6 ){
430
- usage("add ?--raw? ?--propagate? TAGNAME CHECK-IN ?VALUE?");
458
+ usage("add ?options? TAGNAME CHECK-IN ?VALUE?");
431459
}
432460
zValue = g.argc==6 ? g.argv[5] : 0;
433461
db_begin_transaction();
434462
tag_add_artifact(zPrefix, g.argv[3], g.argv[4], zValue,
435
- 1+fPropagate,zDateOvrd,zUserOvrd);
463
+ 1+fPropagate+dryRun,zDateOvrd,zUserOvrd);
436464
db_end_transaction(0);
437465
}else
438466
439467
if( strncmp(g.argv[2],"branch",n)==0 ){
440468
fossil_fatal("the \"fossil tag branch\" command is discontinued\n"
441469
"Use the \"fossil branch new\" command instead.");
442470
}else
443471
444472
if( strncmp(g.argv[2],"cancel",n)==0 ){
473
+ int dryRun = 0;
474
+ if( find_option("dryrun","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN;
445475
if( g.argc!=5 ){
446
- usage("cancel ?--raw? TAGNAME CHECK-IN");
476
+ usage("cancel ?options? TAGNAME CHECK-IN");
447477
}
448478
db_begin_transaction();
449
- tag_add_artifact(zPrefix, g.argv[3], g.argv[4], 0, 0, 0, 0);
479
+ tag_add_artifact(zPrefix, g.argv[3], g.argv[4], 0, dryRun, 0, 0);
450480
db_end_transaction(0);
451481
}else
452482
453483
if( strncmp(g.argv[2],"find",n)==0 ){
454484
Stmt q;
@@ -562,29 +592,33 @@
562592
**
563593
** Create a "parent" tag that causes CHECK-IN to be interpreted as a
564594
** child of PARENT. If multiple PARENTs are listed, then the first is
565595
** the primary parent and others are merge ancestors.
566596
**
567
-** This is an experts-only command. It is used to patch of a repository
597
+** This is an experts-only command. It is used to patch up a repository
568598
** that has been damaged by a shun or that has been pieced together from
569599
** two or more separate repositories. You should never need to reparent
570600
** during normal operations.
571601
**
572602
** Reparenting is accomplished by adding a parent tag. So to undo the
573603
** reparenting operation, simply delete the tag.
574604
**
575
-** --test Make database entries but do not add the tag artifact.
576
-** So the reparent operation will be undone by the next
577
-** "fossil rebuild" command.
605
+** --test Make database entries but do not add the tag artifact.
606
+** So the reparent operation will be undone by the next
607
+** "fossil rebuild" command.
608
+** --dryrun | -n Print the tag that would have been created but do not
609
+** actually change the database in any way.
578610
*/
579611
void reparent_cmd(void){
580612
int bTest = find_option("test","",0)!=0;
581613
int rid;
582614
int i;
583615
Blob value;
584616
char *zUuid;
617
+ int dryRun = 0;
585618
619
+ if( find_option("dryrun","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN;
586620
db_find_and_open_repository(0, 0);
587621
verify_all_options();
588622
if( g.argc<4 ){
589623
usage("reparent [OPTIONS] PARENT ...");
590624
}
@@ -595,15 +629,15 @@
595629
if( i>3 ) blob_append(&value, " ", 1);
596630
zUuid = rid_to_uuid(pid);
597631
blob_append(&value, zUuid, UUID_SIZE);
598632
fossil_free(zUuid);
599633
}
600
- if( bTest ){
634
+ if( bTest && !dryRun ){
601635
tag_insert("parent", 1, blob_str(&value), -1, 0.0, rid);
602636
}else{
603637
zUuid = rid_to_uuid(rid);
604
- tag_add_artifact("","parent",zUuid,blob_str(&value),1,0,0);
638
+ tag_add_artifact("","parent",zUuid,blob_str(&value),1|dryRun,0,0);
605639
}
606640
}
607641
608642
609643
/*
610644
--- src/tag.c
+++ src/tag.c
@@ -279,13 +279,26 @@
279 db_begin_transaction();
280 tag_insert(zTag, tagtype, zValue, -1, 0.0, rid);
281 db_end_transaction(0);
282 }
283
 
 
 
 
 
 
 
 
 
284 /*
285 ** Add a control record to the repository that either creates
286 ** or cancels a tag.
 
 
 
 
287 */
288 void tag_add_artifact(
289 const char *zPrefix, /* Prefix to prepend to tag name */
290 const char *zTagname, /* The tag to add or cancel */
291 const char *zObjName, /* Name of object attached to */
@@ -299,11 +312,16 @@
299 char *zDate;
300 Blob uuid;
301 Blob ctrl;
302 Blob cksum;
303 static const char zTagtype[] = { '-', '+', '*' };
 
304
 
 
 
 
305 assert( tagtype>=0 && tagtype<=2 );
306 user_select();
307 blob_zero(&uuid);
308 blob_append(&uuid, zObjName, -1);
309 if( name_to_uuid(&uuid, 9, "*") ){
@@ -333,12 +351,17 @@
333 blob_appendf(&ctrl, "\n");
334 }
335 blob_appendf(&ctrl, "U %F\n", zUserOvrd ? zUserOvrd : login_name());
336 md5sum_blob(&ctrl, &cksum);
337 blob_appendf(&ctrl, "Z %b\n", &cksum);
338 nrid = content_put(&ctrl);
339 manifest_crosslink(nrid, &ctrl, MC_PERMIT_HOOKS);
 
 
 
 
 
340 assert( blob_is_reset(&ctrl) );
341 }
342
343 /*
344 ** COMMAND: tag
@@ -353,23 +376,26 @@
353 ** be usable instead of a CHECK-IN in commands such as
354 ** update and merge. If the --propagate flag is present,
355 ** the tag value propagates to all descendants of CHECK-IN
356 **
357 ** Options:
358 ** --raw Raw tag name.
359 ** --propagate Propagating tag.
360 ** --date-override DATETIME Set date and time added.
361 ** --user-override USER Name USER when adding the tag.
 
 
362 **
363 ** The --date-override and --user-override options support
364 ** importing history from other SCM systems. DATETIME has
365 ** the form 'YYYY-MMM-DD HH:MM:SS'.
366 **
367 ** %fossil tag cancel ?--raw? TAGNAME CHECK-IN
368 **
369 ** Remove the tag TAGNAME from CHECK-IN, and also remove
370 ** the propagation of the tag to any descendants.
 
371 **
372 ** %fossil tag find ?OPTIONS? TAGNAME
373 **
374 ** List all objects that use TAGNAME. TYPE can be "ci" for
375 ** check-ins or "e" for events. The limit option limits the number
@@ -422,33 +448,37 @@
422 goto tag_cmd_usage;
423 }
424
425 if( strncmp(g.argv[2],"add",n)==0 ){
426 char *zValue;
 
427 const char *zDateOvrd = find_option("date-override",0,1);
428 const char *zUserOvrd = find_option("user-override",0,1);
 
429 if( g.argc!=5 && g.argc!=6 ){
430 usage("add ?--raw? ?--propagate? TAGNAME CHECK-IN ?VALUE?");
431 }
432 zValue = g.argc==6 ? g.argv[5] : 0;
433 db_begin_transaction();
434 tag_add_artifact(zPrefix, g.argv[3], g.argv[4], zValue,
435 1+fPropagate,zDateOvrd,zUserOvrd);
436 db_end_transaction(0);
437 }else
438
439 if( strncmp(g.argv[2],"branch",n)==0 ){
440 fossil_fatal("the \"fossil tag branch\" command is discontinued\n"
441 "Use the \"fossil branch new\" command instead.");
442 }else
443
444 if( strncmp(g.argv[2],"cancel",n)==0 ){
 
 
445 if( g.argc!=5 ){
446 usage("cancel ?--raw? TAGNAME CHECK-IN");
447 }
448 db_begin_transaction();
449 tag_add_artifact(zPrefix, g.argv[3], g.argv[4], 0, 0, 0, 0);
450 db_end_transaction(0);
451 }else
452
453 if( strncmp(g.argv[2],"find",n)==0 ){
454 Stmt q;
@@ -562,29 +592,33 @@
562 **
563 ** Create a "parent" tag that causes CHECK-IN to be interpreted as a
564 ** child of PARENT. If multiple PARENTs are listed, then the first is
565 ** the primary parent and others are merge ancestors.
566 **
567 ** This is an experts-only command. It is used to patch of a repository
568 ** that has been damaged by a shun or that has been pieced together from
569 ** two or more separate repositories. You should never need to reparent
570 ** during normal operations.
571 **
572 ** Reparenting is accomplished by adding a parent tag. So to undo the
573 ** reparenting operation, simply delete the tag.
574 **
575 ** --test Make database entries but do not add the tag artifact.
576 ** So the reparent operation will be undone by the next
577 ** "fossil rebuild" command.
 
 
578 */
579 void reparent_cmd(void){
580 int bTest = find_option("test","",0)!=0;
581 int rid;
582 int i;
583 Blob value;
584 char *zUuid;
 
585
 
586 db_find_and_open_repository(0, 0);
587 verify_all_options();
588 if( g.argc<4 ){
589 usage("reparent [OPTIONS] PARENT ...");
590 }
@@ -595,15 +629,15 @@
595 if( i>3 ) blob_append(&value, " ", 1);
596 zUuid = rid_to_uuid(pid);
597 blob_append(&value, zUuid, UUID_SIZE);
598 fossil_free(zUuid);
599 }
600 if( bTest ){
601 tag_insert("parent", 1, blob_str(&value), -1, 0.0, rid);
602 }else{
603 zUuid = rid_to_uuid(rid);
604 tag_add_artifact("","parent",zUuid,blob_str(&value),1,0,0);
605 }
606 }
607
608
609 /*
610
--- src/tag.c
+++ src/tag.c
@@ -279,13 +279,26 @@
279 db_begin_transaction();
280 tag_insert(zTag, tagtype, zValue, -1, 0.0, rid);
281 db_end_transaction(0);
282 }
283
284 /*
285 ** OR this value into the tagtype argument to tag_add_artifact to
286 ** cause the tag to be displayed on standard output rather than be
287 ** inserted. Used for --dryrun options and debugging.
288 */
289 #if INTERFACE
290 #define TAG_ADD_DRYRUN 0x04
291 #endif
292
293 /*
294 ** Add a control record to the repository that either creates
295 ** or cancels a tag.
296 **
297 ** tagtype should normally be 0, 1, or 2. But if the TAG_ADD_DRYRUN bit
298 ** is also set, then simply print the text of the tag on standard output
299 ** (for testing purposes) rather than create the tag.
300 */
301 void tag_add_artifact(
302 const char *zPrefix, /* Prefix to prepend to tag name */
303 const char *zTagname, /* The tag to add or cancel */
304 const char *zObjName, /* Name of object attached to */
@@ -299,11 +312,16 @@
312 char *zDate;
313 Blob uuid;
314 Blob ctrl;
315 Blob cksum;
316 static const char zTagtype[] = { '-', '+', '*' };
317 int dryRun = 0;
318
319 if( tagtype & TAG_ADD_DRYRUN ){
320 tagtype &= ~TAG_ADD_DRYRUN;
321 dryRun = 1;
322 }
323 assert( tagtype>=0 && tagtype<=2 );
324 user_select();
325 blob_zero(&uuid);
326 blob_append(&uuid, zObjName, -1);
327 if( name_to_uuid(&uuid, 9, "*") ){
@@ -333,12 +351,17 @@
351 blob_appendf(&ctrl, "\n");
352 }
353 blob_appendf(&ctrl, "U %F\n", zUserOvrd ? zUserOvrd : login_name());
354 md5sum_blob(&ctrl, &cksum);
355 blob_appendf(&ctrl, "Z %b\n", &cksum);
356 if( dryRun ){
357 fossil_print("%s", blob_str(&ctrl));
358 blob_reset(&ctrl);
359 }else{
360 nrid = content_put(&ctrl);
361 manifest_crosslink(nrid, &ctrl, MC_PERMIT_HOOKS);
362 }
363 assert( blob_is_reset(&ctrl) );
364 }
365
366 /*
367 ** COMMAND: tag
@@ -353,23 +376,26 @@
376 ** be usable instead of a CHECK-IN in commands such as
377 ** update and merge. If the --propagate flag is present,
378 ** the tag value propagates to all descendants of CHECK-IN
379 **
380 ** Options:
381 ** --raw Raw tag name.
382 ** --propagate Propagating tag.
383 ** --date-override DATETIME Set date and time added.
384 ** --user-override USER Name USER when adding the tag.
385 ** --dryrun|-n Display the tag text, but to not
386 ** actually insert it into the database.
387 **
388 ** The --date-override and --user-override options support
389 ** importing history from other SCM systems. DATETIME has
390 ** the form 'YYYY-MMM-DD HH:MM:SS'.
391 **
392 ** %fossil tag cancel ?--raw? TAGNAME CHECK-IN
393 **
394 ** Remove the tag TAGNAME from CHECK-IN, and also remove
395 ** the propagation of the tag to any descendants. Use the
396 ** the --dryrun or -n options to see what would have happened.
397 **
398 ** %fossil tag find ?OPTIONS? TAGNAME
399 **
400 ** List all objects that use TAGNAME. TYPE can be "ci" for
401 ** check-ins or "e" for events. The limit option limits the number
@@ -422,33 +448,37 @@
448 goto tag_cmd_usage;
449 }
450
451 if( strncmp(g.argv[2],"add",n)==0 ){
452 char *zValue;
453 int dryRun = 0;
454 const char *zDateOvrd = find_option("date-override",0,1);
455 const char *zUserOvrd = find_option("user-override",0,1);
456 if( find_option("dryrun","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN;
457 if( g.argc!=5 && g.argc!=6 ){
458 usage("add ?options? TAGNAME CHECK-IN ?VALUE?");
459 }
460 zValue = g.argc==6 ? g.argv[5] : 0;
461 db_begin_transaction();
462 tag_add_artifact(zPrefix, g.argv[3], g.argv[4], zValue,
463 1+fPropagate+dryRun,zDateOvrd,zUserOvrd);
464 db_end_transaction(0);
465 }else
466
467 if( strncmp(g.argv[2],"branch",n)==0 ){
468 fossil_fatal("the \"fossil tag branch\" command is discontinued\n"
469 "Use the \"fossil branch new\" command instead.");
470 }else
471
472 if( strncmp(g.argv[2],"cancel",n)==0 ){
473 int dryRun = 0;
474 if( find_option("dryrun","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN;
475 if( g.argc!=5 ){
476 usage("cancel ?options? TAGNAME CHECK-IN");
477 }
478 db_begin_transaction();
479 tag_add_artifact(zPrefix, g.argv[3], g.argv[4], 0, dryRun, 0, 0);
480 db_end_transaction(0);
481 }else
482
483 if( strncmp(g.argv[2],"find",n)==0 ){
484 Stmt q;
@@ -562,29 +592,33 @@
592 **
593 ** Create a "parent" tag that causes CHECK-IN to be interpreted as a
594 ** child of PARENT. If multiple PARENTs are listed, then the first is
595 ** the primary parent and others are merge ancestors.
596 **
597 ** This is an experts-only command. It is used to patch up a repository
598 ** that has been damaged by a shun or that has been pieced together from
599 ** two or more separate repositories. You should never need to reparent
600 ** during normal operations.
601 **
602 ** Reparenting is accomplished by adding a parent tag. So to undo the
603 ** reparenting operation, simply delete the tag.
604 **
605 ** --test Make database entries but do not add the tag artifact.
606 ** So the reparent operation will be undone by the next
607 ** "fossil rebuild" command.
608 ** --dryrun | -n Print the tag that would have been created but do not
609 ** actually change the database in any way.
610 */
611 void reparent_cmd(void){
612 int bTest = find_option("test","",0)!=0;
613 int rid;
614 int i;
615 Blob value;
616 char *zUuid;
617 int dryRun = 0;
618
619 if( find_option("dryrun","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN;
620 db_find_and_open_repository(0, 0);
621 verify_all_options();
622 if( g.argc<4 ){
623 usage("reparent [OPTIONS] PARENT ...");
624 }
@@ -595,15 +629,15 @@
629 if( i>3 ) blob_append(&value, " ", 1);
630 zUuid = rid_to_uuid(pid);
631 blob_append(&value, zUuid, UUID_SIZE);
632 fossil_free(zUuid);
633 }
634 if( bTest && !dryRun ){
635 tag_insert("parent", 1, blob_str(&value), -1, 0.0, rid);
636 }else{
637 zUuid = rid_to_uuid(rid);
638 tag_add_artifact("","parent",zUuid,blob_str(&value),1|dryRun,0,0);
639 }
640 }
641
642
643 /*
644

Keyboard Shortcuts

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