Fossil SCM

Merge updates from trunk.

mistachkin 2014-06-15 00:41 dbCloseConfig merge
Commit 9f3dd72d933227a8f50c11f4fe3bfccd403cac33
+1
--- src/main.c
+++ src/main.c
@@ -155,10 +155,11 @@
155155
int cgiOutput; /* Write error and status messages to CGI */
156156
int xferPanic; /* Write error messages in XFER protocol */
157157
int fullHttpReply; /* True for full HTTP reply. False for CGI reply */
158158
Th_Interp *interp; /* The TH1 interpreter */
159159
char *th1Setup; /* The TH1 post-creation setup script, if any */
160
+ int th1Flags; /* The TH1 integration state flags */
160161
FILE *httpIn; /* Accept HTTP input from here */
161162
FILE *httpOut; /* Send HTTP output here */
162163
int xlinkClusterOnly; /* Set when cloning. Only process clusters */
163164
int fTimeFormat; /* 1 for UTC. 2 for localtime. 0 not yet selected */
164165
int *aCommitFile; /* Array of files to be committed */
165166
--- src/main.c
+++ src/main.c
@@ -155,10 +155,11 @@
155 int cgiOutput; /* Write error and status messages to CGI */
156 int xferPanic; /* Write error messages in XFER protocol */
157 int fullHttpReply; /* True for full HTTP reply. False for CGI reply */
158 Th_Interp *interp; /* The TH1 interpreter */
159 char *th1Setup; /* The TH1 post-creation setup script, if any */
 
160 FILE *httpIn; /* Accept HTTP input from here */
161 FILE *httpOut; /* Send HTTP output here */
162 int xlinkClusterOnly; /* Set when cloning. Only process clusters */
163 int fTimeFormat; /* 1 for UTC. 2 for localtime. 0 not yet selected */
164 int *aCommitFile; /* Array of files to be committed */
165
--- src/main.c
+++ src/main.c
@@ -155,10 +155,11 @@
155 int cgiOutput; /* Write error and status messages to CGI */
156 int xferPanic; /* Write error messages in XFER protocol */
157 int fullHttpReply; /* True for full HTTP reply. False for CGI reply */
158 Th_Interp *interp; /* The TH1 interpreter */
159 char *th1Setup; /* The TH1 post-creation setup script, if any */
160 int th1Flags; /* The TH1 integration state flags */
161 FILE *httpIn; /* Accept HTTP input from here */
162 FILE *httpOut; /* Send HTTP output here */
163 int xlinkClusterOnly; /* Set when cloning. Only process clusters */
164 int fTimeFormat; /* 1 for UTC. 2 for localtime. 0 not yet selected */
165 int *aCommitFile; /* Array of files to be committed */
166
+54 -12
--- src/th_main.c
+++ src/th_main.c
@@ -30,14 +30,23 @@
3030
#define TH_INIT_NONE ((u32)0x00000000) /* No flags. */
3131
#define TH_INIT_NEED_CONFIG ((u32)0x00000001) /* Open configuration first? */
3232
#define TH_INIT_FORCE_TCL ((u32)0x00000002) /* Force Tcl to be enabled? */
3333
#define TH_INIT_FORCE_RESET ((u32)0x00000004) /* Force TH1 commands re-added? */
3434
#define TH_INIT_FORCE_SETUP ((u32)0x00000008) /* Force eval of setup script? */
35
+#define TH_INIT_MASK ((u32)0x0000000F) /* All possible init flags. */
3536
#define TH_INIT_DEFAULT (TH_INIT_NONE) /* Default flags. */
3637
#define TH_INIT_HOOK (TH_INIT_NEED_CONFIG | TH_INIT_FORCE_SETUP)
3738
#endif
3839
40
+/*
41
+** Flags set by functions in this file to keep track of integration state
42
+** information. These flags should not be used outside of this file.
43
+*/
44
+#define TH_STATE_CONFIG ((u32)0x00000010) /* We opened the config. */
45
+#define TH_STATE_REPOSITORY ((u32)0x00000020) /* We opened the repository. */
46
+#define TH_STATE_MASK ((u32)0x00000030) /* All possible state flags. */
47
+
3948
#ifdef FOSSIL_ENABLE_TH1_HOOKS
4049
/*
4150
** These are the "well-known" TH1 error messages that occur when no hook is
4251
** registered to be called prior to executing a command or processing a web
4352
** page, respectively. If one of these errors is seen, it will not be sent
@@ -45,10 +54,17 @@
4554
*/
4655
#define NO_COMMAND_HOOK_ERROR "no such command: command_hook"
4756
#define NO_WEBPAGE_HOOK_ERROR "no such command: webpage_hook"
4857
#endif
4958
59
+/*
60
+** These macros are used within this file to detect if the repository and
61
+** configuration ("user") database are currently open.
62
+*/
63
+#define Th_IsRepositoryOpen() (g.repositoryOpen)
64
+#define Th_IsConfigOpen() (g.zConfigDbName!=0)
65
+
5066
/*
5167
** Global variable counting the number of outstanding calls to malloc()
5268
** made by the th1 implementation. This is used to catch memory leaks
5369
** in the interpreter. Obviously, it also means th1 is not threadsafe.
5470
*/
@@ -595,11 +611,13 @@
595611
596612
/*
597613
** TH1 command: checkout ?BOOLEAN?
598614
**
599615
** Return the fully qualified directory name of the current checkout or an
600
-** empty string if it is not available.
616
+** empty string if it is not available. Optionally, it will attempt to find
617
+** the current checkout, opening the configuration ("user") database and the
618
+** repository as necessary, if the boolean argument is non-zero.
601619
*/
602620
static int checkoutCmd(
603621
Th_Interp *interp,
604622
void *p,
605623
int argc,
@@ -608,15 +626,15 @@
608626
){
609627
if( argc!=1 && argc!=2 ){
610628
return Th_WrongNumArgs(interp, "checkout ?BOOLEAN?");
611629
}
612630
if( argc==2 ){
613
- int openRepository = 0;
614
- if( Th_ToInt(interp, argv[1], argl[1], &openRepository) ){
631
+ int openCheckout = 0;
632
+ if( Th_ToInt(interp, argv[1], argl[1], &openCheckout) ){
615633
return TH_ERROR;
616634
}
617
- if( openRepository ) db_find_and_open_repository(OPEN_OK_NOT_FOUND, 0);
635
+ if( openCheckout ) db_open_local(0);
618636
}
619637
Th_SetResult(interp, g.zLocalRoot, -1);
620638
return TH_OK;
621639
}
622640
@@ -719,16 +737,16 @@
719737
int *argl
720738
){
721739
if( argc!=2 ){
722740
return Th_WrongNumArgs(interp, "styleHeader TITLE");
723741
}
724
- if( g.zConfigDbName ){
742
+ if( Th_IsRepositoryOpen() ){
725743
style_header("%s", argv[1]);
726744
Th_SetResult(interp, 0, 0);
727745
return TH_OK;
728746
}else{
729
- Th_SetResult(interp, "configuration unavailable", -1);
747
+ Th_SetResult(interp, "repository unavailable", -1);
730748
return TH_ERROR;
731749
}
732750
}
733751
734752
/*
@@ -744,16 +762,16 @@
744762
int *argl
745763
){
746764
if( argc!=1 ){
747765
return Th_WrongNumArgs(interp, "styleFooter");
748766
}
749
- if( g.zConfigDbName ){
767
+ if( Th_IsRepositoryOpen() ){
750768
style_footer();
751769
Th_SetResult(interp, 0, 0);
752770
return TH_OK;
753771
}else{
754
- Th_SetResult(interp, "configuration unavailable", -1);
772
+ Th_SetResult(interp, "repository unavailable", -1);
755773
return TH_ERROR;
756774
}
757775
}
758776
759777
#ifdef _WIN32
@@ -1160,26 +1178,42 @@
11601178
** attempts to try to find the repository and open it.
11611179
*/
11621180
void Th_OpenConfig(
11631181
int openRepository
11641182
){
1165
- if( openRepository ){
1183
+ if( openRepository && !Th_IsRepositoryOpen() ){
11661184
db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0);
1185
+ if( Th_IsRepositoryOpen() ){
1186
+ g.th1Flags |= TH_STATE_REPOSITORY;
1187
+ }else{
1188
+ g.th1Flags &= ~TH_STATE_REPOSITORY;
1189
+ }
11671190
}
1168
- db_open_config(0);
1191
+ if( !Th_IsConfigOpen() ){
1192
+ db_open_config(0);
1193
+ if( Th_IsConfigOpen() ){
1194
+ g.th1Flags |= TH_STATE_CONFIG;
1195
+ }else{
1196
+ g.th1Flags &= ~TH_STATE_CONFIG;
1197
+ }
1198
+ }
11691199
}
11701200
11711201
/*
11721202
** Attempts to close the configuration ("user") database. Optionally, also
11731203
** attempts to close the repository.
11741204
*/
11751205
void Th_CloseConfig(
11761206
int closeRepository
11771207
){
1178
- db_close_config();
1179
- if( closeRepository ){
1208
+ if( g.th1Flags & TH_STATE_CONFIG ){
1209
+ db_close_config();
1210
+ g.th1Flags &= ~TH_STATE_CONFIG;
1211
+ }
1212
+ if( closeRepository && (g.th1Flags & TH_STATE_REPOSITORY) ){
11801213
db_close(1);
1214
+ g.th1Flags &= ~TH_STATE_REPOSITORY;
11811215
}
11821216
}
11831217
11841218
/*
11851219
** Make sure the interpreter has been initialized. Initialize it if
@@ -1282,10 +1316,12 @@
12821316
if( g.thTrace ){
12831317
Th_Trace("th1-setup {%h} => %h<br />\n", g.th1Setup,
12841318
Th_ReturnCodeName(rc, 0));
12851319
}
12861320
}
1321
+ g.th1Flags &= ~TH_INIT_MASK;
1322
+ g.th1Flags |= (flags & TH_INIT_MASK);
12871323
}
12881324
12891325
/*
12901326
** Store a string value in a variable in the interpreter.
12911327
*/
@@ -1432,10 +1468,11 @@
14321468
char cmdFlags
14331469
){
14341470
int rc = TH_OK;
14351471
Th_OpenConfig(1);
14361472
if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1473
+ Th_CloseConfig(1);
14371474
return rc;
14381475
}
14391476
Th_CloseConfig(1);
14401477
Th_FossilInit(TH_INIT_HOOK);
14411478
Th_Store("cmd_name", zName);
@@ -1479,10 +1516,11 @@
14791516
char cmdFlags
14801517
){
14811518
int rc = TH_OK;
14821519
Th_OpenConfig(1);
14831520
if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1521
+ Th_CloseConfig(1);
14841522
return rc;
14851523
}
14861524
Th_CloseConfig(1);
14871525
Th_FossilInit(TH_INIT_HOOK);
14881526
Th_Store("cmd_name", zName);
@@ -1507,10 +1545,11 @@
15071545
char cmdFlags
15081546
){
15091547
int rc = TH_OK;
15101548
Th_OpenConfig(1);
15111549
if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1550
+ Th_CloseConfig(1);
15121551
return rc;
15131552
}
15141553
Th_CloseConfig(1);
15151554
Th_FossilInit(TH_INIT_HOOK);
15161555
Th_Store("web_name", zName);
@@ -1554,10 +1593,11 @@
15541593
char cmdFlags
15551594
){
15561595
int rc = TH_OK;
15571596
Th_OpenConfig(1);
15581597
if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1598
+ Th_CloseConfig(1);
15591599
return rc;
15601600
}
15611601
Th_CloseConfig(1);
15621602
Th_FossilInit(TH_INIT_HOOK);
15631603
Th_Store("web_name", zName);
@@ -1678,10 +1718,11 @@
16781718
*/
16791719
void test_th_hook(void){
16801720
int rc = TH_OK;
16811721
int nResult = 0;
16821722
char *zResult;
1723
+ Th_InitTraceLog();
16831724
if( g.argc<5 ){
16841725
usage("TYPE NAME FLAGS");
16851726
}
16861727
if( fossil_stricmp(g.argv[2], "cmdhook")==0 ){
16871728
rc = Th_CommandHook(g.argv[3], (char)atoi(g.argv[4]));
@@ -1698,7 +1739,8 @@
16981739
sendText("RESULT (", -1, 0);
16991740
sendText(Th_ReturnCodeName(rc, 0), -1, 0);
17001741
sendText("): ", -1, 0);
17011742
sendText(zResult, nResult, 0);
17021743
sendText("\n", -1, 0);
1744
+ Th_PrintTraceLog();
17031745
}
17041746
#endif
17051747
--- src/th_main.c
+++ src/th_main.c
@@ -30,14 +30,23 @@
30 #define TH_INIT_NONE ((u32)0x00000000) /* No flags. */
31 #define TH_INIT_NEED_CONFIG ((u32)0x00000001) /* Open configuration first? */
32 #define TH_INIT_FORCE_TCL ((u32)0x00000002) /* Force Tcl to be enabled? */
33 #define TH_INIT_FORCE_RESET ((u32)0x00000004) /* Force TH1 commands re-added? */
34 #define TH_INIT_FORCE_SETUP ((u32)0x00000008) /* Force eval of setup script? */
 
35 #define TH_INIT_DEFAULT (TH_INIT_NONE) /* Default flags. */
36 #define TH_INIT_HOOK (TH_INIT_NEED_CONFIG | TH_INIT_FORCE_SETUP)
37 #endif
38
 
 
 
 
 
 
 
 
39 #ifdef FOSSIL_ENABLE_TH1_HOOKS
40 /*
41 ** These are the "well-known" TH1 error messages that occur when no hook is
42 ** registered to be called prior to executing a command or processing a web
43 ** page, respectively. If one of these errors is seen, it will not be sent
@@ -45,10 +54,17 @@
45 */
46 #define NO_COMMAND_HOOK_ERROR "no such command: command_hook"
47 #define NO_WEBPAGE_HOOK_ERROR "no such command: webpage_hook"
48 #endif
49
 
 
 
 
 
 
 
50 /*
51 ** Global variable counting the number of outstanding calls to malloc()
52 ** made by the th1 implementation. This is used to catch memory leaks
53 ** in the interpreter. Obviously, it also means th1 is not threadsafe.
54 */
@@ -595,11 +611,13 @@
595
596 /*
597 ** TH1 command: checkout ?BOOLEAN?
598 **
599 ** Return the fully qualified directory name of the current checkout or an
600 ** empty string if it is not available.
 
 
601 */
602 static int checkoutCmd(
603 Th_Interp *interp,
604 void *p,
605 int argc,
@@ -608,15 +626,15 @@
608 ){
609 if( argc!=1 && argc!=2 ){
610 return Th_WrongNumArgs(interp, "checkout ?BOOLEAN?");
611 }
612 if( argc==2 ){
613 int openRepository = 0;
614 if( Th_ToInt(interp, argv[1], argl[1], &openRepository) ){
615 return TH_ERROR;
616 }
617 if( openRepository ) db_find_and_open_repository(OPEN_OK_NOT_FOUND, 0);
618 }
619 Th_SetResult(interp, g.zLocalRoot, -1);
620 return TH_OK;
621 }
622
@@ -719,16 +737,16 @@
719 int *argl
720 ){
721 if( argc!=2 ){
722 return Th_WrongNumArgs(interp, "styleHeader TITLE");
723 }
724 if( g.zConfigDbName ){
725 style_header("%s", argv[1]);
726 Th_SetResult(interp, 0, 0);
727 return TH_OK;
728 }else{
729 Th_SetResult(interp, "configuration unavailable", -1);
730 return TH_ERROR;
731 }
732 }
733
734 /*
@@ -744,16 +762,16 @@
744 int *argl
745 ){
746 if( argc!=1 ){
747 return Th_WrongNumArgs(interp, "styleFooter");
748 }
749 if( g.zConfigDbName ){
750 style_footer();
751 Th_SetResult(interp, 0, 0);
752 return TH_OK;
753 }else{
754 Th_SetResult(interp, "configuration unavailable", -1);
755 return TH_ERROR;
756 }
757 }
758
759 #ifdef _WIN32
@@ -1160,26 +1178,42 @@
1160 ** attempts to try to find the repository and open it.
1161 */
1162 void Th_OpenConfig(
1163 int openRepository
1164 ){
1165 if( openRepository ){
1166 db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0);
 
 
 
 
 
1167 }
1168 db_open_config(0);
 
 
 
 
 
 
 
1169 }
1170
1171 /*
1172 ** Attempts to close the configuration ("user") database. Optionally, also
1173 ** attempts to close the repository.
1174 */
1175 void Th_CloseConfig(
1176 int closeRepository
1177 ){
1178 db_close_config();
1179 if( closeRepository ){
 
 
 
1180 db_close(1);
 
1181 }
1182 }
1183
1184 /*
1185 ** Make sure the interpreter has been initialized. Initialize it if
@@ -1282,10 +1316,12 @@
1282 if( g.thTrace ){
1283 Th_Trace("th1-setup {%h} => %h<br />\n", g.th1Setup,
1284 Th_ReturnCodeName(rc, 0));
1285 }
1286 }
 
 
1287 }
1288
1289 /*
1290 ** Store a string value in a variable in the interpreter.
1291 */
@@ -1432,10 +1468,11 @@
1432 char cmdFlags
1433 ){
1434 int rc = TH_OK;
1435 Th_OpenConfig(1);
1436 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
 
1437 return rc;
1438 }
1439 Th_CloseConfig(1);
1440 Th_FossilInit(TH_INIT_HOOK);
1441 Th_Store("cmd_name", zName);
@@ -1479,10 +1516,11 @@
1479 char cmdFlags
1480 ){
1481 int rc = TH_OK;
1482 Th_OpenConfig(1);
1483 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
 
1484 return rc;
1485 }
1486 Th_CloseConfig(1);
1487 Th_FossilInit(TH_INIT_HOOK);
1488 Th_Store("cmd_name", zName);
@@ -1507,10 +1545,11 @@
1507 char cmdFlags
1508 ){
1509 int rc = TH_OK;
1510 Th_OpenConfig(1);
1511 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
 
1512 return rc;
1513 }
1514 Th_CloseConfig(1);
1515 Th_FossilInit(TH_INIT_HOOK);
1516 Th_Store("web_name", zName);
@@ -1554,10 +1593,11 @@
1554 char cmdFlags
1555 ){
1556 int rc = TH_OK;
1557 Th_OpenConfig(1);
1558 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
 
1559 return rc;
1560 }
1561 Th_CloseConfig(1);
1562 Th_FossilInit(TH_INIT_HOOK);
1563 Th_Store("web_name", zName);
@@ -1678,10 +1718,11 @@
1678 */
1679 void test_th_hook(void){
1680 int rc = TH_OK;
1681 int nResult = 0;
1682 char *zResult;
 
1683 if( g.argc<5 ){
1684 usage("TYPE NAME FLAGS");
1685 }
1686 if( fossil_stricmp(g.argv[2], "cmdhook")==0 ){
1687 rc = Th_CommandHook(g.argv[3], (char)atoi(g.argv[4]));
@@ -1698,7 +1739,8 @@
1698 sendText("RESULT (", -1, 0);
1699 sendText(Th_ReturnCodeName(rc, 0), -1, 0);
1700 sendText("): ", -1, 0);
1701 sendText(zResult, nResult, 0);
1702 sendText("\n", -1, 0);
 
1703 }
1704 #endif
1705
--- src/th_main.c
+++ src/th_main.c
@@ -30,14 +30,23 @@
30 #define TH_INIT_NONE ((u32)0x00000000) /* No flags. */
31 #define TH_INIT_NEED_CONFIG ((u32)0x00000001) /* Open configuration first? */
32 #define TH_INIT_FORCE_TCL ((u32)0x00000002) /* Force Tcl to be enabled? */
33 #define TH_INIT_FORCE_RESET ((u32)0x00000004) /* Force TH1 commands re-added? */
34 #define TH_INIT_FORCE_SETUP ((u32)0x00000008) /* Force eval of setup script? */
35 #define TH_INIT_MASK ((u32)0x0000000F) /* All possible init flags. */
36 #define TH_INIT_DEFAULT (TH_INIT_NONE) /* Default flags. */
37 #define TH_INIT_HOOK (TH_INIT_NEED_CONFIG | TH_INIT_FORCE_SETUP)
38 #endif
39
40 /*
41 ** Flags set by functions in this file to keep track of integration state
42 ** information. These flags should not be used outside of this file.
43 */
44 #define TH_STATE_CONFIG ((u32)0x00000010) /* We opened the config. */
45 #define TH_STATE_REPOSITORY ((u32)0x00000020) /* We opened the repository. */
46 #define TH_STATE_MASK ((u32)0x00000030) /* All possible state flags. */
47
48 #ifdef FOSSIL_ENABLE_TH1_HOOKS
49 /*
50 ** These are the "well-known" TH1 error messages that occur when no hook is
51 ** registered to be called prior to executing a command or processing a web
52 ** page, respectively. If one of these errors is seen, it will not be sent
@@ -45,10 +54,17 @@
54 */
55 #define NO_COMMAND_HOOK_ERROR "no such command: command_hook"
56 #define NO_WEBPAGE_HOOK_ERROR "no such command: webpage_hook"
57 #endif
58
59 /*
60 ** These macros are used within this file to detect if the repository and
61 ** configuration ("user") database are currently open.
62 */
63 #define Th_IsRepositoryOpen() (g.repositoryOpen)
64 #define Th_IsConfigOpen() (g.zConfigDbName!=0)
65
66 /*
67 ** Global variable counting the number of outstanding calls to malloc()
68 ** made by the th1 implementation. This is used to catch memory leaks
69 ** in the interpreter. Obviously, it also means th1 is not threadsafe.
70 */
@@ -595,11 +611,13 @@
611
612 /*
613 ** TH1 command: checkout ?BOOLEAN?
614 **
615 ** Return the fully qualified directory name of the current checkout or an
616 ** empty string if it is not available. Optionally, it will attempt to find
617 ** the current checkout, opening the configuration ("user") database and the
618 ** repository as necessary, if the boolean argument is non-zero.
619 */
620 static int checkoutCmd(
621 Th_Interp *interp,
622 void *p,
623 int argc,
@@ -608,15 +626,15 @@
626 ){
627 if( argc!=1 && argc!=2 ){
628 return Th_WrongNumArgs(interp, "checkout ?BOOLEAN?");
629 }
630 if( argc==2 ){
631 int openCheckout = 0;
632 if( Th_ToInt(interp, argv[1], argl[1], &openCheckout) ){
633 return TH_ERROR;
634 }
635 if( openCheckout ) db_open_local(0);
636 }
637 Th_SetResult(interp, g.zLocalRoot, -1);
638 return TH_OK;
639 }
640
@@ -719,16 +737,16 @@
737 int *argl
738 ){
739 if( argc!=2 ){
740 return Th_WrongNumArgs(interp, "styleHeader TITLE");
741 }
742 if( Th_IsRepositoryOpen() ){
743 style_header("%s", argv[1]);
744 Th_SetResult(interp, 0, 0);
745 return TH_OK;
746 }else{
747 Th_SetResult(interp, "repository unavailable", -1);
748 return TH_ERROR;
749 }
750 }
751
752 /*
@@ -744,16 +762,16 @@
762 int *argl
763 ){
764 if( argc!=1 ){
765 return Th_WrongNumArgs(interp, "styleFooter");
766 }
767 if( Th_IsRepositoryOpen() ){
768 style_footer();
769 Th_SetResult(interp, 0, 0);
770 return TH_OK;
771 }else{
772 Th_SetResult(interp, "repository unavailable", -1);
773 return TH_ERROR;
774 }
775 }
776
777 #ifdef _WIN32
@@ -1160,26 +1178,42 @@
1178 ** attempts to try to find the repository and open it.
1179 */
1180 void Th_OpenConfig(
1181 int openRepository
1182 ){
1183 if( openRepository && !Th_IsRepositoryOpen() ){
1184 db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0);
1185 if( Th_IsRepositoryOpen() ){
1186 g.th1Flags |= TH_STATE_REPOSITORY;
1187 }else{
1188 g.th1Flags &= ~TH_STATE_REPOSITORY;
1189 }
1190 }
1191 if( !Th_IsConfigOpen() ){
1192 db_open_config(0);
1193 if( Th_IsConfigOpen() ){
1194 g.th1Flags |= TH_STATE_CONFIG;
1195 }else{
1196 g.th1Flags &= ~TH_STATE_CONFIG;
1197 }
1198 }
1199 }
1200
1201 /*
1202 ** Attempts to close the configuration ("user") database. Optionally, also
1203 ** attempts to close the repository.
1204 */
1205 void Th_CloseConfig(
1206 int closeRepository
1207 ){
1208 if( g.th1Flags & TH_STATE_CONFIG ){
1209 db_close_config();
1210 g.th1Flags &= ~TH_STATE_CONFIG;
1211 }
1212 if( closeRepository && (g.th1Flags & TH_STATE_REPOSITORY) ){
1213 db_close(1);
1214 g.th1Flags &= ~TH_STATE_REPOSITORY;
1215 }
1216 }
1217
1218 /*
1219 ** Make sure the interpreter has been initialized. Initialize it if
@@ -1282,10 +1316,12 @@
1316 if( g.thTrace ){
1317 Th_Trace("th1-setup {%h} => %h<br />\n", g.th1Setup,
1318 Th_ReturnCodeName(rc, 0));
1319 }
1320 }
1321 g.th1Flags &= ~TH_INIT_MASK;
1322 g.th1Flags |= (flags & TH_INIT_MASK);
1323 }
1324
1325 /*
1326 ** Store a string value in a variable in the interpreter.
1327 */
@@ -1432,10 +1468,11 @@
1468 char cmdFlags
1469 ){
1470 int rc = TH_OK;
1471 Th_OpenConfig(1);
1472 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1473 Th_CloseConfig(1);
1474 return rc;
1475 }
1476 Th_CloseConfig(1);
1477 Th_FossilInit(TH_INIT_HOOK);
1478 Th_Store("cmd_name", zName);
@@ -1479,10 +1516,11 @@
1516 char cmdFlags
1517 ){
1518 int rc = TH_OK;
1519 Th_OpenConfig(1);
1520 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1521 Th_CloseConfig(1);
1522 return rc;
1523 }
1524 Th_CloseConfig(1);
1525 Th_FossilInit(TH_INIT_HOOK);
1526 Th_Store("cmd_name", zName);
@@ -1507,10 +1545,11 @@
1545 char cmdFlags
1546 ){
1547 int rc = TH_OK;
1548 Th_OpenConfig(1);
1549 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1550 Th_CloseConfig(1);
1551 return rc;
1552 }
1553 Th_CloseConfig(1);
1554 Th_FossilInit(TH_INIT_HOOK);
1555 Th_Store("web_name", zName);
@@ -1554,10 +1593,11 @@
1593 char cmdFlags
1594 ){
1595 int rc = TH_OK;
1596 Th_OpenConfig(1);
1597 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1598 Th_CloseConfig(1);
1599 return rc;
1600 }
1601 Th_CloseConfig(1);
1602 Th_FossilInit(TH_INIT_HOOK);
1603 Th_Store("web_name", zName);
@@ -1678,10 +1718,11 @@
1718 */
1719 void test_th_hook(void){
1720 int rc = TH_OK;
1721 int nResult = 0;
1722 char *zResult;
1723 Th_InitTraceLog();
1724 if( g.argc<5 ){
1725 usage("TYPE NAME FLAGS");
1726 }
1727 if( fossil_stricmp(g.argv[2], "cmdhook")==0 ){
1728 rc = Th_CommandHook(g.argv[3], (char)atoi(g.argv[4]));
@@ -1698,7 +1739,8 @@
1739 sendText("RESULT (", -1, 0);
1740 sendText(Th_ReturnCodeName(rc, 0), -1, 0);
1741 sendText("): ", -1, 0);
1742 sendText(zResult, nResult, 0);
1743 sendText("\n", -1, 0);
1744 Th_PrintTraceLog();
1745 }
1746 #endif
1747
+6 -3
--- test/tester.tcl
+++ test/tester.tcl
@@ -221,24 +221,27 @@
221221
set oldFileName [getTh1SetupFileName]
222222
if {[file exists $oldFileName]} then {
223223
set newFileName [getSavedTh1SetupFileName]
224224
catch {file delete $newFileName}
225225
file rename $oldFileName $newFileName
226
- file delete $oldFileName
227226
}
228227
}
229228
230229
# Restores the original TH1 setup script file by renaming it back, based
231230
# on the current process ID.
232231
#
233232
proc restoreTh1SetupFile {} {
234233
set oldFileName [getSavedTh1SetupFileName]
234
+ set newFileName [getTh1SetupFileName]
235235
if {[file exists $oldFileName]} then {
236
- set newFileName [getTh1SetupFileName]
237236
catch {file delete $newFileName}
238237
file rename $oldFileName $newFileName
239
- file delete $oldFileName
238
+ } else {
239
+ #
240
+ # NOTE: There was no TH1 setup script file, delete the test one.
241
+ #
242
+ file delete $newFileName
240243
}
241244
}
242245
243246
# Perform a test
244247
#
245248
--- test/tester.tcl
+++ test/tester.tcl
@@ -221,24 +221,27 @@
221 set oldFileName [getTh1SetupFileName]
222 if {[file exists $oldFileName]} then {
223 set newFileName [getSavedTh1SetupFileName]
224 catch {file delete $newFileName}
225 file rename $oldFileName $newFileName
226 file delete $oldFileName
227 }
228 }
229
230 # Restores the original TH1 setup script file by renaming it back, based
231 # on the current process ID.
232 #
233 proc restoreTh1SetupFile {} {
234 set oldFileName [getSavedTh1SetupFileName]
 
235 if {[file exists $oldFileName]} then {
236 set newFileName [getTh1SetupFileName]
237 catch {file delete $newFileName}
238 file rename $oldFileName $newFileName
239 file delete $oldFileName
 
 
 
 
240 }
241 }
242
243 # Perform a test
244 #
245
--- test/tester.tcl
+++ test/tester.tcl
@@ -221,24 +221,27 @@
221 set oldFileName [getTh1SetupFileName]
222 if {[file exists $oldFileName]} then {
223 set newFileName [getSavedTh1SetupFileName]
224 catch {file delete $newFileName}
225 file rename $oldFileName $newFileName
 
226 }
227 }
228
229 # Restores the original TH1 setup script file by renaming it back, based
230 # on the current process ID.
231 #
232 proc restoreTh1SetupFile {} {
233 set oldFileName [getSavedTh1SetupFileName]
234 set newFileName [getTh1SetupFileName]
235 if {[file exists $oldFileName]} then {
 
236 catch {file delete $newFileName}
237 file rename $oldFileName $newFileName
238 } else {
239 #
240 # NOTE: There was no TH1 setup script file, delete the test one.
241 #
242 file delete $newFileName
243 }
244 }
245
246 # Perform a test
247 #
248
+32 -8
--- test/th1.test
+++ test/th1.test
@@ -16,10 +16,15 @@
1616
############################################################################
1717
#
1818
# TH1 Commands
1919
#
2020
21
+fossil test-th-eval --th-open-config "setting th1-hooks"
22
+set th1Hooks [expr {$RESULT eq "1"}]
23
+
24
+###############################################################################
25
+
2126
fossil test-th-eval --th-open-config "setting abc"
2227
test th1-setting-1 {$RESULT eq ""}
2328
2429
###############################################################################
2530
@@ -475,17 +480,17 @@
475480
fossil test-th-eval "expr 0+0b"
476481
test th1-expr-35 {$RESULT eq {TH_ERROR: expected number, got: "0b"}}
477482
478483
###############################################################################
479484
480
-fossil test-th-eval "checkout 1"
485
+fossil test-th-eval "checkout 1"; # NOTE: Assumes running "in tree".
481486
test th1-checkout-1 {[string length $RESULT] > 0}
482487
483488
###############################################################################
484489
485
-fossil test-th-eval "checkout"
486
-test th1-checkout-2 {[string length $RESULT] == 0}
490
+fossil test-th-eval "checkout"; # NOTE: Assumes running "in tree".
491
+test th1-checkout-2 {[string length $RESULT] > 0}
487492
488493
###############################################################################
489494
490495
set savedPwd [pwd]; cd /
491496
fossil test-th-eval "checkout 1"
@@ -515,49 +520,68 @@
515520
test th1-trace-1 {$RESULT eq {}}
516521
517522
###############################################################################
518523
519524
fossil test-th-eval --th-trace "trace {}"
520
-test th1-trace-2 {[string map [list \r\n \n] [string trim $RESULT]] eq \
525
+if {$th1Hooks} {
526
+ test th1-trace-2 {[string map [list \r\n \n] [string trim $RESULT]] eq \
521527
{------------------ BEGIN TRACE LOG ------------------
528
+
529
+------------------- END TRACE LOG -------------------}}
530
+} else {
531
+ test th1-trace-2 {[string map [list \r\n \n] [string trim $RESULT]] eq \
532
+ {------------------ BEGIN TRACE LOG ------------------
522533
th1-setup {} => TH_OK<br />
523534
524535
------------------- END TRACE LOG -------------------}}
536
+}
525537
526538
###############################################################################
527539
528540
fossil test-th-eval "trace {this is a trace message.}"
529541
test th1-trace-3 {$RESULT eq {}}
530542
531543
###############################################################################
532544
533545
fossil test-th-eval --th-trace "trace {this is a trace message.}"
534
-test th1-trace-4 {[string map [list \r\n \n] [string trim $RESULT]] eq \
535
-{------------------ BEGIN TRACE LOG ------------------
546
+if {$th1Hooks} {
547
+ test th1-trace-4 {[string map [list \r\n \n] [string trim $RESULT]] eq \
548
+ {------------------ BEGIN TRACE LOG ------------------
549
+this is a trace message.
550
+------------------- END TRACE LOG -------------------}}
551
+} else {
552
+ test th1-trace-4 {[string map [list \r\n \n] [string trim $RESULT]] eq \
553
+ {------------------ BEGIN TRACE LOG ------------------
536554
th1-setup {} => TH_OK<br />
537555
this is a trace message.
538556
------------------- END TRACE LOG -------------------}}
557
+}
539558
540559
###############################################################################
541560
542561
fossil test-th-eval "styleHeader {Page Title Here}"
543
-test th1-header-1 {$RESULT eq {TH_ERROR: configuration unavailable}}
562
+test th1-header-1 {$RESULT eq {TH_ERROR: repository unavailable}}
544563
545564
###############################################################################
546565
547566
fossil test-th-eval --th-open-config "styleHeader {Page Title Here}"
548567
test th1-header-2 {[regexp -- {<title>Fossil: Page Title Here</title>} $RESULT]}
549568
550569
###############################################################################
551570
552571
fossil test-th-eval "styleFooter"
553
-test th1-footer-1 {$RESULT eq {TH_ERROR: configuration unavailable}}
572
+test th1-footer-1 {$RESULT eq {TH_ERROR: repository unavailable}}
554573
555574
###############################################################################
556575
557576
fossil test-th-eval --th-open-config "styleFooter"
558577
test th1-footer-2 {$RESULT eq {}}
578
+
579
+###############################################################################
580
+
581
+fossil test-th-eval --th-open-config "styleHeader {}; styleFooter"
582
+test th1-footer-3 {[regexp -- {</body></html>} $RESULT]}
559583
560584
###############################################################################
561585
562586
fossil test-th-eval "getParameter"
563587
test th1-get-parameter-1 {$RESULT eq \
564588
--- test/th1.test
+++ test/th1.test
@@ -16,10 +16,15 @@
16 ############################################################################
17 #
18 # TH1 Commands
19 #
20
 
 
 
 
 
21 fossil test-th-eval --th-open-config "setting abc"
22 test th1-setting-1 {$RESULT eq ""}
23
24 ###############################################################################
25
@@ -475,17 +480,17 @@
475 fossil test-th-eval "expr 0+0b"
476 test th1-expr-35 {$RESULT eq {TH_ERROR: expected number, got: "0b"}}
477
478 ###############################################################################
479
480 fossil test-th-eval "checkout 1"
481 test th1-checkout-1 {[string length $RESULT] > 0}
482
483 ###############################################################################
484
485 fossil test-th-eval "checkout"
486 test th1-checkout-2 {[string length $RESULT] == 0}
487
488 ###############################################################################
489
490 set savedPwd [pwd]; cd /
491 fossil test-th-eval "checkout 1"
@@ -515,49 +520,68 @@
515 test th1-trace-1 {$RESULT eq {}}
516
517 ###############################################################################
518
519 fossil test-th-eval --th-trace "trace {}"
520 test th1-trace-2 {[string map [list \r\n \n] [string trim $RESULT]] eq \
 
521 {------------------ BEGIN TRACE LOG ------------------
 
 
 
 
 
522 th1-setup {} => TH_OK<br />
523
524 ------------------- END TRACE LOG -------------------}}
 
525
526 ###############################################################################
527
528 fossil test-th-eval "trace {this is a trace message.}"
529 test th1-trace-3 {$RESULT eq {}}
530
531 ###############################################################################
532
533 fossil test-th-eval --th-trace "trace {this is a trace message.}"
534 test th1-trace-4 {[string map [list \r\n \n] [string trim $RESULT]] eq \
535 {------------------ BEGIN TRACE LOG ------------------
 
 
 
 
 
 
536 th1-setup {} => TH_OK<br />
537 this is a trace message.
538 ------------------- END TRACE LOG -------------------}}
 
539
540 ###############################################################################
541
542 fossil test-th-eval "styleHeader {Page Title Here}"
543 test th1-header-1 {$RESULT eq {TH_ERROR: configuration unavailable}}
544
545 ###############################################################################
546
547 fossil test-th-eval --th-open-config "styleHeader {Page Title Here}"
548 test th1-header-2 {[regexp -- {<title>Fossil: Page Title Here</title>} $RESULT]}
549
550 ###############################################################################
551
552 fossil test-th-eval "styleFooter"
553 test th1-footer-1 {$RESULT eq {TH_ERROR: configuration unavailable}}
554
555 ###############################################################################
556
557 fossil test-th-eval --th-open-config "styleFooter"
558 test th1-footer-2 {$RESULT eq {}}
 
 
 
 
 
559
560 ###############################################################################
561
562 fossil test-th-eval "getParameter"
563 test th1-get-parameter-1 {$RESULT eq \
564
--- test/th1.test
+++ test/th1.test
@@ -16,10 +16,15 @@
16 ############################################################################
17 #
18 # TH1 Commands
19 #
20
21 fossil test-th-eval --th-open-config "setting th1-hooks"
22 set th1Hooks [expr {$RESULT eq "1"}]
23
24 ###############################################################################
25
26 fossil test-th-eval --th-open-config "setting abc"
27 test th1-setting-1 {$RESULT eq ""}
28
29 ###############################################################################
30
@@ -475,17 +480,17 @@
480 fossil test-th-eval "expr 0+0b"
481 test th1-expr-35 {$RESULT eq {TH_ERROR: expected number, got: "0b"}}
482
483 ###############################################################################
484
485 fossil test-th-eval "checkout 1"; # NOTE: Assumes running "in tree".
486 test th1-checkout-1 {[string length $RESULT] > 0}
487
488 ###############################################################################
489
490 fossil test-th-eval "checkout"; # NOTE: Assumes running "in tree".
491 test th1-checkout-2 {[string length $RESULT] > 0}
492
493 ###############################################################################
494
495 set savedPwd [pwd]; cd /
496 fossil test-th-eval "checkout 1"
@@ -515,49 +520,68 @@
520 test th1-trace-1 {$RESULT eq {}}
521
522 ###############################################################################
523
524 fossil test-th-eval --th-trace "trace {}"
525 if {$th1Hooks} {
526 test th1-trace-2 {[string map [list \r\n \n] [string trim $RESULT]] eq \
527 {------------------ BEGIN TRACE LOG ------------------
528
529 ------------------- END TRACE LOG -------------------}}
530 } else {
531 test th1-trace-2 {[string map [list \r\n \n] [string trim $RESULT]] eq \
532 {------------------ BEGIN TRACE LOG ------------------
533 th1-setup {} => TH_OK<br />
534
535 ------------------- END TRACE LOG -------------------}}
536 }
537
538 ###############################################################################
539
540 fossil test-th-eval "trace {this is a trace message.}"
541 test th1-trace-3 {$RESULT eq {}}
542
543 ###############################################################################
544
545 fossil test-th-eval --th-trace "trace {this is a trace message.}"
546 if {$th1Hooks} {
547 test th1-trace-4 {[string map [list \r\n \n] [string trim $RESULT]] eq \
548 {------------------ BEGIN TRACE LOG ------------------
549 this is a trace message.
550 ------------------- END TRACE LOG -------------------}}
551 } else {
552 test th1-trace-4 {[string map [list \r\n \n] [string trim $RESULT]] eq \
553 {------------------ BEGIN TRACE LOG ------------------
554 th1-setup {} => TH_OK<br />
555 this is a trace message.
556 ------------------- END TRACE LOG -------------------}}
557 }
558
559 ###############################################################################
560
561 fossil test-th-eval "styleHeader {Page Title Here}"
562 test th1-header-1 {$RESULT eq {TH_ERROR: repository unavailable}}
563
564 ###############################################################################
565
566 fossil test-th-eval --th-open-config "styleHeader {Page Title Here}"
567 test th1-header-2 {[regexp -- {<title>Fossil: Page Title Here</title>} $RESULT]}
568
569 ###############################################################################
570
571 fossil test-th-eval "styleFooter"
572 test th1-footer-1 {$RESULT eq {TH_ERROR: repository unavailable}}
573
574 ###############################################################################
575
576 fossil test-th-eval --th-open-config "styleFooter"
577 test th1-footer-2 {$RESULT eq {}}
578
579 ###############################################################################
580
581 fossil test-th-eval --th-open-config "styleHeader {}; styleFooter"
582 test th1-footer-3 {[regexp -- {</body></html>} $RESULT]}
583
584 ###############################################################################
585
586 fossil test-th-eval "getParameter"
587 test th1-get-parameter-1 {$RESULT eq \
588

Keyboard Shortcuts

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