1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
|
## -*- tcl -*-
# # ## ### ##### ######## ############# #####################
## Copyright (c) 2007-2008 Andreas Kupries.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#
# This software consists of voluntary contributions made by many
# individuals. For exact contribution history, see the revision
# history and logs, available at http://fossil-scm.hwaci.com/fossil
# # ## ### ##### ######## ############# #####################
## Pass V. This pass creates the initial set of project level
## revisions, aka changesets. Later passes will refine them, puts them
## into proper order, set their dependencies, etc.
# # ## ### ##### ######## ############# #####################
## Requirements
package require Tcl 8.4 ; # Required runtime.
package require snit ; # OO system.
package require vc::tools::misc ; # Text formatting.
package require vc::tools::log ; # User feedback.
package require vc::tools::mem ; # Memory tracking.
package require vc::fossil::import::cvs::repository ; # Repository management.
package require vc::fossil::import::cvs::state ; # State storage.
package require vc::fossil::import::cvs::integrity ; # State integrity checks.
package require vc::fossil::import::cvs::project::rev ; # Project level changesets
# # ## ### ##### ######## ############# #####################
## Register the pass with the management
vc::fossil::import::cvs::pass define \
InitCsets \
{Initialize ChangeSets} \
::vc::fossil::import::cvs::pass::initcsets
# # ## ### ##### ######## ############# #####################
##
snit::type ::vc::fossil::import::cvs::pass::initcsets {
# # ## ### ##### ######## #############
## Public API
typemethod setup {} {
# Define the names and structure of the persistent state of
# this pass.
state use project
state use file
state use revision
state use revisionbranchchildren
state use branch
state use tag
state use symbol
state use meta
# Data per changeset, namely the project it belongs to, how it
# was induced (revision or symbol), plus reference to the
# primary entry causing it (meta entry or symbol). An adjunct
# table translates the type id's into human readable labels.
state extend changeset {
cid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
pid INTEGER NOT NULL REFERENCES project,
type INTEGER NOT NULL REFERENCES cstype,
src INTEGER NOT NULL -- REFERENCES meta|symbol (type dependent)
}
state extend cstype {
tid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
UNIQUE (name)
}
# Note: Keep the labels used here in sync with the names for
# singleton helper classes for 'project::rev'. They are
# the valid type names for changesets and also hardwired
# in some code.
state run {
INSERT INTO cstype VALUES (0,'rev');
INSERT INTO cstype VALUES (1,'sym::tag');
INSERT INTO cstype VALUES (2,'sym::branch');
}
# Map from changesets to the (file level) revisions, tags, or
# branches they contain. The pos'ition provides an order of
# the items within a changeset. They are unique within the
# changeset. The items are in principle unique, if we were
# looking only at relevant changesets. However as they come
# from disparate sources the same id may have different
# meaning, be in different changesets and so is formally not
# unique. So we can only say that it is unique within the
# changeset. The integrity module has stronger checks.
state extend csitem {
cid INTEGER NOT NULL REFERENCES changeset,
pos INTEGER NOT NULL,
iid INTEGER NOT NULL, -- REFERENCES revision|tag|branch
UNIQUE (cid, pos),
UNIQUE (cid, iid)
} { iid }
# Index on: iid (successor/predecessor retrieval)
project::rev getcstypes
return
}
typemethod load {} {
# Pass manager interface. Executed to load data computed by
# this pass into memory when this pass is skipped instead of
# executed.
state use changeset
state use csitem
state use cstype
# Need the types first, the constructor used inside of the
# 'load' below uses them to assert the correctness of type
# names.
project::rev getcstypes
project::rev load ::vc::fossil::import::cvs::repository
project::rev loadcounter
return
}
typemethod run {} {
# Pass manager interface. Executed to perform the
# functionality of the pass.
state transaction {
CreateRevisionChangesets ; # Group file revisions into
# preliminary csets and split
# them based on internal
# conflicts.
CreateSymbolChangesets ; # Create csets for tags and
# branches.
}
repository printcsetstatistics
integrity changesets
# Load the changesets for use by the next passes.
project::rev load ::vc::fossil::import::cvs::repository
project::rev loadcounter
return
}
typemethod discard {} {
# Pass manager interface. Executed for all passes after the
# run passes, to remove all data of this pass from the state,
# as being out of date.
state discard changeset
state discard cstype
state discard csitem
return
}
# # ## ### ##### ######## #############
## Internal methods
proc CreateRevisionChangesets {} {
log write 3 initcsets {Create changesets based on revisions}
# To get the initial of changesets we first group all file
# level revisions using the same meta data entry together. As
# the meta data encodes not only author and log message, but
# also line of development and project we can be sure that
# revisions in different project and lines of development are
# not grouped together. In contrast to cvs2svn we do __not__
# use distance in time between revisions to break them
# apart. We have seen CVS repositories (from SF) where a
# single commit contained revisions several hours apart,
# likely due to trouble on the server hosting the repository.
# We order the revisions here by time, this will help the
# later passes (avoids joins later to get at the ordering
# info).
# The changesets made from these groups are immediately
# inspected for internal conflicts and any such are broken by
# splitting the problematic changeset into multiple
# fragments. The results are changesets which have no internal
# dependencies, only external ones.
set n 0
set nx 0
set lastmeta {}
set lastproject {}
set revisions {}
# Note: We could have written this loop to create the csets
# early, extending them with all their revisions. This
# however would mean lots of (slow) method invokations
# on the csets. Doing it like this, late creation, means
# less such calls. None, but the creation itself.
log write 14 initcsets meta_begin
mem::mark
state foreachrow {
SELECT M.mid AS xmid,
R.rid AS xrid,
M.pid AS xpid
FROM revision R,
meta M -- R ==> M, using PK index of M.
WHERE R.mid = M.mid
ORDER BY M.mid, R.date
} {
log write 14 initcsets meta_next
if {$lastmeta != $xmid} {
if {[llength $revisions]} {
incr n
set p [repository projectof $lastproject]
log write 14 initcsets meta_cset_begin
mem::mark
set cset [project::rev %AUTO% $p rev $lastmeta $revisions]
log write 14 initcsets meta_cset_done
set spawned [$cset breakinternaldependencies nx]
$cset persist
$cset destroy
foreach cset $spawned { $cset persist ; $cset destroy }
mem::mark
set revisions {}
}
set lastmeta $xmid
set lastproject $xpid
}
lappend revisions $xrid
}
if {[llength $revisions]} {
incr n
set p [repository projectof $lastproject]
log write 14 initcsets meta_cset_begin
mem::mark
set cset [project::rev %AUTO% $p rev $lastmeta $revisions]
log write 14 initcsets meta_cset_done
set spawned [$cset breakinternaldependencies nx]
$cset persist
$cset destroy
foreach cset $spawned { $cset persist ; $cset destroy }
mem::mark
}
log write 14 initcsets meta_done
mem::mark
log write 4 initcsets "Created and saved [nsp $n {revision changeset}]"
log write 4 initcsets "Created and saved [nsp $nx {additional revision changeset}]"
mem::mark
log write 4 initcsets Ok.
return
}
proc CreateSymbolChangesets {} {
log write 3 initcsets {Create changesets based on symbols}
mem::mark
# Tags and branches induce changesets as well, containing the
# revisions they are attached to (tags), or spawned from
# (branches).
set n 0
# First process the tags, then the branches. We know that
# their ids do not overlap with each other.
set lastsymbol {}
set lastproject {}
set tags {}
state foreachrow {
SELECT S.sid AS xsid,
T.tid AS xtid,
S.pid AS xpid
FROM tag T,
symbol S -- T ==> R/S, using PK indices of R, S.
WHERE T.sid = S.sid
ORDER BY S.sid, T.tid
} {
if {$lastsymbol != $xsid} {
if {[llength $tags]} {
incr n
set p [repository projectof $lastproject]
set cset [project::rev %AUTO% $p sym::tag $lastsymbol $tags]
set tags {}
$cset persist
$cset destroy
}
set lastsymbol $xsid
set lastproject $xpid
}
lappend tags $xtid
}
if {[llength $tags]} {
incr n
set p [repository projectof $lastproject]
set cset [project::rev %AUTO% $p sym::tag $lastsymbol $tags]
$cset persist
$cset destroy
}
set lastsymbol {}
set lasproject {}
set branches {}
state foreachrow {
SELECT S.sid AS xsid,
B.bid AS xbid,
S.pid AS xpid
FROM branch B,
symbol S -- B ==> R/S, using PK indices of R, S.
WHERE B.sid = S.sid
ORDER BY S.sid, B.bid
} {
if {$lastsymbol != $xsid} {
if {[llength $branches]} {
incr n
set p [repository projectof $lastproject]
set cset [project::rev %AUTO% $p sym::branch $lastsymbol $branches]
set branches {}
$cset persist
$cset destroy
}
set lastsymbol $xsid
set lastproject $xpid
}
lappend branches $xbid
}
if {[llength $branches]} {
incr n
set p [repository projectof $lastproject]
set cset [project::rev %AUTO% $p sym::branch $lastsymbol $branches]
$cset persist
$cset destroy
}
log write 4 initcsets "Created and saved [nsp $n {symbol changeset}]"
mem::mark
return
}
# # ## ### ##### ######## #############
## Configuration
pragma -hasinstances no ; # singleton
pragma -hastypeinfo no ; # no introspection
pragma -hastypedestroy no ; # immortal
# # ## ### ##### ######## #############
}
namespace eval ::vc::fossil::import::cvs::pass {
namespace export initcsets
namespace eval initcsets {
namespace import ::vc::fossil::import::cvs::repository
namespace import ::vc::fossil::import::cvs::state
namespace import ::vc::fossil::import::cvs::integrity
namespace eval project {
namespace import ::vc::fossil::import::cvs::project::rev
}
namespace eval mem {
namespace import ::vc::tools::mem::mark
}
namespace import ::vc::tools::misc::*
namespace import ::vc::tools::log
log register initcsets
}
}
# # ## ### ##### ######## ############# #####################
## Ready
package provide vc::fossil::import::cvs::pass::initcsets 1.0
return
|