Skip to content

Commit 3891a84

Browse files
committed
git-gui: create a new namespace for chord script evaluation
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 <[email protected]>
1 parent 8a8efbe commit 3891a84

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/chord.tcl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class SimpleChord {
6464
field notes
6565
field body
6666
field is_completed
67+
field eval_ns
6768

6869
# Constructor:
6970
# set chord [SimpleChord::new {body}]
@@ -74,6 +75,7 @@ class SimpleChord {
7475
set notes [list]
7576
set body $i_body
7677
set is_completed 0
78+
set eval_ns "[namespace qualifiers $this]::eval"
7779
return $this
7880
}
7981

@@ -83,7 +85,7 @@ class SimpleChord {
8385
# the chord body will be evaluated. This can be used to set variable
8486
# values for the chord body to use.
8587
method eval {script} {
86-
namespace eval [namespace qualifiers $this] $script
88+
namespace eval $eval_ns $script
8789
}
8890

8991
# Method:
@@ -111,7 +113,7 @@ class SimpleChord {
111113

112114
set is_completed 1
113115

114-
namespace eval [namespace qualifiers $this] $body
116+
namespace eval $eval_ns $body
115117
delete_this
116118
}
117119
}

0 commit comments

Comments
 (0)