]> git.ipfire.org Git - thirdparty/git.git/commitdiff
gitk: add proc run_themeloader
authorMark Levedahl <mlevedahl@gmail.com>
Mon, 29 Sep 2025 03:04:54 +0000 (23:04 -0400)
committerMark Levedahl <mlevedahl@gmail.com>
Tue, 30 Sep 2025 00:54:09 +0000 (20:54 -0400)
gitk currently accepts a single themeloader file via the config file,
and will source this with errors reported to the console. This is fine
for simple configuration, but will not support interactive theme
exploration from the gui. In particular, a themeloader file must be
sourced only once as the themes defined cannot be re-defined. Also,
errors must be handled rather than just aborting while printing to the
console.  So, add a proc to handle the above, supporting expansion of
the gui config pages.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
gitk

diff --git a/gitk b/gitk
index 2d6a1693f68ec766e60888ccb29a038cf751691e..4798ff37097e3bd5450eab1de8989b1cfad4e504 100755 (executable)
--- a/gitk
+++ b/gitk
@@ -11861,6 +11861,23 @@ proc choose_extdiff {} {
     }
 }
 
+proc run_themeloader {f} {
+    if {![info exists ::_themefiles_seen]} {
+        set ::_themefiles_seen [dict create]
+    }
+
+    set fn [file normalize $f]
+    if {![dict exists $::_themefiles_seen $fn]} {
+        if {[catch {source $fn} err]} {
+            error_popup "could not interpret: $fn\n$err"
+            dict set ::_themefiles_seen $fn 0
+        } else {
+            dict set ::_themefiles_seen $fn 1
+        }
+    }
+    return [dict get $::_themefiles_seen $fn]
+}
+
 proc choosecolor {v vi prefspage x} {
     global $v
 
@@ -12742,7 +12759,10 @@ set nullid2 "0000000000000000000000000000000000000001"
 set nullfile "/dev/null"
 
 if {[file exists $themeloader]} {
-    source $themeloader
+    if {[run_themeloader $themeloader] == 0} {
+        puts stderr "Could not interpret themeloader: $themeloader"
+        exit 1
+    }
 }
 
 set appname "gitk"