Fossil

Check-in [ab12d0f4]
Login

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

Overview
Comment:recreated deconstruct command
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wolfgangFormat2CSS_2
Files: files | file ages | folders
SHA1:ab12d0f4d296aa6ad599ec44ce09edfa77cfec90
User & Date: wolfgang 2010-09-27 12:10:21
Context
2010-09-27
12:29
corrected -L 0 for deconstruct check-in: f7fd6765 user: wolfgang tags: wolfgangFormat2CSS_2
12:10
recreated deconstruct command check-in: ab12d0f4 user: wolfgang tags: wolfgangFormat2CSS_2
2010-09-26
16:33
added build environment for PellesC check-in: c343cd98 user: wolfgang tags: wolfgangFormat2CSS_2
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/rebuild.c.

460
461
462
463
464
465
466

























































































  db_end_transaction(0);
  printf("project-id: %s\n", db_get("project-code", 0));
  printf("server-id: %s\n", db_get("server-code", 0));
  zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
  printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword);
}































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
506
507
508
509
510
511
512
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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554

  db_end_transaction(0);
  printf("project-id: %s\n", db_get("project-code", 0));
  printf("server-id: %s\n", db_get("server-code", 0));
  zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
  printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword);
}

/*
** COMMAND: deconstruct
**
** Usage %fossil deconstruct ?-R|--repository REPOSITORY? ?-L|--prefixlength N? DESTINATION
**
** This command exports all artifacts of o given repository and
** writes all artifacts to the file system. The DESTINATION directory
** will be populated with subdirectories AA and files AA/BBBBBBBBB.., where
** AABBBBBBBBB.. is the 40 character artifact ID, AA the first 2 characters.
** Ivf -L|--prefixlength is given, the length (default 2) of the directory
** prefix can be set to 0,1,..,9 characters.
*/
void deconstruct_cmd(void){
  const char *zDestDir;
  const char *zPrefixOpt;
  int         prefixLength;
  char       *zAFileOutFormat;
  Stmt        q;

  /* check number of arguments */
  if( (g.argc != 3) && (g.argc != 5)  && (g.argc != 7)){
    usage ("?-R|--repository REPOSITORY? ?-L|--prefixlength N? DESTINATION");
  }
  /* get and check argument destination directory */
  zDestDir = g.argv[g.argc-1];
  if( !*zDestDir  || !file_isdir(zDestDir)) {
    fossil_panic("DESTINATION(%s) is not a directory!",zDestDir);
  }
  /* get and check prefix length argument and build format string */
  zPrefixOpt=find_option("prefixlength","L",1);
  if (!zPrefixOpt){
    prefixLength = 2;
  }else{
    switch(*zPrefixOpt){
      case '0': prefixLength = 0;break;
      case '1': prefixLength = 1;break;
      case '2': prefixLength = 2;break;
      case '3': prefixLength = 3;break;
      case '4': prefixLength = 4;break;
      case '5': prefixLength = 5;break;
      case '6': prefixLength = 6;break;
      case '7': prefixLength = 7;break;
      case '8': prefixLength = 8;break;
      case '9': prefixLength = 9;break;
      default:  fossil_panic("N(%s) is not a a valid prefix length!",zPrefixOpt);
    }
  }
  zAFileOutFormat = mprintf("%%s/%%.%ds/%%s",prefixLength);
#ifndef _WIN32
  if( access(zDestDir, W_OK) ){
    fossil_panic("DESTINATION(%s) is not writeable!",zDestDir);
  }
#else
  /* write access on windows is not checked, errors will be
  ** dected on blob_write_to_file
  */
#endif
  /* open repository and open query for all artifacts */
  db_find_and_open_repository(1);
  db_prepare(&q, "SELECT rid,uuid FROM blob");
  /* loop over artifacts and write them to single files */
  while( db_step(&q)==SQLITE_ROW ){
    int         aRid;
    const char *zAUuid;
    char       *zAFName;
    Blob        zACont;

    /* get data from query */
    aRid   = db_column_int (&q, 0);
    zAUuid = db_column_text(&q, 1);

    /* construct output filename */
    zAFName = mprintf(zAFileOutFormat, zDestDir, zAUuid, zAUuid + prefixLength);

    /* read artifact contents from db and write to file */
    content_get(aRid,&zACont);
    blob_write_to_file(&zACont,zAFName);
    blob_reset(&zACont);

    /* free artifact filename string */
    free(zAFName);
  }
  /* close query statement */
  db_finalize(&q);
  /* free filename format string */
  free(zAFileOutFormat);
}