Fossil SCM

Further corrections to configuration handling by the TH1 hooks support functions.

mistachkin 2014-06-15 01:54 trunk
Commit e52682ece13f18007ad1524e84c3810fd2f0a092
1 file changed +51 -24
+51 -24
--- src/th_main.c
+++ src/th_main.c
@@ -1467,10 +1467,29 @@
14671467
}
14681468
return i;
14691469
}
14701470
14711471
#ifdef FOSSIL_ENABLE_TH1_HOOKS
1472
+/*
1473
+** This function determines if TH1 hooks are enabled for the repository. It
1474
+** may be necessary to open the repository and/or the configuration ("user")
1475
+** database from within this function. Before this function returns, any
1476
+** database opened will be closed again. This is very important because some
1477
+** commands do not expect the repository and/or the configuration ("user")
1478
+** database to be open prior to their own code doing so.
1479
+*/
1480
+int Th_AreHooksEnabled(void){
1481
+ int rc;
1482
+ if( fossil_getenv("TH1_ENABLE_HOOKS")!=0 ){
1483
+ return 1;
1484
+ }
1485
+ Th_OpenConfig(1);
1486
+ rc = db_get_boolean("th1-hooks", 0);
1487
+ Th_CloseConfig(1);
1488
+ return rc;
1489
+}
1490
+
14721491
/*
14731492
** This function is called by Fossil just prior to dispatching a command.
14741493
** Returning a value other than TH_OK from this function (i.e. via an
14751494
** evaluated script raising an error or calling [break]/[continue]) will
14761495
** cause the actual command execution to be skipped.
@@ -1478,16 +1497,11 @@
14781497
int Th_CommandHook(
14791498
const char *zName,
14801499
char cmdFlags
14811500
){
14821501
int rc = TH_OK;
1483
- Th_OpenConfig(1);
1484
- if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1485
- Th_CloseConfig(1);
1486
- return rc;
1487
- }
1488
- Th_CloseConfig(1);
1502
+ if( !Th_AreHooksEnabled() ) return rc;
14891503
Th_FossilInit(TH_INIT_HOOK);
14901504
Th_Store("cmd_name", zName);
14911505
Th_StoreList("cmd_args", g.argv, g.argc);
14921506
Th_StoreInt("cmd_flags", cmdFlags);
14931507
rc = Th_Eval(g.interp, 0, "command_hook", -1);
@@ -1511,10 +1525,17 @@
15111525
*/
15121526
if( g.thTrace ){
15131527
Th_Trace("[command_hook {%h}] => %h<br />\n", zName,
15141528
Th_ReturnCodeName(rc, 0));
15151529
}
1530
+ /*
1531
+ ** Does our call to Th_FossilInit() result in opening a database? If so,
1532
+ ** clean it up now. This is very important because some commands do not
1533
+ ** expect the repository and/or the configuration ("user") database to be
1534
+ ** open prior to their own code doing so.
1535
+ */
1536
+ if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
15161537
return (rc != TH_ERROR) ? rc : TH_OK;
15171538
}
15181539
15191540
/*
15201541
** This function is called by Fossil just after dispatching a command.
@@ -1526,25 +1547,27 @@
15261547
int Th_CommandNotify(
15271548
const char *zName,
15281549
char cmdFlags
15291550
){
15301551
int rc = TH_OK;
1531
- Th_OpenConfig(1);
1532
- if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1533
- Th_CloseConfig(1);
1534
- return rc;
1535
- }
1536
- Th_CloseConfig(1);
1552
+ if( !Th_AreHooksEnabled() ) return rc;
15371553
Th_FossilInit(TH_INIT_HOOK);
15381554
Th_Store("cmd_name", zName);
15391555
Th_StoreList("cmd_args", g.argv, g.argc);
15401556
Th_StoreInt("cmd_flags", cmdFlags);
15411557
rc = Th_Eval(g.interp, 0, "command_notify", -1);
15421558
if( g.thTrace ){
15431559
Th_Trace("[command_notify {%h}] => %h<br />\n", zName,
15441560
Th_ReturnCodeName(rc, 0));
15451561
}
1562
+ /*
1563
+ ** Does our call to Th_FossilInit() result in opening a database? If so,
1564
+ ** clean it up now. This is very important because some commands do not
1565
+ ** expect the repository and/or the configuration ("user") database to be
1566
+ ** open prior to their own code doing so.
1567
+ */
1568
+ if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
15461569
return rc;
15471570
}
15481571
15491572
/*
15501573
** This function is called by Fossil just prior to processing a web page.
@@ -1555,16 +1578,11 @@
15551578
int Th_WebpageHook(
15561579
const char *zName,
15571580
char cmdFlags
15581581
){
15591582
int rc = TH_OK;
1560
- Th_OpenConfig(1);
1561
- if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1562
- Th_CloseConfig(1);
1563
- return rc;
1564
- }
1565
- Th_CloseConfig(1);
1583
+ if( !Th_AreHooksEnabled() ) return rc;
15661584
Th_FossilInit(TH_INIT_HOOK);
15671585
Th_Store("web_name", zName);
15681586
Th_StoreList("web_args", g.argv, g.argc);
15691587
Th_StoreInt("web_flags", cmdFlags);
15701588
rc = Th_Eval(g.interp, 0, "webpage_hook", -1);
@@ -1588,10 +1606,17 @@
15881606
*/
15891607
if( g.thTrace ){
15901608
Th_Trace("[webpage_hook {%h}] => %h<br />\n", zName,
15911609
Th_ReturnCodeName(rc, 0));
15921610
}
1611
+ /*
1612
+ ** Does our call to Th_FossilInit() result in opening a database? If so,
1613
+ ** clean it up now. This is very important because some commands do not
1614
+ ** expect the repository and/or the configuration ("user") database to be
1615
+ ** open prior to their own code doing so.
1616
+ */
1617
+ if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
15931618
return (rc != TH_ERROR) ? rc : TH_OK;
15941619
}
15951620
15961621
/*
15971622
** This function is called by Fossil just after processing a web page.
@@ -1603,25 +1628,27 @@
16031628
int Th_WebpageNotify(
16041629
const char *zName,
16051630
char cmdFlags
16061631
){
16071632
int rc = TH_OK;
1608
- Th_OpenConfig(1);
1609
- if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1610
- Th_CloseConfig(1);
1611
- return rc;
1612
- }
1613
- Th_CloseConfig(1);
1633
+ if( !Th_AreHooksEnabled() ) return rc;
16141634
Th_FossilInit(TH_INIT_HOOK);
16151635
Th_Store("web_name", zName);
16161636
Th_StoreList("web_args", g.argv, g.argc);
16171637
Th_StoreInt("web_flags", cmdFlags);
16181638
rc = Th_Eval(g.interp, 0, "webpage_notify", -1);
16191639
if( g.thTrace ){
16201640
Th_Trace("[webpage_notify {%h}] => %h<br />\n", zName,
16211641
Th_ReturnCodeName(rc, 0));
16221642
}
1643
+ /*
1644
+ ** Does our call to Th_FossilInit() result in opening a database? If so,
1645
+ ** clean it up now. This is very important because some commands do not
1646
+ ** expect the repository and/or the configuration ("user") database to be
1647
+ ** open prior to their own code doing so.
1648
+ */
1649
+ if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
16231650
return rc;
16241651
}
16251652
#endif
16261653
16271654
/*
16281655
--- src/th_main.c
+++ src/th_main.c
@@ -1467,10 +1467,29 @@
1467 }
1468 return i;
1469 }
1470
1471 #ifdef FOSSIL_ENABLE_TH1_HOOKS
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1472 /*
1473 ** This function is called by Fossil just prior to dispatching a command.
1474 ** Returning a value other than TH_OK from this function (i.e. via an
1475 ** evaluated script raising an error or calling [break]/[continue]) will
1476 ** cause the actual command execution to be skipped.
@@ -1478,16 +1497,11 @@
1478 int Th_CommandHook(
1479 const char *zName,
1480 char cmdFlags
1481 ){
1482 int rc = TH_OK;
1483 Th_OpenConfig(1);
1484 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1485 Th_CloseConfig(1);
1486 return rc;
1487 }
1488 Th_CloseConfig(1);
1489 Th_FossilInit(TH_INIT_HOOK);
1490 Th_Store("cmd_name", zName);
1491 Th_StoreList("cmd_args", g.argv, g.argc);
1492 Th_StoreInt("cmd_flags", cmdFlags);
1493 rc = Th_Eval(g.interp, 0, "command_hook", -1);
@@ -1511,10 +1525,17 @@
1511 */
1512 if( g.thTrace ){
1513 Th_Trace("[command_hook {%h}] => %h<br />\n", zName,
1514 Th_ReturnCodeName(rc, 0));
1515 }
 
 
 
 
 
 
 
1516 return (rc != TH_ERROR) ? rc : TH_OK;
1517 }
1518
1519 /*
1520 ** This function is called by Fossil just after dispatching a command.
@@ -1526,25 +1547,27 @@
1526 int Th_CommandNotify(
1527 const char *zName,
1528 char cmdFlags
1529 ){
1530 int rc = TH_OK;
1531 Th_OpenConfig(1);
1532 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1533 Th_CloseConfig(1);
1534 return rc;
1535 }
1536 Th_CloseConfig(1);
1537 Th_FossilInit(TH_INIT_HOOK);
1538 Th_Store("cmd_name", zName);
1539 Th_StoreList("cmd_args", g.argv, g.argc);
1540 Th_StoreInt("cmd_flags", cmdFlags);
1541 rc = Th_Eval(g.interp, 0, "command_notify", -1);
1542 if( g.thTrace ){
1543 Th_Trace("[command_notify {%h}] => %h<br />\n", zName,
1544 Th_ReturnCodeName(rc, 0));
1545 }
 
 
 
 
 
 
 
1546 return rc;
1547 }
1548
1549 /*
1550 ** This function is called by Fossil just prior to processing a web page.
@@ -1555,16 +1578,11 @@
1555 int Th_WebpageHook(
1556 const char *zName,
1557 char cmdFlags
1558 ){
1559 int rc = TH_OK;
1560 Th_OpenConfig(1);
1561 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1562 Th_CloseConfig(1);
1563 return rc;
1564 }
1565 Th_CloseConfig(1);
1566 Th_FossilInit(TH_INIT_HOOK);
1567 Th_Store("web_name", zName);
1568 Th_StoreList("web_args", g.argv, g.argc);
1569 Th_StoreInt("web_flags", cmdFlags);
1570 rc = Th_Eval(g.interp, 0, "webpage_hook", -1);
@@ -1588,10 +1606,17 @@
1588 */
1589 if( g.thTrace ){
1590 Th_Trace("[webpage_hook {%h}] => %h<br />\n", zName,
1591 Th_ReturnCodeName(rc, 0));
1592 }
 
 
 
 
 
 
 
1593 return (rc != TH_ERROR) ? rc : TH_OK;
1594 }
1595
1596 /*
1597 ** This function is called by Fossil just after processing a web page.
@@ -1603,25 +1628,27 @@
1603 int Th_WebpageNotify(
1604 const char *zName,
1605 char cmdFlags
1606 ){
1607 int rc = TH_OK;
1608 Th_OpenConfig(1);
1609 if( fossil_getenv("TH1_ENABLE_HOOKS")==0 && !db_get_boolean("th1-hooks", 0) ){
1610 Th_CloseConfig(1);
1611 return rc;
1612 }
1613 Th_CloseConfig(1);
1614 Th_FossilInit(TH_INIT_HOOK);
1615 Th_Store("web_name", zName);
1616 Th_StoreList("web_args", g.argv, g.argc);
1617 Th_StoreInt("web_flags", cmdFlags);
1618 rc = Th_Eval(g.interp, 0, "webpage_notify", -1);
1619 if( g.thTrace ){
1620 Th_Trace("[webpage_notify {%h}] => %h<br />\n", zName,
1621 Th_ReturnCodeName(rc, 0));
1622 }
 
 
 
 
 
 
 
1623 return rc;
1624 }
1625 #endif
1626
1627 /*
1628
--- src/th_main.c
+++ src/th_main.c
@@ -1467,10 +1467,29 @@
1467 }
1468 return i;
1469 }
1470
1471 #ifdef FOSSIL_ENABLE_TH1_HOOKS
1472 /*
1473 ** This function determines if TH1 hooks are enabled for the repository. It
1474 ** may be necessary to open the repository and/or the configuration ("user")
1475 ** database from within this function. Before this function returns, any
1476 ** database opened will be closed again. This is very important because some
1477 ** commands do not expect the repository and/or the configuration ("user")
1478 ** database to be open prior to their own code doing so.
1479 */
1480 int Th_AreHooksEnabled(void){
1481 int rc;
1482 if( fossil_getenv("TH1_ENABLE_HOOKS")!=0 ){
1483 return 1;
1484 }
1485 Th_OpenConfig(1);
1486 rc = db_get_boolean("th1-hooks", 0);
1487 Th_CloseConfig(1);
1488 return rc;
1489 }
1490
1491 /*
1492 ** This function is called by Fossil just prior to dispatching a command.
1493 ** Returning a value other than TH_OK from this function (i.e. via an
1494 ** evaluated script raising an error or calling [break]/[continue]) will
1495 ** cause the actual command execution to be skipped.
@@ -1478,16 +1497,11 @@
1497 int Th_CommandHook(
1498 const char *zName,
1499 char cmdFlags
1500 ){
1501 int rc = TH_OK;
1502 if( !Th_AreHooksEnabled() ) return rc;
 
 
 
 
 
1503 Th_FossilInit(TH_INIT_HOOK);
1504 Th_Store("cmd_name", zName);
1505 Th_StoreList("cmd_args", g.argv, g.argc);
1506 Th_StoreInt("cmd_flags", cmdFlags);
1507 rc = Th_Eval(g.interp, 0, "command_hook", -1);
@@ -1511,10 +1525,17 @@
1525 */
1526 if( g.thTrace ){
1527 Th_Trace("[command_hook {%h}] => %h<br />\n", zName,
1528 Th_ReturnCodeName(rc, 0));
1529 }
1530 /*
1531 ** Does our call to Th_FossilInit() result in opening a database? If so,
1532 ** clean it up now. This is very important because some commands do not
1533 ** expect the repository and/or the configuration ("user") database to be
1534 ** open prior to their own code doing so.
1535 */
1536 if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
1537 return (rc != TH_ERROR) ? rc : TH_OK;
1538 }
1539
1540 /*
1541 ** This function is called by Fossil just after dispatching a command.
@@ -1526,25 +1547,27 @@
1547 int Th_CommandNotify(
1548 const char *zName,
1549 char cmdFlags
1550 ){
1551 int rc = TH_OK;
1552 if( !Th_AreHooksEnabled() ) return rc;
 
 
 
 
 
1553 Th_FossilInit(TH_INIT_HOOK);
1554 Th_Store("cmd_name", zName);
1555 Th_StoreList("cmd_args", g.argv, g.argc);
1556 Th_StoreInt("cmd_flags", cmdFlags);
1557 rc = Th_Eval(g.interp, 0, "command_notify", -1);
1558 if( g.thTrace ){
1559 Th_Trace("[command_notify {%h}] => %h<br />\n", zName,
1560 Th_ReturnCodeName(rc, 0));
1561 }
1562 /*
1563 ** Does our call to Th_FossilInit() result in opening a database? If so,
1564 ** clean it up now. This is very important because some commands do not
1565 ** expect the repository and/or the configuration ("user") database to be
1566 ** open prior to their own code doing so.
1567 */
1568 if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
1569 return rc;
1570 }
1571
1572 /*
1573 ** This function is called by Fossil just prior to processing a web page.
@@ -1555,16 +1578,11 @@
1578 int Th_WebpageHook(
1579 const char *zName,
1580 char cmdFlags
1581 ){
1582 int rc = TH_OK;
1583 if( !Th_AreHooksEnabled() ) return rc;
 
 
 
 
 
1584 Th_FossilInit(TH_INIT_HOOK);
1585 Th_Store("web_name", zName);
1586 Th_StoreList("web_args", g.argv, g.argc);
1587 Th_StoreInt("web_flags", cmdFlags);
1588 rc = Th_Eval(g.interp, 0, "webpage_hook", -1);
@@ -1588,10 +1606,17 @@
1606 */
1607 if( g.thTrace ){
1608 Th_Trace("[webpage_hook {%h}] => %h<br />\n", zName,
1609 Th_ReturnCodeName(rc, 0));
1610 }
1611 /*
1612 ** Does our call to Th_FossilInit() result in opening a database? If so,
1613 ** clean it up now. This is very important because some commands do not
1614 ** expect the repository and/or the configuration ("user") database to be
1615 ** open prior to their own code doing so.
1616 */
1617 if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
1618 return (rc != TH_ERROR) ? rc : TH_OK;
1619 }
1620
1621 /*
1622 ** This function is called by Fossil just after processing a web page.
@@ -1603,25 +1628,27 @@
1628 int Th_WebpageNotify(
1629 const char *zName,
1630 char cmdFlags
1631 ){
1632 int rc = TH_OK;
1633 if( !Th_AreHooksEnabled() ) return rc;
 
 
 
 
 
1634 Th_FossilInit(TH_INIT_HOOK);
1635 Th_Store("web_name", zName);
1636 Th_StoreList("web_args", g.argv, g.argc);
1637 Th_StoreInt("web_flags", cmdFlags);
1638 rc = Th_Eval(g.interp, 0, "webpage_notify", -1);
1639 if( g.thTrace ){
1640 Th_Trace("[webpage_notify {%h}] => %h<br />\n", zName,
1641 Th_ReturnCodeName(rc, 0));
1642 }
1643 /*
1644 ** Does our call to Th_FossilInit() result in opening a database? If so,
1645 ** clean it up now. This is very important because some commands do not
1646 ** expect the repository and/or the configuration ("user") database to be
1647 ** open prior to their own code doing so.
1648 */
1649 if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
1650 return rc;
1651 }
1652 #endif
1653
1654 /*
1655

Keyboard Shortcuts

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