Announce: scripting fossil with tcl (early stages)
(1) By Stephan Beal (stephan) on 2025-05-24 16:24:28 [link] [source]
For those who are Tcl-inclined...
As of today, libfossil has some rudimentary Tcl scripting capabilities, provided in the form of a Tcl loadable extension.
It's demonstrated in this test script and what features are available are documented here.
Current capabilities:
- Create new fossil context objects and use them to...
- Open/close repos.
- Resolve symbolic fossil names to their UUIDs or RIDs.
- Run arbitrary SQL, including access to the libfossil SQL functions, via a pretty spiffy pair of SQL-execution APIs:
- It has flexible way to specify data types when binding SQL parameters (keeping in mind that in Tcl, everything is a string).
- It can "eval" a user-provided script for each result row.
- Its query API can return query results directly to the caller.
- The user can specify one of several formats for data returned from a query, e.g. just column 3 of the first row, or column 2 of all rows, or one of several list-based and dict-based formats.
This code is all new - it was started only a week ago - and the list of TODOs is effectively endless, but it shows some promise. Collaborators are welcomed - get in touch.
(2) By Torsten Berg (torstenberg) on 2025-05-26 12:25:37 in reply to 1 [link] [source]
Wow. Cool to hear this.
This is another heavy argument for me to try libfossil! I have to find some time for this and explore the possibilities.
Thanks so much for doing all this!
(3) By Stephan Beal (stephan) on 2025-05-26 15:57:00 in reply to 2 [link] [source]
Thanks so much for doing all this!
Thank you for the feedback! This is my 9th(10th?) time binding sqlite to a scripting engine, so it's moving pretty quickly, but this is my first time using the C Tcl API for anything beyond literally "Hello, World!" so there's a learning curve there. Even so, the db part of the API is "mostly" feature-complete, with parameter binding and column fetching in multiple flavors, transactions, and scalar UDFs (aggregates and window functions are coming Real Soon Now™. The infrastructure is all in place, they just need to be added on top of it).
(4) By Torsten Berg (torstenberg) on 2025-05-27 18:37:49 in reply to 3 [link] [source]
If you need help with the Tcl C API, I can recommend to ask on comp.lang.tcl where you always will find some Tcl wizards listening. I have only limited experience with the C API (only having used it for some gdal binding to Tcl yet). In general, the Tcl C API function are quite well documented in the respective manual pages and there are good books on their basic usage.
(5) By Stephan Beal (stephan) on 2025-06-08 09:58:15 in reply to 2 [source]
I have to find some time for this and explore the possibilities.
The possibilities have just been extended: it now supports all of the major db features, including prepared statements and aggregate and window user-defined SQL functions. (This might be the first SQLite Tcl binding ever to support those. Any prior art for those particular features is unknown to me.)
It's my current belief that most value from scripting fossil is of the "reporting" variety - pulling stuff out of its db, even if that just means doing an "ls" on the current version's files. Thus the overwhelming majority of the Tcl binding (something like 75 or 80%) is specifically the db API. Whether scripting SCM capabilities like checking in files makes practical sense is debatable (there's no technical hurdle to adding it, but whether it's worth the effort is questionable).
What currently works is documented here.