|
1
|
## -*- tcl -*- |
|
2
|
# # ## ### ##### ######## ############# ##################### |
|
3
|
## Copyright (c) 2007 Andreas Kupries. |
|
4
|
# |
|
5
|
# This software is licensed as described in the file LICENSE, which |
|
6
|
# you should have received as part of this distribution. |
|
7
|
# |
|
8
|
# This software consists of voluntary contributions made by many |
|
9
|
# individuals. For exact contribution history, see the revision |
|
10
|
# history and logs, available at http://fossil-scm.hwaci.com/fossil |
|
11
|
# # ## ### ##### ######## ############# ##################### |
|
12
|
|
|
13
|
## Pass manager. All passes register here, with code, description, and |
|
14
|
## callbacks (... setup, run, finalize). Option processing and help |
|
15
|
## query this manager to dynamically create the relevant texts. |
|
16
|
|
|
17
|
# # ## ### ##### ######## ############# ##################### |
|
18
|
## Requirements |
|
19
|
|
|
20
|
package require Tcl 8.4 ; # Required runtime. |
|
21
|
package require snit ; # OO system. |
|
22
|
package require vc::fossil::import::cvs::state ; # State storage |
|
23
|
package require vc::fossil::import::cvs::integrity ; # State integrity checks. |
|
24
|
package require vc::tools::misc ; # Text formatting |
|
25
|
package require vc::tools::trouble ; # Error reporting. |
|
26
|
package require vc::tools::log ; # User feedback. |
|
27
|
package require struct::list ; # Portable lassign |
|
28
|
|
|
29
|
# # ## ### ##### ######## ############# ##################### |
|
30
|
## |
|
31
|
|
|
32
|
snit::type ::vc::fossil::import::cvs::pass { |
|
33
|
# # ## ### ##### ######## ############# |
|
34
|
## Public API, Methods (Setup, query) |
|
35
|
|
|
36
|
typemethod define {name description command} { |
|
37
|
integrity assert { |
|
38
|
![info exists mydesc($name)] |
|
39
|
} {Multiple definitions for pass code '$name'} |
|
40
|
lappend mypasses $name |
|
41
|
set mydesc($name) $description |
|
42
|
set mycmd($name) $command |
|
43
|
return |
|
44
|
} |
|
45
|
|
|
46
|
typemethod help {} { |
|
47
|
trouble info "" |
|
48
|
trouble info "Conversion passes:" |
|
49
|
trouble info "" |
|
50
|
set n 0 |
|
51
|
|
|
52
|
set clen [max [struct::list map $mypasses {string length}]] |
|
53
|
set cfmt %-${clen}s |
|
54
|
set nfmt %[string length [llength $mypasses]]s |
|
55
|
|
|
56
|
foreach code $mypasses { |
|
57
|
trouble info " [format $nfmt $n]: [format $cfmt $code] : $mydesc($code)" |
|
58
|
incr n |
|
59
|
} |
|
60
|
trouble info "" |
|
61
|
return |
|
62
|
} |
|
63
|
|
|
64
|
# # ## ### ##### ######## ############# |
|
65
|
## Public API, Methods (Execution) |
|
66
|
|
|
67
|
typemethod select {passdef} { |
|
68
|
set pl [split $passdef :] |
|
69
|
if {[llength $pl] > 2} { |
|
70
|
trouble fatal "Bad pass definition '$passdef'" |
|
71
|
trouble fatal "Expected at most one ':'" |
|
72
|
} elseif {[llength $pl] == 2} { |
|
73
|
struct::list assign $pl start end |
|
74
|
|
|
75
|
if {($start eq "") && ($end eq "")} { |
|
76
|
trouble fatal "Specify at least one of start- or end-pass" |
|
77
|
set ok 0 |
|
78
|
} else { |
|
79
|
set ok 1 |
|
80
|
Ok? $start start ok |
|
81
|
Ok? $end end ok |
|
82
|
} |
|
83
|
|
|
84
|
if {$ok} { |
|
85
|
set mystart [Convert $start 0] |
|
86
|
set myend [Convert $end [expr {[llength $mypasses] - 1}]] |
|
87
|
if {$mystart > $myend} { |
|
88
|
trouble fatal "Start pass is after end pass" |
|
89
|
} |
|
90
|
} |
|
91
|
} elseif {[llength $pl] < 2} { |
|
92
|
set start [lindex $pl 0] |
|
93
|
Ok? $start "" __dummy__ 0 |
|
94
|
set mystart [Id $start] |
|
95
|
set myend $mystart |
|
96
|
} |
|
97
|
} |
|
98
|
|
|
99
|
typemethod run {} { |
|
100
|
if {$mystart < 0} {set mystart 0} |
|
101
|
if {$myend < 0} {set myend [expr {[llength $mypasses] - 1}]} |
|
102
|
|
|
103
|
set skipped [lrange $mypasses 0 [expr {$mystart - 1}]] |
|
104
|
set run [lrange $mypasses $mystart $myend] |
|
105
|
set defered [lrange $mypasses [expr {$myend + 1}] end] |
|
106
|
|
|
107
|
foreach p $skipped { |
|
108
|
log write 0 pass "Skip $p" |
|
109
|
Call $p load |
|
110
|
} |
|
111
|
foreach p $run { |
|
112
|
log write 0 pass "Setup $p" |
|
113
|
Call $p setup |
|
114
|
} |
|
115
|
foreach p $run { |
|
116
|
log write 0 pass "Begin $p" |
|
117
|
set secbegin [clock seconds] |
|
118
|
Call $p run |
|
119
|
set secstop [clock seconds] |
|
120
|
log write 0 pass "Done $p" |
|
121
|
Time $p [expr {$secstop - $secbegin}] |
|
122
|
trouble abort? |
|
123
|
} |
|
124
|
foreach p $defered { |
|
125
|
log write 0 pass "Defer $p" |
|
126
|
Call $p discard |
|
127
|
} |
|
128
|
|
|
129
|
state release |
|
130
|
ShowTimes |
|
131
|
return |
|
132
|
} |
|
133
|
|
|
134
|
typemethod current {} { return $mycurrentpass } |
|
135
|
|
|
136
|
# # ## ### ##### ######## ############# |
|
137
|
## Internal methods |
|
138
|
|
|
139
|
proc Time {pass seconds} { |
|
140
|
::variable mytime |
|
141
|
lappend mytime $pass $seconds |
|
142
|
ShowTime $pass $seconds |
|
143
|
return |
|
144
|
} |
|
145
|
|
|
146
|
proc ShowTimes {} { |
|
147
|
::variable mytime |
|
148
|
set total 0 |
|
149
|
foreach {pass seconds} $mytime { |
|
150
|
ShowTime $pass $seconds |
|
151
|
incr total $seconds |
|
152
|
} |
|
153
|
ShowTime Total $total |
|
154
|
return |
|
155
|
} |
|
156
|
|
|
157
|
proc ShowTime {pass seconds} { |
|
158
|
if {$seconds > 3600} { |
|
159
|
set hr [expr {$seconds / 3600}] |
|
160
|
set min [expr {$seconds % 3600}] |
|
161
|
set sec [expr {$min % 60}] |
|
162
|
set min [expr {$min / 60}] |
|
163
|
|
|
164
|
log write 0 pass "[format %8d $seconds] sec/$pass ([nsp $hr hour] [nsp $min minute] [nsp $sec second])" |
|
165
|
} elseif {$seconds > 60} { |
|
166
|
set min [expr {$seconds / 60}] |
|
167
|
set sec [expr {$seconds % 60}] |
|
168
|
|
|
169
|
log write 0 pass "[format %8d $seconds] sec/$pass ([nsp $min minute] [nsp $sec second])" |
|
170
|
} else { |
|
171
|
log write 0 pass "[format %8d $seconds] sec/$pass" |
|
172
|
} |
|
173
|
return |
|
174
|
} |
|
175
|
|
|
176
|
proc Ok? {code label ov {emptyok 1}} { |
|
177
|
upvar 1 $ov ok |
|
178
|
::variable mydesc |
|
179
|
if {$emptyok && ($code eq "")} return |
|
180
|
if {[info exists mydesc($code)]} return |
|
181
|
if {$label ne ""} {append label " "} |
|
182
|
trouble fatal "Bad ${label}pass code $code" |
|
183
|
set ok 0 |
|
184
|
return |
|
185
|
} |
|
186
|
|
|
187
|
proc Convert {code default} { |
|
188
|
::variable mypasses |
|
189
|
return [expr {($code eq "") ? $default : [Id $code]}] |
|
190
|
} |
|
191
|
|
|
192
|
proc Id {code} { |
|
193
|
::variable mypasses |
|
194
|
return [lsearch -exact $mypasses $code] |
|
195
|
} |
|
196
|
|
|
197
|
proc Call {code args} { |
|
198
|
::variable mycmd |
|
199
|
set cmd $mycmd($code) |
|
200
|
foreach a $args { lappend cmd $a } |
|
201
|
eval $cmd |
|
202
|
return |
|
203
|
} |
|
204
|
|
|
205
|
# # ## ### ##### ######## ############# |
|
206
|
## Internal, state |
|
207
|
|
|
208
|
typevariable mypasses {} ; # List of registered passes (codes). |
|
209
|
typevariable mydesc -array {} ; # Pass descriptions (one line). |
|
210
|
typevariable mycmd -array {} ; # Pass callback command. |
|
211
|
|
|
212
|
typevariable mystart -1 |
|
213
|
typevariable myend -1 |
|
214
|
typevariable mytime {} ; # Timing data for each executed pass. |
|
215
|
typevariable mycurrentpass {} ; # Pass currently running. |
|
216
|
|
|
217
|
# # ## ### ##### ######## ############# |
|
218
|
## Configuration |
|
219
|
|
|
220
|
pragma -hasinstances no ; # singleton |
|
221
|
pragma -hastypeinfo no ; # no introspection |
|
222
|
pragma -hastypedestroy no ; # immortal |
|
223
|
|
|
224
|
# # ## ### ##### ######## ############# |
|
225
|
} |
|
226
|
|
|
227
|
namespace eval ::vc::fossil::import::cvs { |
|
228
|
namespace export pass |
|
229
|
namespace eval pass { |
|
230
|
namespace import ::vc::fossil::import::cvs::state |
|
231
|
namespace import ::vc::fossil::import::cvs::integrity |
|
232
|
namespace import ::vc::tools::misc::* |
|
233
|
namespace import ::vc::tools::trouble |
|
234
|
namespace import ::vc::tools::log |
|
235
|
log register pass |
|
236
|
} |
|
237
|
} |
|
238
|
|
|
239
|
# # ## ### ##### ######## ############# ##################### |
|
240
|
## Ready |
|
241
|
|
|
242
|
package provide vc::fossil::import::cvs::pass 1.0 |
|
243
|
return |
|
244
|
|