| | @@ -989,10 +989,36 @@ |
| 989 | 989 | "synchronous requests are not yet implemented", 0, 0); |
| 990 | 990 | blob_reset(&payload); |
| 991 | 991 | return TH_ERROR; |
| 992 | 992 | } |
| 993 | 993 | } |
| 994 | + |
| 995 | +/* |
| 996 | +** Attempts to open the configuration ("user") database. Optionally, also |
| 997 | +** attempts to try to find the repository and open it. |
| 998 | +*/ |
| 999 | +void Th_OpenConfig( |
| 1000 | + int openRepository |
| 1001 | +){ |
| 1002 | + if( openRepository ){ |
| 1003 | + db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0); |
| 1004 | + } |
| 1005 | + db_open_config(0); |
| 1006 | +} |
| 1007 | + |
| 1008 | +/* |
| 1009 | +** Attempts to close the configuration ("user") database. Optionally, also |
| 1010 | +** attempts to close the repository. |
| 1011 | +*/ |
| 1012 | +void Th_CloseConfig( |
| 1013 | + int closeRepository |
| 1014 | +){ |
| 1015 | + db_close_config(); |
| 1016 | + if( closeRepository ){ |
| 1017 | + db_close(1); |
| 1018 | + } |
| 1019 | +} |
| 994 | 1020 | |
| 995 | 1021 | /* |
| 996 | 1022 | ** Make sure the interpreter has been initialized. Initialize it if |
| 997 | 1023 | ** it has not been already. |
| 998 | 1024 | ** |
| | @@ -1039,12 +1065,11 @@ |
| 1039 | 1065 | ** This function uses several settings which may be defined in the |
| 1040 | 1066 | ** repository and/or the global configuration. Since the caller |
| 1041 | 1067 | ** passed a non-zero value for the needConfig parameter, make sure |
| 1042 | 1068 | ** the necessary database connections are open prior to continuing. |
| 1043 | 1069 | */ |
| 1044 | | - db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0); |
| 1045 | | - db_open_config(0); |
| 1070 | + Th_OpenConfig(1); |
| 1046 | 1071 | } |
| 1047 | 1072 | if( forceReset || forceTcl || g.interp==0 ){ |
| 1048 | 1073 | int created = 0; |
| 1049 | 1074 | int i; |
| 1050 | 1075 | if( g.interp==0 ){ |
| | @@ -1235,14 +1260,16 @@ |
| 1235 | 1260 | int Th_CommandHook( |
| 1236 | 1261 | const char *zName, |
| 1237 | 1262 | char cmdFlags |
| 1238 | 1263 | ){ |
| 1239 | 1264 | int rc = TH_OK; |
| 1240 | | - Th_FossilInit(TH_INIT_HOOK); |
| 1265 | + Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */ |
| 1241 | 1266 | if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){ |
| 1242 | 1267 | return rc; |
| 1243 | 1268 | } |
| 1269 | + Th_CloseConfig(0); |
| 1270 | + Th_FossilInit(TH_INIT_HOOK); |
| 1244 | 1271 | Th_Store("cmd_name", zName); |
| 1245 | 1272 | Th_StoreList("cmd_args", g.argv, g.argc); |
| 1246 | 1273 | Th_StoreInt("cmd_flags", cmdFlags); |
| 1247 | 1274 | rc = Th_Eval(g.interp, 0, "command_hook", -1); |
| 1248 | 1275 | if( rc==TH_ERROR ){ |
| | @@ -1280,14 +1307,16 @@ |
| 1280 | 1307 | int Th_CommandNotify( |
| 1281 | 1308 | const char *zName, |
| 1282 | 1309 | char cmdFlags |
| 1283 | 1310 | ){ |
| 1284 | 1311 | int rc = TH_OK; |
| 1285 | | - Th_FossilInit(TH_INIT_HOOK); |
| 1312 | + Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */ |
| 1286 | 1313 | if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){ |
| 1287 | 1314 | return rc; |
| 1288 | 1315 | } |
| 1316 | + Th_CloseConfig(0); |
| 1317 | + Th_FossilInit(TH_INIT_HOOK); |
| 1289 | 1318 | Th_Store("cmd_name", zName); |
| 1290 | 1319 | Th_StoreList("cmd_args", g.argv, g.argc); |
| 1291 | 1320 | Th_StoreInt("cmd_flags", cmdFlags); |
| 1292 | 1321 | rc = Th_Eval(g.interp, 0, "command_notify", -1); |
| 1293 | 1322 | if( g.thTrace ){ |
| | @@ -1306,14 +1335,16 @@ |
| 1306 | 1335 | int Th_WebpageHook( |
| 1307 | 1336 | const char *zName, |
| 1308 | 1337 | char cmdFlags |
| 1309 | 1338 | ){ |
| 1310 | 1339 | int rc = TH_OK; |
| 1311 | | - Th_FossilInit(TH_INIT_HOOK); |
| 1340 | + Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */ |
| 1312 | 1341 | if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){ |
| 1313 | 1342 | return rc; |
| 1314 | 1343 | } |
| 1344 | + Th_CloseConfig(0); |
| 1345 | + Th_FossilInit(TH_INIT_HOOK); |
| 1315 | 1346 | Th_Store("web_name", zName); |
| 1316 | 1347 | Th_StoreList("web_args", g.argv, g.argc); |
| 1317 | 1348 | Th_StoreInt("web_flags", cmdFlags); |
| 1318 | 1349 | rc = Th_Eval(g.interp, 0, "webpage_hook", -1); |
| 1319 | 1350 | if( rc==TH_ERROR ){ |
| | @@ -1351,14 +1382,16 @@ |
| 1351 | 1382 | int Th_WebpageNotify( |
| 1352 | 1383 | const char *zName, |
| 1353 | 1384 | char cmdFlags |
| 1354 | 1385 | ){ |
| 1355 | 1386 | int rc = TH_OK; |
| 1356 | | - Th_FossilInit(TH_INIT_HOOK); |
| 1387 | + Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */ |
| 1357 | 1388 | if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){ |
| 1358 | 1389 | return rc; |
| 1359 | 1390 | } |
| 1391 | + Th_CloseConfig(0); |
| 1392 | + Th_FossilInit(TH_INIT_HOOK); |
| 1360 | 1393 | Th_Store("web_name", zName); |
| 1361 | 1394 | Th_StoreList("web_args", g.argv, g.argc); |
| 1362 | 1395 | Th_StoreInt("web_flags", cmdFlags); |
| 1363 | 1396 | rc = Th_Eval(g.interp, 0, "webpage_notify", -1); |
| 1364 | 1397 | if( g.thTrace ){ |
| | @@ -1436,12 +1469,11 @@ |
| 1436 | 1469 | */ |
| 1437 | 1470 | void test_th_render(void){ |
| 1438 | 1471 | Blob in; |
| 1439 | 1472 | Th_InitTraceLog(); |
| 1440 | 1473 | if( find_option("th-open-config", 0, 0)!=0 ){ |
| 1441 | | - db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0); |
| 1442 | | - db_open_config(0); |
| 1474 | + Th_OpenConfig(1); |
| 1443 | 1475 | } |
| 1444 | 1476 | if( g.argc<3 ){ |
| 1445 | 1477 | usage("FILE"); |
| 1446 | 1478 | } |
| 1447 | 1479 | blob_zero(&in); |
| | @@ -1456,12 +1488,11 @@ |
| 1456 | 1488 | void test_th_eval(void){ |
| 1457 | 1489 | int rc; |
| 1458 | 1490 | const char *zRc; |
| 1459 | 1491 | Th_InitTraceLog(); |
| 1460 | 1492 | if( find_option("th-open-config", 0, 0)!=0 ){ |
| 1461 | | - db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0); |
| 1462 | | - db_open_config(0); |
| 1493 | + Th_OpenConfig(1); |
| 1463 | 1494 | } |
| 1464 | 1495 | if( g.argc!=3 ){ |
| 1465 | 1496 | usage("script"); |
| 1466 | 1497 | } |
| 1467 | 1498 | Th_FossilInit(TH_INIT_DEFAULT); |
| 1468 | 1499 | |