|
1
|
## -*- tcl -*- |
|
2
|
# # ## ### ##### ######## ############# ##################### |
|
3
|
## Copyright (c) 2008 Andreas Kupries. |
|
4
|
# |
|
5
|
# This software is licensed as described in the file LICENSE, which |
|
6
|
# you should have received as part of this distribution. |
|
7
|
# |
|
8
|
# This software consists of voluntary contributions made by many |
|
9
|
# individuals. For exact contribution history, see the revision |
|
10
|
# history and logs, available at http://fossil-scm.hwaci.com/fossil |
|
11
|
# # ## ### ##### ######## ############# ##################### |
|
12
|
|
|
13
|
## Blob storage. Each instance stores the blob data of a single rcs |
|
14
|
## archive file, i.e. which file, all text ranges, delta dependencies, |
|
15
|
## and associated revisions (as object references). The data is |
|
16
|
## persistent and used by the import pass(es) to expand the revisions |
|
17
|
## of a file. |
|
18
|
|
|
19
|
# # ## ### ##### ######## ############# ##################### |
|
20
|
## Requirements |
|
21
|
|
|
22
|
package require Tcl 8.4 ; # Required runtime. |
|
23
|
package require snit ; # OO system. |
|
24
|
package require vc::fossil::import::cvs::state ; # State storage. |
|
25
|
package require vc::fossil::import::cvs::integrity ; # State integrity checks. |
|
26
|
package require vc::tools::trouble ; # Error reporting. |
|
27
|
package require vc::tools::log ; # User feedback |
|
28
|
#package require vc::tools::misc ; # Text formatting |
|
29
|
|
|
30
|
# # ## ### ##### ######## ############# ##################### |
|
31
|
## |
|
32
|
|
|
33
|
snit::type ::vc::fossil::import::cvs::blobstore { |
|
34
|
# # ## ### ##### ######## ############# |
|
35
|
## Public API |
|
36
|
|
|
37
|
constructor {fid} { |
|
38
|
set myfile $fid |
|
39
|
array set myparent {} |
|
40
|
array set myblob {} |
|
41
|
return |
|
42
|
} |
|
43
|
|
|
44
|
method setid {id} { |
|
45
|
integrity assert {$myfile eq ""} {Already has an id, '$myfile'} |
|
46
|
set myfile $id |
|
47
|
return |
|
48
|
} |
|
49
|
|
|
50
|
# Remember the file revision object for the revision REVNR. |
|
51
|
|
|
52
|
method add {revnr rev} { |
|
53
|
set myblob($revnr) $rev |
|
54
|
return |
|
55
|
} |
|
56
|
|
|
57
|
# Remember that the DELTA revision is specified as a delta against |
|
58
|
# the BASE revision. Both are specified as revision numbers. |
|
59
|
|
|
60
|
method delta {delta base} { |
|
61
|
set myparent($delta) $base |
|
62
|
return |
|
63
|
} |
|
64
|
|
|
65
|
# Specify the text range in the archive file for the data of the |
|
66
|
# revision identified by REVNR. |
|
67
|
|
|
68
|
method extend {revnr textrange} { |
|
69
|
struct::list assign $textrange coff end |
|
70
|
set clen [expr {$end - $coff}] |
|
71
|
lappend myblob($revnr) $coff $clen |
|
72
|
return |
|
73
|
} |
|
74
|
|
|
75
|
# Write the stored information into the persistent state. |
|
76
|
|
|
77
|
method persist {} { |
|
78
|
array set bids {} |
|
79
|
state transaction { |
|
80
|
# Phase I: Store the basic blob information. |
|
81
|
|
|
82
|
foreach revnr [lsort [array names myblob]] { |
|
83
|
struct::list assign $myblob($revnr) rev coff clen |
|
84
|
state run { |
|
85
|
INSERT INTO blob (bid, rid, fid, coff, clen, pid) |
|
86
|
VALUES (NULL, NULL, $myfile, $coff, $clen, NULL) |
|
87
|
} |
|
88
|
set current [state id] |
|
89
|
set bids($revnr) $current |
|
90
|
|
|
91
|
# Ia. Set the reference to the revision of the blob, |
|
92
|
# if applicable. We can have blobs without revisions, |
|
93
|
# their revisions were removed as irrelevant. We need |
|
94
|
# them however for the proper delta ordering and patch |
|
95
|
# application when expanding a file (-> Import passes). |
|
96
|
|
|
97
|
set rid [$rev id] |
|
98
|
if {$rid eq ""} continue |
|
99
|
state run { |
|
100
|
UPDATE blob |
|
101
|
SET rid = $rid |
|
102
|
WHERE bid = $current |
|
103
|
} |
|
104
|
} |
|
105
|
|
|
106
|
# Phase II: Set the parent links for deltas. |
|
107
|
foreach revnr [array names myparent] { |
|
108
|
set bid $bids($revnr) |
|
109
|
set pid $bids($myparent($revnr)) |
|
110
|
|
|
111
|
state run { |
|
112
|
UPDATE blob |
|
113
|
SET pid = $pid |
|
114
|
WHERE bid = $bid |
|
115
|
} |
|
116
|
} |
|
117
|
} |
|
118
|
return |
|
119
|
} |
|
120
|
|
|
121
|
# # ## ### ##### ######## ############# |
|
122
|
## State |
|
123
|
|
|
124
|
variable myfile {} ; # Id of the file the blobs belong to. |
|
125
|
variable myparent -array {} ; # Map delta-encoded revision numbers |
|
126
|
# to their baseline revisions. |
|
127
|
variable myblob -array {} ; # Map revision numbers to associated |
|
128
|
# file revision object and text |
|
129
|
# range. |
|
130
|
|
|
131
|
# # ## ### ##### ######## ############# |
|
132
|
## Configuration |
|
133
|
|
|
134
|
pragma -hastypeinfo no ; # no type introspection |
|
135
|
pragma -hasinfo no ; # no object introspection |
|
136
|
pragma -hastypemethods no ; # type is not relevant. |
|
137
|
|
|
138
|
# # ## ### ##### ######## ############# |
|
139
|
} |
|
140
|
|
|
141
|
namespace eval ::vc::fossil::import::cvs { |
|
142
|
namespace export blobstore |
|
143
|
namespace eval blobstore { |
|
144
|
namespace import ::vc::tools::trouble |
|
145
|
namespace import ::vc::tools::log |
|
146
|
namespace import ::vc::fossil::import::cvs::state |
|
147
|
namespace import ::vc::fossil::import::cvs::integrity |
|
148
|
} |
|
149
|
} |
|
150
|
|
|
151
|
# # ## ### ##### ######## ############# ##################### |
|
152
|
## Ready |
|
153
|
|
|
154
|
package provide vc::fossil::import::cvs::blobstore 1.0 |
|
155
|
return |
|
156
|
|