File Annotation
Not logged in
b6bf21e2a8 2007-12-05       aku: ## -*- tcl -*-
b6bf21e2a8 2007-12-05       aku: # # ## ### ##### ######## ############# #####################
b6bf21e2a8 2007-12-05       aku: ## Copyright (c) 2007 Andreas Kupries.
b6bf21e2a8 2007-12-05       aku: #
b6bf21e2a8 2007-12-05       aku: # This software is licensed as described in the file LICENSE, which
b6bf21e2a8 2007-12-05       aku: # you should have received as part of this distribution.
b6bf21e2a8 2007-12-05       aku: #
b6bf21e2a8 2007-12-05       aku: # This software consists of voluntary contributions made by many
b6bf21e2a8 2007-12-05       aku: # individuals.  For exact contribution history, see the revision
b6bf21e2a8 2007-12-05       aku: # history and logs, available at http://fossil-scm.hwaci.com/fossil
b6bf21e2a8 2007-12-05       aku: # # ## ### ##### ######## ############# #####################
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku: ## Fossil, a helper class managing the access to fossil repositories.
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku: # # ## ### ##### ######## ############# #####################
b6bf21e2a8 2007-12-05       aku: ## Requirements
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku: package require Tcl 8.4                             ; # Required runtime.
b6bf21e2a8 2007-12-05       aku: package require fileutil                            ; # Temp.dir/file
b6bf21e2a8 2007-12-05       aku: package require snit                                ; # OO system.
b6bf21e2a8 2007-12-05       aku: package require vc::tools::trouble                  ; # Error reporting.
b6bf21e2a8 2007-12-05       aku: package require vc::tools::log                      ; # User feedback
b6bf21e2a8 2007-12-05       aku: package require vc::fossil::import::cvs::integrity  ; # State integrity checks.
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku: # # ## ### ##### ######## ############# #####################
b6bf21e2a8 2007-12-05       aku: ##
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku: snit::type ::vc::fossil::import::cvs::fossil {
b6bf21e2a8 2007-12-05       aku:     # # ## ### ##### ######## #############
b6bf21e2a8 2007-12-05       aku:     ## Public API
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     constructor {} {
b6bf21e2a8 2007-12-05       aku: 	set myrepository [fileutil::tempfile cvs2fossil_repo_]
b6bf21e2a8 2007-12-05       aku: 	set myworkspace  [fileutil::tempfile cvs2fossil_wspc_]
7208c7ac4d 2008-01-28  mjanssen: 	::file delete $myworkspace
7208c7ac4d 2008-01-28  mjanssen: 	::file mkdir  $myworkspace
7208c7ac4d 2008-01-28  mjanssen: 
7208c7ac4d 2008-01-28  mjanssen: 	Do new [::file nativename $myrepository]
7208c7ac4d 2008-01-28  mjanssen: 	$self InWorkspace ; Do open [::file nativename $myrepository]
b6bf21e2a8 2007-12-05       aku: 	$self RestorePwd
9214c11831 2008-02-02       aku: 
9214c11831 2008-02-02       aku: 	log write 8 fossil {scratch repository $myrepository}
9214c11831 2008-02-02       aku: 	log write 8 fossil {scratch workspace  $myworkspace}
b6bf21e2a8 2007-12-05       aku: 	return
b6bf21e2a8 2007-12-05       aku:     }
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     # # ## ### ##### ######## #############
b6bf21e2a8 2007-12-05       aku:     ##
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     method root {} {
b6bf21e2a8 2007-12-05       aku: 	# The id of the root manifest is hardwired into fossil. This
b6bf21e2a8 2007-12-05       aku: 	# manifest is created when a new repository is made (See
b6bf21e2a8 2007-12-05       aku: 	# 'new', in the constructor).
b6bf21e2a8 2007-12-05       aku: 	return 1
b6bf21e2a8 2007-12-05       aku:     }
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     method workspace {} { return $myworkspace }
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     method importfiles {map} {
b6bf21e2a8 2007-12-05       aku: 	# map = list (instruction), instruction = add|delta
b6bf21e2a8 2007-12-05       aku: 	# add   = list ('A', path)
b6bf21e2a8 2007-12-05       aku: 	# delta = list ('D', path, src)
b6bf21e2a8 2007-12-05       aku: 
e60ba15821 2008-01-27       aku: 	log write 3 fossil {Importing revisions...}
08f8085700 2007-12-06       aku: 
b6bf21e2a8 2007-12-05       aku: 	array set id {}
b6bf21e2a8 2007-12-05       aku: 	$self InWorkspace
08f8085700 2007-12-06       aku: 
08f8085700 2007-12-06       aku: 	set n   0
08f8085700 2007-12-06       aku: 	set max [llength $map]
08f8085700 2007-12-06       aku: 
b6bf21e2a8 2007-12-05       aku: 	foreach insn $map {
08f8085700 2007-12-06       aku: 	    log progress 3 fossil $n $max ; incr n
08f8085700 2007-12-06       aku: 
b6bf21e2a8 2007-12-05       aku: 	    struct::list assign $insn cmd pa pb
b6bf21e2a8 2007-12-05       aku: 	    switch -exact -- $cmd {
b6bf21e2a8 2007-12-05       aku: 		A {
08f8085700 2007-12-06       aku: 		    log write 8 fossil {Importing   <$pa>,}
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku: 		    # Result = 'inserted as record :FOO:'
b6bf21e2a8 2007-12-05       aku: 		    #           0        1  2     3
b6bf21e2a8 2007-12-05       aku: 		    set res [Do test-content-put $pa]
b6bf21e2a8 2007-12-05       aku: 		    integrity assert {
b6bf21e2a8 2007-12-05       aku: 			[regexp {^inserted as record \d+$} $res]
b6bf21e2a8 2007-12-05       aku: 		    } {Unable to process unexpected fossil output '$res'}
b6bf21e2a8 2007-12-05       aku: 		    set id($pa) [lindex $res 3]
b6bf21e2a8 2007-12-05       aku: 		}
b6bf21e2a8 2007-12-05       aku: 		D {
08f8085700 2007-12-06       aku: 		    log write 8 fossil {Compressing <$pa>, as delta of <$pb>}
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku: 		    Do test-content-deltify $id($pa) $id($pb) 1
b6bf21e2a8 2007-12-05       aku: 		}
b6bf21e2a8 2007-12-05       aku: 	    }
b6bf21e2a8 2007-12-05       aku: 	}
b6bf21e2a8 2007-12-05       aku: 	$self RestorePwd
e60ba15821 2008-01-27       aku: 
e60ba15821 2008-01-27       aku: 	log write 3 fossil Done.
b6bf21e2a8 2007-12-05       aku: 	return [array get id]
b6bf21e2a8 2007-12-05       aku:     }
b6bf21e2a8 2007-12-05       aku: 
f9e0d23d97 2008-01-30       aku:     method importrevision {label user message date parent revisions} {
f9e0d23d97 2008-01-30       aku: 	# TODO = Write the actual import, and up the log level.
f9e0d23d97 2008-01-30       aku: 
f9e0d23d97 2008-01-30       aku: 	# Massage the commit message to remember the old user name
f9e0d23d97 2008-01-30       aku: 	# which did the commit in CVS.
f9e0d23d97 2008-01-30       aku: 
f9e0d23d97 2008-01-30       aku: 	set message "By $user:\n$message"
f9e0d23d97 2008-01-30       aku: 
7c43583de1 2008-01-31       aku: 	log write 2 fossil {== $user @ [clock format $date]}
7c43583de1 2008-01-31       aku: 	log write 2 fossil {-> $parent}
7c43583de1 2008-01-31       aku: 	log write 2 fossil {%% [join [split $message \n] "\n%% "]}
7c43583de1 2008-01-31       aku: 
7c43583de1 2008-01-31       aku: 	lappend cmd Do test-import-manifest $date $message
b7a93530ef 2008-02-01       aku: 	if {$parent ne ""} { lappend cmd -p $parent }
7c43583de1 2008-01-31       aku: 	foreach {frid fpath flabel} $revisions {
b7a93530ef 2008-02-01       aku: 	    lappend cmd -f $frid $fpath
b7a93530ef 2008-02-01       aku: 	    log write 2 fossil {** <[format %5d $frid]> = <$flabel>}
7c43583de1 2008-01-31       aku: 	}
7c43583de1 2008-01-31       aku: 
f9e0d23d97 2008-01-30       aku: 	# run fossil test-command performing the import.
9214c11831 2008-02-02       aku: 	log write 8 fossil {	[lreplace $cmd 3 3 @@]}
9214c11831 2008-02-02       aku: 
9214c11831 2008-02-02       aku: 	$self InWorkspace
9214c11831 2008-02-02       aku: 	set res [eval $cmd]
9214c11831 2008-02-02       aku: 	$self RestorePwd
9214c11831 2008-02-02       aku: 
9214c11831 2008-02-02       aku: 	integrity assert {
9214c11831 2008-02-02       aku: 	    [regexp {^inserted as record \d+$} $res]
9214c11831 2008-02-02       aku: 	} {Unable to process unexpected fossil output '$res'}
9214c11831 2008-02-02       aku: 	set uuid [lindex $res 3]
7c43583de1 2008-01-31       aku: 
7c43583de1 2008-01-31       aku: 	log write 2 fossil {== $uuid}
9214c11831 2008-02-02       aku: 	log write 2 fossil { }
9214c11831 2008-02-02       aku: 	log write 2 fossil { }
9214c11831 2008-02-02       aku: 
7c43583de1 2008-01-31       aku: 	return $uuid
f9e0d23d97 2008-01-30       aku:     }
f9e0d23d97 2008-01-30       aku: 
b6bf21e2a8 2007-12-05       aku:     method finalize {destination} {
9214c11831 2008-02-02       aku: 	Do rebuild [::file nativename $myrepository]
9214c11831 2008-02-02       aku: 
7208c7ac4d 2008-01-28  mjanssen: 	::file rename -force $myrepository $destination
7208c7ac4d 2008-01-28  mjanssen: 	::file delete -force $myworkspace
b6bf21e2a8 2007-12-05       aku: 	$self destroy
b6bf21e2a8 2007-12-05       aku: 	return
b6bf21e2a8 2007-12-05       aku:     }
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     # # ## ### ##### ######## #############
b6bf21e2a8 2007-12-05       aku:     ##
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     typemethod setlocation {path} {
b6bf21e2a8 2007-12-05       aku: 	set myfossilcmd    $path
b6bf21e2a8 2007-12-05       aku: 	set myneedlocation 0
b6bf21e2a8 2007-12-05       aku: 	return
b6bf21e2a8 2007-12-05       aku:     }
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     typemethod validate {} {
b6bf21e2a8 2007-12-05       aku: 	if {!$myneedlocation} {
b6bf21e2a8 2007-12-05       aku: 	    if {![fileutil::test $myfossilcmd efrx msg]} {
b6bf21e2a8 2007-12-05       aku: 		trouble fatal "Bad path for fossil executable: $msg"
b6bf21e2a8 2007-12-05       aku: 	    }
b6bf21e2a8 2007-12-05       aku: 	} else {
b6bf21e2a8 2007-12-05       aku: 	    trouble fatal "Don't know where to find the 'fossil' executable"
b6bf21e2a8 2007-12-05       aku: 	}
b6bf21e2a8 2007-12-05       aku: 	return
b6bf21e2a8 2007-12-05       aku:     }
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     typeconstructor {
b6bf21e2a8 2007-12-05       aku: 	set location [auto_execok fossil]
b6bf21e2a8 2007-12-05       aku: 	set myneedlocation [expr {$location eq ""}]
b6bf21e2a8 2007-12-05       aku: 	if {$myneedlocation} return
b6bf21e2a8 2007-12-05       aku: 	$type setlocation $location
b6bf21e2a8 2007-12-05       aku: 	return
b6bf21e2a8 2007-12-05       aku:     }
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     # # ## ### ##### ######## #############
b6bf21e2a8 2007-12-05       aku:     ## State
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     variable mypwd        {} ; # Path to last CWD
b6bf21e2a8 2007-12-05       aku:     variable myrepository {} ; # Path to our fossil database.
b6bf21e2a8 2007-12-05       aku:     variable myworkspace  {} ; # Path to the workspace for our fossil
b6bf21e2a8 2007-12-05       aku: 			       # database.
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     typevariable myfossilcmd    ; # Path to fossil executable.
b6bf21e2a8 2007-12-05       aku:     typevariable myneedlocation ; # Boolean, indicates if user has to
b6bf21e2a8 2007-12-05       aku: 				  # tell us where fossil lives or not.
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     # # ## ### ##### ######## #############
b6bf21e2a8 2007-12-05       aku:     ## Internal methods
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     proc Do {args} {
b6bf21e2a8 2007-12-05       aku: 	# 8.5: exec $myfossilcmd {*}$args
b6bf21e2a8 2007-12-05       aku: 	return [eval [linsert $args 0 exec $myfossilcmd]]
b6bf21e2a8 2007-12-05       aku:     }
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     method InWorkspace {} { set mypwd [pwd] ; cd $myworkspace ; return }
b6bf21e2a8 2007-12-05       aku:     method RestorePwd  {} { cd $mypwd       ; set mypwd {}    ; return }
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     # # ## ### ##### ######## #############
b6bf21e2a8 2007-12-05       aku:     ## Configuration
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     pragma -hastypeinfo    no  ; # no type introspection
b6bf21e2a8 2007-12-05       aku:     pragma -hasinfo        no  ; # no object introspection
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku:     # # ## ### ##### ######## #############
b6bf21e2a8 2007-12-05       aku: }
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku: namespace eval ::vc::fossil::import::cvs {
b6bf21e2a8 2007-12-05       aku:     namespace export fossil
b6bf21e2a8 2007-12-05       aku:     namespace eval   fossil {
b6bf21e2a8 2007-12-05       aku: 	namespace import ::vc::tools::trouble
b6bf21e2a8 2007-12-05       aku: 	namespace import ::vc::tools::log
b6bf21e2a8 2007-12-05       aku: 	namespace import ::vc::fossil::import::cvs::integrity
b6bf21e2a8 2007-12-05       aku:     }
b6bf21e2a8 2007-12-05       aku: }
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku: # # ## ### ##### ######## ############# #####################
b6bf21e2a8 2007-12-05       aku: ## Ready
b6bf21e2a8 2007-12-05       aku: 
b6bf21e2a8 2007-12-05       aku: package provide vc::fossil::import::cvs::fossil 1.0
b6bf21e2a8 2007-12-05       aku: return