| | @@ -19,10 +19,12 @@ |
| 19 | 19 | package require Tcl 8.4 ; # Required runtime. |
| 20 | 20 | package require snit ; # OO system. |
| 21 | 21 | package require struct::set ; # Set operations. |
| 22 | 22 | package require vc::fossil::import::cvs::file::rev ; # CVS per file revisions. |
| 23 | 23 | package require vc::fossil::import::cvs::file::sym ; # CVS per file symbols. |
| 24 | +package require vc::tools::trouble ; # Error reporting. |
| 25 | +package require vc::tools::misc ; # Text formatting |
| 24 | 26 | |
| 25 | 27 | # # ## ### ##### ######## ############# ##################### |
| 26 | 28 | ## |
| 27 | 29 | |
| 28 | 30 | snit::type ::vc::fossil::import::cvs::file { |
| | @@ -97,11 +99,11 @@ |
| 97 | 99 | method admindone {} { |
| 98 | 100 | # We do nothing at the boundary of admin and revision data |
| 99 | 101 | } |
| 100 | 102 | |
| 101 | 103 | method def {revnr date author state next branches} { |
| 102 | | - $self LookForUnlabeledBranches $branches |
| 104 | + $self RecordBranchCommits $branches |
| 103 | 105 | $myproject author $author |
| 104 | 106 | |
| 105 | 107 | if {[info exists myrev($revnr)]} { |
| 106 | 108 | trouble fatal "File $mypath contains duplicate definitions for revision $revnr." |
| 107 | 109 | return |
| | @@ -112,10 +114,20 @@ |
| 112 | 114 | RecordBasicDependencies $revnr $next |
| 113 | 115 | return |
| 114 | 116 | } |
| 115 | 117 | |
| 116 | 118 | method defdone {} { |
| 119 | + # This is all done after the revision tree has been extracted |
| 120 | + # from the file, before the commit mesages and delta texts are |
| 121 | + # processed. |
| 122 | + |
| 123 | + ProcessPrimaryDependencies |
| 124 | + ProcessBranchDependencies |
| 125 | + SortBranches |
| 126 | + ProcessTagDependencies |
| 127 | + DetermineTheRootRevision |
| 128 | + return |
| 117 | 129 | } |
| 118 | 130 | |
| 119 | 131 | method setdesc {d} {# ignore} |
| 120 | 132 | |
| 121 | 133 | method extend {revnr commitmsg deltarange} { |
| | @@ -146,11 +158,11 @@ |
| 146 | 158 | |
| 147 | 159 | $rev setcommitmsg $cm |
| 148 | 160 | $rev settext $deltarange |
| 149 | 161 | |
| 150 | 162 | if {![rev istrunkrevnr $revnr]} { |
| 151 | | - $rev setbranch [[$self Rev2Branch $revnr] name] |
| 163 | + $rev setbranchname [[$self Rev2Branch $revnr] name] |
| 152 | 164 | } |
| 153 | 165 | |
| 154 | 166 | # If this is revision 1.1, we have to determine whether the |
| 155 | 167 | # file seems to have been created through 'cvs add' instead of |
| 156 | 168 | # 'cvs import'. This can be done by looking at the un- |
| | @@ -174,43 +186,68 @@ |
| 174 | 186 | method done {} {} |
| 175 | 187 | |
| 176 | 188 | # # ## ### ##### ######## ############# |
| 177 | 189 | ## State |
| 178 | 190 | |
| 179 | | - variable mypath {} ; # Path of rcs archive |
| 180 | | - variable myproject {} ; # Project object the file belongs to. |
| 181 | | - variable myrev -array {} ; # All revisions and their connections. |
| 182 | | - variable myrevisions {} ; # Same as myrev, but a list, giving us the order |
| 183 | | - # ; # of revisions. |
| 191 | + variable mypath {} ; # Path of our rcs archive. |
| 192 | + variable myproject {} ; # Reference to the project object |
| 193 | + # the file belongs to. |
| 194 | + variable myrev -array {} ; # Maps revision number to the |
| 195 | + # associated revision object. |
| 196 | + variable myrevisions {} ; # Same as myrev, but a list, |
| 197 | + # giving us the order of |
| 198 | + # revisions. |
| 184 | 199 | variable myhead {} ; # Head revision (revision number) |
| 185 | | - variable myprincipal {} ; # Principal branch (branch number) |
| 186 | | - # ; # Contrary to the name this is the default branch. |
| 187 | | - variable mydependencies {} ; # Dictionary parent -> child, dependency recorder. |
| 188 | | - variable myimported 0 ; # Boolean flag. Set iff rev 1.1 of the file seemingly |
| 189 | | - # ; # was imported instead of added normally. |
| 190 | | - variable myroot {} ; # Revision number of the root revision. Usually '1.1'. |
| 191 | | - # ; # Can be a different number, because of 'cvsadmin -o'. |
| 192 | | - variable mybranches -array {} ; # branch number -> symbol object handling the branch |
| 193 | | - variable mytags -array {} ; # revision number -> list of symbol object for the tags |
| 194 | | - # ; # associated with the revision. |
| 195 | | - variable mysymbols {} ; # Set of symbol names found in this file. |
| 200 | + variable myprincipal {} ; # Principal branch (branch number). |
| 201 | + # Contrary to the name this is the |
| 202 | + # default branch. |
| 203 | + variable mydependencies {} ; # Dictionary parent -> child, |
| 204 | + # records primary dependencies. |
| 205 | + variable myimported 0 ; # Boolean flag. Set if and only if |
| 206 | + # rev 1.1 of the file seemingly |
| 207 | + # was imported instead of added |
| 208 | + # normally. |
| 209 | + variable myroot {} ; # Reference to the revision object |
| 210 | + # holding the root revision. Its |
| 211 | + # number usually is '1.1'. Can be |
| 212 | + # a different number, because of |
| 213 | + # gaps created via 'cvsadmin -o'. |
| 214 | + variable mybranches -array {} ; # Maps branch number to the symbol |
| 215 | + # object handling the branch. |
| 216 | + variable mytags -array {} ; # Maps revision number to the list |
| 217 | + # of symbol objects for the tags |
| 218 | + # associated with the revision. |
| 219 | + variable mysymbols {} ; # Set of the symbol names found in |
| 220 | + # this file. |
| 221 | + |
| 222 | + variable mybranchcnt 0 ; # Counter for branches, to record their |
| 223 | + # order of definition. This also defines |
| 224 | + # their order of creation, which is the |
| 225 | + # reverse of definition. I.e. a smaller |
| 226 | + # number means 'Defined earlier', means |
| 227 | + # 'Created later'. |
| 196 | 228 | |
| 197 | 229 | ### TODO ### |
| 198 | 230 | ### File flag - executable, |
| 199 | 231 | ### RCS mode info (kb, kkb, ...) |
| 200 | 232 | |
| 201 | 233 | # # ## ### ##### ######## ############# |
| 202 | 234 | ## Internal methods |
| 203 | 235 | |
| 204 | | - method LookForUnlabeledBranches {branches} { |
| 236 | + method RecordBranchCommits {branches} { |
| 205 | 237 | foreach branchrevnr $branches { |
| 206 | 238 | if {[catch { |
| 207 | 239 | set branch [$self Rev2Branch $branchrevnr] |
| 208 | 240 | }]} { |
| 209 | 241 | set branch [$self AddUnlabeledBranch [rev 2branchnr $branchrevnr]] |
| 210 | 242 | } |
| 211 | | - # TODO $branch child $branchrevnr - when add-unlabeled has sensible return value |
| 243 | + |
| 244 | + # Record the commit, just as revision number for |
| 245 | + # now. ProcesBranchDependencies will extend that ito a |
| 246 | + # proper object reference. |
| 247 | + |
| 248 | + $branch setchildrevnr $branchrevnr |
| 212 | 249 | } |
| 213 | 250 | return |
| 214 | 251 | } |
| 215 | 252 | |
| 216 | 253 | method Rev2Branch {revnr} { |
| | @@ -229,10 +266,11 @@ |
| 229 | 266 | log write 1 file "In '$mypath': Branch '$branchnr' named '[$mybranches($branchnr) name]'" |
| 230 | 267 | log write 1 file "Cannot have second name '$name', ignoring it" |
| 231 | 268 | return |
| 232 | 269 | } |
| 233 | 270 | set branch [sym %AUTO% branch $branchnr [$myproject getsymbol $name]] |
| 271 | + $branch setposition [incr mybranchcnt] |
| 234 | 272 | set mybranches($branchnr) $branch |
| 235 | 273 | return $branch |
| 236 | 274 | } |
| 237 | 275 | |
| 238 | 276 | method AddTag {name revnr} { |
| | @@ -271,10 +309,101 @@ |
| 271 | 309 | lappend mydependencies $revnr $next |
| 272 | 310 | } |
| 273 | 311 | return |
| 274 | 312 | } |
| 275 | 313 | |
| 314 | + proc ProcessPrimaryDependencies {} { |
| 315 | + upvar 1 mydependencies mydependencies myrev myrev |
| 316 | + |
| 317 | + foreach {parentrevnr childrevnr} $mydependencies { |
| 318 | + set parent $myrev($parentrevnr) |
| 319 | + set child $myrev($childrevnr) |
| 320 | + $parent setchild $child |
| 321 | + $child setparent $parent |
| 322 | + } |
| 323 | + return |
| 324 | + } |
| 325 | + |
| 326 | + proc ProcessBranchDependencies {} { |
| 327 | + upvar 1 mybranches mybranches myrev myrev |
| 328 | + |
| 329 | + foreach {branchnr branch} [array get mybranches] { |
| 330 | + set revnr [$branch parentrevnr] |
| 331 | + |
| 332 | + if {![info exists myrev($revnr)]} { |
| 333 | + log write 1 file "In '$mypath': The branch '[$branch name]' references" |
| 334 | + log write 1 file "the bogus revision '$revnr' and will be ignored." |
| 335 | + $branch destroy |
| 336 | + unset mybranches($branchnr) |
| 337 | + } else { |
| 338 | + set rev $myrev($revnr) |
| 339 | + $rev addbranch $branch |
| 340 | + |
| 341 | + # If revisions were committed on the branch we store a |
| 342 | + # reference to the branch there, and further declare |
| 343 | + # the first child's parent to be branch's parent, and |
| 344 | + # list this child in the parent revision. |
| 345 | + |
| 346 | + if {[$branch haschild]} { |
| 347 | + set childrevnr [$branch childrevnr] |
| 348 | + set child $myrev($childrevnr) |
| 349 | + |
| 350 | + $child setparentbranch $branch |
| 351 | + $child setparent $rev |
| 352 | + $rev addchildonbranch $child |
| 353 | + } |
| 354 | + } |
| 355 | + } |
| 356 | + return |
| 357 | + } |
| 358 | + |
| 359 | + proc SortBranches {} { |
| 360 | + upvar 1 myrev myrev |
| 361 | + |
| 362 | + foreach {revnr rev} [array get myrev] { |
| 363 | + $rev sortbranches |
| 364 | + } |
| 365 | + return |
| 366 | + } |
| 367 | + |
| 368 | + proc ProcessTagDependencies {} { |
| 369 | + upvar 1 mytags mytags myrev myrev |
| 370 | + |
| 371 | + foreach {revnr taglist} [array get mytags] { |
| 372 | + if {![info exists myrev($revnr)]} { |
| 373 | + set n [llength $taglist] |
| 374 | + log write 1 file "In '$mypath': The following [nsp $n tag] reference" |
| 375 | + log write 1 file "the bogus revision '$revnr' and will be ignored." |
| 376 | + foreach tag $taglist { |
| 377 | + log write 1 file " [$tag name]" |
| 378 | + $tag destroy |
| 379 | + } |
| 380 | + unset mytags($revnr) |
| 381 | + } else { |
| 382 | + set rev $myrev($revnr) |
| 383 | + foreach tag $taglist { $rev addtag $tag } |
| 384 | + } |
| 385 | + } |
| 386 | + return |
| 387 | + } |
| 388 | + |
| 389 | + proc DetermineTheRootRevision {} { |
| 390 | + upvar 1 myrev myrev myroot myroot |
| 391 | + |
| 392 | + # The root is the one revision which has no parent. By |
| 393 | + # checking all revisions we ensure that we can detect and |
| 394 | + # report the case of multiple roots. Without that we could |
| 395 | + # simply take one revision and follow the parent links to |
| 396 | + # their root (sic!). |
| 397 | + |
| 398 | + foreach {revnr rev} [array get myrev] { |
| 399 | + if {[$rev hasparent]} continue |
| 400 | + if {$myroot ne ""} { trouble internal "Multiple root revisions found" } |
| 401 | + set myroot $rev |
| 402 | + } |
| 403 | + return |
| 404 | + } |
| 276 | 405 | |
| 277 | 406 | # # ## ### ##### ######## ############# |
| 278 | 407 | ## Configuration |
| 279 | 408 | |
| 280 | 409 | pragma -hastypeinfo no ; # no type introspection |
| | @@ -287,15 +416,17 @@ |
| 287 | 416 | |
| 288 | 417 | namespace eval ::vc::fossil::import::cvs { |
| 289 | 418 | namespace export file |
| 290 | 419 | namespace eval file { |
| 291 | 420 | # Import not required, already a child namespace. |
| 292 | | - # namespace import vc::fossil::import::cvs::file::rev |
| 293 | | - # namespace import vc::fossil::import::cvs::file::sym |
| 421 | + # namespace import ::vc::fossil::import::cvs::file::rev |
| 422 | + # namespace import ::vc::fossil::import::cvs::file::sym |
| 423 | + namespace import ::vc::tools::misc::* |
| 424 | + namespace import ::vc::tools::trouble |
| 294 | 425 | } |
| 295 | 426 | } |
| 296 | 427 | |
| 297 | 428 | # # ## ### ##### ######## ############# ##################### |
| 298 | 429 | ## Ready |
| 299 | 430 | |
| 300 | 431 | package provide vc::fossil::import::cvs::file 1.0 |
| 301 | 432 | return |
| 302 | 433 | |