Fossil

Check-in [353bfbac]
Login

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

Overview
Comment:Fix the "purge cat" command to work as documented. Add the "purge obliterate" command.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | DBP-workflow
Files: files | file ages | folders
SHA1: 353bfbacb9d20c3db3dca4f2ea0d4ce4985a8200
User & Date: drh 2014-11-26 14:58:37.641
Context
2014-11-26
15:11
When undoing a purge, make sure to also unshun all resurrected elements. ... (check-in: 454c7271 user: drh tags: DBP-workflow)
14:58
Fix the "purge cat" command to work as documented. Add the "purge obliterate" command. ... (check-in: 353bfbac user: drh tags: DBP-workflow)
14:26
Improved select of delta basis files for "bundle export". Added the --standalone option to "bundle export". Improved help messages for both the bundle and purge commands. ... (check-in: eb3ae3d6 user: drh tags: DBP-workflow)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/purge.c.
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
438
439
440
441
442
443
444
445
446















447
448
449
450
451
452
453
454
455
456
457
458
















459
460
461
462
463
464
465
** using the "fossil purge undo" command.
**
**   fossil purge cat UUID...
**
**      Write the content of one or more artifacts in the graveyard onto
**      standard output.
**
**   fossil purge [checkin] TAGS... [--explain]
**
**      Move the checkins identified by TAGS and all of their descendants
**      out of the repository and into the graveyard.  If a TAG is a branch



**      name then it means all the checkins on that branch.  If the --explain
**      option appears, then the repository and graveyard are unchanged and

**      an explaination of what would have happened is shown instead.  The
**      "checkin" subcommand keyword is only required if TAGS would be
**      ambiguous with one of the other subcommands.
**
**   fossil purge list|ls [-l]
**
**      Show the graveyard of prior purges.  The -l option gives more
**      detail in the output.
**





**   fossil purge undo ID
**
**      Restore the content previously removed by purge ID.
**
** SUMMARY:
**   fossil purge cat UUID...
**   fossil purge [checkin] TAGS... [--explain]
**   fossil purge list

**   fossil purge undo ID
*/
void purge_cmd(void){
  const char *zSubcmd;
  int n;
  Stmt q;
  if( g.argc<3 ) usage("SUBCOMMAND ?ARGS?");
  zSubcmd = g.argv[2];
  db_find_and_open_repository(0,0);
  n = (int)strlen(zSubcmd);















  if( strncmp(zSubcmd, "list", n)==0 || strcmp(zSubcmd,"ls")==0 ){
    int showDetail = find_option("l","l",0)!=0;
    if( db_int(-1,"PRAGMA table_info('purgeevent')")<0 ) return;
    db_prepare(&q, "SELECT peid, datetime(ctime,'unixepoch','localtime')"
                   " FROM purgeevent");
    while( db_step(&q)==SQLITE_ROW ){
      fossil_print("%4d on %s\n", db_column_int(&q,0), db_column_text(&q,1));
      if( showDetail ){
        purge_list_event_content(db_column_int(&q,0));
      }
    }
    db_finalize(&q);
















  }else if( strncmp(zSubcmd, "undo", n)==0 ){
    int peid;
    if( g.argc!=4 ) usage("undo ID");
    peid = atoi(g.argv[3]);
    db_begin_transaction();
    db_multi_exec(
      "CREATE TEMP TABLE ix("







|


|
>
>
>
|
|
>
|
<
|

|




>
>
>
>
>






|

>










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|











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







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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
** using the "fossil purge undo" command.
**
**   fossil purge cat UUID...
**
**      Write the content of one or more artifacts in the graveyard onto
**      standard output.
**
**   fossil purge ?checkins? TAGS... ?OPTIONS?
**
**      Move the checkins identified by TAGS and all of their descendants
**      out of the repository and into the graveyard.  The "checkins" 
**      subcommand keyword is option and can be omitted as long as TAGS
**      does not conflict with any other subcommand.
**
**      If a TAGS includes a branch name then it means all the checkins
**      on the most recent occurrance of that branch.
**
**           --explain         Make no changes, but show what would happen.

**           --dry-run         Make no chances.
**
**   fossil purge list|ls ?-l?
**
**      Show the graveyard of prior purges.  The -l option gives more
**      detail in the output.
**
**   fossil purge obliterate ID...
**
**      Remove one or more purge events from the graveyard.  Once a purge
**      event is obliterated, it can no longer be undone.
**
**   fossil purge undo ID
**
**      Restore the content previously removed by purge ID.
**
** SUMMARY:
**   fossil purge cat UUID...
**   fossil purge [checkins] TAGS... [--explain]
**   fossil purge list
**   fossil purge obliterate ID...
**   fossil purge undo ID
*/
void purge_cmd(void){
  const char *zSubcmd;
  int n;
  Stmt q;
  if( g.argc<3 ) usage("SUBCOMMAND ?ARGS?");
  zSubcmd = g.argv[2];
  db_find_and_open_repository(0,0);
  n = (int)strlen(zSubcmd);
  if( strncmp(zSubcmd, "cat", n)==0 ){
    const char *zOutFile;
    int i, piid;
    Blob content;
    if( g.argc<4 ) usage("cat UUID...");
    for(i=3; i<g.argc; i++){
      piid = db_int(0, "SELECT piid FROM purgeitem WHERE uuid LIKE '%q%%'",
                       g.argv[i]);
      if( piid==0 ) fossil_fatal("no such item: %s", g.argv[3]);
      purge_extract_item(piid, &content);
      blob_write_to_file(&content, "-");
      blob_reset(&content);
    }
  /* The "checkins" subcommand goes here in alphabetical order, but it must
  ** be moved to the end since it is the default case */
  }else if( strncmp(zSubcmd, "list", n)==0 || strcmp(zSubcmd,"ls")==0 ){
    int showDetail = find_option("l","l",0)!=0;
    if( db_int(-1,"PRAGMA table_info('purgeevent')")<0 ) return;
    db_prepare(&q, "SELECT peid, datetime(ctime,'unixepoch','localtime')"
                   " FROM purgeevent");
    while( db_step(&q)==SQLITE_ROW ){
      fossil_print("%4d on %s\n", db_column_int(&q,0), db_column_text(&q,1));
      if( showDetail ){
        purge_list_event_content(db_column_int(&q,0));
      }
    }
    db_finalize(&q);
  }else if( strncmp(zSubcmd, "obliterate", n)==0 ){
    int i;
    if( g.argc<4 ) usage("obliterate ID...");
    db_begin_transaction();
    for(i=3; i<g.argc; i++){
      int peid = atoi(g.argv[i]);
      if( !db_exists("SELECT 1 FROM purgeevent WHERE peid=%d",peid) ){
        fossil_fatal("no such purge event: %s", g.argv[i]);
      }
      db_multi_exec(
        "DELETE FROM purgeevent WHERE peid=%d;"
        "DELETE FROM purgeitem WHERE peid=%d;",
        peid, peid
      );
    }
    db_end_transaction(0);
  }else if( strncmp(zSubcmd, "undo", n)==0 ){
    int peid;
    if( g.argc!=4 ) usage("undo ID");
    peid = atoi(g.argv[3]);
    db_begin_transaction();
    db_multi_exec(
      "CREATE TEMP TABLE ix("
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492

493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
    );
    manifest_crosslink_begin();
    purge_item_resurrect(0, 0);
    manifest_crosslink_end(0);
    db_multi_exec("DELETE FROM purgeevent WHERE peid=%d", peid);
    db_multi_exec("DELETE FROM purgeitem WHERE peid=%d", peid);
    db_end_transaction(0);
  }else if( strncmp(zSubcmd, "cat", n)==0 ){
    const char *zOutFile;
    int piid;
    Blob content;
    if( g.argc!=4 && g.argc!=5 ) usage("cat UUID [FILENAME]");
    zOutFile = g.argc==5 ? g.argv[4] : "-";
    piid = db_int(0, "SELECT piid FROM purgeitem WHERE uuid LIKE '%q%%'",
                     g.argv[3]);
    if( piid==0 ) fossil_fatal("no such item: %s", g.argv[3]);
    purge_extract_item(piid, &content);
    blob_write_to_file(&content, zOutFile);
    blob_reset(&content);
  }else{

    int explainOnly = find_option("explain",0,0)!=0;
    int dryRun = find_option("dry-run",0,0)!=0;
    const char *zTag;
    int i;
    int vid;
    int nCkin;
    int nArtifact;
    verify_all_options();
    db_begin_transaction();
    i = strncmp(zSubcmd,"checkin",n)==0 ? 3 : 2;
    if( i>=g.argc ) usage("[checkin] TAGS... [--explain]");
    db_multi_exec("CREATE TEMP TABLE ok(rid INTEGER PRIMARY KEY)");
    for(; i<g.argc; i++){
      int r = name_to_typed_rid(g.argv[i], "br");
      compute_descendants(r, 1000000000);
    }
    vid = db_lget_int("checkout",0);







<
<
<
<
<
<
<
<
<
<
<
<

>









|







513
514
515
516
517
518
519












520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
    );
    manifest_crosslink_begin();
    purge_item_resurrect(0, 0);
    manifest_crosslink_end(0);
    db_multi_exec("DELETE FROM purgeevent WHERE peid=%d", peid);
    db_multi_exec("DELETE FROM purgeitem WHERE peid=%d", peid);
    db_end_transaction(0);












  }else{
    /* The "checkins" command is the default and so must occur last */
    int explainOnly = find_option("explain",0,0)!=0;
    int dryRun = find_option("dry-run",0,0)!=0;
    const char *zTag;
    int i;
    int vid;
    int nCkin;
    int nArtifact;
    verify_all_options();
    db_begin_transaction();
    i = strncmp(zSubcmd,"checkins",n)==0 ? 3 : 2;
    if( i>=g.argc ) usage("[checkin] TAGS... [--explain]");
    db_multi_exec("CREATE TEMP TABLE ok(rid INTEGER PRIMARY KEY)");
    for(; i<g.argc; i++){
      int r = name_to_typed_rid(g.argv[i], "br");
      compute_descendants(r, 1000000000);
    }
    vid = db_lget_int("checkout",0);