Index: src/th_main.c ================================================================== --- src/th_main.c +++ src/th_main.c @@ -669,10 +669,79 @@ Th_Trace("%s", argv[1]); } Th_SetResult(interp, 0, 0); return TH_OK; } + +/* +** TH1 command: globalState NAME ?DEFAULT? +** +** Returns a string containing the value of the specified global state +** variable -OR- the specified default value. Currently, the supported +** items are: +** +** "checkout" = The active local checkout directory, if any. +** "configuration" = The active configuration database file name, +** if any. +** "executable" = The fully qualified executable file name. +** "log" = The error log file name, if any. +** "repository" = The active local repository file name, if +** any. +** "top" = The base path for the active server instance, +** if applicable. +** "user" = The active user name, if any. +** "vfs" = The SQLite VFS in use, if overridden. +** +** Attempts to query for unsupported global state variables will result +** in a script error. Additional global state variables may be exposed +** in the future. +** +** See also: checkout, repository, setting +*/ +static int globalStateCmd( + Th_Interp *interp, + void *p, + int argc, + const char **argv, + int *argl +){ + const char *zDefault = 0; + if( argc!=2 && argc!=3 ){ + return Th_WrongNumArgs(interp, "globalState NAME ?DEFAULT?"); + } + if( argc==3 ){ + zDefault = argv[2]; + } + if( fossil_strnicmp(argv[1], "checkout\0", 9)==0 ){ + Th_SetResult(interp, g.zLocalRoot ? g.zLocalRoot : zDefault, -1); + return TH_OK; + }else if( fossil_strnicmp(argv[1], "configuration\0", 14)==0 ){ + Th_SetResult(interp, g.zConfigDbName ? g.zConfigDbName : zDefault, -1); + return TH_OK; + }else if( fossil_strnicmp(argv[1], "executable\0", 11)==0 ){ + Th_SetResult(interp, g.nameOfExe ? g.nameOfExe : zDefault, -1); + return TH_OK; + }else if( fossil_strnicmp(argv[1], "log\0", 4)==0 ){ + Th_SetResult(interp, g.zErrlog ? g.zErrlog : zDefault, -1); + return TH_OK; + }else if( fossil_strnicmp(argv[1], "repository\0", 11)==0 ){ + Th_SetResult(interp, g.zRepositoryName ? g.zRepositoryName : zDefault, -1); + return TH_OK; + }else if( fossil_strnicmp(argv[1], "top\0", 4)==0 ){ + Th_SetResult(interp, g.zTop ? g.zTop : zDefault, -1); + return TH_OK; + }else if( fossil_strnicmp(argv[1], "user\0", 5)==0 ){ + Th_SetResult(interp, g.zLogin ? g.zLogin : zDefault, -1); + return TH_OK; + }else if( fossil_strnicmp(argv[1], "vfs\0", 4)==0 ){ + Th_SetResult(interp, g.zVfsName ? g.zVfsName : zDefault, -1); + return TH_OK; + }else{ + Th_ErrorMessage(interp, "unsupported global state:", argv[1], argl[1]); + return TH_ERROR; + } +} /* ** TH1 command: getParameter NAME ?DEFAULT? ** ** Return the value of the specified query parameter or the specified default @@ -1290,10 +1359,11 @@ {"combobox", comboboxCmd, 0}, {"date", dateCmd, 0}, {"decorate", wikiCmd, (void*)&aFlags[2]}, {"enable_output", enableOutputCmd, 0}, {"getParameter", getParameterCmd, 0}, + {"globalState", globalStateCmd, 0}, {"httpize", httpizeCmd, 0}, {"hascap", hascapCmd, 0}, {"hasfeature", hasfeatureCmd, 0}, {"html", putsCmd, (void*)&aFlags[0]}, {"htmlize", htmlizeCmd, 0}, Index: test/th1.test ================================================================== --- test/th1.test +++ test/th1.test @@ -676,5 +676,88 @@ ############################################################################### fossil test-th-eval --th-open-config "artifact 0000000000 test/th1.test" test th1-artifact-9 {$RESULT eq {TH_ERROR: artifact not found}} + +############################################################################### + +fossil test-th-eval "globalState checkout" +test th1-globalState-1 {[string length $RESULT] > 0} + +############################################################################### + +fossil test-th-eval "globalState checkout" +test th1-globalState-2 {$RESULT eq [fossil test-th-eval checkout]} + +############################################################################### + +fossil test-th-eval "globalState configuration" +test th1-globalState-3 {[string length $RESULT] == 0} + +############################################################################### + +fossil test-th-eval --th-open-config "globalState configuration" +test th1-globalState-4 {[string length $RESULT] > 0} + +############################################################################### + +fossil test-th-eval "globalState executable" +test th1-globalState-5 {[file rootname [file tail $RESULT]] eq "fossil"} + +############################################################################### + +fossil test-th-eval "globalState log" +test th1-globalState-6 {[string length $RESULT] == 0} + +############################################################################### + +fossil test-th-eval --errorlog foserrors.log "globalState log" +test th1-globalState-7 {$RESULT eq "foserrors.log"} + +############################################################################### + +fossil test-th-eval "globalState repository" +test th1-globalState-8 {[string length $RESULT] > 0} + +############################################################################### + +fossil test-th-eval "globalState repository" +test th1-globalState-9 {$RESULT eq [fossil test-th-eval repository]} + +############################################################################### + +fossil test-th-eval "globalState top" +test th1-globalState-10 {[string length $RESULT] == 0} + +############################################################################### + +fossil test-th-eval "globalState user" +test th1-globalState-11 {[string length $RESULT] == 0} + +############################################################################### + +fossil test-th-eval --user fossil-th1-test "globalState user" +test th1-globalState-12 {$RESULT eq "fossil-th1-test"} + +############################################################################### + +fossil test-th-eval "globalState vfs" +test th1-globalState-13 {[string length $RESULT] == 0} + +############################################################################### + +fossil test-th-eval "globalState vfs" +test th1-globalState-14 {[string length $RESULT] == 0} + +############################################################################### + +if {$tcl_platform(platform) eq "windows"} then { + set altVfs win32-longpath +} else { + set altVfs unix-dotfile +} + +############################################################################### + +fossil test-th-eval --vfs $altVfs "globalState vfs" +test th1-globalState-15 {$RESULT eq $altVfs} Index: www/changes.wiki ================================================================== --- www/changes.wiki +++ www/changes.wiki @@ -9,12 +9,12 @@ support FuseFS. * Support customization of commands and webpages, including the ability to add new ones, via the "TH1 hooks" feature. Disabled by default. Enabled via a compile-time option. * Add the [checkout], [render], [styleHeader], [styleFooter], - [trace], [getParameter], [setParameter], and [artifact] commands - to TH1, primarily for use by TH1 hooks. + [trace], [getParameter], [setParameter], [artifact], and + [globalState] commands to TH1, primarily for use by TH1 hooks. * Bring in the latest version of autosetup from upstream. * When committing a (non-binary) file which contains bytes forming an invalid UTF-8 stream, fossil now adds the possibility to convert it to a valid UTF-8 stream ('c') if you like. * Let [/help?cmd=new|fossil new] no longer create an initial empty commit