@matheusbsbs / matheus-bagliano / commits / 8a8efbe414
Fork 0

git-gui: reduce Tcl version requirement from 8.6 to 8.5

On some MacOS distributions like High Sierra, Tcl 8.5 is shipped by default. This makes git-gui error out at startup because of the version mismatch. The only part that requires Tcl 8.6 is SimpleChord, which depends on TclOO. So, don't use it and use our homegrown class.tcl instead. This means some slight syntax changes. Since class.tcl doesn't have an "unknown" method like TclOO does, we can't just call '$note', but have to use '$note activate' instead. The constructor now needs a proper namespace qualifier. Update the documentation to reflect the new syntax. As of now, the only part of git-gui that needs Tcl 8.5 is a call to 'apply' in lib/index.tcl::lambda. Keep using it until someone shows up shouting that their OS ships with 8.4 only. Then we would have to look into implementing it in pure Tcl. Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>

Pratyush Yadav committed Feb 17, 2020 at 21:09 UTC 8a8efbe4140fd732e1890cbba6eaa85c0fac85e2
3 files changed +33 -35
git-gui.sh
+2 -2
@@ -30,8 +30,8 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.}]
30 ##
31 ## Tcl/Tk sanity check
32
33 -if {[catch {package require Tcl 8.6} err]
34 - || [catch {package require Tk 8.6} err]
33 +if {[catch {package require Tcl 8.5} err]
34 + || [catch {package require Tk 8.5} err]
35 } {
36 catch {wm withdraw .}
37 tk_messageBox \
lib/chord.tcl
+25 -29
@@ -27,7 +27,7 @@
27 # # Turn off the UI while running a couple of async operations.
28 # lock_ui
29 #
30 -# set chord [SimpleChord new {
30 +# set chord [SimpleChord::new {
31 # unlock_ui
32 # # Note: $notice here is not referenced in the calling scope
33 # if {$notice} { info_popup $notice }
@@ -37,9 +37,9 @@
37 # # all operations have been initiated.
38 # set common_note [$chord add_note]
39 #
40 -# # Pass notes as 'after' callbacks to other operations
41 -# async_operation $args [$chord add_note]
42 -# other_async_operation $args [$chord add_note]
40 +# # Activate notes in 'after' callbacks to other operations
41 +# set newnote [$chord add_note]
42 +# async_operation $args [list $newnote activate]
43 #
44 # # Communicate with the chord body
45 # if {$condition} {
@@ -48,7 +48,7 @@
48 # }
49 #
50 # # Activate the common note, making the chord eligible to complete
51 -# $common_note
51 +# $common_note activate
52 #
53 # At this point, the chord will complete at some unknown point in the future.
54 # The common note might have been the first note activated, or the async
@@ -60,18 +60,21 @@
60 # Represents a procedure that conceptually has multiple entrypoints that must
61 # all be called before the procedure executes. Each entrypoint is called a
62 # "note". The chord is only "completed" when all the notes are "activated".
63 -oo::class create SimpleChord {
64 - variable notes body is_completed
63 +class SimpleChord {
64 + field notes
65 + field body
66 + field is_completed
67
68 # Constructor:
67 - # set chord [SimpleChord new {body}]
69 + # set chord [SimpleChord::new {body}]
70 # Creates a new chord object with the specified body script. The
71 # body script is evaluated at most once, when a note is activated
72 # and the chord has no other non-activated notes.
71 - constructor {body} {
73 + constructor new {i_body} {
74 set notes [list]
73 - my eval [list set body $body]
75 + set body $i_body
76 set is_completed 0
77 + return $this
78 }
79
80 # Method:
@@ -80,7 +83,7 @@ oo::class create SimpleChord {
83 # the chord body will be evaluated. This can be used to set variable
84 # values for the chord body to use.
85 method eval {script} {
83 - namespace eval [self] $script
86 + namespace eval [namespace qualifiers $this] $script
87 }
88
89 # Method:
@@ -92,7 +95,7 @@ oo::class create SimpleChord {
95 method add_note {} {
96 if {$is_completed} { error "Cannot add a note to a completed chord" }
97
95 - set note [ChordNote new [self]]
98 + set note [ChordNote::new $this]
99
100 lappend notes $note
101
@@ -108,8 +111,8 @@ oo::class create SimpleChord {
111
112 set is_completed 1
113
111 - namespace eval [self] $body
112 - namespace delete [self]
114 + namespace eval [namespace qualifiers $this] $body
115 + delete_this
116 }
117 }
118 }
@@ -119,15 +122,17 @@ oo::class create SimpleChord {
122 # final note of the chord is activated (this can be any note in the chord,
123 # with all other notes already previously activated in any order), the chord's
124 # body is evaluated.
122 -oo::class create ChordNote {
123 - variable chord is_activated
125 +class ChordNote {
126 + field chord
127 + field is_activated
128
129 # Constructor:
130 # Instances of ChordNote are created internally by calling add_note on
131 # SimpleChord objects.
128 - constructor {chord} {
129 - my eval set chord $chord
132 + constructor new {c} {
133 + set chord $c
134 set is_activated 0
135 + return $this
136 }
137
138 # Method:
@@ -138,20 +143,11 @@ oo::class create ChordNote {
143 }
144
145 # Method:
141 - # $note
146 + # $note activate
147 # Activates the note, if it has not already been activated, and
148 # completes the chord if there are no other notes awaiting
149 # activation. Subsequent calls will have no further effect.
145 - #
146 - # NB: In TclOO, if an object is invoked like a method without supplying
147 - # any method name, then this internal method `unknown` is what
148 - # actually runs (with no parameters). It is used in the ChordNote
149 - # class for the purpose of allowing the note object to be called as
150 - # a function (see example above). (The `unknown` method can also be
151 - # used to support dynamic dispatch, but must take parameters to
152 - # identify the "unknown" method to be invoked. In this form, this
153 - # proc serves only to make instances behave directly like methods.)
154 - method unknown {} {
150 + method activate {} {
151 if {!$is_activated} {
152 set is_activated 1
153 $chord notify_note_activation
lib/index.tcl
+6 -4
@@ -436,7 +436,7 @@ proc revert_helper {txt paths} {
436 #
437 # The asynchronous operations are each indicated below by a comment
438 # before the code block that starts the async operation.
439 - set after_chord [SimpleChord new {
439 + set after_chord [SimpleChord::new {
440 if {[string trim $err] != ""} {
441 rescan_on_error $err
442 } else {
@@ -522,10 +522,11 @@ proc revert_helper {txt paths} {
522 ]
523
524 if {$reply == 1} {
525 + set note [$after_chord add_note]
526 checkout_index \
527 $txt \
528 $path_list \
528 - [$after_chord add_note] \
529 + [list $note activate] \
530 $capture_error
531 }
532 }
@@ -567,14 +568,15 @@ proc revert_helper {txt paths} {
568 if {$reply == 1} {
569 $after_chord eval { set should_reshow_diff 1 }
570
570 - delete_files $untracked_list [$after_chord add_note]
571 + set note [$after_chord add_note]
572 + delete_files $untracked_list [list $note activate]
573 }
574 }
575
576 # Activate the common note. If no other notes were created, this
577 # completes the chord. If other notes were created, then this common
578 # note prevents a race condition where the chord might complete early.
577 - $after_common_note
579 + $after_common_note activate
580 }
581
582 # Delete all of the specified files, performing deletion in batches to allow the