git-gui: Squash populate_{push,fetch}_menu to populate_remotes_menu
The meat of the routines is now separated to add_fetch_entry() and add_push_entry(). This refactoring will allow easy implementation of adding individual remotes later. Signed-off-by: Petr Baudis <petr.baudis@novartis.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Petr Baudis committed
Sep 24, 2008 at 22:44 UTC
8329bd07250e0b26b76105d299b6153a68c3c404
2 files changed
+70
-70
git-gui.sh
+1
-2
@@ -3263,8 +3263,7 @@ if {[is_enabled transport]} {
3263
load_all_remotes
3264
3265
set n [.mbar.remote index end]
3266
- populate_push_menu
3267
- populate_fetch_menu
3266
+ populate_remotes_menu
3267
set n [expr {[.mbar.remote index end] - $n}]
3268
if {$n > 0} {
3269
if {[.mbar.remote type 0] eq "tearoff"} { incr n }
lib/remote.tcl
+69
-68
@@ -132,91 +132,92 @@ proc load_all_remotes {} {
132
set all_remotes [lsort -unique $all_remotes]
133
}
134
135
-proc populate_fetch_menu {} {
136
- global all_remotes repo_config
137
-
135
+proc add_fetch_entry {r} {
136
+ global repo_config
137
set remote_m .mbar.remote
138
set fetch_m $remote_m.fetch
139
set prune_m $remote_m.prune
141
-
142
- foreach r $all_remotes {
143
- set enable 0
144
- if {![catch {set a $repo_config(remote.$r.url)}]} {
145
- if {![catch {set a $repo_config(remote.$r.fetch)}]} {
146
- set enable 1
147
- }
148
- } else {
149
- catch {
150
- set fd [open [gitdir remotes $r] r]
151
- while {[gets $fd n] >= 0} {
152
- if {[regexp {^Pull:[ \t]*([^:]+):} $n]} {
153
- set enable 1
154
- break
155
- }
140
+ set enable 0
141
+ if {![catch {set a $repo_config(remote.$r.url)}]} {
142
+ if {![catch {set a $repo_config(remote.$r.fetch)}]} {
143
+ set enable 1
144
+ }
145
+ } else {
146
+ catch {
147
+ set fd [open [gitdir remotes $r] r]
148
+ while {[gets $fd n] >= 0} {
149
+ if {[regexp {^Pull:[ \t]*([^:]+):} $n]} {
150
+ set enable 1
151
+ break
152
}
157
- close $fd
153
}
154
+ close $fd
155
}
156
+ }
157
161
- if {$enable} {
162
- if {![winfo exists $fetch_m]} {
163
- menu $prune_m
164
- $remote_m insert 0 cascade \
165
- -label [mc "Prune from"] \
166
- -menu $prune_m
167
-
168
- menu $fetch_m
169
- $remote_m insert 0 cascade \
170
- -label [mc "Fetch from"] \
171
- -menu $fetch_m
172
- }
173
-
174
- $fetch_m add command \
175
- -label $r \
176
- -command [list fetch_from $r]
177
- $prune_m add command \
178
- -label $r \
179
- -command [list prune_from $r]
158
+ if {$enable} {
159
+ if {![winfo exists $fetch_m]} {
160
+ menu $prune_m
161
+ $remote_m insert 0 cascade \
162
+ -label [mc "Prune from"] \
163
+ -menu $prune_m
164
+
165
+ menu $fetch_m
166
+ $remote_m insert 0 cascade \
167
+ -label [mc "Fetch from"] \
168
+ -menu $fetch_m
169
}
170
+
171
+ $fetch_m add command \
172
+ -label $r \
173
+ -command [list fetch_from $r]
174
+ $prune_m add command \
175
+ -label $r \
176
+ -command [list prune_from $r]
177
}
178
}
179
184
-proc populate_push_menu {} {
185
- global all_remotes repo_config
186
-
180
+proc add_push_entry {r} {
181
+ global repo_config
182
set remote_m .mbar.remote
183
set push_m $remote_m.push
189
-
190
- foreach r $all_remotes {
191
- set enable 0
192
- if {![catch {set a $repo_config(remote.$r.url)}]} {
193
- if {![catch {set a $repo_config(remote.$r.push)}]} {
194
- set enable 1
195
- }
196
- } else {
197
- catch {
198
- set fd [open [gitdir remotes $r] r]
199
- while {[gets $fd n] >= 0} {
200
- if {[regexp {^Push:[ \t]*([^:]+):} $n]} {
201
- set enable 1
202
- break
203
- }
184
+ set enable 0
185
+ if {![catch {set a $repo_config(remote.$r.url)}]} {
186
+ if {![catch {set a $repo_config(remote.$r.push)}]} {
187
+ set enable 1
188
+ }
189
+ } else {
190
+ catch {
191
+ set fd [open [gitdir remotes $r] r]
192
+ while {[gets $fd n] >= 0} {
193
+ if {[regexp {^Push:[ \t]*([^:]+):} $n]} {
194
+ set enable 1
195
+ break
196
}
205
- close $fd
197
}
198
+ close $fd
199
}
200
+ }
201
209
- if {$enable} {
210
- if {![winfo exists $push_m]} {
211
- menu $push_m
212
- $remote_m insert 0 cascade \
213
- -label [mc "Push to"] \
214
- -menu $push_m
215
- }
216
-
217
- $push_m add command \
218
- -label $r \
219
- -command [list push_to $r]
202
+ if {$enable} {
203
+ if {![winfo exists $push_m]} {
204
+ menu $push_m
205
+ $remote_m insert 0 cascade \
206
+ -label [mc "Push to"] \
207
+ -menu $push_m
208
}
209
+
210
+ $push_m add command \
211
+ -label $r \
212
+ -command [list push_to $r]
213
+ }
214
+}
215
+
216
+proc populate_remotes_menu {} {
217
+ global all_remotes
218
+
219
+ foreach r $all_remotes {
220
+ add_fetch_entry $r
221
+ add_push_entry $r
222
}
223
}