@matheusbsbs / matheus-bagliano / commits / a35d65d9c8
Fork 0

git-gui: Move console procs into their own namespace

To help modularize git-gui better I'm isolating the code and variables required to handle our little console windows into their own namespace. This way we can say console::new rather than new_console, and the hidden internal procs to create the window and read data from our filehandle are off in their own private little land, where most users don't see them. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed May 1, 2007 at 02:59 UTC a35d65d9c8a2a6a10d369c00e22aded6fbdff2a9
4 files changed +57 -39
lib/console.tcl
+38 -22
@@ -1,17 +1,25 @@
1 # git-gui console support
2 # Copyright (C) 2006, 2007 Shawn Pearce
3
4 -set next_console_id 0
4 +namespace eval console {
5 +
6 +variable next_console_id 0
7 +variable console_data
8 +variable console_cr
9 +
10 +proc new {short_title long_title} {
11 + variable next_console_id
12 + variable console_data
13
6 -proc new_console {short_title long_title} {
7 - global next_console_id console_data
14 set w .console[incr next_console_id]
15 set console_data($w) [list $short_title $long_title]
10 - return [console_init $w]
16 + return [_init $w]
17 }
18
13 -proc console_init {w} {
14 - global console_cr console_data M1B
19 +proc _init {w} {
20 + global M1B
21 + variable console_cr
22 + variable console_data
23
24 set console_cr($w) 1.0
25 toplevel $w
@@ -63,7 +71,7 @@ proc console_init {w} {
71 return $w
72 }
73
66 -proc console_exec {w cmd after} {
74 +proc exec {w cmd {after {}}} {
75 # -- Cygwin's Tcl tosses the enviroment when we exec our child.
76 # But most users need that so we have to relogin. :-(
77 #
@@ -78,15 +86,16 @@ proc console_exec {w cmd after} {
86
87 set fd_f [open $cmd r]
88 fconfigure $fd_f -blocking 0 -translation binary
81 - fileevent $fd_f readable [list console_read $w $fd_f $after]
89 + fileevent $fd_f readable \
90 + [namespace code [list _read $w $fd_f $after]]
91 }
92
84 -proc console_read {w fd after} {
85 - global console_cr
93 +proc _read {w fd after} {
94 + variable console_cr
95
96 set buf [read $fd]
97 if {$buf ne {}} {
89 - if {![winfo exists $w]} {console_init $w}
98 + if {![winfo exists $w]} {_init $w}
99 $w.m.t conf -state normal
100 set c 0
101 set n [string length $buf]
@@ -120,36 +129,41 @@ proc console_read {w fd after} {
129 } else {
130 set ok 1
131 }
123 - uplevel #0 $after $w $ok
132 + if {$after ne {}} {
133 + uplevel #0 $after $w $ok
134 + } else {
135 + done $w $ok
136 + }
137 return
138 }
139 fconfigure $fd -blocking 0
140 }
141
129 -proc console_chain {cmdlist w {ok 1}} {
142 +proc chain {cmdlist w {ok 1}} {
143 if {$ok} {
144 if {[llength $cmdlist] == 0} {
132 - console_done $w $ok
145 + done $w $ok
146 return
147 }
148
149 set cmd [lindex $cmdlist 0]
150 set cmdlist [lrange $cmdlist 1 end]
151
139 - if {[lindex $cmd 0] eq {console_exec}} {
140 - console_exec $w \
152 + if {[lindex $cmd 0] eq {exec}} {
153 + exec $w \
154 [lindex $cmd 1] \
142 - [list console_chain $cmdlist]
155 + [namespace code [list chain $cmdlist]]
156 } else {
157 uplevel #0 $cmd $cmdlist $w $ok
158 }
159 } else {
147 - console_done $w $ok
160 + done $w $ok
161 }
162 }
163
151 -proc console_done {args} {
152 - global console_cr console_data
164 +proc done {args} {
165 + variable console_cr
166 + variable console_data
167
168 switch -- [llength $args] {
169 2 {
@@ -161,7 +175,7 @@ proc console_done {args} {
175 set ok [lindex $args 2]
176 }
177 default {
164 - error "wrong number of args: console_done ?ignored? w ok"
178 + error "wrong number of args: done ?ignored? w ok"
179 }
180 }
181
@@ -173,7 +187,7 @@ proc console_done {args} {
187 }
188 } else {
189 if {![winfo exists $w]} {
176 - console_init $w
190 + _init $w
191 }
192 $w.m.s conf -background red -text {Error: Command Failed}
193 $w.ok conf -state normal
@@ -183,3 +197,5 @@ proc console_done {args} {
197 array unset console_cr $w
198 array unset console_data $w
199 }
200 +
201 +}
lib/database.tcl
+8 -8
@@ -69,21 +69,21 @@ proc do_stats {} {
69 }
70
71 proc do_gc {} {
72 - set w [new_console {gc} {Compressing the object database}]
73 - console_chain {
74 - {console_exec {git pack-refs --prune}}
75 - {console_exec {git reflog expire --all}}
76 - {console_exec {git repack -a -d -l}}
77 - {console_exec {git rerere gc}}
72 + set w [console::new {gc} {Compressing the object database}]
73 + console::chain {
74 + {exec {git pack-refs --prune}}
75 + {exec {git reflog expire --all}}
76 + {exec {git repack -a -d -l}}
77 + {exec {git rerere gc}}
78 } $w
79 }
80
81 proc do_fsck_objects {} {
82 - set w [new_console {fsck-objects} \
82 + set w [console::new {fsck-objects} \
83 {Verifying the object database with fsck-objects}]
84 set cmd [list git fsck-objects]
85 lappend cmd --full
86 lappend cmd --cache
87 lappend cmd --strict
88 - console_exec $w $cmd console_done
88 + console::exec $w $cmd
89 }
lib/merge.tcl
+3 -3
@@ -120,14 +120,14 @@ Please select fewer branches. To merge more than 15 branches, merge the branche
120
121 set msg "Merging $current_branch, [join $names {, }]"
122 set ui_status_value "$msg..."
123 - set cons [new_console "Merge" $msg]
124 - console_exec $cons $cmd [list finish_merge $revcnt]
123 + set cons [console::new "Merge" $msg]
124 + console::exec $cons $cmd [list finish_merge $revcnt]
125 bind $w <Destroy> {}
126 destroy $w
127 }
128
129 proc finish_merge {revcnt w ok} {
130 - console_done $w $ok
130 + console::done $w $ok
131 if {$ok} {
132 set msg {Merge completed successfully.}
133 } else {
lib/transport.tcl
+8 -6
@@ -2,22 +2,22 @@
2 # Copyright (C) 2006, 2007 Shawn Pearce
3
4 proc fetch_from {remote} {
5 - set w [new_console \
5 + set w [console::new \
6 "fetch $remote" \
7 "Fetching new changes from $remote"]
8 set cmd [list git fetch]
9 lappend cmd $remote
10 - console_exec $w $cmd console_done
10 + console::exec $w $cmd
11 }
12
13 proc push_to {remote} {
14 - set w [new_console \
14 + set w [console::new \
15 "push $remote" \
16 "Pushing changes to $remote"]
17 set cmd [list git push]
18 lappend cmd -v
19 lappend cmd $remote
20 - console_exec $w $cmd console_done
20 + console::exec $w $cmd
21 }
22
23 proc start_push_anywhere_action {w} {
@@ -53,8 +53,10 @@ proc start_push_anywhere_action {w} {
53 set unit branches
54 }
55
56 - set cons [new_console "push $r_url" "Pushing $cnt $unit to $r_url"]
57 - console_exec $cons $cmd console_done
56 + set cons [console::new \
57 + "push $r_url" \
58 + "Pushing $cnt $unit to $r_url"]
59 + console::exec $cons $cmd
60 destroy $w
61 }
62