Fossil SCM
Centralize the handling of opening the configuration database and repository on behalf of TH1.
Commit
9773eba5fe037b50e97465dd0dae834d4b796c0a
Parent
a17919af857c35b…
1 file changed
+16
-6
+16
-6
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -971,10 +971,23 @@ | ||
| 971 | 971 | "synchronous requests are not yet implemented", 0, 0); |
| 972 | 972 | blob_reset(&payload); |
| 973 | 973 | return TH_ERROR; |
| 974 | 974 | } |
| 975 | 975 | } |
| 976 | + | |
| 977 | +/* | |
| 978 | +** Attempts to open the configuration ("user") database. Optionally, also | |
| 979 | +** attempts to try to find the repository and open it. | |
| 980 | +*/ | |
| 981 | +void Th_OpenConfig( | |
| 982 | + int openRepository | |
| 983 | +){ | |
| 984 | + if( openRepository ){ | |
| 985 | + db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0); | |
| 986 | + } | |
| 987 | + db_open_config(0); | |
| 988 | +} | |
| 976 | 989 | |
| 977 | 990 | /* |
| 978 | 991 | ** Make sure the interpreter has been initialized. Initialize it if |
| 979 | 992 | ** it has not been already. |
| 980 | 993 | ** |
| @@ -1021,12 +1034,11 @@ | ||
| 1021 | 1034 | ** This function uses several settings which may be defined in the |
| 1022 | 1035 | ** repository and/or the global configuration. Since the caller |
| 1023 | 1036 | ** passed a non-zero value for the needConfig parameter, make sure |
| 1024 | 1037 | ** the necessary database connections are open prior to continuing. |
| 1025 | 1038 | */ |
| 1026 | - db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0); | |
| 1027 | - db_open_config(0); | |
| 1039 | + Th_OpenConfig(1); | |
| 1028 | 1040 | } |
| 1029 | 1041 | if( forceReset || forceTcl || g.interp==0 ){ |
| 1030 | 1042 | int created = 0; |
| 1031 | 1043 | int i; |
| 1032 | 1044 | if( g.interp==0 ){ |
| @@ -1250,12 +1262,11 @@ | ||
| 1250 | 1262 | */ |
| 1251 | 1263 | void test_th_render(void){ |
| 1252 | 1264 | Blob in; |
| 1253 | 1265 | Th_InitTraceLog(); |
| 1254 | 1266 | if( find_option("th-open-config", 0, 0)!=0 ){ |
| 1255 | - db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0); | |
| 1256 | - db_open_config(0); | |
| 1267 | + Th_OpenConfig(1); | |
| 1257 | 1268 | } |
| 1258 | 1269 | if( g.argc<3 ){ |
| 1259 | 1270 | usage("FILE"); |
| 1260 | 1271 | } |
| 1261 | 1272 | blob_zero(&in); |
| @@ -1270,12 +1281,11 @@ | ||
| 1270 | 1281 | void test_th_eval(void){ |
| 1271 | 1282 | int rc; |
| 1272 | 1283 | const char *zRc; |
| 1273 | 1284 | Th_InitTraceLog(); |
| 1274 | 1285 | if( find_option("th-open-config", 0, 0)!=0 ){ |
| 1275 | - db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0); | |
| 1276 | - db_open_config(0); | |
| 1286 | + Th_OpenConfig(1); | |
| 1277 | 1287 | } |
| 1278 | 1288 | if( g.argc!=3 ){ |
| 1279 | 1289 | usage("script"); |
| 1280 | 1290 | } |
| 1281 | 1291 | Th_FossilInit(TH_INIT_DEFAULT); |
| 1282 | 1292 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -971,10 +971,23 @@ | |
| 971 | "synchronous requests are not yet implemented", 0, 0); |
| 972 | blob_reset(&payload); |
| 973 | return TH_ERROR; |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | /* |
| 978 | ** Make sure the interpreter has been initialized. Initialize it if |
| 979 | ** it has not been already. |
| 980 | ** |
| @@ -1021,12 +1034,11 @@ | |
| 1021 | ** This function uses several settings which may be defined in the |
| 1022 | ** repository and/or the global configuration. Since the caller |
| 1023 | ** passed a non-zero value for the needConfig parameter, make sure |
| 1024 | ** the necessary database connections are open prior to continuing. |
| 1025 | */ |
| 1026 | db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0); |
| 1027 | db_open_config(0); |
| 1028 | } |
| 1029 | if( forceReset || forceTcl || g.interp==0 ){ |
| 1030 | int created = 0; |
| 1031 | int i; |
| 1032 | if( g.interp==0 ){ |
| @@ -1250,12 +1262,11 @@ | |
| 1250 | */ |
| 1251 | void test_th_render(void){ |
| 1252 | Blob in; |
| 1253 | Th_InitTraceLog(); |
| 1254 | if( find_option("th-open-config", 0, 0)!=0 ){ |
| 1255 | db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0); |
| 1256 | db_open_config(0); |
| 1257 | } |
| 1258 | if( g.argc<3 ){ |
| 1259 | usage("FILE"); |
| 1260 | } |
| 1261 | blob_zero(&in); |
| @@ -1270,12 +1281,11 @@ | |
| 1270 | void test_th_eval(void){ |
| 1271 | int rc; |
| 1272 | const char *zRc; |
| 1273 | Th_InitTraceLog(); |
| 1274 | if( find_option("th-open-config", 0, 0)!=0 ){ |
| 1275 | db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0); |
| 1276 | db_open_config(0); |
| 1277 | } |
| 1278 | if( g.argc!=3 ){ |
| 1279 | usage("script"); |
| 1280 | } |
| 1281 | Th_FossilInit(TH_INIT_DEFAULT); |
| 1282 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -971,10 +971,23 @@ | |
| 971 | "synchronous requests are not yet implemented", 0, 0); |
| 972 | blob_reset(&payload); |
| 973 | return TH_ERROR; |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | /* |
| 978 | ** Attempts to open the configuration ("user") database. Optionally, also |
| 979 | ** attempts to try to find the repository and open it. |
| 980 | */ |
| 981 | void Th_OpenConfig( |
| 982 | int openRepository |
| 983 | ){ |
| 984 | if( openRepository ){ |
| 985 | db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0); |
| 986 | } |
| 987 | db_open_config(0); |
| 988 | } |
| 989 | |
| 990 | /* |
| 991 | ** Make sure the interpreter has been initialized. Initialize it if |
| 992 | ** it has not been already. |
| 993 | ** |
| @@ -1021,12 +1034,11 @@ | |
| 1034 | ** This function uses several settings which may be defined in the |
| 1035 | ** repository and/or the global configuration. Since the caller |
| 1036 | ** passed a non-zero value for the needConfig parameter, make sure |
| 1037 | ** the necessary database connections are open prior to continuing. |
| 1038 | */ |
| 1039 | Th_OpenConfig(1); |
| 1040 | } |
| 1041 | if( forceReset || forceTcl || g.interp==0 ){ |
| 1042 | int created = 0; |
| 1043 | int i; |
| 1044 | if( g.interp==0 ){ |
| @@ -1250,12 +1262,11 @@ | |
| 1262 | */ |
| 1263 | void test_th_render(void){ |
| 1264 | Blob in; |
| 1265 | Th_InitTraceLog(); |
| 1266 | if( find_option("th-open-config", 0, 0)!=0 ){ |
| 1267 | Th_OpenConfig(1); |
| 1268 | } |
| 1269 | if( g.argc<3 ){ |
| 1270 | usage("FILE"); |
| 1271 | } |
| 1272 | blob_zero(&in); |
| @@ -1270,12 +1281,11 @@ | |
| 1281 | void test_th_eval(void){ |
| 1282 | int rc; |
| 1283 | const char *zRc; |
| 1284 | Th_InitTraceLog(); |
| 1285 | if( find_option("th-open-config", 0, 0)!=0 ){ |
| 1286 | Th_OpenConfig(1); |
| 1287 | } |
| 1288 | if( g.argc!=3 ){ |
| 1289 | usage("script"); |
| 1290 | } |
| 1291 | Th_FossilInit(TH_INIT_DEFAULT); |
| 1292 |