Fossil

Check-in [e00384d26d]
Login

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

Overview
Comment:Moved the core logic of both "rebuild_database" and "create_repository_cmd" into their own functions, for sharing with "reconstruct_cmd".
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e00384d26d5e24bc41daf1788352e38dd85968c9
User & Date: aku 2007-08-29 02:42:24.000
Context
2007-08-29
02:46
Added implementations for the methods "deconstruct", and "construct". ... (check-in: fc95255785 user: aku tags: trunk)
02:42
Moved the core logic of both "rebuild_database" and "create_repository_cmd" into their own functions, for sharing with "reconstruct_cmd". ... (check-in: e00384d26d user: aku tags: trunk)
2007-08-28
07:12
Fixed bug in blob_write_to_file, added missing argument to fossil_panic. ... (check-in: 033ad72c71 user: aku tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/db.c.
640
641
642
643
644
645
646
647
648



649
650
651
652
653
654
655
656

657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
     zFilename,
     zRepositorySchema1,
     zRepositorySchema2,
     (char*)0
  );
}


/*



** COMMAND: new
**
** Usage: %fossil new FILENAME
** Create a repository for a new project in the file named FILENAME.
** This command is distinct from "clone".  The "clone" command makes
** a copy of an existing project.  This command starts a new project.
*/
void create_repository_cmd(void){

  char *zDate;
  char *zUser;
  Blob hash;
  Blob manifest;

  if( g.argc!=3 ){
    usage("REPOSITORY-NAME");
  }
  db_create_repository(g.argv[2]);
  db_open_repository(g.argv[2]);
  db_open_config();
  db_begin_transaction();
  db_set("content-schema", CONTENT_SCHEMA);
  db_set("aux-schema", AUX_SCHEMA);
  db_set_int("authenticate-localhost", 0);
  db_multi_exec(
    "INSERT INTO config(name,value) VALUES('server-code', hex(randomblob(20)));"
    "INSERT INTO config(name,value) VALUES('project-code',hex(randomblob(20)));"
  );







<

>
>
>
|

<
<
|
|

|
>





<
<
<
<
<
<
<







640
641
642
643
644
645
646

647
648
649
650
651
652


653
654
655
656
657
658
659
660
661
662







663
664
665
666
667
668
669
     zFilename,
     zRepositorySchema1,
     zRepositorySchema2,
     (char*)0
  );
}


/*
** Fill an empty repository database with the basic information for a
** repository. This function is shared between 'create_repository_cmd'
** ('new') and 'reconstruct_cmd' ('reconstruct'), both of which create
** new repositories.
**


** The caller determines wheter the function inserts an empty root
** manifest (zRoot == TRUE), or not (zRoot == FALSE).
*/

void db_initial_setup (int zRoot){
  char *zDate;
  char *zUser;
  Blob hash;
  Blob manifest;








  db_set("content-schema", CONTENT_SCHEMA);
  db_set("aux-schema", AUX_SCHEMA);
  db_set_int("authenticate-localhost", 0);
  db_multi_exec(
    "INSERT INTO config(name,value) VALUES('server-code', hex(randomblob(20)));"
    "INSERT INTO config(name,value) VALUES('project-code',hex(randomblob(20)));"
  );
687
688
689
690
691
692
693


694
695
696
697
698
699
700
701
702
703
704
705
706




















707
708
709
710
711
712
713
  db_multi_exec(
     "INSERT INTO user(login,pw,cap,info)"
     "   VALUES('anonymous','anonymous','hjkorw','Anon');"
     "INSERT INTO user(login,pw,cap,info)"
     "   VALUES('nobody','','jor','Nobody');"
  );
  user_select();


  blob_zero(&manifest);
  blob_appendf(&manifest, "C initial\\sempty\\sbaseline\n");
  zDate = db_text(0, "SELECT datetime('now')");
  zDate[10]='T';
  blob_appendf(&manifest, "D %s\n", zDate);
  blob_appendf(&manifest, "P\n");
  md5sum_init();
  blob_appendf(&manifest, "R %s\n", md5sum_finish(0));
  blob_appendf(&manifest, "U %F\n", g.zLogin);
  md5sum_blob(&manifest, &hash);
  blob_appendf(&manifest, "Z %b\n", &hash);
  blob_reset(&hash);
  content_put(&manifest, 0, 0);




















  db_end_transaction(0);
  printf("project-id: %s\n", db_get("project-code", 0));
  printf("server-id:  %s\n", db_get("server-code", 0));
  printf("admin-user: %s (no password set yet!)\n", g.zLogin);
  printf("baseline:   %s\n", db_text(0, "SELECT uuid FROM blob"));
}








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







681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
  db_multi_exec(
     "INSERT INTO user(login,pw,cap,info)"
     "   VALUES('anonymous','anonymous','hjkorw','Anon');"
     "INSERT INTO user(login,pw,cap,info)"
     "   VALUES('nobody','','jor','Nobody');"
  );
  user_select();

  if (zRoot){
    blob_zero(&manifest);
    blob_appendf(&manifest, "C initial\\sempty\\sbaseline\n");
    zDate = db_text(0, "SELECT datetime('now')");
    zDate[10]='T';
    blob_appendf(&manifest, "D %s\n", zDate);
    blob_appendf(&manifest, "P\n");
    md5sum_init();
    blob_appendf(&manifest, "R %s\n", md5sum_finish(0));
    blob_appendf(&manifest, "U %F\n", g.zLogin);
    md5sum_blob(&manifest, &hash);
    blob_appendf(&manifest, "Z %b\n", &hash);
    blob_reset(&hash);
    content_put(&manifest, 0, 0);
  }
}

/*
** COMMAND: new
**
** Usage: %fossil new FILENAME
** Create a repository for a new project in the file named FILENAME.
** This command is distinct from "clone".  The "clone" command makes
** a copy of an existing project.  This command starts a new project.
*/
void create_repository_cmd(void){
  if( g.argc!=3 ){
    usage("REPOSITORY-NAME");
  }
  db_create_repository(g.argv[2]);
  db_open_repository(g.argv[2]);
  db_open_config();
  db_begin_transaction();
  db_initial_setup (1);
  db_end_transaction(0);
  printf("project-id: %s\n", db_get("project-code", 0));
  printf("server-id:  %s\n", db_get("server-code", 0));
  printf("admin-user: %s (no password set yet!)\n", g.zLogin);
  printf("baseline:   %s\n", db_text(0, "SELECT uuid FROM blob"));
}

Changes to src/rebuild.c.
23
24
25
26
27
28
29
30
31
32
33
34


35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
**
** This file contains code used to rebuild the database.
*/
#include "config.h"
#include "rebuild.h"
#include <assert.h>


/*
** COMMAND:  rebuild
**
** Usage: %fossil rebuild REPOSITORY


**
** Reconstruct the named repository database from the core
** records.  Run this command after updating the fossil
** executable in a way that changes the database schema.
*/

void rebuild_database(void){
  Stmt s;
  int errCnt;
  int forceFlag;
  char *zTable;

  forceFlag = find_option("force","f",0)!=0;
  if( g.argc!=3 ){
    usage("REPOSITORY-FILENAME");
  }
  errCnt = 0;
  db_open_repository(g.argv[2]);
  db_begin_transaction();
  db_multi_exec(
    "CREATE INDEX IF NOT EXISTS delta_i1 ON delta(srcid);"
  );
  for(;;){
    zTable = db_text(0,
       "SELECT name FROM sqlite_master"
       " WHERE type='table'"







<

|
<
|
>
>
|
<
<
<

>
|

|
<


<
<
<
<
<
<
<







23
24
25
26
27
28
29

30
31

32
33
34
35



36
37
38
39
40

41
42







43
44
45
46
47
48
49
**
** This file contains code used to rebuild the database.
*/
#include "config.h"
#include "rebuild.h"
#include <assert.h>


/*
** Core function to rebuild the infomration in the derived tables of a

** fossil repository from the blobs. This function is shared between
** 'rebuild_database' ('rebuild') and 'reconstruct_cmd'
** ('reconstruct'), both of which have to regenerate this information
** from scratch.



*/

int rebuild_db(void){
  Stmt s;
  int errCnt = 0;

  char *zTable;








  db_multi_exec(
    "CREATE INDEX IF NOT EXISTS delta_i1 ON delta(srcid);"
  );
  for(;;){
    zTable = db_text(0,
       "SELECT name FROM sqlite_master"
       " WHERE type='table'"
73
74
75
76
77
78
79

80





















81
82
83
84
85
86
87
88
      content_get(rid, &content);
      manifest_crosslink(rid, &content);
      blob_reset(&content);
    }else{
      db_multi_exec("INSERT INTO phantom VALUES(%d)", rid);
    }
  }























  if( errCnt && !forceFlag ){
    printf("%d errors. Rolling back changes. Use --force to force a commit.\n",
            errCnt);
    db_end_transaction(1);
  }else{
    db_end_transaction(0);
  }
}







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








63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
      content_get(rid, &content);
      manifest_crosslink(rid, &content);
      blob_reset(&content);
    }else{
      db_multi_exec("INSERT INTO phantom VALUES(%d)", rid);
    }
  }
  return errCnt;
}

/*
** COMMAND:  rebuild
**
** Usage: %fossil rebuild REPOSITORY
**
** Reconstruct the named repository database from the core
** records.  Run this command after updating the fossil
** executable in a way that changes the database schema.
*/
void rebuild_database(void){
  int forceFlag;
  int errCnt;

  forceFlag = find_option("force","f",0)!=0;
  if( g.argc!=3 ){
    usage("REPOSITORY-FILENAME");
  }
  db_open_repository(g.argv[2]);
  db_begin_transaction();
  errCnt = rebuild_db();
  if( errCnt && !forceFlag ){
    printf("%d errors. Rolling back changes. Use --force to force a commit.\n",
            errCnt);
    db_end_transaction(1);
  }else{
    db_end_transaction(0);
  }
}