]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-gui: create a new namespace for chord script evaluation
authorPratyush Yadav <me@yadavpratyush.com>
Sat, 14 Mar 2020 21:38:36 +0000 (03:08 +0530)
committerPratyush Yadav <me@yadavpratyush.com>
Tue, 17 Mar 2020 13:18:54 +0000 (18:48 +0530)
Evaluating the script in the same namespace as the chord itself creates
potential for variable name collision. And in that case the script would
unknowingly use the chord's variables.

For example, say the script has a variable called 'is_completed', which
also exists in the chord's namespace. The script then calls 'eval' and
sets 'is_completed' to 1 thinking it is setting its own variable,
completely unaware of how the chord works behind the scenes. This leads
to the chord never actually executing because it sees 'is_completed' as
true and thinks it has already completed.

Avoid the potential collision by creating a separate namespace for the
script that is a child of the chord's namespace.

Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>
lib/chord.tcl

index 7de7cba8c9e37195de84568dc26c22e98caa59bb..e21e7d3d0b7924f85c29dad248492e22de0bf39b 100644 (file)
@@ -64,6 +64,7 @@ class SimpleChord {
        field notes
        field body
        field is_completed
+       field eval_ns
 
        # Constructor:
        #   set chord [SimpleChord::new {body}]
@@ -74,6 +75,7 @@ class SimpleChord {
                set notes [list]
                set body $i_body
                set is_completed 0
+               set eval_ns "[namespace qualifiers $this]::eval"
                return $this
        }
 
@@ -83,7 +85,7 @@ class SimpleChord {
        #     the chord body will be evaluated. This can be used to set variable
        #     values for the chord body to use.
        method eval {script} {
-               namespace eval [namespace qualifiers $this] $script
+               namespace eval $eval_ns $script
        }
 
        # Method:
@@ -111,7 +113,7 @@ class SimpleChord {
 
                        set is_completed 1
 
-                       namespace eval [namespace qualifiers $this] $body
+                       namespace eval $eval_ns $body
                        delete_this
                }
        }