Fossil SCM

Create the initial HNAME table on a rebuild. Also fix a hash size error in sha3.c.

drh 2017-02-27 14:44 fossil-2.0
Commit 82487bece305bd6b28a97a535fd0292c3cff1c8a
3 files changed +47 -15 +14 +2 -2
+47 -15
--- src/rebuild.c
+++ src/rebuild.c
@@ -78,19 +78,39 @@
7878
@ mtime INTEGER, -- Time last modified. Seconds since 1970
7979
@ cols TEXT, -- A color-key specification
8080
@ sqlcode TEXT -- An SQL SELECT statement for this report
8181
@ );
8282
;
83
+static const char zCreateHnameTable[] =
84
+@ -- The hname table provides mappings from artifact hashes (hval) to the
85
+@ -- artifact id (rid). This table was added in Fossil-2.0. Prior to
86
+@ -- Fossil-2.0, there was only a single SHA1 hash value for each artifact
87
+@ -- which was stored in the BLOB.UUID field. With the introduction of
88
+@ -- multiple hash algorithms, the hval to rid mapping went from one-to-one to
89
+@ -- many-to-one and a new table became necessary.
90
+@ --
91
+@ CREATE TABLE hname(
92
+@ hval TEXT, -- Hex-encoded hash value
93
+@ htype ANY, -- Type of hash. Preferred hash: 0
94
+@ rid INTEGER REFERENCES blob, -- Blob that this hash names
95
+@ PRIMARY KEY(hval,htype)
96
+@ ) WITHOUT ROWID;
97
+@ INSERT INTO hname(hval,htype,rid) SELECT uuid,0,rid FROM blob;
98
+@ CREATE INDEX hname_rid ON hname(rid,htype);
99
+;
83100
101
+/*
102
+** Update the schema as necessary
103
+*/
84104
static void rebuild_update_schema(void){
85105
int rc;
86106
db_multi_exec("%s", zSchemaUpdates1 /*safe-for-%s*/);
87107
db_multi_exec("%s", zSchemaUpdates2 /*safe-for-%s*/);
88108
89
- rc = db_exists("SELECT 1 FROM sqlite_master"
90
- " WHERE name='user' AND sql GLOB '* mtime *'");
91
- if( rc==0 ){
109
+ /* Add the user.mtime column if it is missing.
110
+ */
111
+ if( !db_table_has_column("repository", "user", "mtime") ){
92112
db_multi_exec(
93113
"CREATE TEMP TABLE temp_user AS SELECT * FROM user;"
94114
"DROP TABLE user;"
95115
"CREATE TABLE user(\n"
96116
" uid INTEGER PRIMARY KEY,\n"
@@ -109,32 +129,32 @@
109129
" ipaddr, cexpire, info, now(), photo FROM temp_user;"
110130
"DROP TABLE temp_user;"
111131
);
112132
}
113133
114
- rc = db_exists("SELECT 1 FROM sqlite_master"
115
- " WHERE name='config' AND sql GLOB '* mtime *'");
116
- if( rc==0 ){
134
+ /* Add the config.mtime column if it is missing.
135
+ */
136
+ if( !db_table_has_column("repository", "config", "mtime") ){
117137
db_multi_exec(
118138
"ALTER TABLE config ADD COLUMN mtime INTEGER;"
119139
"UPDATE config SET mtime=now();"
120140
);
121141
}
122142
123
- rc = db_exists("SELECT 1 FROM sqlite_master"
124
- " WHERE name='shun' AND sql GLOB '* mtime *'");
125
- if( rc==0 ){
143
+ /* Add the shun.mtime and shun.scom columns if they are missing.
144
+ */
145
+ if( !db_table_has_column("repository", "shun", "mtime") ){
126146
db_multi_exec(
127147
"ALTER TABLE shun ADD COLUMN mtime INTEGER;"
128148
"ALTER TABLE shun ADD COLUMN scom TEXT;"
129149
"UPDATE shun SET mtime=now();"
130150
);
131151
}
132152
133
- rc = db_exists("SELECT 1 FROM sqlite_master"
134
- " WHERE name='reportfmt' AND sql GLOB '* mtime *'");
135
- if( rc==0 ){
153
+ /* Add the reportfmt.mtime column if it is missing.
154
+ */
155
+ if( !db_table_has_column("repository", "reportfmt", "mtime") ){
136156
db_multi_exec(
137157
"CREATE TEMP TABLE old_fmt AS SELECT * FROM reportfmt;"
138158
"DROP TABLE reportfmt;"
139159
);
140160
db_multi_exec("%s", zSchemaUpdates2/*safe-for-%s*/);
@@ -145,18 +165,30 @@
145165
" SELECT rn, owner, title || ' (' || rn || ')', cols, sqlcode, now()"
146166
" FROM old_fmt;"
147167
);
148168
}
149169
150
- rc = db_exists("SELECT 1 FROM sqlite_master"
151
- " WHERE name='concealed' AND sql GLOB '* mtime *'");
152
- if( rc==0 ){
170
+ /* Add the concealed.mtime column if it is missing.
171
+ */
172
+ if( !db_table_has_column("repository", "concealed", "mtime") ){
153173
db_multi_exec(
154174
"ALTER TABLE concealed ADD COLUMN mtime INTEGER;"
155175
"UPDATE concealed SET mtime=now();"
156176
);
157177
}
178
+
179
+ /* If the hname table is missing, that means we are dealing with an
180
+ ** older Fossil 1.x database. Create the hname table an populate it
181
+ ** with the SHA1 hash values in the blob.uuid field.
182
+ **
183
+ ** TODO: After all the rest of the code is updated to use the hname
184
+ ** table instead of the blob.uuid column, also delete the blob.uuid
185
+ ** column.
186
+ */
187
+ if( !db_table_exists("repository", "hname") ){
188
+ db_multi_exec("%s", zCreateHnameTable/*safe-for-%s*/);
189
+ }
158190
}
159191
160192
/*
161193
** Variables used to store state information about an on-going "rebuild"
162194
** or "deconstruct".
163195
--- src/rebuild.c
+++ src/rebuild.c
@@ -78,19 +78,39 @@
78 @ mtime INTEGER, -- Time last modified. Seconds since 1970
79 @ cols TEXT, -- A color-key specification
80 @ sqlcode TEXT -- An SQL SELECT statement for this report
81 @ );
82 ;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
 
 
84 static void rebuild_update_schema(void){
85 int rc;
86 db_multi_exec("%s", zSchemaUpdates1 /*safe-for-%s*/);
87 db_multi_exec("%s", zSchemaUpdates2 /*safe-for-%s*/);
88
89 rc = db_exists("SELECT 1 FROM sqlite_master"
90 " WHERE name='user' AND sql GLOB '* mtime *'");
91 if( rc==0 ){
92 db_multi_exec(
93 "CREATE TEMP TABLE temp_user AS SELECT * FROM user;"
94 "DROP TABLE user;"
95 "CREATE TABLE user(\n"
96 " uid INTEGER PRIMARY KEY,\n"
@@ -109,32 +129,32 @@
109 " ipaddr, cexpire, info, now(), photo FROM temp_user;"
110 "DROP TABLE temp_user;"
111 );
112 }
113
114 rc = db_exists("SELECT 1 FROM sqlite_master"
115 " WHERE name='config' AND sql GLOB '* mtime *'");
116 if( rc==0 ){
117 db_multi_exec(
118 "ALTER TABLE config ADD COLUMN mtime INTEGER;"
119 "UPDATE config SET mtime=now();"
120 );
121 }
122
123 rc = db_exists("SELECT 1 FROM sqlite_master"
124 " WHERE name='shun' AND sql GLOB '* mtime *'");
125 if( rc==0 ){
126 db_multi_exec(
127 "ALTER TABLE shun ADD COLUMN mtime INTEGER;"
128 "ALTER TABLE shun ADD COLUMN scom TEXT;"
129 "UPDATE shun SET mtime=now();"
130 );
131 }
132
133 rc = db_exists("SELECT 1 FROM sqlite_master"
134 " WHERE name='reportfmt' AND sql GLOB '* mtime *'");
135 if( rc==0 ){
136 db_multi_exec(
137 "CREATE TEMP TABLE old_fmt AS SELECT * FROM reportfmt;"
138 "DROP TABLE reportfmt;"
139 );
140 db_multi_exec("%s", zSchemaUpdates2/*safe-for-%s*/);
@@ -145,18 +165,30 @@
145 " SELECT rn, owner, title || ' (' || rn || ')', cols, sqlcode, now()"
146 " FROM old_fmt;"
147 );
148 }
149
150 rc = db_exists("SELECT 1 FROM sqlite_master"
151 " WHERE name='concealed' AND sql GLOB '* mtime *'");
152 if( rc==0 ){
153 db_multi_exec(
154 "ALTER TABLE concealed ADD COLUMN mtime INTEGER;"
155 "UPDATE concealed SET mtime=now();"
156 );
157 }
 
 
 
 
 
 
 
 
 
 
 
 
158 }
159
160 /*
161 ** Variables used to store state information about an on-going "rebuild"
162 ** or "deconstruct".
163
--- src/rebuild.c
+++ src/rebuild.c
@@ -78,19 +78,39 @@
78 @ mtime INTEGER, -- Time last modified. Seconds since 1970
79 @ cols TEXT, -- A color-key specification
80 @ sqlcode TEXT -- An SQL SELECT statement for this report
81 @ );
82 ;
83 static const char zCreateHnameTable[] =
84 @ -- The hname table provides mappings from artifact hashes (hval) to the
85 @ -- artifact id (rid). This table was added in Fossil-2.0. Prior to
86 @ -- Fossil-2.0, there was only a single SHA1 hash value for each artifact
87 @ -- which was stored in the BLOB.UUID field. With the introduction of
88 @ -- multiple hash algorithms, the hval to rid mapping went from one-to-one to
89 @ -- many-to-one and a new table became necessary.
90 @ --
91 @ CREATE TABLE hname(
92 @ hval TEXT, -- Hex-encoded hash value
93 @ htype ANY, -- Type of hash. Preferred hash: 0
94 @ rid INTEGER REFERENCES blob, -- Blob that this hash names
95 @ PRIMARY KEY(hval,htype)
96 @ ) WITHOUT ROWID;
97 @ INSERT INTO hname(hval,htype,rid) SELECT uuid,0,rid FROM blob;
98 @ CREATE INDEX hname_rid ON hname(rid,htype);
99 ;
100
101 /*
102 ** Update the schema as necessary
103 */
104 static void rebuild_update_schema(void){
105 int rc;
106 db_multi_exec("%s", zSchemaUpdates1 /*safe-for-%s*/);
107 db_multi_exec("%s", zSchemaUpdates2 /*safe-for-%s*/);
108
109 /* Add the user.mtime column if it is missing.
110 */
111 if( !db_table_has_column("repository", "user", "mtime") ){
112 db_multi_exec(
113 "CREATE TEMP TABLE temp_user AS SELECT * FROM user;"
114 "DROP TABLE user;"
115 "CREATE TABLE user(\n"
116 " uid INTEGER PRIMARY KEY,\n"
@@ -109,32 +129,32 @@
129 " ipaddr, cexpire, info, now(), photo FROM temp_user;"
130 "DROP TABLE temp_user;"
131 );
132 }
133
134 /* Add the config.mtime column if it is missing.
135 */
136 if( !db_table_has_column("repository", "config", "mtime") ){
137 db_multi_exec(
138 "ALTER TABLE config ADD COLUMN mtime INTEGER;"
139 "UPDATE config SET mtime=now();"
140 );
141 }
142
143 /* Add the shun.mtime and shun.scom columns if they are missing.
144 */
145 if( !db_table_has_column("repository", "shun", "mtime") ){
146 db_multi_exec(
147 "ALTER TABLE shun ADD COLUMN mtime INTEGER;"
148 "ALTER TABLE shun ADD COLUMN scom TEXT;"
149 "UPDATE shun SET mtime=now();"
150 );
151 }
152
153 /* Add the reportfmt.mtime column if it is missing.
154 */
155 if( !db_table_has_column("repository", "reportfmt", "mtime") ){
156 db_multi_exec(
157 "CREATE TEMP TABLE old_fmt AS SELECT * FROM reportfmt;"
158 "DROP TABLE reportfmt;"
159 );
160 db_multi_exec("%s", zSchemaUpdates2/*safe-for-%s*/);
@@ -145,18 +165,30 @@
165 " SELECT rn, owner, title || ' (' || rn || ')', cols, sqlcode, now()"
166 " FROM old_fmt;"
167 );
168 }
169
170 /* Add the concealed.mtime column if it is missing.
171 */
172 if( !db_table_has_column("repository", "concealed", "mtime") ){
173 db_multi_exec(
174 "ALTER TABLE concealed ADD COLUMN mtime INTEGER;"
175 "UPDATE concealed SET mtime=now();"
176 );
177 }
178
179 /* If the hname table is missing, that means we are dealing with an
180 ** older Fossil 1.x database. Create the hname table an populate it
181 ** with the SHA1 hash values in the blob.uuid field.
182 **
183 ** TODO: After all the rest of the code is updated to use the hname
184 ** table instead of the blob.uuid column, also delete the blob.uuid
185 ** column.
186 */
187 if( !db_table_exists("repository", "hname") ){
188 db_multi_exec("%s", zCreateHnameTable/*safe-for-%s*/);
189 }
190 }
191
192 /*
193 ** Variables used to store state information about an on-going "rebuild"
194 ** or "deconstruct".
195
+14
--- src/schema.c
+++ src/schema.c
@@ -106,10 +106,24 @@
106106
@ uid INTEGER REFERENCES user, -- User login
107107
@ mtime DATETIME, -- Time of receipt. Julian day.
108108
@ nonce TEXT UNIQUE, -- Nonce used for login
109109
@ ipaddr TEXT -- Remote IP address. NULL for direct.
110110
@ );
111
+@
112
+@ -- The hname table maps hash values (hval) into artifact IDs (rid).
113
+@ -- Prior to Fossil 2.0 (early 2017) there was only a single SHA1 hash
114
+@ -- value, and so the one-to-one mapping was accomplished using the
115
+@ -- BLOB.UUID column. Beginning with 2.0, the mapping is many-to-one
116
+@ -- and so a separate table became necessary.
117
+@ --
118
+@ CREATE TABLE hname(
119
+@ hval TEXT, -- Hex-encoded hash value
120
+@ htype ANY, -- Type of hash. Preferred hash: 0
121
+@ rid INTEGER REFERENCES blob, -- Blob that this hash names
122
+@ PRIMARY KEY(hval,htype)
123
+@ ) WITHOUT ROWID;
124
+@ CREATE INDEX hname_rid ON hname(rid,htype)
111125
@
112126
@ -- Information about users
113127
@ --
114128
@ -- The user.pw field can be either cleartext of the password, or
115129
@ -- a SHA1 hash of the password. If the user.pw field is exactly 40
116130
--- src/schema.c
+++ src/schema.c
@@ -106,10 +106,24 @@
106 @ uid INTEGER REFERENCES user, -- User login
107 @ mtime DATETIME, -- Time of receipt. Julian day.
108 @ nonce TEXT UNIQUE, -- Nonce used for login
109 @ ipaddr TEXT -- Remote IP address. NULL for direct.
110 @ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111 @
112 @ -- Information about users
113 @ --
114 @ -- The user.pw field can be either cleartext of the password, or
115 @ -- a SHA1 hash of the password. If the user.pw field is exactly 40
116
--- src/schema.c
+++ src/schema.c
@@ -106,10 +106,24 @@
106 @ uid INTEGER REFERENCES user, -- User login
107 @ mtime DATETIME, -- Time of receipt. Julian day.
108 @ nonce TEXT UNIQUE, -- Nonce used for login
109 @ ipaddr TEXT -- Remote IP address. NULL for direct.
110 @ );
111 @
112 @ -- The hname table maps hash values (hval) into artifact IDs (rid).
113 @ -- Prior to Fossil 2.0 (early 2017) there was only a single SHA1 hash
114 @ -- value, and so the one-to-one mapping was accomplished using the
115 @ -- BLOB.UUID column. Beginning with 2.0, the mapping is many-to-one
116 @ -- and so a separate table became necessary.
117 @ --
118 @ CREATE TABLE hname(
119 @ hval TEXT, -- Hex-encoded hash value
120 @ htype ANY, -- Type of hash. Preferred hash: 0
121 @ rid INTEGER REFERENCES blob, -- Blob that this hash names
122 @ PRIMARY KEY(hval,htype)
123 @ ) WITHOUT ROWID;
124 @ CREATE INDEX hname_rid ON hname(rid,htype)
125 @
126 @ -- Information about users
127 @ --
128 @ -- The user.pw field can be either cleartext of the password, or
129 @ -- a SHA1 hash of the password. If the user.pw field is exactly 40
130
+2 -2
--- src/sha3.c
+++ src/sha3.c
@@ -608,11 +608,11 @@
608608
** Compute an SHA3 checksum of all files named on the command-line.
609609
** If a file is named "-" then take its content from standard input.
610610
**
611611
** Options:
612612
**
613
-** --228 Compute a SHA3-228 hash (the default)
613
+** --224 Compute a SHA3-224 hash (the default)
614614
** --256 Compute a SHA3-256 hash
615615
** --384 Compute a SHA3-384 hash
616616
** --512 Compute a SHA3-512 hash
617617
** --size N An N-bit hash. N must be a multiple of 32 between 128
618618
** and 512.
@@ -621,11 +621,11 @@
621621
int i;
622622
Blob in;
623623
Blob cksum;
624624
int iSize = 224;
625625
626
- if( find_option("228",0,0)!=0 ) iSize = 228;
626
+ if( find_option("224",0,0)!=0 ) iSize = 224;
627627
else if( find_option("256",0,0)!=0 ) iSize = 256;
628628
else if( find_option("384",0,0)!=0 ) iSize = 384;
629629
else if( find_option("512",0,0)!=0 ) iSize = 512;
630630
else{
631631
const char *zN = find_option("size",0,1);
632632
--- src/sha3.c
+++ src/sha3.c
@@ -608,11 +608,11 @@
608 ** Compute an SHA3 checksum of all files named on the command-line.
609 ** If a file is named "-" then take its content from standard input.
610 **
611 ** Options:
612 **
613 ** --228 Compute a SHA3-228 hash (the default)
614 ** --256 Compute a SHA3-256 hash
615 ** --384 Compute a SHA3-384 hash
616 ** --512 Compute a SHA3-512 hash
617 ** --size N An N-bit hash. N must be a multiple of 32 between 128
618 ** and 512.
@@ -621,11 +621,11 @@
621 int i;
622 Blob in;
623 Blob cksum;
624 int iSize = 224;
625
626 if( find_option("228",0,0)!=0 ) iSize = 228;
627 else if( find_option("256",0,0)!=0 ) iSize = 256;
628 else if( find_option("384",0,0)!=0 ) iSize = 384;
629 else if( find_option("512",0,0)!=0 ) iSize = 512;
630 else{
631 const char *zN = find_option("size",0,1);
632
--- src/sha3.c
+++ src/sha3.c
@@ -608,11 +608,11 @@
608 ** Compute an SHA3 checksum of all files named on the command-line.
609 ** If a file is named "-" then take its content from standard input.
610 **
611 ** Options:
612 **
613 ** --224 Compute a SHA3-224 hash (the default)
614 ** --256 Compute a SHA3-256 hash
615 ** --384 Compute a SHA3-384 hash
616 ** --512 Compute a SHA3-512 hash
617 ** --size N An N-bit hash. N must be a multiple of 32 between 128
618 ** and 512.
@@ -621,11 +621,11 @@
621 int i;
622 Blob in;
623 Blob cksum;
624 int iSize = 224;
625
626 if( find_option("224",0,0)!=0 ) iSize = 224;
627 else if( find_option("256",0,0)!=0 ) iSize = 256;
628 else if( find_option("384",0,0)!=0 ) iSize = 384;
629 else if( find_option("512",0,0)!=0 ) iSize = 512;
630 else{
631 const char *zN = find_option("size",0,1);
632

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button