File: c2f_project.tcl

package info (click to toggle)
fossil 1%3A1.22.1%2Bdfsg-0.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 10,588 kB
  • sloc: ansic: 151,799; tcl: 10,291; sh: 4,413; makefile: 1,822; sql: 376
file content (233 lines) | stat: -rw-r--r-- 6,938 bytes parent folder | download | duplicates (9)
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
## -*- 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
# # ## ### ##### ######## ############# #####################

## Project, part of a CVS repository. Multiple instances are possible.

# # ## ### ##### ######## ############# #####################
## Requirements

package require Tcl 8.4                                 ; # Required runtime.
package require snit                                    ; # OO system.
package require vc::fossil::import::cvs::file           ; # CVS archive file.
package require vc::fossil::import::cvs::state          ; # State storage.
package require vc::fossil::import::cvs::project::rev   ; # Changesets.
package require vc::fossil::import::cvs::project::sym   ; # Per project symbols.
package require vc::fossil::import::cvs::project::trunk ; # Per project trunk, main lod
package require vc::tools::log                          ; # User feedback
package require struct::list                            ; # Advanced list operations..

# # ## ### ##### ######## ############# #####################
##

snit::type ::vc::fossil::import::cvs::project {
    # # ## ### ##### ######## #############
    ## Public API

    constructor {path r} {
	set mybase       $path
	set myrepository $r
	set mytrunk      [trunk %AUTO% $self]
	set mysymbol([$mytrunk name]) $mytrunk
	return
    }

    method base  {} { return $mybase  }
    method trunk {} { return $mytrunk }

    method fullpath {} { return [$myrepository base?]/$mybase }

    method printbase {} {
	if {$mybase eq ""} {return <Repository>}
	return $mybase
    }

    method id    {}   { return $myid }
    method setid {id} { set myid $id ; return }

    method addfile {rcs usr executable {fid {}}} {
	set myfiles($rcs) [list $usr $executable $fid]
	return
    }

    method filenames {} {
	return [lsort -dict [array names myfiles]]
    }

    method files {} {
	return [TheFiles]
    }

    delegate method defauthor       to myrepository
    delegate method defcmessage     to myrepository
    delegate method trunkonly       to myrepository
    delegate method commitmessageof to myrepository

    method defmeta {bid aid cid} {
	return [$myrepository defmeta $myid $bid $aid $cid]
    }

    method getsymbol {name} {
	if {![info exists mysymbol($name)]} {
	    set mysymbol($name) \
		[sym %AUTO% $name [$myrepository defsymbol $myid $name] $self]
	}
	return $mysymbol($name)
    }

    method hassymbol {name} {
	return [info exists mysymbol($name)]
    }

    method purgeghostsymbols {} {
	set changes 1
	while {$changes} {
	    set changes 0
	    foreach {name symbol} [array get mysymbol] {
		if {![$symbol isghost]} continue
		log write 3 project "$mybase: Deleting ghost symbol '$name'"
		$symbol destroy
		unset mysymbol($name)
		set changes 1
	    }
	}
	return
    }

    method determinesymboltypes {} {
	foreach {name symbol} [array get mysymbol] {
	    $symbol determinetype
	}
	return
    }

    # pass I persistence
    method persist {} {
	TheFiles ; # Force id assignment.

	state transaction {
	    # Project data first. Required so that we have its id
	    # ready for the files.

	    state run {
		INSERT INTO project (pid,  name)
		VALUES              (NULL, $mybase);
	    }
	    set myid [state id]

	    # Then all files, with proper backreference to their
	    # project.

	    foreach rcs [lsort -dict [array names myfiles]] {
		struct::list assign $myfiles($rcs) usr executable _fid_
		state run {
		    INSERT INTO file (fid,  pid,   name, visible, exec)
		    VALUES           (NULL, $myid, $rcs, $usr,    $executable);
		}
		$myfmap($rcs) setid [state id]
	    }
	}
	return
    }

    # pass II persistence
    method persistrev {} {
	# Note: The per file information (incl. revisions and symbols)
	# has already been saved and dropped. This was done
	# immediately after processing it, i.e. as part of the main
	# segment of the pass, to keep out use of memory under
	# control.
	#
	# The repository level information has been saved as well too,
	# just before saving the projects started. So now we just have
	# to save the remaining project level parts to fix the
	# left-over dangling references, which are the symbols.

	state transaction {
	    foreach {name symbol} [array get mysymbol] {
		$symbol persistrev
	    }
	}
	return
    }

    method changesetsinorder {} {
	return [rev inorder $myid]
    }

    delegate method getmeta to myrepository

    # # ## ### ##### ######## #############
    ## State

    variable mybase           {} ; # Project directory.
    variable myid             {} ; # Project id in the persistent state.
    variable mytrunk          {} ; # Reference to the main line of
				   # development for the project.
    variable myfiles   -array {} ; # Maps the rcs archive paths to
				   # their user-visible files.
    variable myfobj           {} ; # File objects for the rcs archives
    variable myfmap    -array {} ; # Map rcs archive to their object.
    variable myrepository     {} ; # Repository the project belongs to.
    variable mysymbol  -array {} ; # Map symbol names to project-level
				   # symbol objects.

    # # ## ### ##### ######## #############
    ## Internal methods

    proc TheFiles {} {
	upvar 1 myfiles myfiles myfobj myfobj self self myfmap myfmap
	if {![llength $myfobj]} {
	    set myfobj [EmptyFiles myfiles]
	}
	return $myfobj
    }

    proc EmptyFiles {fv} {
	upvar 1 $fv myfiles self self myfmap myfmap
	set res {}
	foreach rcs [lsort -dict [array names myfiles]] {
	    struct::list assign $myfiles($rcs) f executable fid
	    set file [file %AUTO% $fid $rcs $f $executable $self]
	    lappend res $file
	    set myfmap($rcs) $file
	}
	return $res
    }

    # # ## ### ##### ######## #############
    ## Configuration

    pragma -hastypeinfo    no  ; # no type introspection
    pragma -hasinfo        no  ; # no object introspection
    pragma -hastypemethods no  ; # type is not relevant.

    # # ## ### ##### ######## #############
}

namespace eval ::vc::fossil::import::cvs {
    namespace export project
    namespace eval project {
	namespace import ::vc::tools::log
	namespace import ::vc::fossil::import::cvs::file
	namespace import ::vc::fossil::import::cvs::state
	# Import not required, already a child namespace.
	# namespace import ::vc::fossil::import::cvs::project::sym
	# Import not required, already a child namespace.
	# namespace import ::vc::fossil::import::cvs::project::rev
    }
}

# # ## ### ##### ######## ############# #####################
## Ready

package provide vc::fossil::import::cvs::project 1.0
return