|
66c85b4…
|
aku
|
1 |
## -*- tcl -*- |
|
66c85b4…
|
aku
|
2 |
# # ## ### ##### ######## ############# ##################### |
|
66c85b4…
|
aku
|
3 |
## Copyright (c) 2007 Andreas Kupries. |
|
66c85b4…
|
aku
|
4 |
# |
|
66c85b4…
|
aku
|
5 |
# This software is licensed as described in the file LICENSE, which |
|
66c85b4…
|
aku
|
6 |
# you should have received as part of this distribution. |
|
66c85b4…
|
aku
|
7 |
# |
|
66c85b4…
|
aku
|
8 |
# This software consists of voluntary contributions made by many |
|
66c85b4…
|
aku
|
9 |
# individuals. For exact contribution history, see the revision |
|
66c85b4…
|
aku
|
10 |
# history and logs, available at http://fossil-scm.hwaci.com/fossil |
|
66c85b4…
|
aku
|
11 |
# # ## ### ##### ######## ############# ##################### |
|
66c85b4…
|
aku
|
12 |
|
|
00bf8c1…
|
aku
|
13 |
## Pass XI. This pass goes over all changesets and sorts them |
|
66c85b4…
|
aku
|
14 |
## topologically. It assumes that there are no cycles which could |
|
66c85b4…
|
aku
|
15 |
## impede it, any remaining having been broken by the previous two |
|
66c85b4…
|
aku
|
16 |
## passes, and aborts if that condition doesn't hold. |
|
66c85b4…
|
aku
|
17 |
|
|
66c85b4…
|
aku
|
18 |
# # ## ### ##### ######## ############# ##################### |
|
66c85b4…
|
aku
|
19 |
## Requirements |
|
66c85b4…
|
aku
|
20 |
|
|
66c85b4…
|
aku
|
21 |
package require Tcl 8.4 ; # Required runtime. |
|
66c85b4…
|
aku
|
22 |
package require snit ; # OO system. |
|
66c85b4…
|
aku
|
23 |
package require struct::list ; # Higher order list operations. |
|
66c85b4…
|
aku
|
24 |
package require vc::tools::log ; # User feedback. |
|
66c85b4…
|
aku
|
25 |
package require vc::fossil::import::cvs::cyclebreaker ; # Breaking dependency cycles. |
|
66c85b4…
|
aku
|
26 |
package require vc::fossil::import::cvs::state ; # State storage. |
|
66c85b4…
|
aku
|
27 |
package require vc::fossil::import::cvs::project::rev ; # Project level changesets |
|
66c85b4…
|
aku
|
28 |
|
|
66c85b4…
|
aku
|
29 |
# # ## ### ##### ######## ############# ##################### |
|
66c85b4…
|
aku
|
30 |
## Register the pass with the management |
|
66c85b4…
|
aku
|
31 |
|
|
66c85b4…
|
aku
|
32 |
vc::fossil::import::cvs::pass define \ |
|
66c85b4…
|
aku
|
33 |
AllTopologicalSort \ |
|
66c85b4…
|
aku
|
34 |
{Topologically Sort All ChangeSets} \ |
|
66c85b4…
|
aku
|
35 |
::vc::fossil::import::cvs::pass::atopsort |
|
66c85b4…
|
aku
|
36 |
|
|
66c85b4…
|
aku
|
37 |
# # ## ### ##### ######## ############# ##################### |
|
b679ca3…
|
aku
|
38 |
## |
|
66c85b4…
|
aku
|
39 |
|
|
66c85b4…
|
aku
|
40 |
snit::type ::vc::fossil::import::cvs::pass::atopsort { |
|
66c85b4…
|
aku
|
41 |
# # ## ### ##### ######## ############# |
|
66c85b4…
|
aku
|
42 |
## Public API |
|
66c85b4…
|
aku
|
43 |
|
|
66c85b4…
|
aku
|
44 |
typemethod setup {} { |
|
66c85b4…
|
aku
|
45 |
# Define the names and structure of the persistent state of |
|
66c85b4…
|
aku
|
46 |
# this pass. |
|
66c85b4…
|
aku
|
47 |
|
|
e288af3…
|
aku
|
48 |
state use revision |
|
e288af3…
|
aku
|
49 |
state use tag |
|
e288af3…
|
aku
|
50 |
state use branch |
|
e288af3…
|
aku
|
51 |
state use symbol |
|
e288af3…
|
aku
|
52 |
state use changeset |
|
e288af3…
|
aku
|
53 |
state use csitem |
|
e288af3…
|
aku
|
54 |
state use cssuccessor |
|
e288af3…
|
aku
|
55 |
state use csorder |
|
66c85b4…
|
aku
|
56 |
|
|
e288af3…
|
aku
|
57 |
state extend cstimestamp { |
|
66c85b4…
|
aku
|
58 |
-- Commit order of all changesets based on their |
|
66c85b4…
|
aku
|
59 |
-- dependencies, plus a monotonically increasing |
|
66c85b4…
|
aku
|
60 |
-- timestamp. |
|
66c85b4…
|
aku
|
61 |
|
|
66c85b4…
|
aku
|
62 |
cid INTEGER NOT NULL REFERENCES changeset, |
|
66c85b4…
|
aku
|
63 |
pos INTEGER NOT NULL, |
|
66c85b4…
|
aku
|
64 |
date INTEGER NOT NULL, |
|
66c85b4…
|
aku
|
65 |
UNIQUE (cid), |
|
66c85b4…
|
aku
|
66 |
UNIQUE (pos), |
|
66c85b4…
|
aku
|
67 |
UNIQUE (date) |
|
66c85b4…
|
aku
|
68 |
} |
|
66c85b4…
|
aku
|
69 |
return |
|
66c85b4…
|
aku
|
70 |
} |
|
66c85b4…
|
aku
|
71 |
|
|
66c85b4…
|
aku
|
72 |
typemethod load {} { |
|
66c85b4…
|
aku
|
73 |
# Pass manager interface. Executed to load data computed by |
|
66c85b4…
|
aku
|
74 |
# this pass into memory when this pass is skipped instead of |
|
66c85b4…
|
aku
|
75 |
# executed. |
|
66c85b4…
|
aku
|
76 |
return |
|
66c85b4…
|
aku
|
77 |
} |
|
66c85b4…
|
aku
|
78 |
|
|
66c85b4…
|
aku
|
79 |
typemethod run {} { |
|
66c85b4…
|
aku
|
80 |
# Pass manager interface. Executed to perform the |
|
66c85b4…
|
aku
|
81 |
# functionality of the pass. |
|
1c39e57…
|
aku
|
82 |
|
|
1c39e57…
|
aku
|
83 |
set len [string length [project::rev num]] |
|
1c39e57…
|
aku
|
84 |
set myatfmt %${len}s |
|
1c39e57…
|
aku
|
85 |
incr len 12 |
|
1c39e57…
|
aku
|
86 |
set mycsfmt %${len}s |
|
63052cb…
|
aku
|
87 |
|
|
66c85b4…
|
aku
|
88 |
cyclebreaker savecmd [myproc SaveTimestamps] |
|
66c85b4…
|
aku
|
89 |
|
|
66c85b4…
|
aku
|
90 |
state transaction { |
|
66c85b4…
|
aku
|
91 |
LoadSymbolChangesets |
|
63052cb…
|
aku
|
92 |
cyclebreaker run tsort-all [myproc Changesets] |
|
66c85b4…
|
aku
|
93 |
} |
|
66c85b4…
|
aku
|
94 |
return |
|
66c85b4…
|
aku
|
95 |
} |
|
66c85b4…
|
aku
|
96 |
|
|
66c85b4…
|
aku
|
97 |
typemethod discard {} { |
|
66c85b4…
|
aku
|
98 |
# Pass manager interface. Executed for all passes after the |
|
66c85b4…
|
aku
|
99 |
# run passes, to remove all data of this pass from the state, |
|
66c85b4…
|
aku
|
100 |
# as being out of date. |
|
66c85b4…
|
aku
|
101 |
|
|
66c85b4…
|
aku
|
102 |
state discard cstimestamp |
|
66c85b4…
|
aku
|
103 |
return |
|
66c85b4…
|
aku
|
104 |
} |
|
66c85b4…
|
aku
|
105 |
|
|
66c85b4…
|
aku
|
106 |
# # ## ### ##### ######## ############# |
|
66c85b4…
|
aku
|
107 |
## Internal methods |
|
66c85b4…
|
aku
|
108 |
|
|
66c85b4…
|
aku
|
109 |
proc Changesets {} { project::rev all } |
|
66c85b4…
|
aku
|
110 |
|
|
66c85b4…
|
aku
|
111 |
proc LoadSymbolChangesets {} { |
|
83ecb5b…
|
aku
|
112 |
# Consider use of 'project::rev sym' here. |
|
66c85b4…
|
aku
|
113 |
set mysymchangesets [struct::list filter [project::rev all] [myproc IsBySymbol]] |
|
66c85b4…
|
aku
|
114 |
return |
|
66c85b4…
|
aku
|
115 |
} |
|
63052cb…
|
aku
|
116 |
|
|
63052cb…
|
aku
|
117 |
proc IsBySymbol {cset} { $cset bysymbol } |
|
66c85b4…
|
aku
|
118 |
|
|
66c85b4…
|
aku
|
119 |
proc SaveTimestamps {graph at cset} { |
|
66c85b4…
|
aku
|
120 |
set cid [$cset id] |
|
66c85b4…
|
aku
|
121 |
|
|
66c85b4…
|
aku
|
122 |
set date [GetTime [lindex [$graph node get $cset timerange] 1] \ |
|
7208c7a…
|
mjanssen
|
123 |
[struct::set contains $mysymchangesets $cset] \ |
|
1c39e57…
|
aku
|
124 |
message] |
|
66c85b4…
|
aku
|
125 |
|
|
6b78df3…
|
drh
|
126 |
log write 4 atopsort "Changeset @ [format $myatfmt $at]: [format $mycsfmt [$cset str]] '[$cset lod]' $message" |
|
1c39e57…
|
aku
|
127 |
|
|
66c85b4…
|
aku
|
128 |
state run { |
|
66c85b4…
|
aku
|
129 |
INSERT INTO cstimestamp (cid, pos, date) |
|
66c85b4…
|
aku
|
130 |
VALUES ($cid, $at, $date) |
|
66c85b4…
|
aku
|
131 |
} |
|
66c85b4…
|
aku
|
132 |
return |
|
66c85b4…
|
aku
|
133 |
} |
|
66c85b4…
|
aku
|
134 |
|
|
1c39e57…
|
aku
|
135 |
proc GetTime {stamp expectchange mv} { |
|
66c85b4…
|
aku
|
136 |
::variable mylasttimestamp |
|
1c39e57…
|
aku
|
137 |
upvar 1 $mv message |
|
1c39e57…
|
aku
|
138 |
set message "" |
|
66c85b4…
|
aku
|
139 |
if {$stamp > $mymaxtimestamp} { |
|
66c85b4…
|
aku
|
140 |
# A timestamp in the future is believed to be bogus and |
|
66c85b4…
|
aku
|
141 |
# shifted backwars in time to prevent it from forcing |
|
66c85b4…
|
aku
|
142 |
# other timestamps to be pushed even further in the |
|
66c85b4…
|
aku
|
143 |
# future. |
|
66c85b4…
|
aku
|
144 |
|
|
66c85b4…
|
aku
|
145 |
# From cvs2svn: Note that this is not nearly a complete |
|
66c85b4…
|
aku
|
146 |
# solution to the bogus timestamp problem. A timestamp in |
|
66c85b4…
|
aku
|
147 |
# the future still affects the ordering of changesets, and |
|
66c85b4…
|
aku
|
148 |
# a changeset having such a timestamp will not be |
|
66c85b4…
|
aku
|
149 |
# committed until all changesets with earlier timestamps |
|
66c85b4…
|
aku
|
150 |
# have been committed, even if other changesets with even |
|
66c85b4…
|
aku
|
151 |
# earlier timestamps depend on this one. |
|
66c85b4…
|
aku
|
152 |
|
|
66c85b4…
|
aku
|
153 |
incr mylasttimestamp |
|
66c85b4…
|
aku
|
154 |
if {!$expectchange} { |
|
1c39e57…
|
aku
|
155 |
set message " Timestamp [clock format $stamp] is in the future; shifted back to [clock format $mylasttimestamp] ([expr {$mylasttimestamp - $stamp}])" |
|
66c85b4…
|
aku
|
156 |
} |
|
66c85b4…
|
aku
|
157 |
} elseif {$stamp < ($mylasttimestamp)+1} { |
|
66c85b4…
|
aku
|
158 |
incr mylasttimestamp |
|
66c85b4…
|
aku
|
159 |
if {!$expectchange} { |
|
1c39e57…
|
aku
|
160 |
set message " Timestamp [clock format $stamp] adjusted to [clock format $mylasttimestamp] (+[expr {$mylasttimestamp - $stamp}])" |
|
66c85b4…
|
aku
|
161 |
} |
|
66c85b4…
|
aku
|
162 |
} else { |
|
66c85b4…
|
aku
|
163 |
set mylasttimestamp $stamp |
|
66c85b4…
|
aku
|
164 |
} |
|
66c85b4…
|
aku
|
165 |
return $mylasttimestamp |
|
66c85b4…
|
aku
|
166 |
} |
|
1c39e57…
|
aku
|
167 |
|
|
1c39e57…
|
aku
|
168 |
typevariable myatfmt ; # Format for log output to gain better alignment of the various columns. |
|
1c39e57…
|
aku
|
169 |
typevariable mycsfmt ; # Ditto for the changesets. |
|
b679ca3…
|
aku
|
170 |
|
|
66c85b4…
|
aku
|
171 |
typevariable mysymchangesets {} ; # Set of the symbol changesets. |
|
66c85b4…
|
aku
|
172 |
typevariable mylasttimestamp 0 ; # Last delivered timestamp. |
|
b679ca3…
|
aku
|
173 |
typevariable mymaxtimestamp |
|
66c85b4…
|
aku
|
174 |
|
|
66c85b4…
|
aku
|
175 |
typeconstructor { |
|
66c85b4…
|
aku
|
176 |
# The maximum timestamp considered as reasonable is |
|
66c85b4…
|
aku
|
177 |
# "now + 1 day". |
|
66c85b4…
|
aku
|
178 |
set mymaxtimestamp [clock seconds] |
|
66c85b4…
|
aku
|
179 |
incr mymaxtimestamp 86400 ; # 24h * 60min * 60sec |
|
66c85b4…
|
aku
|
180 |
return |
|
66c85b4…
|
aku
|
181 |
} |
|
66c85b4…
|
aku
|
182 |
|
|
66c85b4…
|
aku
|
183 |
# # ## ### ##### ######## ############# |
|
66c85b4…
|
aku
|
184 |
## Configuration |
|
66c85b4…
|
aku
|
185 |
|
|
66c85b4…
|
aku
|
186 |
pragma -hasinstances no ; # singleton |
|
66c85b4…
|
aku
|
187 |
pragma -hastypeinfo no ; # no introspection |
|
66c85b4…
|
aku
|
188 |
pragma -hastypedestroy no ; # immortal |
|
66c85b4…
|
aku
|
189 |
|
|
66c85b4…
|
aku
|
190 |
# # ## ### ##### ######## ############# |
|
66c85b4…
|
aku
|
191 |
} |
|
66c85b4…
|
aku
|
192 |
|
|
66c85b4…
|
aku
|
193 |
namespace eval ::vc::fossil::import::cvs::pass { |
|
66c85b4…
|
aku
|
194 |
namespace export atopsort |
|
66c85b4…
|
aku
|
195 |
namespace eval atopsort { |
|
66c85b4…
|
aku
|
196 |
namespace import ::vc::fossil::import::cvs::cyclebreaker |
|
66c85b4…
|
aku
|
197 |
namespace import ::vc::fossil::import::cvs::state |
|
66c85b4…
|
aku
|
198 |
namespace eval project { |
|
66c85b4…
|
aku
|
199 |
namespace import ::vc::fossil::import::cvs::project::rev |
|
66c85b4…
|
aku
|
200 |
} |
|
66c85b4…
|
aku
|
201 |
namespace import ::vc::tools::log |
|
66c85b4…
|
aku
|
202 |
log register atopsort |
|
66c85b4…
|
aku
|
203 |
} |
|
66c85b4…
|
aku
|
204 |
} |
|
66c85b4…
|
aku
|
205 |
|
|
66c85b4…
|
aku
|
206 |
# # ## ### ##### ######## ############# ##################### |
|
66c85b4…
|
aku
|
207 |
## Ready |
|
66c85b4…
|
aku
|
208 |
|
|
66c85b4…
|
aku
|
209 |
package provide vc::fossil::import::cvs::pass::atopsort 1.0 |
|
66c85b4…
|
aku
|
210 |
return |