Fossil SCM
Further corrections to configuration handling by the TH1 hooks support functions.
Commit
e52682ece13f18007ad1524e84c3810fd2f0a092
Parent
c1915c33470a2c7…
1 file changed
+51
-24
+51
-24
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -1467,10 +1467,29 @@ | ||
| 1467 | 1467 | } |
| 1468 | 1468 | return i; |
| 1469 | 1469 | } |
| 1470 | 1470 | |
| 1471 | 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 | + | |
| 1472 | 1491 | /* |
| 1473 | 1492 | ** This function is called by Fossil just prior to dispatching a command. |
| 1474 | 1493 | ** Returning a value other than TH_OK from this function (i.e. via an |
| 1475 | 1494 | ** evaluated script raising an error or calling [break]/[continue]) will |
| 1476 | 1495 | ** cause the actual command execution to be skipped. |
| @@ -1478,16 +1497,11 @@ | ||
| 1478 | 1497 | int Th_CommandHook( |
| 1479 | 1498 | const char *zName, |
| 1480 | 1499 | char cmdFlags |
| 1481 | 1500 | ){ |
| 1482 | 1501 | 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; | |
| 1489 | 1503 | Th_FossilInit(TH_INIT_HOOK); |
| 1490 | 1504 | Th_Store("cmd_name", zName); |
| 1491 | 1505 | Th_StoreList("cmd_args", g.argv, g.argc); |
| 1492 | 1506 | Th_StoreInt("cmd_flags", cmdFlags); |
| 1493 | 1507 | rc = Th_Eval(g.interp, 0, "command_hook", -1); |
| @@ -1511,10 +1525,17 @@ | ||
| 1511 | 1525 | */ |
| 1512 | 1526 | if( g.thTrace ){ |
| 1513 | 1527 | Th_Trace("[command_hook {%h}] => %h<br />\n", zName, |
| 1514 | 1528 | Th_ReturnCodeName(rc, 0)); |
| 1515 | 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); | |
| 1516 | 1537 | return (rc != TH_ERROR) ? rc : TH_OK; |
| 1517 | 1538 | } |
| 1518 | 1539 | |
| 1519 | 1540 | /* |
| 1520 | 1541 | ** This function is called by Fossil just after dispatching a command. |
| @@ -1526,25 +1547,27 @@ | ||
| 1526 | 1547 | int Th_CommandNotify( |
| 1527 | 1548 | const char *zName, |
| 1528 | 1549 | char cmdFlags |
| 1529 | 1550 | ){ |
| 1530 | 1551 | 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; | |
| 1537 | 1553 | Th_FossilInit(TH_INIT_HOOK); |
| 1538 | 1554 | Th_Store("cmd_name", zName); |
| 1539 | 1555 | Th_StoreList("cmd_args", g.argv, g.argc); |
| 1540 | 1556 | Th_StoreInt("cmd_flags", cmdFlags); |
| 1541 | 1557 | rc = Th_Eval(g.interp, 0, "command_notify", -1); |
| 1542 | 1558 | if( g.thTrace ){ |
| 1543 | 1559 | Th_Trace("[command_notify {%h}] => %h<br />\n", zName, |
| 1544 | 1560 | Th_ReturnCodeName(rc, 0)); |
| 1545 | 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); | |
| 1546 | 1569 | return rc; |
| 1547 | 1570 | } |
| 1548 | 1571 | |
| 1549 | 1572 | /* |
| 1550 | 1573 | ** This function is called by Fossil just prior to processing a web page. |
| @@ -1555,16 +1578,11 @@ | ||
| 1555 | 1578 | int Th_WebpageHook( |
| 1556 | 1579 | const char *zName, |
| 1557 | 1580 | char cmdFlags |
| 1558 | 1581 | ){ |
| 1559 | 1582 | 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; | |
| 1566 | 1584 | Th_FossilInit(TH_INIT_HOOK); |
| 1567 | 1585 | Th_Store("web_name", zName); |
| 1568 | 1586 | Th_StoreList("web_args", g.argv, g.argc); |
| 1569 | 1587 | Th_StoreInt("web_flags", cmdFlags); |
| 1570 | 1588 | rc = Th_Eval(g.interp, 0, "webpage_hook", -1); |
| @@ -1588,10 +1606,17 @@ | ||
| 1588 | 1606 | */ |
| 1589 | 1607 | if( g.thTrace ){ |
| 1590 | 1608 | Th_Trace("[webpage_hook {%h}] => %h<br />\n", zName, |
| 1591 | 1609 | Th_ReturnCodeName(rc, 0)); |
| 1592 | 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); | |
| 1593 | 1618 | return (rc != TH_ERROR) ? rc : TH_OK; |
| 1594 | 1619 | } |
| 1595 | 1620 | |
| 1596 | 1621 | /* |
| 1597 | 1622 | ** This function is called by Fossil just after processing a web page. |
| @@ -1603,25 +1628,27 @@ | ||
| 1603 | 1628 | int Th_WebpageNotify( |
| 1604 | 1629 | const char *zName, |
| 1605 | 1630 | char cmdFlags |
| 1606 | 1631 | ){ |
| 1607 | 1632 | 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; | |
| 1614 | 1634 | Th_FossilInit(TH_INIT_HOOK); |
| 1615 | 1635 | Th_Store("web_name", zName); |
| 1616 | 1636 | Th_StoreList("web_args", g.argv, g.argc); |
| 1617 | 1637 | Th_StoreInt("web_flags", cmdFlags); |
| 1618 | 1638 | rc = Th_Eval(g.interp, 0, "webpage_notify", -1); |
| 1619 | 1639 | if( g.thTrace ){ |
| 1620 | 1640 | Th_Trace("[webpage_notify {%h}] => %h<br />\n", zName, |
| 1621 | 1641 | Th_ReturnCodeName(rc, 0)); |
| 1622 | 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); | |
| 1623 | 1650 | return rc; |
| 1624 | 1651 | } |
| 1625 | 1652 | #endif |
| 1626 | 1653 | |
| 1627 | 1654 | /* |
| 1628 | 1655 |
| --- 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 |