Fossil SCM
New repositories default to hash policy "shun-sha1" with a SHA3 initial check-in. But this can be overridden using the --template option with a template repository that is already set to a different hash policy.
Commit
95543ce45b6fbc981c831a7508495de8769f10a8
Parent
a616c04b6a010ba…
2 files changed
+1
-4
+13
-4
M
src/db.c
+1
-4
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1833,10 +1833,11 @@ | ||
| 1833 | 1833 | " AND name NOT GLOB 'project-*'" |
| 1834 | 1834 | " AND name NOT GLOB 'short-project-*';", |
| 1835 | 1835 | configure_inop_rhs(CONFIGSET_ALL), |
| 1836 | 1836 | db_setting_inop_rhs() |
| 1837 | 1837 | ); |
| 1838 | + g.eHashPolicy = db_get_int("hash-policy", g.eHashPolicy); | |
| 1838 | 1839 | db_multi_exec( |
| 1839 | 1840 | "REPLACE INTO reportfmt SELECT * FROM settingSrc.reportfmt;" |
| 1840 | 1841 | ); |
| 1841 | 1842 | |
| 1842 | 1843 | /* |
| @@ -1927,12 +1928,10 @@ | ||
| 1927 | 1928 | |
| 1928 | 1929 | |
| 1929 | 1930 | zTemplate = find_option("template",0,1); |
| 1930 | 1931 | zDate = find_option("date-override",0,1); |
| 1931 | 1932 | zDefaultUser = find_option("admin-user","A",1); |
| 1932 | - g.eHashPolicy = HPOLICY_SHUN_SHA1; | |
| 1933 | - if( find_option("sha1",0,0)!=0 ) g.eHashPolicy = HPOLICY_SHA1; | |
| 1934 | 1933 | /* We should be done with options.. */ |
| 1935 | 1934 | verify_all_options(); |
| 1936 | 1935 | |
| 1937 | 1936 | if( g.argc!=3 ){ |
| 1938 | 1937 | usage("REPOSITORY-NAME"); |
| @@ -1945,12 +1944,10 @@ | ||
| 1945 | 1944 | db_create_repository(g.argv[2]); |
| 1946 | 1945 | db_open_repository(g.argv[2]); |
| 1947 | 1946 | db_open_config(0, 0); |
| 1948 | 1947 | if( zTemplate ) db_attach(zTemplate, "settingSrc"); |
| 1949 | 1948 | db_begin_transaction(); |
| 1950 | - g.eHashPolicy = db_get_int("hash-policy", g.eHashPolicy); | |
| 1951 | - db_set_int("hash-policy", g.eHashPolicy, 0); | |
| 1952 | 1949 | if( zDate==0 ) zDate = "now"; |
| 1953 | 1950 | db_initial_setup(zTemplate, zDate, zDefaultUser); |
| 1954 | 1951 | db_end_transaction(0); |
| 1955 | 1952 | if( zTemplate ) db_detach("settingSrc"); |
| 1956 | 1953 | fossil_print("project-id: %s\n", db_get("project-code", 0)); |
| 1957 | 1954 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1833,10 +1833,11 @@ | |
| 1833 | " AND name NOT GLOB 'project-*'" |
| 1834 | " AND name NOT GLOB 'short-project-*';", |
| 1835 | configure_inop_rhs(CONFIGSET_ALL), |
| 1836 | db_setting_inop_rhs() |
| 1837 | ); |
| 1838 | db_multi_exec( |
| 1839 | "REPLACE INTO reportfmt SELECT * FROM settingSrc.reportfmt;" |
| 1840 | ); |
| 1841 | |
| 1842 | /* |
| @@ -1927,12 +1928,10 @@ | |
| 1927 | |
| 1928 | |
| 1929 | zTemplate = find_option("template",0,1); |
| 1930 | zDate = find_option("date-override",0,1); |
| 1931 | zDefaultUser = find_option("admin-user","A",1); |
| 1932 | g.eHashPolicy = HPOLICY_SHUN_SHA1; |
| 1933 | if( find_option("sha1",0,0)!=0 ) g.eHashPolicy = HPOLICY_SHA1; |
| 1934 | /* We should be done with options.. */ |
| 1935 | verify_all_options(); |
| 1936 | |
| 1937 | if( g.argc!=3 ){ |
| 1938 | usage("REPOSITORY-NAME"); |
| @@ -1945,12 +1944,10 @@ | |
| 1945 | db_create_repository(g.argv[2]); |
| 1946 | db_open_repository(g.argv[2]); |
| 1947 | db_open_config(0, 0); |
| 1948 | if( zTemplate ) db_attach(zTemplate, "settingSrc"); |
| 1949 | db_begin_transaction(); |
| 1950 | g.eHashPolicy = db_get_int("hash-policy", g.eHashPolicy); |
| 1951 | db_set_int("hash-policy", g.eHashPolicy, 0); |
| 1952 | if( zDate==0 ) zDate = "now"; |
| 1953 | db_initial_setup(zTemplate, zDate, zDefaultUser); |
| 1954 | db_end_transaction(0); |
| 1955 | if( zTemplate ) db_detach("settingSrc"); |
| 1956 | fossil_print("project-id: %s\n", db_get("project-code", 0)); |
| 1957 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1833,10 +1833,11 @@ | |
| 1833 | " AND name NOT GLOB 'project-*'" |
| 1834 | " AND name NOT GLOB 'short-project-*';", |
| 1835 | configure_inop_rhs(CONFIGSET_ALL), |
| 1836 | db_setting_inop_rhs() |
| 1837 | ); |
| 1838 | g.eHashPolicy = db_get_int("hash-policy", g.eHashPolicy); |
| 1839 | db_multi_exec( |
| 1840 | "REPLACE INTO reportfmt SELECT * FROM settingSrc.reportfmt;" |
| 1841 | ); |
| 1842 | |
| 1843 | /* |
| @@ -1927,12 +1928,10 @@ | |
| 1928 | |
| 1929 | |
| 1930 | zTemplate = find_option("template",0,1); |
| 1931 | zDate = find_option("date-override",0,1); |
| 1932 | zDefaultUser = find_option("admin-user","A",1); |
| 1933 | /* We should be done with options.. */ |
| 1934 | verify_all_options(); |
| 1935 | |
| 1936 | if( g.argc!=3 ){ |
| 1937 | usage("REPOSITORY-NAME"); |
| @@ -1945,12 +1944,10 @@ | |
| 1944 | db_create_repository(g.argv[2]); |
| 1945 | db_open_repository(g.argv[2]); |
| 1946 | db_open_config(0, 0); |
| 1947 | if( zTemplate ) db_attach(zTemplate, "settingSrc"); |
| 1948 | db_begin_transaction(); |
| 1949 | if( zDate==0 ) zDate = "now"; |
| 1950 | db_initial_setup(zTemplate, zDate, zDefaultUser); |
| 1951 | db_end_transaction(0); |
| 1952 | if( zTemplate ) db_detach("settingSrc"); |
| 1953 | fossil_print("project-id: %s\n", db_get("project-code", 0)); |
| 1954 |
+13
-4
| --- src/hname.c | ||
| +++ src/hname.c | ||
| @@ -198,19 +198,22 @@ | ||
| 198 | 198 | |
| 199 | 199 | /* |
| 200 | 200 | ** Return the default hash policy for repositories that do not currently |
| 201 | 201 | ** have an assigned hash policy. |
| 202 | 202 | ** |
| 203 | -** Make the default HPOLICY_AUTO if there are no SHA3 artifacts in the | |
| 204 | -** repository, and make the default HPOLICY_SHA3 if there are one or more | |
| 205 | -** SHA3 artifacts. | |
| 203 | +** Make the default HPOLICY_AUTO if there are SHA1 artficats but no SHA3 | |
| 204 | +** artifacts in the repository. Make the default HPOLICY_SHA3 if there | |
| 205 | +** are one or more SHA3 artifacts. Make the default policy HPOLICY_SHUN_SHA1 | |
| 206 | +** if the repository contains no artifact at all. | |
| 206 | 207 | */ |
| 207 | 208 | int hname_default_policy(void){ |
| 208 | 209 | if( db_exists("SELECT 1 FROM blob WHERE length(uuid)>40") ){ |
| 209 | 210 | return HPOLICY_SHA3; |
| 210 | - }else{ | |
| 211 | + }else if( db_exists("SELECT 1 FROM blob WHERE length(uuid)==40") ){ | |
| 211 | 212 | return HPOLICY_AUTO; |
| 213 | + }else{ | |
| 214 | + return HPOLICY_SHUN_SHA1; | |
| 212 | 215 | } |
| 213 | 216 | } |
| 214 | 217 | |
| 215 | 218 | /* |
| 216 | 219 | ** COMMAND: hash-policy* |
| @@ -252,13 +255,19 @@ | ||
| 252 | 255 | fossil_print("%s\n", azPolicy[g.eHashPolicy]); |
| 253 | 256 | return; |
| 254 | 257 | } |
| 255 | 258 | for(i=HPOLICY_SHA1; i<=HPOLICY_SHUN_SHA1; i++){ |
| 256 | 259 | if( fossil_strcmp(g.argv[2],azPolicy[i])==0 ){ |
| 260 | + if( i==HPOLICY_AUTO | |
| 261 | + && db_exists("SELECT 1 FROM blob WHERE length(uuid)>40") | |
| 262 | + ){ | |
| 263 | + i = HPOLICY_SHA3; | |
| 264 | + } | |
| 257 | 265 | g.eHashPolicy = i; |
| 258 | 266 | db_set_int("hash-policy", i, 0); |
| 267 | + fossil_print("%s\n", azPolicy[i]); | |
| 259 | 268 | return; |
| 260 | 269 | } |
| 261 | 270 | } |
| 262 | 271 | fossil_fatal("unknown hash policy \"%s\" - should be one of: sha1 auto" |
| 263 | 272 | " sha3 sha3-only shun-sha1", g.argv[2]); |
| 264 | 273 | } |
| 265 | 274 |
| --- src/hname.c | |
| +++ src/hname.c | |
| @@ -198,19 +198,22 @@ | |
| 198 | |
| 199 | /* |
| 200 | ** Return the default hash policy for repositories that do not currently |
| 201 | ** have an assigned hash policy. |
| 202 | ** |
| 203 | ** Make the default HPOLICY_AUTO if there are no SHA3 artifacts in the |
| 204 | ** repository, and make the default HPOLICY_SHA3 if there are one or more |
| 205 | ** SHA3 artifacts. |
| 206 | */ |
| 207 | int hname_default_policy(void){ |
| 208 | if( db_exists("SELECT 1 FROM blob WHERE length(uuid)>40") ){ |
| 209 | return HPOLICY_SHA3; |
| 210 | }else{ |
| 211 | return HPOLICY_AUTO; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | /* |
| 216 | ** COMMAND: hash-policy* |
| @@ -252,13 +255,19 @@ | |
| 252 | fossil_print("%s\n", azPolicy[g.eHashPolicy]); |
| 253 | return; |
| 254 | } |
| 255 | for(i=HPOLICY_SHA1; i<=HPOLICY_SHUN_SHA1; i++){ |
| 256 | if( fossil_strcmp(g.argv[2],azPolicy[i])==0 ){ |
| 257 | g.eHashPolicy = i; |
| 258 | db_set_int("hash-policy", i, 0); |
| 259 | return; |
| 260 | } |
| 261 | } |
| 262 | fossil_fatal("unknown hash policy \"%s\" - should be one of: sha1 auto" |
| 263 | " sha3 sha3-only shun-sha1", g.argv[2]); |
| 264 | } |
| 265 |
| --- src/hname.c | |
| +++ src/hname.c | |
| @@ -198,19 +198,22 @@ | |
| 198 | |
| 199 | /* |
| 200 | ** Return the default hash policy for repositories that do not currently |
| 201 | ** have an assigned hash policy. |
| 202 | ** |
| 203 | ** Make the default HPOLICY_AUTO if there are SHA1 artficats but no SHA3 |
| 204 | ** artifacts in the repository. Make the default HPOLICY_SHA3 if there |
| 205 | ** are one or more SHA3 artifacts. Make the default policy HPOLICY_SHUN_SHA1 |
| 206 | ** if the repository contains no artifact at all. |
| 207 | */ |
| 208 | int hname_default_policy(void){ |
| 209 | if( db_exists("SELECT 1 FROM blob WHERE length(uuid)>40") ){ |
| 210 | return HPOLICY_SHA3; |
| 211 | }else if( db_exists("SELECT 1 FROM blob WHERE length(uuid)==40") ){ |
| 212 | return HPOLICY_AUTO; |
| 213 | }else{ |
| 214 | return HPOLICY_SHUN_SHA1; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /* |
| 219 | ** COMMAND: hash-policy* |
| @@ -252,13 +255,19 @@ | |
| 255 | fossil_print("%s\n", azPolicy[g.eHashPolicy]); |
| 256 | return; |
| 257 | } |
| 258 | for(i=HPOLICY_SHA1; i<=HPOLICY_SHUN_SHA1; i++){ |
| 259 | if( fossil_strcmp(g.argv[2],azPolicy[i])==0 ){ |
| 260 | if( i==HPOLICY_AUTO |
| 261 | && db_exists("SELECT 1 FROM blob WHERE length(uuid)>40") |
| 262 | ){ |
| 263 | i = HPOLICY_SHA3; |
| 264 | } |
| 265 | g.eHashPolicy = i; |
| 266 | db_set_int("hash-policy", i, 0); |
| 267 | fossil_print("%s\n", azPolicy[i]); |
| 268 | return; |
| 269 | } |
| 270 | } |
| 271 | fossil_fatal("unknown hash policy \"%s\" - should be one of: sha1 auto" |
| 272 | " sha3 sha3-only shun-sha1", g.argv[2]); |
| 273 | } |
| 274 |