Fossil

Check-in [6759e00e]
Login

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

Overview
Comment:reconstruct handles subdirectories
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wolfgangFormat2CSS_2
Files: files | file ages | folders
SHA1:6759e00eb89fcf3d6cbac66aa1028ce6508a0975
User & Date: wolfgang 2010-09-28 14:48:03
Context
2010-09-28
15:45
more formats to css check-in: e05f750a user: wolfgang tags: wolfgangFormat2CSS_2
14:48
reconstruct handles subdirectories check-in: 6759e00e user: wolfgang tags: wolfgangFormat2CSS_2
09:02
solved ticket [1b41304d8b]: moved style clear: both from code for content to css, adding the corresponding div only, if a sidebox wass used check-in: 26fc585e user: Ratte tags: wolfgangFormat2CSS_2
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/rebuild.c.

   399    399       db_end_transaction(0);
   400    400       db_multi_exec("VACUUM;");
   401    401     }else{
   402    402       rebuild_db(0, 1);
   403    403       db_end_transaction(0);
   404    404     }
   405    405   }
          406  +
          407  +/* 
          408  +** help function for reconstruct for recursiv directory
          409  +** reading.
          410  +*/
          411  +void recon_read_dir(char * zPath){
          412  +  DIR *d;
          413  +  struct dirent *pEntry;
          414  +  Blob aContent; /* content of the just read artifact */
          415  +
          416  +  d = opendir(zPath);
          417  +  if( d ){
          418  +    while( (pEntry=readdir(d))!=0 ){
          419  +      Blob path;
          420  +      char *zSubpath;
          421  +
          422  +      if( pEntry->d_name[0]=='.' ){
          423  +        continue;
          424  +      }
          425  +      zSubpath = mprintf("%s/%s",zPath,pEntry->d_name);
          426  +      if( file_isdir(zSubpath)==1 ){
          427  +        recon_read_dir(zSubpath);
          428  +      }
          429  +      blob_init(&path, 0, 0);
          430  +      blob_appendf(&path, "%s", zSubpath);
          431  +      if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
          432  +        fossil_panic("Some unknown error occurred while reading \"%s\"", blob_str(&path));
          433  +      }
          434  +      content_put(&aContent, 0, 0);
          435  +      blob_reset(&path);
          436  +      blob_reset(&aContent);
          437  +      free(zSubpath);
          438  +    }
          439  +  }
          440  +  else {
          441  +    fossil_panic("Encountered error %d while trying to open \"%s\".", errno, g.argv[3]);
          442  +  }
          443  +}
   406    444   
   407    445   /*
   408    446   ** COMMAND: reconstruct
   409    447   **
   410    448   ** Usage: %fossil reconstruct FILENAME DIRECTORY
   411    449   **
   412    450   ** This command studies the artifacts (files) in DIRECTORY and
   413    451   ** reconstructs the fossil record from them. It places the new
   414         -** fossil repository in FILENAME. Subdirectories are ignored.
          452  +** fossil repository in FILENAME. Subdirectories are read, files
          453  +** with leading `. in the filename are ignored.
   415    454   **
   416    455   */
   417    456   void reconstruct_cmd(void) {
   418    457     char *zPassword;
   419         -  DIR *d;
   420         -  struct dirent *pEntry;
   421         -  Blob aContent; /* content of the just read artifact */
   422    458     if( g.argc!=4 ){
   423    459       usage("FILENAME DIRECTORY");
   424    460     }
   425    461     if( file_isdir(g.argv[3])!=1 ){
   426    462       printf("\"%s\" is not a directory\n\n", g.argv[3]);
   427    463       usage("FILENAME DIRECTORY");
   428    464     }
   429    465     db_create_repository(g.argv[2]);
   430    466     db_open_repository(g.argv[2]);
   431    467     db_open_config(0);
   432    468     db_begin_transaction();
   433    469     db_initial_setup(0, 0, 1);
   434    470   
   435         -  d = opendir(g.argv[3]);
   436         -  if( d ){
   437         -    while( (pEntry=readdir(d))!=0 ){
   438         -      Blob path;
   439         -      blob_init(&path, 0, 0);
   440         -      if( pEntry->d_name[0]=='.' ){
   441         -        continue;
   442         -      }
   443         -      if( file_isdir(pEntry->d_name)==1 ){
   444         -        continue;
   445         -      }
   446         -      blob_appendf(&path, "%s/%s", g.argv[3], pEntry->d_name);
   447         -      if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
   448         -        fossil_panic("Some unknown error occurred while reading \"%s\"", blob_str(&path));
   449         -      }
   450         -      content_put(&aContent, 0, 0);
   451         -      blob_reset(&path);
   452         -      blob_reset(&aContent);
   453         -    }
   454         -  }
   455         -  else {
   456         -    fossil_panic("Encountered error %d while trying to open \"%s\".", errno, g.argv[3]);
   457         -  }
          471  +  recon_read_dir(g.argv[3]);
   458    472   
   459    473     rebuild_db(0, 1);
   460    474   
   461    475     db_end_transaction(0);
   462    476     printf("project-id: %s\n", db_get("project-code", 0));
   463    477     printf("server-id: %s\n", db_get("server-code", 0));
   464    478     zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
................................................................................
   472    486   **
   473    487   ** This command exports all artifacts of o given repository and
   474    488   ** writes all artifacts to the file system. The DESTINATION directory
   475    489   ** will be populated with subdirectories AA and files AA/BBBBBBBBB.., where
   476    490   ** AABBBBBBBBB.. is the 40 character artifact ID, AA the first 2 characters.
   477    491   ** If -L|--prefixlength is given, the length (default 2) of the directory
   478    492   ** prefix can be set to 0,1,..,9 characters.
   479         -**
   480         -** To use use the deconstructed artifacts with reconstruct, -L 0 should be used.
   481    493   */
   482    494   void deconstruct_cmd(void){
   483    495     const char *zDestDir;
   484    496     const char *zPrefixOpt;
   485    497     int         prefixLength;
   486    498     char       *zAFileOutFormat;
   487    499     Stmt        q;
................................................................................
   496    508       fossil_panic("DESTINATION(%s) is not a directory!",zDestDir);
   497    509     }
   498    510     /* get and check prefix length argument and build format string */
   499    511     zPrefixOpt=find_option("prefixlength","L",1);
   500    512     if (!zPrefixOpt){
   501    513       prefixLength = 2;
   502    514     }else{
   503         -    switch(*zPrefixOpt){
   504         -      case '0': prefixLength = 0;break;
   505         -      case '1': prefixLength = 1;break;
   506         -      case '2': prefixLength = 2;break;
   507         -      case '3': prefixLength = 3;break;
   508         -      case '4': prefixLength = 4;break;
   509         -      case '5': prefixLength = 5;break;
   510         -      case '6': prefixLength = 6;break;
   511         -      case '7': prefixLength = 7;break;
   512         -      case '8': prefixLength = 8;break;
   513         -      case '9': prefixLength = 9;break;
   514         -      default:  fossil_panic("N(%s) is not a a valid prefix length!",zPrefixOpt);
          515  +    if (zPrefixOpt[0]>='0' && zPrefixOpt[0]<='9' && !zPrefixOpt[1]){
          516  +      prefixLength = (int)(*zPrefixOpt-'0');
          517  +    }else{
          518  +      fossil_panic("N(%s) is not a a valid prefix length!",zPrefixOpt);
   515    519       }
   516    520     }
   517    521     if (prefixLength){
   518    522       zAFileOutFormat = mprintf("%%s/%%.%ds/%%s",prefixLength);
   519    523     }else{
   520    524       zAFileOutFormat = mprintf("%%s/%%s");
   521    525     }