Fossil SCM
recreated deconstruct command
Commit
ab12d0f4d296aa6ad599ec44ce09edfa77cfec90
Parent
c343cd9873b3c43…
1 file changed
+88
+88
| --- src/rebuild.c | ||
| +++ src/rebuild.c | ||
| @@ -462,5 +462,93 @@ | ||
| 462 | 462 | printf("project-id: %s\n", db_get("project-code", 0)); |
| 463 | 463 | printf("server-id: %s\n", db_get("server-code", 0)); |
| 464 | 464 | zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin); |
| 465 | 465 | printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword); |
| 466 | 466 | } |
| 467 | + | |
| 468 | +/* | |
| 469 | +** COMMAND: deconstruct | |
| 470 | +** | |
| 471 | +** Usage %fossil deconstruct ?-R|--repository REPOSITORY? ?-L|--prefixlength N? DESTINATION | |
| 472 | +** | |
| 473 | +** This command exports all artifacts of o given repository and | |
| 474 | +** writes all artifacts to the file system. The DESTINATION directory | |
| 475 | +** will be populated with subdirectories AA and files AA/BBBBBBBBB.., where | |
| 476 | +** AABBBBBBBBB.. is the 40 character artifact ID, AA the first 2 characters. | |
| 477 | +** Ivf -L|--prefixlength is given, the length (default 2) of the directory | |
| 478 | +** prefix can be set to 0,1,..,9 characters. | |
| 479 | +*/ | |
| 480 | +void deconstruct_cmd(void){ | |
| 481 | + const char *zDestDir; | |
| 482 | + const char *zPrefixOpt; | |
| 483 | + int prefixLength; | |
| 484 | + char *zAFileOutFormat; | |
| 485 | + Stmt q; | |
| 486 | + | |
| 487 | + /* check number of arguments */ | |
| 488 | + if( (g.argc != 3) && (g.argc != 5) && (g.argc != 7)){ | |
| 489 | + usage ("?-R|--repository REPOSITORY? ?-L|--prefixlength N? DESTINATION"); | |
| 490 | + } | |
| 491 | + /* get and check argument destination directory */ | |
| 492 | + zDestDir = g.argv[g.argc-1]; | |
| 493 | + if( !*zDestDir || !file_isdir(zDestDir)) { | |
| 494 | + fossil_panic("DESTINATION(%s) is not a directory!",zDestDir); | |
| 495 | + } | |
| 496 | + /* get and check prefix length argument and build format string */ | |
| 497 | + zPrefixOpt=find_option("prefixlength","L",1); | |
| 498 | + if (!zPrefixOpt){ | |
| 499 | + prefixLength = 2; | |
| 500 | + }else{ | |
| 501 | + switch(*zPrefixOpt){ | |
| 502 | + case '0': prefixLength = 0;break; | |
| 503 | + case '1': prefixLength = 1;break; | |
| 504 | + case '2': prefixLength = 2;break; | |
| 505 | + case '3': prefixLength = 3;break; | |
| 506 | + case '4': prefixLength = 4;break; | |
| 507 | + case '5': prefixLength = 5;break; | |
| 508 | + case '6': prefixLength = 6;break; | |
| 509 | + case '7': prefixLength = 7;break; | |
| 510 | + case '8': prefixLength = 8;break; | |
| 511 | + case '9': prefixLength = 9;break; | |
| 512 | + default: fossil_panic("N(%s) is not a a valid prefix length!",zPrefixOpt); | |
| 513 | + } | |
| 514 | + } | |
| 515 | + zAFileOutFormat = mprintf("%%s/%%.%ds/%%s",prefixLength); | |
| 516 | +#ifndef _WIN32 | |
| 517 | + if( access(zDestDir, W_OK) ){ | |
| 518 | + fossil_panic("DESTINATION(%s) is not writeable!",zDestDir); | |
| 519 | + } | |
| 520 | +#else | |
| 521 | + /* write access on windows is not checked, errors will be | |
| 522 | + ** dected on blob_write_to_file | |
| 523 | + */ | |
| 524 | +#endif | |
| 525 | + /* open repository and open query for all artifacts */ | |
| 526 | + db_find_and_open_repository(1); | |
| 527 | + db_prepare(&q, "SELECT rid,uuid FROM blob"); | |
| 528 | + /* loop over artifacts and write them to single files */ | |
| 529 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 530 | + int aRid; | |
| 531 | + const char *zAUuid; | |
| 532 | + char *zAFName; | |
| 533 | + Blob zACont; | |
| 534 | + | |
| 535 | + /* get data from query */ | |
| 536 | + aRid = db_column_int (&q, 0); | |
| 537 | + zAUuid = db_column_text(&q, 1); | |
| 538 | + | |
| 539 | + /* construct output filename */ | |
| 540 | + zAFName = mprintf(zAFileOutFormat, zDestDir, zAUuid, zAUuid + prefixLength); | |
| 541 | + | |
| 542 | + /* read artifact contents from db and write to file */ | |
| 543 | + content_get(aRid,&zACont); | |
| 544 | + blob_write_to_file(&zACont,zAFName); | |
| 545 | + blob_reset(&zACont); | |
| 546 | + | |
| 547 | + /* free artifact filename string */ | |
| 548 | + free(zAFName); | |
| 549 | + } | |
| 550 | + /* close query statement */ | |
| 551 | + db_finalize(&q); | |
| 552 | + /* free filename format string */ | |
| 553 | + free(zAFileOutFormat); | |
| 554 | +} | |
| 467 | 555 |
| --- src/rebuild.c | |
| +++ src/rebuild.c | |
| @@ -462,5 +462,93 @@ | |
| 462 | printf("project-id: %s\n", db_get("project-code", 0)); |
| 463 | printf("server-id: %s\n", db_get("server-code", 0)); |
| 464 | zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin); |
| 465 | printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword); |
| 466 | } |
| 467 |
| --- src/rebuild.c | |
| +++ src/rebuild.c | |
| @@ -462,5 +462,93 @@ | |
| 462 | printf("project-id: %s\n", db_get("project-code", 0)); |
| 463 | printf("server-id: %s\n", db_get("server-code", 0)); |
| 464 | zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin); |
| 465 | printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword); |
| 466 | } |
| 467 | |
| 468 | /* |
| 469 | ** COMMAND: deconstruct |
| 470 | ** |
| 471 | ** Usage %fossil deconstruct ?-R|--repository REPOSITORY? ?-L|--prefixlength N? DESTINATION |
| 472 | ** |
| 473 | ** This command exports all artifacts of o given repository and |
| 474 | ** writes all artifacts to the file system. The DESTINATION directory |
| 475 | ** will be populated with subdirectories AA and files AA/BBBBBBBBB.., where |
| 476 | ** AABBBBBBBBB.. is the 40 character artifact ID, AA the first 2 characters. |
| 477 | ** Ivf -L|--prefixlength is given, the length (default 2) of the directory |
| 478 | ** prefix can be set to 0,1,..,9 characters. |
| 479 | */ |
| 480 | void deconstruct_cmd(void){ |
| 481 | const char *zDestDir; |
| 482 | const char *zPrefixOpt; |
| 483 | int prefixLength; |
| 484 | char *zAFileOutFormat; |
| 485 | Stmt q; |
| 486 | |
| 487 | /* check number of arguments */ |
| 488 | if( (g.argc != 3) && (g.argc != 5) && (g.argc != 7)){ |
| 489 | usage ("?-R|--repository REPOSITORY? ?-L|--prefixlength N? DESTINATION"); |
| 490 | } |
| 491 | /* get and check argument destination directory */ |
| 492 | zDestDir = g.argv[g.argc-1]; |
| 493 | if( !*zDestDir || !file_isdir(zDestDir)) { |
| 494 | fossil_panic("DESTINATION(%s) is not a directory!",zDestDir); |
| 495 | } |
| 496 | /* get and check prefix length argument and build format string */ |
| 497 | zPrefixOpt=find_option("prefixlength","L",1); |
| 498 | if (!zPrefixOpt){ |
| 499 | prefixLength = 2; |
| 500 | }else{ |
| 501 | switch(*zPrefixOpt){ |
| 502 | case '0': prefixLength = 0;break; |
| 503 | case '1': prefixLength = 1;break; |
| 504 | case '2': prefixLength = 2;break; |
| 505 | case '3': prefixLength = 3;break; |
| 506 | case '4': prefixLength = 4;break; |
| 507 | case '5': prefixLength = 5;break; |
| 508 | case '6': prefixLength = 6;break; |
| 509 | case '7': prefixLength = 7;break; |
| 510 | case '8': prefixLength = 8;break; |
| 511 | case '9': prefixLength = 9;break; |
| 512 | default: fossil_panic("N(%s) is not a a valid prefix length!",zPrefixOpt); |
| 513 | } |
| 514 | } |
| 515 | zAFileOutFormat = mprintf("%%s/%%.%ds/%%s",prefixLength); |
| 516 | #ifndef _WIN32 |
| 517 | if( access(zDestDir, W_OK) ){ |
| 518 | fossil_panic("DESTINATION(%s) is not writeable!",zDestDir); |
| 519 | } |
| 520 | #else |
| 521 | /* write access on windows is not checked, errors will be |
| 522 | ** dected on blob_write_to_file |
| 523 | */ |
| 524 | #endif |
| 525 | /* open repository and open query for all artifacts */ |
| 526 | db_find_and_open_repository(1); |
| 527 | db_prepare(&q, "SELECT rid,uuid FROM blob"); |
| 528 | /* loop over artifacts and write them to single files */ |
| 529 | while( db_step(&q)==SQLITE_ROW ){ |
| 530 | int aRid; |
| 531 | const char *zAUuid; |
| 532 | char *zAFName; |
| 533 | Blob zACont; |
| 534 | |
| 535 | /* get data from query */ |
| 536 | aRid = db_column_int (&q, 0); |
| 537 | zAUuid = db_column_text(&q, 1); |
| 538 | |
| 539 | /* construct output filename */ |
| 540 | zAFName = mprintf(zAFileOutFormat, zDestDir, zAUuid, zAUuid + prefixLength); |
| 541 | |
| 542 | /* read artifact contents from db and write to file */ |
| 543 | content_get(aRid,&zACont); |
| 544 | blob_write_to_file(&zACont,zAFName); |
| 545 | blob_reset(&zACont); |
| 546 | |
| 547 | /* free artifact filename string */ |
| 548 | free(zAFName); |
| 549 | } |
| 550 | /* close query statement */ |
| 551 | db_finalize(&q); |
| 552 | /* free filename format string */ |
| 553 | free(zAFileOutFormat); |
| 554 | } |
| 555 |