|
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 VIII. This pass goes over the set of revision based changesets |
|
14
|
## and sorts them topologically. It assumes that there are no cycles |
|
15
|
## which could impede it, any having been broken by the previous pass, |
|
16
|
## and aborts if that condition doesn't hold. |
|
17
|
|
|
18
|
# # ## ### ##### ######## ############# ##################### |
|
19
|
## Requirements |
|
20
|
|
|
21
|
package require Tcl 8.4 ; # Required runtime. |
|
22
|
package require snit ; # OO system. |
|
23
|
package require struct::list ; # Higher order list operations. |
|
24
|
package require vc::tools::log ; # User feedback. |
|
25
|
package require vc::fossil::import::cvs::cyclebreaker ; # Breaking dependency cycles. |
|
26
|
package require vc::fossil::import::cvs::state ; # State storage. |
|
27
|
package require vc::fossil::import::cvs::project::rev ; # Project level changesets |
|
28
|
|
|
29
|
# # ## ### ##### ######## ############# ##################### |
|
30
|
## Register the pass with the management |
|
31
|
|
|
32
|
vc::fossil::import::cvs::pass define \ |
|
33
|
RevTopologicalSort \ |
|
34
|
{Topologically Sort Revision ChangeSets} \ |
|
35
|
::vc::fossil::import::cvs::pass::rtopsort |
|
36
|
|
|
37
|
# # ## ### ##### ######## ############# ##################### |
|
38
|
## |
|
39
|
|
|
40
|
snit::type ::vc::fossil::import::cvs::pass::rtopsort { |
|
41
|
# # ## ### ##### ######## ############# |
|
42
|
## Public API |
|
43
|
|
|
44
|
typemethod setup {} { |
|
45
|
# Define the names and structure of the persistent state of |
|
46
|
# this pass. |
|
47
|
|
|
48
|
state use revision |
|
49
|
state use symbol |
|
50
|
state use changeset |
|
51
|
state use csitem |
|
52
|
state use cstype |
|
53
|
state use cssuccessor |
|
54
|
|
|
55
|
state extend csorder { |
|
56
|
-- Commit order of the revision changesets based on their |
|
57
|
-- dependencies |
|
58
|
|
|
59
|
cid INTEGER NOT NULL REFERENCES changeset, |
|
60
|
pos INTEGER NOT NULL, |
|
61
|
UNIQUE (cid), |
|
62
|
UNIQUE (pos) |
|
63
|
} |
|
64
|
return |
|
65
|
} |
|
66
|
|
|
67
|
typemethod load {} { |
|
68
|
# Pass manager interface. Executed to load data computed by |
|
69
|
# this pass into memory when this pass is skipped instead of |
|
70
|
# executed. |
|
71
|
|
|
72
|
state use changeset |
|
73
|
project::rev loadcounter |
|
74
|
return |
|
75
|
} |
|
76
|
|
|
77
|
typemethod run {} { |
|
78
|
# Pass manager interface. Executed to perform the |
|
79
|
# functionality of the pass. |
|
80
|
|
|
81
|
set len [string length [project::rev num]] |
|
82
|
set myatfmt %${len}s |
|
83
|
incr len 12 |
|
84
|
set mycsfmt %${len}s |
|
85
|
|
|
86
|
cyclebreaker savecmd [myproc SaveOrder] |
|
87
|
|
|
88
|
state transaction { |
|
89
|
cyclebreaker run tsort-rev [myproc Changesets] |
|
90
|
} |
|
91
|
return |
|
92
|
} |
|
93
|
|
|
94
|
typemethod discard {} { |
|
95
|
# Pass manager interface. Executed for all passes after the |
|
96
|
# run passes, to remove all data of this pass from the state, |
|
97
|
# as being out of date. |
|
98
|
|
|
99
|
state discard csorder |
|
100
|
return |
|
101
|
} |
|
102
|
|
|
103
|
# # ## ### ##### ######## ############# |
|
104
|
## Internal methods |
|
105
|
|
|
106
|
proc Changesets {} { |
|
107
|
log write 2 breakscycle {Selecting the revision changesets} |
|
108
|
return [project::rev rev] |
|
109
|
} |
|
110
|
|
|
111
|
proc SaveOrder {graph at cset} { |
|
112
|
::variable myatfmt |
|
113
|
::variable mycsfmt |
|
114
|
|
|
115
|
set cid [$cset id] |
|
116
|
|
|
117
|
log write 4 rtopsort "Changeset @ [format $myatfmt $at]: [format $mycsfmt [$cset str]] '[$cset lod]' <<[FormatTR $graph $cset]>>" |
|
118
|
state run { |
|
119
|
INSERT INTO csorder (cid, pos) |
|
120
|
VALUES ($cid, $at) |
|
121
|
} |
|
122
|
return |
|
123
|
} |
|
124
|
|
|
125
|
proc FormatTR {graph cset} { |
|
126
|
return [join [struct::list map [$graph node set $cset timerange] {clock format}] { -- }] |
|
127
|
} |
|
128
|
|
|
129
|
typevariable myatfmt ; # Format for log output to gain better alignment of the various columns. |
|
130
|
typevariable mycsfmt ; # Ditto for the changesets. |
|
131
|
|
|
132
|
# # ## ### ##### ######## ############# |
|
133
|
## Configuration |
|
134
|
|
|
135
|
pragma -hasinstances no ; # singleton |
|
136
|
pragma -hastypeinfo no ; # no introspection |
|
137
|
pragma -hastypedestroy no ; # immortal |
|
138
|
|
|
139
|
# # ## ### ##### ######## ############# |
|
140
|
} |
|
141
|
|
|
142
|
namespace eval ::vc::fossil::import::cvs::pass { |
|
143
|
namespace export rtopsort |
|
144
|
namespace eval rtopsort { |
|
145
|
namespace import ::vc::fossil::import::cvs::cyclebreaker |
|
146
|
namespace import ::vc::fossil::import::cvs::state |
|
147
|
namespace eval project { |
|
148
|
namespace import ::vc::fossil::import::cvs::project::rev |
|
149
|
} |
|
150
|
namespace import ::vc::tools::log |
|
151
|
log register rtopsort |
|
152
|
} |
|
153
|
} |
|
154
|
|
|
155
|
# # ## ### ##### ######## ############# ##################### |
|
156
|
## Ready |
|
157
|
|
|
158
|
package provide vc::fossil::import::cvs::pass::rtopsort 1.0 |
|
159
|
return |
|
160
|
|