Fossil SCM

Improvements to handling of the configuration database.

mistachkin 2014-06-11 01:23 UTC th1Hooks merge
Commit 79533e2b31ec5bd9fd00b0c0e10c14c4a6615a6c
4 files changed +22 -12 +22 -12 +41 -10 +41 -10
+22 -12
--- src/db.c
+++ src/db.c
@@ -785,10 +785,31 @@
785785
assert( g.zMainDbType!=0 );
786786
db_attach(zDbName, zLabel);
787787
if( pWasAttached ) *pWasAttached = 1;
788788
}
789789
}
790
+
791
+/*
792
+** Close the user database.
793
+*/
794
+void db_close_config(){
795
+ if( g.useAttach ){
796
+ db_detach("configdb");
797
+ g.useAttach = 0;
798
+ g.zConfigDbName = 0;
799
+ }else if( g.dbConfig ){
800
+ sqlite3_close(g.dbConfig);
801
+ g.dbConfig = 0;
802
+ g.zConfigDbType = 0;
803
+ g.zConfigDbName = 0;
804
+ }else if( g.db && fossil_strcmp(g.zMainDbType, "configdb")==0 ){
805
+ sqlite3_close(g.db);
806
+ g.db = 0;
807
+ g.zMainDbType = 0;
808
+ g.zConfigDbName = 0;
809
+ }
810
+}
790811
791812
/*
792813
** Open the user database in "~/.fossil". Create the database anew if
793814
** it does not already exist.
794815
**
@@ -803,22 +824,11 @@
803824
void db_open_config(int useAttach){
804825
char *zDbName;
805826
char *zHome;
806827
if( g.zConfigDbName ){
807828
if( useAttach==g.useAttach ) return;
808
- if( g.useAttach ){
809
- db_detach("configdb");
810
- g.useAttach = 0;
811
- }else if( g.dbConfig ){
812
- sqlite3_close(g.dbConfig);
813
- g.dbConfig = 0;
814
- g.zConfigDbType = 0;
815
- }else if( g.db ){
816
- sqlite3_close(g.db);
817
- g.db = 0;
818
- g.zMainDbType = 0;
819
- }
829
+ db_close_config();
820830
}
821831
#if defined(_WIN32) || defined(__CYGWIN__)
822832
zHome = fossil_getenv("LOCALAPPDATA");
823833
if( zHome==0 ){
824834
zHome = fossil_getenv("APPDATA");
825835
--- src/db.c
+++ src/db.c
@@ -785,10 +785,31 @@
785 assert( g.zMainDbType!=0 );
786 db_attach(zDbName, zLabel);
787 if( pWasAttached ) *pWasAttached = 1;
788 }
789 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
790
791 /*
792 ** Open the user database in "~/.fossil". Create the database anew if
793 ** it does not already exist.
794 **
@@ -803,22 +824,11 @@
803 void db_open_config(int useAttach){
804 char *zDbName;
805 char *zHome;
806 if( g.zConfigDbName ){
807 if( useAttach==g.useAttach ) return;
808 if( g.useAttach ){
809 db_detach("configdb");
810 g.useAttach = 0;
811 }else if( g.dbConfig ){
812 sqlite3_close(g.dbConfig);
813 g.dbConfig = 0;
814 g.zConfigDbType = 0;
815 }else if( g.db ){
816 sqlite3_close(g.db);
817 g.db = 0;
818 g.zMainDbType = 0;
819 }
820 }
821 #if defined(_WIN32) || defined(__CYGWIN__)
822 zHome = fossil_getenv("LOCALAPPDATA");
823 if( zHome==0 ){
824 zHome = fossil_getenv("APPDATA");
825
--- src/db.c
+++ src/db.c
@@ -785,10 +785,31 @@
785 assert( g.zMainDbType!=0 );
786 db_attach(zDbName, zLabel);
787 if( pWasAttached ) *pWasAttached = 1;
788 }
789 }
790
791 /*
792 ** Close the user database.
793 */
794 void db_close_config(){
795 if( g.useAttach ){
796 db_detach("configdb");
797 g.useAttach = 0;
798 g.zConfigDbName = 0;
799 }else if( g.dbConfig ){
800 sqlite3_close(g.dbConfig);
801 g.dbConfig = 0;
802 g.zConfigDbType = 0;
803 g.zConfigDbName = 0;
804 }else if( g.db && fossil_strcmp(g.zMainDbType, "configdb")==0 ){
805 sqlite3_close(g.db);
806 g.db = 0;
807 g.zMainDbType = 0;
808 g.zConfigDbName = 0;
809 }
810 }
811
812 /*
813 ** Open the user database in "~/.fossil". Create the database anew if
814 ** it does not already exist.
815 **
@@ -803,22 +824,11 @@
824 void db_open_config(int useAttach){
825 char *zDbName;
826 char *zHome;
827 if( g.zConfigDbName ){
828 if( useAttach==g.useAttach ) return;
829 db_close_config();
 
 
 
 
 
 
 
 
 
 
 
830 }
831 #if defined(_WIN32) || defined(__CYGWIN__)
832 zHome = fossil_getenv("LOCALAPPDATA");
833 if( zHome==0 ){
834 zHome = fossil_getenv("APPDATA");
835
+22 -12
--- src/db.c
+++ src/db.c
@@ -785,10 +785,31 @@
785785
assert( g.zMainDbType!=0 );
786786
db_attach(zDbName, zLabel);
787787
if( pWasAttached ) *pWasAttached = 1;
788788
}
789789
}
790
+
791
+/*
792
+** Close the user database.
793
+*/
794
+void db_close_config(){
795
+ if( g.useAttach ){
796
+ db_detach("configdb");
797
+ g.useAttach = 0;
798
+ g.zConfigDbName = 0;
799
+ }else if( g.dbConfig ){
800
+ sqlite3_close(g.dbConfig);
801
+ g.dbConfig = 0;
802
+ g.zConfigDbType = 0;
803
+ g.zConfigDbName = 0;
804
+ }else if( g.db && fossil_strcmp(g.zMainDbType, "configdb")==0 ){
805
+ sqlite3_close(g.db);
806
+ g.db = 0;
807
+ g.zMainDbType = 0;
808
+ g.zConfigDbName = 0;
809
+ }
810
+}
790811
791812
/*
792813
** Open the user database in "~/.fossil". Create the database anew if
793814
** it does not already exist.
794815
**
@@ -803,22 +824,11 @@
803824
void db_open_config(int useAttach){
804825
char *zDbName;
805826
char *zHome;
806827
if( g.zConfigDbName ){
807828
if( useAttach==g.useAttach ) return;
808
- if( g.useAttach ){
809
- db_detach("configdb");
810
- g.useAttach = 0;
811
- }else if( g.dbConfig ){
812
- sqlite3_close(g.dbConfig);
813
- g.dbConfig = 0;
814
- g.zConfigDbType = 0;
815
- }else if( g.db ){
816
- sqlite3_close(g.db);
817
- g.db = 0;
818
- g.zMainDbType = 0;
819
- }
829
+ db_close_config();
820830
}
821831
#if defined(_WIN32) || defined(__CYGWIN__)
822832
zHome = fossil_getenv("LOCALAPPDATA");
823833
if( zHome==0 ){
824834
zHome = fossil_getenv("APPDATA");
825835
--- src/db.c
+++ src/db.c
@@ -785,10 +785,31 @@
785 assert( g.zMainDbType!=0 );
786 db_attach(zDbName, zLabel);
787 if( pWasAttached ) *pWasAttached = 1;
788 }
789 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
790
791 /*
792 ** Open the user database in "~/.fossil". Create the database anew if
793 ** it does not already exist.
794 **
@@ -803,22 +824,11 @@
803 void db_open_config(int useAttach){
804 char *zDbName;
805 char *zHome;
806 if( g.zConfigDbName ){
807 if( useAttach==g.useAttach ) return;
808 if( g.useAttach ){
809 db_detach("configdb");
810 g.useAttach = 0;
811 }else if( g.dbConfig ){
812 sqlite3_close(g.dbConfig);
813 g.dbConfig = 0;
814 g.zConfigDbType = 0;
815 }else if( g.db ){
816 sqlite3_close(g.db);
817 g.db = 0;
818 g.zMainDbType = 0;
819 }
820 }
821 #if defined(_WIN32) || defined(__CYGWIN__)
822 zHome = fossil_getenv("LOCALAPPDATA");
823 if( zHome==0 ){
824 zHome = fossil_getenv("APPDATA");
825
--- src/db.c
+++ src/db.c
@@ -785,10 +785,31 @@
785 assert( g.zMainDbType!=0 );
786 db_attach(zDbName, zLabel);
787 if( pWasAttached ) *pWasAttached = 1;
788 }
789 }
790
791 /*
792 ** Close the user database.
793 */
794 void db_close_config(){
795 if( g.useAttach ){
796 db_detach("configdb");
797 g.useAttach = 0;
798 g.zConfigDbName = 0;
799 }else if( g.dbConfig ){
800 sqlite3_close(g.dbConfig);
801 g.dbConfig = 0;
802 g.zConfigDbType = 0;
803 g.zConfigDbName = 0;
804 }else if( g.db && fossil_strcmp(g.zMainDbType, "configdb")==0 ){
805 sqlite3_close(g.db);
806 g.db = 0;
807 g.zMainDbType = 0;
808 g.zConfigDbName = 0;
809 }
810 }
811
812 /*
813 ** Open the user database in "~/.fossil". Create the database anew if
814 ** it does not already exist.
815 **
@@ -803,22 +824,11 @@
824 void db_open_config(int useAttach){
825 char *zDbName;
826 char *zHome;
827 if( g.zConfigDbName ){
828 if( useAttach==g.useAttach ) return;
829 db_close_config();
 
 
 
 
 
 
 
 
 
 
 
830 }
831 #if defined(_WIN32) || defined(__CYGWIN__)
832 zHome = fossil_getenv("LOCALAPPDATA");
833 if( zHome==0 ){
834 zHome = fossil_getenv("APPDATA");
835
+41 -10
--- src/th_main.c
+++ src/th_main.c
@@ -989,10 +989,36 @@
989989
"synchronous requests are not yet implemented", 0, 0);
990990
blob_reset(&payload);
991991
return TH_ERROR;
992992
}
993993
}
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
+}
9941020
9951021
/*
9961022
** Make sure the interpreter has been initialized. Initialize it if
9971023
** it has not been already.
9981024
**
@@ -1039,12 +1065,11 @@
10391065
** This function uses several settings which may be defined in the
10401066
** repository and/or the global configuration. Since the caller
10411067
** passed a non-zero value for the needConfig parameter, make sure
10421068
** the necessary database connections are open prior to continuing.
10431069
*/
1044
- db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0);
1045
- db_open_config(0);
1070
+ Th_OpenConfig(1);
10461071
}
10471072
if( forceReset || forceTcl || g.interp==0 ){
10481073
int created = 0;
10491074
int i;
10501075
if( g.interp==0 ){
@@ -1235,14 +1260,16 @@
12351260
int Th_CommandHook(
12361261
const char *zName,
12371262
char cmdFlags
12381263
){
12391264
int rc = TH_OK;
1240
- Th_FossilInit(TH_INIT_HOOK);
1265
+ Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
12411266
if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
12421267
return rc;
12431268
}
1269
+ Th_CloseConfig(0);
1270
+ Th_FossilInit(TH_INIT_HOOK);
12441271
Th_Store("cmd_name", zName);
12451272
Th_StoreList("cmd_args", g.argv, g.argc);
12461273
Th_StoreInt("cmd_flags", cmdFlags);
12471274
rc = Th_Eval(g.interp, 0, "command_hook", -1);
12481275
if( rc==TH_ERROR ){
@@ -1280,14 +1307,16 @@
12801307
int Th_CommandNotify(
12811308
const char *zName,
12821309
char cmdFlags
12831310
){
12841311
int rc = TH_OK;
1285
- Th_FossilInit(TH_INIT_HOOK);
1312
+ Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
12861313
if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
12871314
return rc;
12881315
}
1316
+ Th_CloseConfig(0);
1317
+ Th_FossilInit(TH_INIT_HOOK);
12891318
Th_Store("cmd_name", zName);
12901319
Th_StoreList("cmd_args", g.argv, g.argc);
12911320
Th_StoreInt("cmd_flags", cmdFlags);
12921321
rc = Th_Eval(g.interp, 0, "command_notify", -1);
12931322
if( g.thTrace ){
@@ -1306,14 +1335,16 @@
13061335
int Th_WebpageHook(
13071336
const char *zName,
13081337
char cmdFlags
13091338
){
13101339
int rc = TH_OK;
1311
- Th_FossilInit(TH_INIT_HOOK);
1340
+ Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
13121341
if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
13131342
return rc;
13141343
}
1344
+ Th_CloseConfig(0);
1345
+ Th_FossilInit(TH_INIT_HOOK);
13151346
Th_Store("web_name", zName);
13161347
Th_StoreList("web_args", g.argv, g.argc);
13171348
Th_StoreInt("web_flags", cmdFlags);
13181349
rc = Th_Eval(g.interp, 0, "webpage_hook", -1);
13191350
if( rc==TH_ERROR ){
@@ -1351,14 +1382,16 @@
13511382
int Th_WebpageNotify(
13521383
const char *zName,
13531384
char cmdFlags
13541385
){
13551386
int rc = TH_OK;
1356
- Th_FossilInit(TH_INIT_HOOK);
1387
+ Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
13571388
if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
13581389
return rc;
13591390
}
1391
+ Th_CloseConfig(0);
1392
+ Th_FossilInit(TH_INIT_HOOK);
13601393
Th_Store("web_name", zName);
13611394
Th_StoreList("web_args", g.argv, g.argc);
13621395
Th_StoreInt("web_flags", cmdFlags);
13631396
rc = Th_Eval(g.interp, 0, "webpage_notify", -1);
13641397
if( g.thTrace ){
@@ -1436,12 +1469,11 @@
14361469
*/
14371470
void test_th_render(void){
14381471
Blob in;
14391472
Th_InitTraceLog();
14401473
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);
14431475
}
14441476
if( g.argc<3 ){
14451477
usage("FILE");
14461478
}
14471479
blob_zero(&in);
@@ -1456,12 +1488,11 @@
14561488
void test_th_eval(void){
14571489
int rc;
14581490
const char *zRc;
14591491
Th_InitTraceLog();
14601492
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);
14631494
}
14641495
if( g.argc!=3 ){
14651496
usage("script");
14661497
}
14671498
Th_FossilInit(TH_INIT_DEFAULT);
14681499
--- src/th_main.c
+++ src/th_main.c
@@ -989,10 +989,36 @@
989 "synchronous requests are not yet implemented", 0, 0);
990 blob_reset(&payload);
991 return TH_ERROR;
992 }
993 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
994
995 /*
996 ** Make sure the interpreter has been initialized. Initialize it if
997 ** it has not been already.
998 **
@@ -1039,12 +1065,11 @@
1039 ** This function uses several settings which may be defined in the
1040 ** repository and/or the global configuration. Since the caller
1041 ** passed a non-zero value for the needConfig parameter, make sure
1042 ** the necessary database connections are open prior to continuing.
1043 */
1044 db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0);
1045 db_open_config(0);
1046 }
1047 if( forceReset || forceTcl || g.interp==0 ){
1048 int created = 0;
1049 int i;
1050 if( g.interp==0 ){
@@ -1235,14 +1260,16 @@
1235 int Th_CommandHook(
1236 const char *zName,
1237 char cmdFlags
1238 ){
1239 int rc = TH_OK;
1240 Th_FossilInit(TH_INIT_HOOK);
1241 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1242 return rc;
1243 }
 
 
1244 Th_Store("cmd_name", zName);
1245 Th_StoreList("cmd_args", g.argv, g.argc);
1246 Th_StoreInt("cmd_flags", cmdFlags);
1247 rc = Th_Eval(g.interp, 0, "command_hook", -1);
1248 if( rc==TH_ERROR ){
@@ -1280,14 +1307,16 @@
1280 int Th_CommandNotify(
1281 const char *zName,
1282 char cmdFlags
1283 ){
1284 int rc = TH_OK;
1285 Th_FossilInit(TH_INIT_HOOK);
1286 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1287 return rc;
1288 }
 
 
1289 Th_Store("cmd_name", zName);
1290 Th_StoreList("cmd_args", g.argv, g.argc);
1291 Th_StoreInt("cmd_flags", cmdFlags);
1292 rc = Th_Eval(g.interp, 0, "command_notify", -1);
1293 if( g.thTrace ){
@@ -1306,14 +1335,16 @@
1306 int Th_WebpageHook(
1307 const char *zName,
1308 char cmdFlags
1309 ){
1310 int rc = TH_OK;
1311 Th_FossilInit(TH_INIT_HOOK);
1312 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1313 return rc;
1314 }
 
 
1315 Th_Store("web_name", zName);
1316 Th_StoreList("web_args", g.argv, g.argc);
1317 Th_StoreInt("web_flags", cmdFlags);
1318 rc = Th_Eval(g.interp, 0, "webpage_hook", -1);
1319 if( rc==TH_ERROR ){
@@ -1351,14 +1382,16 @@
1351 int Th_WebpageNotify(
1352 const char *zName,
1353 char cmdFlags
1354 ){
1355 int rc = TH_OK;
1356 Th_FossilInit(TH_INIT_HOOK);
1357 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1358 return rc;
1359 }
 
 
1360 Th_Store("web_name", zName);
1361 Th_StoreList("web_args", g.argv, g.argc);
1362 Th_StoreInt("web_flags", cmdFlags);
1363 rc = Th_Eval(g.interp, 0, "webpage_notify", -1);
1364 if( g.thTrace ){
@@ -1436,12 +1469,11 @@
1436 */
1437 void test_th_render(void){
1438 Blob in;
1439 Th_InitTraceLog();
1440 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);
1443 }
1444 if( g.argc<3 ){
1445 usage("FILE");
1446 }
1447 blob_zero(&in);
@@ -1456,12 +1488,11 @@
1456 void test_th_eval(void){
1457 int rc;
1458 const char *zRc;
1459 Th_InitTraceLog();
1460 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);
1463 }
1464 if( g.argc!=3 ){
1465 usage("script");
1466 }
1467 Th_FossilInit(TH_INIT_DEFAULT);
1468
--- src/th_main.c
+++ src/th_main.c
@@ -989,10 +989,36 @@
989 "synchronous requests are not yet implemented", 0, 0);
990 blob_reset(&payload);
991 return TH_ERROR;
992 }
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 }
1020
1021 /*
1022 ** Make sure the interpreter has been initialized. Initialize it if
1023 ** it has not been already.
1024 **
@@ -1039,12 +1065,11 @@
1065 ** This function uses several settings which may be defined in the
1066 ** repository and/or the global configuration. Since the caller
1067 ** passed a non-zero value for the needConfig parameter, make sure
1068 ** the necessary database connections are open prior to continuing.
1069 */
1070 Th_OpenConfig(1);
 
1071 }
1072 if( forceReset || forceTcl || g.interp==0 ){
1073 int created = 0;
1074 int i;
1075 if( g.interp==0 ){
@@ -1235,14 +1260,16 @@
1260 int Th_CommandHook(
1261 const char *zName,
1262 char cmdFlags
1263 ){
1264 int rc = TH_OK;
1265 Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
1266 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1267 return rc;
1268 }
1269 Th_CloseConfig(0);
1270 Th_FossilInit(TH_INIT_HOOK);
1271 Th_Store("cmd_name", zName);
1272 Th_StoreList("cmd_args", g.argv, g.argc);
1273 Th_StoreInt("cmd_flags", cmdFlags);
1274 rc = Th_Eval(g.interp, 0, "command_hook", -1);
1275 if( rc==TH_ERROR ){
@@ -1280,14 +1307,16 @@
1307 int Th_CommandNotify(
1308 const char *zName,
1309 char cmdFlags
1310 ){
1311 int rc = TH_OK;
1312 Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
1313 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1314 return rc;
1315 }
1316 Th_CloseConfig(0);
1317 Th_FossilInit(TH_INIT_HOOK);
1318 Th_Store("cmd_name", zName);
1319 Th_StoreList("cmd_args", g.argv, g.argc);
1320 Th_StoreInt("cmd_flags", cmdFlags);
1321 rc = Th_Eval(g.interp, 0, "command_notify", -1);
1322 if( g.thTrace ){
@@ -1306,14 +1335,16 @@
1335 int Th_WebpageHook(
1336 const char *zName,
1337 char cmdFlags
1338 ){
1339 int rc = TH_OK;
1340 Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
1341 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1342 return rc;
1343 }
1344 Th_CloseConfig(0);
1345 Th_FossilInit(TH_INIT_HOOK);
1346 Th_Store("web_name", zName);
1347 Th_StoreList("web_args", g.argv, g.argc);
1348 Th_StoreInt("web_flags", cmdFlags);
1349 rc = Th_Eval(g.interp, 0, "webpage_hook", -1);
1350 if( rc==TH_ERROR ){
@@ -1351,14 +1382,16 @@
1382 int Th_WebpageNotify(
1383 const char *zName,
1384 char cmdFlags
1385 ){
1386 int rc = TH_OK;
1387 Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
1388 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1389 return rc;
1390 }
1391 Th_CloseConfig(0);
1392 Th_FossilInit(TH_INIT_HOOK);
1393 Th_Store("web_name", zName);
1394 Th_StoreList("web_args", g.argv, g.argc);
1395 Th_StoreInt("web_flags", cmdFlags);
1396 rc = Th_Eval(g.interp, 0, "webpage_notify", -1);
1397 if( g.thTrace ){
@@ -1436,12 +1469,11 @@
1469 */
1470 void test_th_render(void){
1471 Blob in;
1472 Th_InitTraceLog();
1473 if( find_option("th-open-config", 0, 0)!=0 ){
1474 Th_OpenConfig(1);
 
1475 }
1476 if( g.argc<3 ){
1477 usage("FILE");
1478 }
1479 blob_zero(&in);
@@ -1456,12 +1488,11 @@
1488 void test_th_eval(void){
1489 int rc;
1490 const char *zRc;
1491 Th_InitTraceLog();
1492 if( find_option("th-open-config", 0, 0)!=0 ){
1493 Th_OpenConfig(1);
 
1494 }
1495 if( g.argc!=3 ){
1496 usage("script");
1497 }
1498 Th_FossilInit(TH_INIT_DEFAULT);
1499
+41 -10
--- src/th_main.c
+++ src/th_main.c
@@ -989,10 +989,36 @@
989989
"synchronous requests are not yet implemented", 0, 0);
990990
blob_reset(&payload);
991991
return TH_ERROR;
992992
}
993993
}
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
+}
9941020
9951021
/*
9961022
** Make sure the interpreter has been initialized. Initialize it if
9971023
** it has not been already.
9981024
**
@@ -1039,12 +1065,11 @@
10391065
** This function uses several settings which may be defined in the
10401066
** repository and/or the global configuration. Since the caller
10411067
** passed a non-zero value for the needConfig parameter, make sure
10421068
** the necessary database connections are open prior to continuing.
10431069
*/
1044
- db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0);
1045
- db_open_config(0);
1070
+ Th_OpenConfig(1);
10461071
}
10471072
if( forceReset || forceTcl || g.interp==0 ){
10481073
int created = 0;
10491074
int i;
10501075
if( g.interp==0 ){
@@ -1235,14 +1260,16 @@
12351260
int Th_CommandHook(
12361261
const char *zName,
12371262
char cmdFlags
12381263
){
12391264
int rc = TH_OK;
1240
- Th_FossilInit(TH_INIT_HOOK);
1265
+ Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
12411266
if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
12421267
return rc;
12431268
}
1269
+ Th_CloseConfig(0);
1270
+ Th_FossilInit(TH_INIT_HOOK);
12441271
Th_Store("cmd_name", zName);
12451272
Th_StoreList("cmd_args", g.argv, g.argc);
12461273
Th_StoreInt("cmd_flags", cmdFlags);
12471274
rc = Th_Eval(g.interp, 0, "command_hook", -1);
12481275
if( rc==TH_ERROR ){
@@ -1280,14 +1307,16 @@
12801307
int Th_CommandNotify(
12811308
const char *zName,
12821309
char cmdFlags
12831310
){
12841311
int rc = TH_OK;
1285
- Th_FossilInit(TH_INIT_HOOK);
1312
+ Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
12861313
if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
12871314
return rc;
12881315
}
1316
+ Th_CloseConfig(0);
1317
+ Th_FossilInit(TH_INIT_HOOK);
12891318
Th_Store("cmd_name", zName);
12901319
Th_StoreList("cmd_args", g.argv, g.argc);
12911320
Th_StoreInt("cmd_flags", cmdFlags);
12921321
rc = Th_Eval(g.interp, 0, "command_notify", -1);
12931322
if( g.thTrace ){
@@ -1306,14 +1335,16 @@
13061335
int Th_WebpageHook(
13071336
const char *zName,
13081337
char cmdFlags
13091338
){
13101339
int rc = TH_OK;
1311
- Th_FossilInit(TH_INIT_HOOK);
1340
+ Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
13121341
if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
13131342
return rc;
13141343
}
1344
+ Th_CloseConfig(0);
1345
+ Th_FossilInit(TH_INIT_HOOK);
13151346
Th_Store("web_name", zName);
13161347
Th_StoreList("web_args", g.argv, g.argc);
13171348
Th_StoreInt("web_flags", cmdFlags);
13181349
rc = Th_Eval(g.interp, 0, "webpage_hook", -1);
13191350
if( rc==TH_ERROR ){
@@ -1351,14 +1382,16 @@
13511382
int Th_WebpageNotify(
13521383
const char *zName,
13531384
char cmdFlags
13541385
){
13551386
int rc = TH_OK;
1356
- Th_FossilInit(TH_INIT_HOOK);
1387
+ Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
13571388
if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
13581389
return rc;
13591390
}
1391
+ Th_CloseConfig(0);
1392
+ Th_FossilInit(TH_INIT_HOOK);
13601393
Th_Store("web_name", zName);
13611394
Th_StoreList("web_args", g.argv, g.argc);
13621395
Th_StoreInt("web_flags", cmdFlags);
13631396
rc = Th_Eval(g.interp, 0, "webpage_notify", -1);
13641397
if( g.thTrace ){
@@ -1436,12 +1469,11 @@
14361469
*/
14371470
void test_th_render(void){
14381471
Blob in;
14391472
Th_InitTraceLog();
14401473
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);
14431475
}
14441476
if( g.argc<3 ){
14451477
usage("FILE");
14461478
}
14471479
blob_zero(&in);
@@ -1456,12 +1488,11 @@
14561488
void test_th_eval(void){
14571489
int rc;
14581490
const char *zRc;
14591491
Th_InitTraceLog();
14601492
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);
14631494
}
14641495
if( g.argc!=3 ){
14651496
usage("script");
14661497
}
14671498
Th_FossilInit(TH_INIT_DEFAULT);
14681499
--- src/th_main.c
+++ src/th_main.c
@@ -989,10 +989,36 @@
989 "synchronous requests are not yet implemented", 0, 0);
990 blob_reset(&payload);
991 return TH_ERROR;
992 }
993 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
994
995 /*
996 ** Make sure the interpreter has been initialized. Initialize it if
997 ** it has not been already.
998 **
@@ -1039,12 +1065,11 @@
1039 ** This function uses several settings which may be defined in the
1040 ** repository and/or the global configuration. Since the caller
1041 ** passed a non-zero value for the needConfig parameter, make sure
1042 ** the necessary database connections are open prior to continuing.
1043 */
1044 db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0);
1045 db_open_config(0);
1046 }
1047 if( forceReset || forceTcl || g.interp==0 ){
1048 int created = 0;
1049 int i;
1050 if( g.interp==0 ){
@@ -1235,14 +1260,16 @@
1235 int Th_CommandHook(
1236 const char *zName,
1237 char cmdFlags
1238 ){
1239 int rc = TH_OK;
1240 Th_FossilInit(TH_INIT_HOOK);
1241 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1242 return rc;
1243 }
 
 
1244 Th_Store("cmd_name", zName);
1245 Th_StoreList("cmd_args", g.argv, g.argc);
1246 Th_StoreInt("cmd_flags", cmdFlags);
1247 rc = Th_Eval(g.interp, 0, "command_hook", -1);
1248 if( rc==TH_ERROR ){
@@ -1280,14 +1307,16 @@
1280 int Th_CommandNotify(
1281 const char *zName,
1282 char cmdFlags
1283 ){
1284 int rc = TH_OK;
1285 Th_FossilInit(TH_INIT_HOOK);
1286 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1287 return rc;
1288 }
 
 
1289 Th_Store("cmd_name", zName);
1290 Th_StoreList("cmd_args", g.argv, g.argc);
1291 Th_StoreInt("cmd_flags", cmdFlags);
1292 rc = Th_Eval(g.interp, 0, "command_notify", -1);
1293 if( g.thTrace ){
@@ -1306,14 +1335,16 @@
1306 int Th_WebpageHook(
1307 const char *zName,
1308 char cmdFlags
1309 ){
1310 int rc = TH_OK;
1311 Th_FossilInit(TH_INIT_HOOK);
1312 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1313 return rc;
1314 }
 
 
1315 Th_Store("web_name", zName);
1316 Th_StoreList("web_args", g.argv, g.argc);
1317 Th_StoreInt("web_flags", cmdFlags);
1318 rc = Th_Eval(g.interp, 0, "webpage_hook", -1);
1319 if( rc==TH_ERROR ){
@@ -1351,14 +1382,16 @@
1351 int Th_WebpageNotify(
1352 const char *zName,
1353 char cmdFlags
1354 ){
1355 int rc = TH_OK;
1356 Th_FossilInit(TH_INIT_HOOK);
1357 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1358 return rc;
1359 }
 
 
1360 Th_Store("web_name", zName);
1361 Th_StoreList("web_args", g.argv, g.argc);
1362 Th_StoreInt("web_flags", cmdFlags);
1363 rc = Th_Eval(g.interp, 0, "webpage_notify", -1);
1364 if( g.thTrace ){
@@ -1436,12 +1469,11 @@
1436 */
1437 void test_th_render(void){
1438 Blob in;
1439 Th_InitTraceLog();
1440 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);
1443 }
1444 if( g.argc<3 ){
1445 usage("FILE");
1446 }
1447 blob_zero(&in);
@@ -1456,12 +1488,11 @@
1456 void test_th_eval(void){
1457 int rc;
1458 const char *zRc;
1459 Th_InitTraceLog();
1460 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);
1463 }
1464 if( g.argc!=3 ){
1465 usage("script");
1466 }
1467 Th_FossilInit(TH_INIT_DEFAULT);
1468
--- src/th_main.c
+++ src/th_main.c
@@ -989,10 +989,36 @@
989 "synchronous requests are not yet implemented", 0, 0);
990 blob_reset(&payload);
991 return TH_ERROR;
992 }
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 }
1020
1021 /*
1022 ** Make sure the interpreter has been initialized. Initialize it if
1023 ** it has not been already.
1024 **
@@ -1039,12 +1065,11 @@
1065 ** This function uses several settings which may be defined in the
1066 ** repository and/or the global configuration. Since the caller
1067 ** passed a non-zero value for the needConfig parameter, make sure
1068 ** the necessary database connections are open prior to continuing.
1069 */
1070 Th_OpenConfig(1);
 
1071 }
1072 if( forceReset || forceTcl || g.interp==0 ){
1073 int created = 0;
1074 int i;
1075 if( g.interp==0 ){
@@ -1235,14 +1260,16 @@
1260 int Th_CommandHook(
1261 const char *zName,
1262 char cmdFlags
1263 ){
1264 int rc = TH_OK;
1265 Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
1266 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1267 return rc;
1268 }
1269 Th_CloseConfig(0);
1270 Th_FossilInit(TH_INIT_HOOK);
1271 Th_Store("cmd_name", zName);
1272 Th_StoreList("cmd_args", g.argv, g.argc);
1273 Th_StoreInt("cmd_flags", cmdFlags);
1274 rc = Th_Eval(g.interp, 0, "command_hook", -1);
1275 if( rc==TH_ERROR ){
@@ -1280,14 +1307,16 @@
1307 int Th_CommandNotify(
1308 const char *zName,
1309 char cmdFlags
1310 ){
1311 int rc = TH_OK;
1312 Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
1313 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1314 return rc;
1315 }
1316 Th_CloseConfig(0);
1317 Th_FossilInit(TH_INIT_HOOK);
1318 Th_Store("cmd_name", zName);
1319 Th_StoreList("cmd_args", g.argv, g.argc);
1320 Th_StoreInt("cmd_flags", cmdFlags);
1321 rc = Th_Eval(g.interp, 0, "command_notify", -1);
1322 if( g.thTrace ){
@@ -1306,14 +1335,16 @@
1335 int Th_WebpageHook(
1336 const char *zName,
1337 char cmdFlags
1338 ){
1339 int rc = TH_OK;
1340 Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
1341 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1342 return rc;
1343 }
1344 Th_CloseConfig(0);
1345 Th_FossilInit(TH_INIT_HOOK);
1346 Th_Store("web_name", zName);
1347 Th_StoreList("web_args", g.argv, g.argc);
1348 Th_StoreInt("web_flags", cmdFlags);
1349 rc = Th_Eval(g.interp, 0, "webpage_hook", -1);
1350 if( rc==TH_ERROR ){
@@ -1351,14 +1382,16 @@
1382 int Th_WebpageNotify(
1383 const char *zName,
1384 char cmdFlags
1385 ){
1386 int rc = TH_OK;
1387 Th_OpenConfig(0); /* NOTE: Minimum needed to check "th1-hooks" setting. */
1388 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1389 return rc;
1390 }
1391 Th_CloseConfig(0);
1392 Th_FossilInit(TH_INIT_HOOK);
1393 Th_Store("web_name", zName);
1394 Th_StoreList("web_args", g.argv, g.argc);
1395 Th_StoreInt("web_flags", cmdFlags);
1396 rc = Th_Eval(g.interp, 0, "webpage_notify", -1);
1397 if( g.thTrace ){
@@ -1436,12 +1469,11 @@
1469 */
1470 void test_th_render(void){
1471 Blob in;
1472 Th_InitTraceLog();
1473 if( find_option("th-open-config", 0, 0)!=0 ){
1474 Th_OpenConfig(1);
 
1475 }
1476 if( g.argc<3 ){
1477 usage("FILE");
1478 }
1479 blob_zero(&in);
@@ -1456,12 +1488,11 @@
1488 void test_th_eval(void){
1489 int rc;
1490 const char *zRc;
1491 Th_InitTraceLog();
1492 if( find_option("th-open-config", 0, 0)!=0 ){
1493 Th_OpenConfig(1);
 
1494 }
1495 if( g.argc!=3 ){
1496 usage("script");
1497 }
1498 Th_FossilInit(TH_INIT_DEFAULT);
1499

Keyboard Shortcuts

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