File Annotation
Not logged in
df91d389d5 2007-09-04       aku: # -----------------------------------------------------------------------------
df91d389d5 2007-09-04       aku: # Repository management (FOSSIL)
df91d389d5 2007-09-04       aku: 
df91d389d5 2007-09-04       aku: # -----------------------------------------------------------------------------
df91d389d5 2007-09-04       aku: # Requirements
df91d389d5 2007-09-04       aku: 
df91d389d5 2007-09-04       aku: package require Tcl 8.4
cdf5e6d8b7 2007-09-13       aku: package require vc::tools::log  ; # User feedback
cdf5e6d8b7 2007-09-13       aku: package require vc::fossil::cmd ; # Access to fossil application.
45cd12f05a 2007-09-13       aku: 
45cd12f05a 2007-09-13       aku: namespace eval ::vc::fossil::ws {
86a7f249c1 2007-09-09       aku:     vc::tools::log::system fossil
86a7f249c1 2007-09-09       aku:     namespace import ::vc::tools::log::write
cdf5e6d8b7 2007-09-13       aku:     namespace import ::vc::fossil::cmd::do
cdf5e6d8b7 2007-09-13       aku:     namespace import ::vc::fossil::cmd::dova
be32ebcb41 2007-09-08       aku: }
df91d389d5 2007-09-04       aku: 
df91d389d5 2007-09-04       aku: # -----------------------------------------------------------------------------
df91d389d5 2007-09-04       aku: # API
df91d389d5 2007-09-04       aku: 
7b2619b7ef 2007-09-13       aku: # vc::fossil::ws::configure key value         - Configure the subsystem.
7b2619b7ef 2007-09-13       aku: # vc::fossil::ws::begin     src               - Start new workspace for directory
7b2619b7ef 2007-09-13       aku: # vc::fossil::ws::done      dst               - Close workspace and copy to destination.
7b2619b7ef 2007-09-13       aku: # vc::fossil::ws::commit    cset usr time msg - Look for changes and commit as new revision.
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku: # Configuration keys:
7b2619b7ef 2007-09-13       aku: #
7b2619b7ef 2007-09-13       aku: # -nosign  bool		default 0 (= sign imported changesets)
7b2619b7ef 2007-09-13       aku: # -breakat num		default empty, no breakpoint.
7b2619b7ef 2007-09-13       aku: #			Otherwise stop before committing the identified changeset.
7b2619b7ef 2007-09-13       aku: # -saveto  path		default empty, no saving.
7b2619b7ef 2007-09-13       aku: #			Otherwise save the commit command to a file.
7b2619b7ef 2007-09-13       aku: # -appname string	Default empty. Text to add to all commit messages.
7b2619b7ef 2007-09-13       aku: # -ignore  cmdprefix	Command to check if a file is relevant to the commit or not.
7b2619b7ef 2007-09-13       aku: #			Signature: cmdprefix path -> bool; true => ignore.
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku: # -----------------------------------------------------------------------------
7b2619b7ef 2007-09-13       aku: # API Implementation
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku: proc ::vc::fossil::ws::configure {key value} {
7b2619b7ef 2007-09-13       aku:     variable nosign
7b2619b7ef 2007-09-13       aku:     variable breakat
7b2619b7ef 2007-09-13       aku:     variable saveto
7b2619b7ef 2007-09-13       aku:     variable appname
7b2619b7ef 2007-09-13       aku:     variable ignore
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku:     switch -exact -- $key {
7b2619b7ef 2007-09-13       aku: 	-appname { set appname $value }
7b2619b7ef 2007-09-13       aku: 	-breakat { set breakat $value }
7b2619b7ef 2007-09-13       aku: 	-ignore  { set ignore  $value }
7b2619b7ef 2007-09-13       aku: 	-nosign {
7b2619b7ef 2007-09-13       aku: 	    if {![string is boolean -strict $value]} {
7b2619b7ef 2007-09-13       aku: 		return -code error "Expected boolean, got \"$value\""
7b2619b7ef 2007-09-13       aku: 	    }
7b2619b7ef 2007-09-13       aku: 	    set nosign $value
7b2619b7ef 2007-09-13       aku: 	}
7b2619b7ef 2007-09-13       aku: 	-saveto  { set saveto $value }
7b2619b7ef 2007-09-13       aku: 	default {
7b2619b7ef 2007-09-13       aku: 	    return -code error "Unknown switch $key, expected one of \
7b2619b7ef 2007-09-13       aku:                                    -appname, -breakat, -ignore, -nosign, or -saveto"
7b2619b7ef 2007-09-13       aku: 	}
492531e3a8 2007-09-04       aku:     }
492531e3a8 2007-09-04       aku:     return
df91d389d5 2007-09-04       aku: }
df91d389d5 2007-09-04       aku: 
7b2619b7ef 2007-09-13       aku: proc ::vc::fossil::ws::begin {origin} {
7b2619b7ef 2007-09-13       aku:     variable rp [file normalize [fileutil::tempfile import2_fsl_rp_]]
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku:     cd $origin
7b2619b7ef 2007-09-13       aku:     dova new  $rp ; # create and ...
7b2619b7ef 2007-09-13       aku:     dova open $rp ; # ... connect
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku:     write 0 fossil "Repository: $rp"
df91d389d5 2007-09-04       aku:     return
df91d389d5 2007-09-04       aku: }
df91d389d5 2007-09-04       aku: 
7b2619b7ef 2007-09-13       aku: proc ::vc::fossil::ws::done {destination} {
7b2619b7ef 2007-09-13       aku:     variable rp
7b2619b7ef 2007-09-13       aku:     file rename -force $rp $destination
7b2619b7ef 2007-09-13       aku:     set rp {}
df91d389d5 2007-09-04       aku:     return
df91d389d5 2007-09-04       aku: }
df91d389d5 2007-09-04       aku: 
7b2619b7ef 2007-09-13       aku: proc ::vc::fossil::ws::commit {cset user timestamp message} {
df91d389d5 2007-09-04       aku:     variable lastuuid
df91d389d5 2007-09-04       aku: 
df91d389d5 2007-09-04       aku:     # Commit the current state of the workspace. Scan for new and
df91d389d5 2007-09-04       aku:     # removed files and issue the appropriate fossil add/rm commands
df91d389d5 2007-09-04       aku:     # before actually comitting.
df91d389d5 2007-09-04       aku: 
7b2619b7ef 2007-09-13       aku:     HandleChanges added removed changed
df91d389d5 2007-09-04       aku: 
df91d389d5 2007-09-04       aku:     # Now commit, using the provided meta data, and capture the uuid
df91d389d5 2007-09-04       aku:     # of the new baseline.
df91d389d5 2007-09-04       aku: 
7b2619b7ef 2007-09-13       aku:     set cmd [Command $cset [Message $user $timestamp $message]]
df91d389d5 2007-09-04       aku: 
df91d389d5 2007-09-04       aku:     if {[catch {
cdf5e6d8b7 2007-09-13       aku: 	do $cmd
df91d389d5 2007-09-04       aku:     } line]} {
df91d389d5 2007-09-04       aku: 	if {![string match "*nothing has changed*" $line]} {
df91d389d5 2007-09-04       aku: 	    return -code error $line
df91d389d5 2007-09-04       aku: 	}
df91d389d5 2007-09-04       aku: 
df91d389d5 2007-09-04       aku: 	# 'Nothing changed' can happen for changesets containing only
df91d389d5 2007-09-04       aku: 	# dead-first revisions of one or more files. For fossil we
df91d389d5 2007-09-04       aku: 	# re-use the last baseline. TODO: Mark them as branchpoint,
df91d389d5 2007-09-04       aku: 	# and for what file.
df91d389d5 2007-09-04       aku: 
be32ebcb41 2007-09-08       aku: 	write 1 fossil "UNCHANGED, keeping last"
df91d389d5 2007-09-04       aku: 
df91d389d5 2007-09-04       aku: 	return [list $lastuuid 0 0 0]
df91d389d5 2007-09-04       aku:     }
df91d389d5 2007-09-04       aku: 
7b2619b7ef 2007-09-13       aku:     # Extract the uuid of the new revision.
7b2619b7ef 2007-09-13       aku:     regsub -nocase -- {^\s*New_Version:\s*} [string trim $line] {} uuid
df91d389d5 2007-09-04       aku: 
df91d389d5 2007-09-04       aku:     set lastuuid $uuid
df91d389d5 2007-09-04       aku:     return [list $uuid $added $removed $changed]
df91d389d5 2007-09-04       aku: }
df91d389d5 2007-09-04       aku: 
df91d389d5 2007-09-04       aku: # -----------------------------------------------------------------------------
7b2619b7ef 2007-09-13       aku: # Internal helper commands, and data structures.
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku: proc ::vc::fossil::ws::HandleChanges {av rv cv} {
7b2619b7ef 2007-09-13       aku:     upvar 1 $av added $rv removed $cv changed
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku:     set added   0
7b2619b7ef 2007-09-13       aku:     set removed 0
7b2619b7ef 2007-09-13       aku:     set changed 0
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku:     # Look for modified/removed files first, that way there won't be
7b2619b7ef 2007-09-13       aku:     # any ADDED indicators. Nor REMOVED, only EDITED. Removed files
7b2619b7ef 2007-09-13       aku:     # show up as EDITED while they are not registered as removed.
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku:     foreach line [split [do changes] \n] {
7b2619b7ef 2007-09-13       aku:         regsub {^\s*EDITED\s*} $line {} path
7b2619b7ef 2007-09-13       aku:         if {[Ignore $path]} continue
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku:         if {![file exists $path]} {
7b2619b7ef 2007-09-13       aku: 	    dova rm $path
7b2619b7ef 2007-09-13       aku:             incr removed
7b2619b7ef 2007-09-13       aku:             write 2 fossil "-  $path"
7b2619b7ef 2007-09-13       aku:         } else {
7b2619b7ef 2007-09-13       aku:             incr changed
7b2619b7ef 2007-09-13       aku:             write 2 fossil "*  $path"
7b2619b7ef 2007-09-13       aku:         }
7b2619b7ef 2007-09-13       aku:     }
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku:     # Now look for unregistered added files.
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku:     foreach path [split [do extra] \n] {
7b2619b7ef 2007-09-13       aku:         if {[Ignore $path]} continue
7b2619b7ef 2007-09-13       aku:         dova add $path
7b2619b7ef 2007-09-13       aku:         incr added
7b2619b7ef 2007-09-13       aku:         write 2 fossil "+  $path"
7b2619b7ef 2007-09-13       aku:     }
7b2619b7ef 2007-09-13       aku: 
df91d389d5 2007-09-04       aku:     return
df91d389d5 2007-09-04       aku: }
df91d389d5 2007-09-04       aku: 
7b2619b7ef 2007-09-13       aku: proc ::vc::fossil::ws::Message {user timestamp message} {
7b2619b7ef 2007-09-13       aku:     variable appname
7b2619b7ef 2007-09-13       aku:     set lines {}
7b2619b7ef 2007-09-13       aku:     lappend lines "-- Originally by $user @ $timestamp"
7b2619b7ef 2007-09-13       aku:     if {$appname ne ""} {
7b2619b7ef 2007-09-13       aku: 	lappend lines "-- Imported by $appname"
7b2619b7ef 2007-09-13       aku:     }
7b2619b7ef 2007-09-13       aku:     lappend lines [string trim $message]
7b2619b7ef 2007-09-13       aku:     return [join $lines \n]
7b2619b7ef 2007-09-13       aku: }
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku: proc ::vc::fossil::ws::Command {cset message} {
7b2619b7ef 2007-09-13       aku:     variable nosign
7b2619b7ef 2007-09-13       aku:     variable saveto
7b2619b7ef 2007-09-13       aku:     variable breakat
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku:     set cmd [list commit -m $message]
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku:     if {$nosign}           { lappend cmd --nosign }
7b2619b7ef 2007-09-13       aku:     if {$saveto ne ""}     { fileutil::writeFile $saveto "$cmd\n" }
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku:     if {$breakat eq $cset} {
7b2619b7ef 2007-09-13       aku: 	write 0 fossil Stopped.
7b2619b7ef 2007-09-13       aku: 	exit 0
7b2619b7ef 2007-09-13       aku:     }
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku:     return $cmd
7b2619b7ef 2007-09-13       aku: }
be32ebcb41 2007-09-08       aku: 
7b2619b7ef 2007-09-13       aku: proc ::vc::fossil::ws::Ignore {path} {
7b2619b7ef 2007-09-13       aku:     variable ignore
7b2619b7ef 2007-09-13       aku:     if {![llength $ignore]} {return 0}
be32ebcb41 2007-09-08       aku:     return [uplevel #0 [linsert $ignore end $path]]
00228d1547 2007-09-13       aku: }
00228d1547 2007-09-13       aku: 
00228d1547 2007-09-13       aku: namespace eval ::vc::fossil::ws {
7b2619b7ef 2007-09-13       aku:     # Configuration settings.
7b2619b7ef 2007-09-13       aku:     variable nosign 0   ; # Sign imported changesets
7b2619b7ef 2007-09-13       aku:     variable breakat {} ; # Do not stop
7b2619b7ef 2007-09-13       aku:     variable saveto  {} ; # Do not save commit message
7b2619b7ef 2007-09-13       aku:     variable appname {} ; # Name of importer application using the package.
7b2619b7ef 2007-09-13       aku:     variable ignore  {} ; # No files to ignore.
7b2619b7ef 2007-09-13       aku: 
7b2619b7ef 2007-09-13       aku:     variable rp       {} ; # Repository the package works on.
7b2619b7ef 2007-09-13       aku:     variable lastuuid {} ; # Uuid of last imported changeset.
df91d389d5 2007-09-04       aku: 
7b2619b7ef 2007-09-13       aku:     namespace export configure begin done commit
df91d389d5 2007-09-04       aku: }
df91d389d5 2007-09-04       aku: 
df91d389d5 2007-09-04       aku: # -----------------------------------------------------------------------------
df91d389d5 2007-09-04       aku: # Ready
df91d389d5 2007-09-04       aku: 
45cd12f05a 2007-09-13       aku: package provide vc::fossil::ws 1.0
df91d389d5 2007-09-04       aku: return