|
1
|
# |
|
2
|
# Copyright (c) 2026 Dan Mestas |
|
3
|
# |
|
4
|
# This program is free software; you can redistribute it and/or |
|
5
|
# modify it under the terms of the Simplified BSD License (also |
|
6
|
# known as the "2-Clause License" or "FreeBSD License".) |
|
7
|
# |
|
8
|
# This program is distributed in the hope that it will be useful, |
|
9
|
# but without any warranty; without even the implied warranty of |
|
10
|
# merchantability or fitness for a particular purpose. |
|
11
|
# |
|
12
|
############################################################################ |
|
13
|
# |
|
14
|
# "fossil rebuild" with each of its options, "fossil repack", "fossil |
|
15
|
# deconstruct" and "fossil reconstruct", "fossil detach", the prompt of |
|
16
|
# "fossil scrub", and the cluster test commands. None of them may change |
|
17
|
# what a repository holds: after each, the artifacts, the timeline and the |
|
18
|
# links between check-ins and files are compared with what was there |
|
19
|
# before, and the repository must still be sound. |
|
20
|
# |
|
21
|
|
|
22
|
# The first sections run at every level, and the rest need |
|
23
|
# -assurance stress. |
|
24
|
require_no_open_checkout |
|
25
|
|
|
26
|
test_setup |
|
27
|
|
|
28
|
proc rebuild_sql {sql {repo .rep.fossil}} { |
|
29
|
return [fossil_sql $sql $repo] |
|
30
|
} |
|
31
|
|
|
32
|
# The hashes of the artifacts a repository has the content of, in order; |
|
33
|
# WHERE narrows them. |
|
34
|
proc rebuild_hashes {repo {where 1}} { |
|
35
|
return [split [rebuild_sql "SELECT uuid FROM blob |
|
36
|
WHERE size>=0 AND $where ORDER BY uuid" $repo] \n] |
|
37
|
} |
|
38
|
|
|
39
|
# Text of LENGTH characters that has nothing in common with the text for |
|
40
|
# another SEED, so that neither is stored as a delta of the other. |
|
41
|
proc rebuild_noise {seed length} { |
|
42
|
set x [expr {$seed*7919 + 17}] |
|
43
|
set out "" |
|
44
|
for {set i 0} {$i < $length} {incr i} { |
|
45
|
set x [expr {($x*1103515245 + 12345) % 2147483648}] |
|
46
|
append out [format %c [expr {33 + ($x >> 16) % 90}]] |
|
47
|
if {$i % 60 == 59} {append out \n} |
|
48
|
} |
|
49
|
return "$out\n" |
|
50
|
} |
|
51
|
|
|
52
|
# The files below DIR whose names do not begin with a dot, each as its |
|
53
|
# path below DIR. |
|
54
|
proc rebuild_files {dir {below ""}} { |
|
55
|
set out {} |
|
56
|
foreach f [lsort [glob -nocomplain -tails -directory \ |
|
57
|
[file join $dir $below] *]] { |
|
58
|
if {$below eq ""} {set rel $f} else {set rel $below/$f} |
|
59
|
if {[file isdirectory [file join $dir $rel]]} { |
|
60
|
lappend out {*}[rebuild_files $dir $rel] |
|
61
|
} else { |
|
62
|
lappend out $rel |
|
63
|
} |
|
64
|
} |
|
65
|
return $out |
|
66
|
} |
|
67
|
|
|
68
|
# The names a deconstruct into DIR gave the artifacts, with the directory |
|
69
|
# part folded back into the hash, in order. |
|
70
|
proc rebuild_names {dir} { |
|
71
|
set out {} |
|
72
|
foreach f [rebuild_files $dir] { lappend out [string map {/ ""} $f] } |
|
73
|
return [lsort $out] |
|
74
|
} |
|
75
|
|
|
76
|
############################################################################### |
|
77
|
# Seven check-ins on trunk. Each has a new version of a.txt, which is |
|
78
|
# stored as deltas, and a new n.txt that has nothing in common with the |
|
79
|
# one before. A branch off the third with a file of its own; a tag, a |
|
80
|
# wiki page and a ticket; and a private branch of two check-ins. |
|
81
|
|
|
82
|
fossil settings autosync off |
|
83
|
set rebuildText "" |
|
84
|
for {set rebuildI 0} {$rebuildI < 60} {incr rebuildI} { |
|
85
|
append rebuildText "line $rebuildI of a file that is stored as deltas\n" |
|
86
|
} |
|
87
|
set rebuildTrunk {} |
|
88
|
for {set rebuildI 1} {$rebuildI <= 7} {incr rebuildI} { |
|
89
|
append rebuildText "version $rebuildI\n" |
|
90
|
write_file a.txt $rebuildText |
|
91
|
write_file n.txt [rebuild_noise $rebuildI 1500] |
|
92
|
if {$rebuildI == 1} {fossil add a.txt n.txt} |
|
93
|
fossil commit -m rebuild-trunk-$rebuildI --no-warnings |
|
94
|
lappend rebuildTrunk [checkin_hash rebuild-trunk-$rebuildI] |
|
95
|
} |
|
96
|
fossil update [lindex $rebuildTrunk 2] |
|
97
|
fossil branch new side current |
|
98
|
fossil update side |
|
99
|
commit_file b.txt "a file only the branch has\n" rebuild-side-1 --no-warnings |
|
100
|
set rebuildSide [checkin_hash rebuild-side-1] |
|
101
|
fossil update trunk |
|
102
|
fossil tag add rebuild-tag [lindex $rebuildTrunk 1] |
|
103
|
write_file page.txt "A wiki page.\n" |
|
104
|
fossil wiki create RebuildPage page.txt |
|
105
|
fossil ticket add title "a ticket" status Open |
|
106
|
set rebuildSecretText "" |
|
107
|
for {set rebuildI 0} {$rebuildI < 60} {incr rebuildI} { |
|
108
|
append rebuildSecretText "line $rebuildI of private content\n" |
|
109
|
} |
|
110
|
commit_file secret.txt $rebuildSecretText rebuild-secret-1 --no-warnings \ |
|
111
|
--private --branch secret |
|
112
|
set rebuildSecret1 [checkin_hash rebuild-secret-1] |
|
113
|
write_file secret.txt "${rebuildSecretText}one more\n" |
|
114
|
fossil commit -m rebuild-secret-2 --no-warnings |
|
115
|
set rebuildSecret2 [checkin_hash rebuild-secret-2] |
|
116
|
set rebuildSecretFile1 [checkin_file_hash $rebuildSecret1 secret.txt] |
|
117
|
set rebuildSecretFile2 [checkin_file_hash $rebuildSecret2 secret.txt] |
|
118
|
fossil update trunk |
|
119
|
|
|
120
|
repository_sound rebuild-start |
|
121
|
set rebuildStart [repository_state] |
|
122
|
set rebuildAll [rebuild_hashes .rep.fossil] |
|
123
|
set rebuildPublic [rebuild_hashes .rep.fossil "rid NOT IN private"] |
|
124
|
test rebuild-start-setup {[llength $rebuildAll] > [llength $rebuildPublic] && |
|
125
|
[rebuild_sql "SELECT count(*) FROM delta"] > 0} |
|
126
|
file copy .rep.fossil full.fossil |
|
127
|
|
|
128
|
############################################################################### |
|
129
|
# Rebuild with each option, one after another on one copy. Each row is a |
|
130
|
# name, the options, a pattern the output must match, a query, and the |
|
131
|
# answer the query must give afterwards. After every one the repository |
|
132
|
# holds what it held and is sound. |
|
133
|
|
|
134
|
file copy full.fossil r.fossil |
|
135
|
set rebuildCheckins [rebuild_sql "SELECT count(*) FROM event WHERE type='ci'"] |
|
136
|
foreach {rebuildName rebuildOpts rebuildOut rebuildQuery rebuildWant} [list \ |
|
137
|
plain {} \ |
|
138
|
"*100.0% complete*" \ |
|
139
|
"SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ |
|
140
|
quiet {--quiet} \ |
|
141
|
"" \ |
|
142
|
"SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ |
|
143
|
cluster {--cluster} \ |
|
144
|
"*100.0% complete*" \ |
|
145
|
"SELECT count(*) FROM tagxref WHERE tagid=(SELECT tagid FROM tag |
|
146
|
WHERE tagname='cluster')" 0 \ |
|
147
|
noverify {--noverify} \ |
|
148
|
"*100.0% complete*" \ |
|
149
|
"SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ |
|
150
|
force {--force} \ |
|
151
|
"*100.0% complete*" \ |
|
152
|
"SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ |
|
153
|
analyze {--analyze} \ |
|
154
|
"*Analyzing the database... done*" \ |
|
155
|
"SELECT count(*) FROM sqlite_schema WHERE name='sqlite_stat1'" 1 \ |
|
156
|
vacuum {--vacuum} \ |
|
157
|
"*Vacuuming the database... done*" \ |
|
158
|
"PRAGMA repository.freelist_count" 0 \ |
|
159
|
pagesize {--pagesize 8192} \ |
|
160
|
"*Vacuuming the database... done*" \ |
|
161
|
"PRAGMA repository.page_size" 8192 \ |
|
162
|
wal {--wal} \ |
|
163
|
"*100.0% complete*" \ |
|
164
|
"PRAGMA repository.journal_mode" wal \ |
|
165
|
pagesize-in-wal {--pagesize 2048} \ |
|
166
|
"*Vacuuming the database... done*" \ |
|
167
|
"PRAGMA repository.page_size; PRAGMA repository.journal_mode" \ |
|
168
|
"2048\nwal" \ |
|
169
|
stats {--stats} \ |
|
170
|
"*Artifacts:*Manifests:*Clusters:*Tags:*Wikis:*Tickets:*Other:*" \ |
|
171
|
"SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ |
|
172
|
compress {--compress} \ |
|
173
|
"*100.0% complete*Extra delta compression... *" \ |
|
174
|
"SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ |
|
175
|
compress-only {--compress-only} \ |
|
176
|
"Extra delta compression... *" \ |
|
177
|
"SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ |
|
178
|
] { |
|
179
|
fossil rebuild r.fossil {*}$rebuildOpts |
|
180
|
test rebuild-$rebuildName {$CODE == 0 && |
|
181
|
[string match $rebuildOut $RESULT]} |
|
182
|
test_eq rebuild-$rebuildName-effect [rebuild_sql $rebuildQuery r.fossil] \ |
|
183
|
$rebuildWant |
|
184
|
test_eq rebuild-$rebuildName-state \ |
|
185
|
[repository_state_diff $rebuildStart [repository_state r.fossil]] "" |
|
186
|
repository_sound rebuild-$rebuildName r.fossil |
|
187
|
} |
|
188
|
|
|
189
|
if {[test_assurance] ne "stress"} { |
|
190
|
test_skip "the tests after the first sections need -assurance stress" |
|
191
|
} |
|
192
|
|
|
193
|
# --deanalyze removes the statistics that --analyze made. The file is |
|
194
|
# read with --no-repository, because a command that opens the repository |
|
195
|
# runs PRAGMA optimize when it closes it, which makes them again. |
|
196
|
test_eq rebuild-deanalyze-setup [rebuild_sql "SELECT count(*) |
|
197
|
FROM sqlite_schema WHERE name='sqlite_stat1'" r.fossil] 1 |
|
198
|
fossil rebuild r.fossil --deanalyze |
|
199
|
test rebuild-deanalyze {$CODE == 0} |
|
200
|
fossil sql --no-repository r.fossil \ |
|
201
|
"SELECT count(*) FROM sqlite_schema WHERE name='sqlite_stat1'" |
|
202
|
test_eq rebuild-deanalyze-effect [string trim $RESULT] 0 |
|
203
|
test_eq rebuild-deanalyze-state \ |
|
204
|
[repository_state_diff $rebuildStart [repository_state r.fossil]] "" |
|
205
|
|
|
206
|
# --stats counts each kind of artifact. |
|
207
|
fossil rebuild r.fossil --stats |
|
208
|
set rebuildStats $RESULT |
|
209
|
foreach {rebuildName rebuildLabel rebuildType} { |
|
210
|
manifests Manifests ci |
|
211
|
tags Tags g |
|
212
|
wikis Wikis w |
|
213
|
tickets Tickets t |
|
214
|
} { |
|
215
|
set rebuildCount "" |
|
216
|
regexp -line "^$rebuildLabel: +(\\d+)" $rebuildStats -> rebuildCount |
|
217
|
test_eq rebuild-stats-$rebuildName $rebuildCount [rebuild_sql "SELECT |
|
218
|
count(*) FROM event WHERE type='$rebuildType'" full.fossil] |
|
219
|
} |
|
220
|
|
|
221
|
# A page size that is too small, too large, or not a power of two is |
|
222
|
# refused and nothing is rebuilt. |
|
223
|
fossil sql -R r.fossil "UPDATE config SET mtime=1 WHERE name='rebuilt'" |
|
224
|
foreach rebuildSize {256 131072 1000 abc} { |
|
225
|
fossil rebuild r.fossil --pagesize $rebuildSize -expectError |
|
226
|
test rebuild-pagesize-$rebuildSize-refused {$CODE != 0 && |
|
227
|
[string match "*page size must be a power of two*" $RESULT]} |
|
228
|
} |
|
229
|
test_eq rebuild-pagesize-refused-unchanged [rebuild_sql "PRAGMA |
|
230
|
repository.page_size; SELECT mtime FROM config WHERE name='rebuilt'" \ |
|
231
|
r.fossil] "2048\n1" |
|
232
|
|
|
233
|
# --ifneeded does nothing when the schema is the current one, and |
|
234
|
# rebuilds when the repository says it has an older one. |
|
235
|
set rebuildSchema [rebuild_sql "SELECT value FROM config |
|
236
|
WHERE name='aux-schema'" r.fossil] |
|
237
|
fossil rebuild r.fossil --ifneeded |
|
238
|
test rebuild-ifneeded-not-needed {$CODE == 0 && $RESULT eq ""} |
|
239
|
test_eq rebuild-ifneeded-not-needed-untouched [rebuild_sql "SELECT mtime |
|
240
|
FROM config WHERE name='rebuilt'" r.fossil] 1 |
|
241
|
fossil sql -R r.fossil "UPDATE config SET value='2011-04-25 19:50' |
|
242
|
WHERE name='aux-schema'" |
|
243
|
fossil rebuild r.fossil --ifneeded |
|
244
|
test rebuild-ifneeded-needed {$CODE == 0 && |
|
245
|
[string match "*100.0% complete*" $RESULT]} |
|
246
|
test_eq rebuild-ifneeded-needed-schema [rebuild_sql "SELECT value FROM config |
|
247
|
WHERE name='aux-schema'" r.fossil] $rebuildSchema |
|
248
|
test rebuild-ifneeded-needed-rebuilt {[rebuild_sql "SELECT mtime FROM config |
|
249
|
WHERE name='rebuilt'" r.fossil] > 1} |
|
250
|
test_eq rebuild-ifneeded-needed-state \ |
|
251
|
[repository_state_diff $rebuildStart [repository_state r.fossil]] "" |
|
252
|
|
|
253
|
# Two repository names are one too many. Without a name, the repository |
|
254
|
# of the check-out is rebuilt. |
|
255
|
fossil rebuild r.fossil full.fossil -expectError |
|
256
|
test rebuild-usage {$CODE != 0 && [string match "*Usage:*" $RESULT]} |
|
257
|
fossil rebuild |
|
258
|
test rebuild-checkout {$CODE == 0} |
|
259
|
test_eq rebuild-checkout-state \ |
|
260
|
[repository_state_diff $rebuildStart [repository_state]] "" |
|
261
|
|
|
262
|
############################################################################### |
|
263
|
# A repository with the table definitions of an old Fossil: no baseid in |
|
264
|
# plink (before 2014-11-28), no pmid and isaux in mlink (before |
|
265
|
# 2015-01-24), no mtime in user, config, shun, reportfmt and concealed |
|
266
|
# (before 2011-04-27), no jx in user and reportfmt, and a blob table that |
|
267
|
# takes only hashes of 40 characters (before 2.0). It is made from a new |
|
268
|
# one by dropping the columns and editing the stored definition with SQL. |
|
269
|
# Rebuild brings every table up to date and loses none of their rows. |
|
270
|
|
|
271
|
file copy full.fossil old.fossil |
|
272
|
fossil sql -R old.fossil " |
|
273
|
INSERT INTO concealed(hash,content,mtime) |
|
274
|
VALUES('abc','[email protected]',1); |
|
275
|
INSERT INTO shun(uuid,mtime,scom) |
|
276
|
VALUES('[string repeat b 64]',1,'a reason'); |
|
277
|
ALTER TABLE plink DROP COLUMN baseid; |
|
278
|
DROP INDEX mlink_i4; |
|
279
|
ALTER TABLE mlink DROP COLUMN isaux; |
|
280
|
ALTER TABLE mlink DROP COLUMN pmid; |
|
281
|
ALTER TABLE user DROP COLUMN jx; |
|
282
|
ALTER TABLE user DROP COLUMN mtime; |
|
283
|
ALTER TABLE shun DROP COLUMN mtime; |
|
284
|
ALTER TABLE shun DROP COLUMN scom; |
|
285
|
ALTER TABLE reportfmt DROP COLUMN jx; |
|
286
|
ALTER TABLE reportfmt DROP COLUMN mtime; |
|
287
|
ALTER TABLE concealed DROP COLUMN mtime; |
|
288
|
ALTER TABLE config DROP COLUMN mtime; |
|
289
|
" |
|
290
|
fossil sql -R old.fossil ".dbconfig defensive off" \ |
|
291
|
"PRAGMA writable_schema=ON" \ |
|
292
|
"UPDATE repository.sqlite_schema |
|
293
|
SET sql=replace(sql,'length(uuid)>=40','length(uuid)==40') |
|
294
|
WHERE name='blob'" \ |
|
295
|
"PRAGMA writable_schema=OFF" |
|
296
|
proc rebuild_columns {repo} { |
|
297
|
return [rebuild_sql " |
|
298
|
SELECT group_concat(m.name || '.' || p.name, ' ') FROM ( |
|
299
|
SELECT 'plink' AS name UNION ALL SELECT 'mlink' UNION ALL |
|
300
|
SELECT 'user' UNION ALL SELECT 'config' UNION ALL SELECT 'shun' |
|
301
|
UNION ALL SELECT 'reportfmt' UNION ALL SELECT 'concealed') AS m, |
|
302
|
pragma_table_info(m.name, 'repository') AS p |
|
303
|
WHERE m.name || '.' || p.name IN ('plink.baseid', 'mlink.pmid', |
|
304
|
'mlink.isaux', 'user.mtime', 'user.jx', 'config.mtime', |
|
305
|
'shun.mtime', 'shun.scom', 'reportfmt.mtime', 'reportfmt.jx', |
|
306
|
'concealed.mtime')" $repo] |
|
307
|
} |
|
308
|
proc rebuild_blob_check {repo} { |
|
309
|
return [rebuild_sql "SELECT sql LIKE '%length(uuid)>=40%' |
|
310
|
FROM repository.sqlite_schema WHERE name='blob'" $repo] |
|
311
|
} |
|
312
|
test_eq rebuild-old-schema-setup-columns [rebuild_columns old.fossil] "" |
|
313
|
test_eq rebuild-old-schema-setup-blob [rebuild_blob_check old.fossil] 0 |
|
314
|
set rebuildUsers [rebuild_sql "SELECT group_concat(login || '/' || cap, ' ') |
|
315
|
FROM (SELECT login, cap FROM user ORDER BY login)" full.fossil] |
|
316
|
set rebuildCode [rebuild_sql "SELECT value FROM config |
|
317
|
WHERE name='project-code'" full.fossil] |
|
318
|
set rebuildReports [rebuild_sql "SELECT group_concat(title, '|') |
|
319
|
FROM (SELECT title FROM reportfmt ORDER BY rn)" full.fossil] |
|
320
|
fossil rebuild old.fossil |
|
321
|
test rebuild-old-schema {$CODE == 0} |
|
322
|
test_eq rebuild-old-schema-columns [lsort [rebuild_columns old.fossil]] \ |
|
323
|
[lsort [rebuild_columns full.fossil]] |
|
324
|
test_eq rebuild-old-schema-blob [rebuild_blob_check old.fossil] 1 |
|
325
|
test_eq rebuild-old-schema-users [rebuild_sql "SELECT group_concat(login |
|
326
|
|| '/' || cap, ' ') FROM (SELECT login, cap FROM user ORDER BY login)" \ |
|
327
|
old.fossil] $rebuildUsers |
|
328
|
test_eq rebuild-old-schema-users-dated [rebuild_sql "SELECT count(*) FROM user |
|
329
|
WHERE mtime IS NULL" old.fossil] 0 |
|
330
|
test_eq rebuild-old-schema-config [rebuild_sql "SELECT value, mtime>1 |
|
331
|
FROM config WHERE name='project-code'" old.fossil] "$rebuildCode|1" |
|
332
|
test_eq rebuild-old-schema-shun [rebuild_sql "SELECT uuid, mtime>1 FROM shun" \ |
|
333
|
old.fossil] "[string repeat b 64]|1" |
|
334
|
test_eq rebuild-old-schema-reports [rebuild_sql "SELECT group_concat(title, '|') |
|
335
|
FROM (SELECT title FROM reportfmt ORDER BY rn)" old.fossil] $rebuildReports |
|
336
|
test_eq rebuild-old-schema-reports-dated [rebuild_sql "SELECT count(*) |
|
337
|
FROM reportfmt WHERE mtime IS NULL" old.fossil] 0 |
|
338
|
test_eq rebuild-old-schema-concealed [rebuild_sql "SELECT hash, content, |
|
339
|
mtime>1 FROM concealed" old.fossil] "abc|[email protected]|1" |
|
340
|
test_eq rebuild-old-schema-state \ |
|
341
|
[repository_state_diff $rebuildStart [repository_state old.fossil]] "" |
|
342
|
repository_sound rebuild-old-schema old.fossil |
|
343
|
|
|
344
|
############################################################################### |
|
345
|
# When the main-branch setting names a branch that no check-in has, |
|
346
|
# rebuild puts the first check-in on it. Everything that was there stays. |
|
347
|
|
|
348
|
file copy full.fossil main.fossil |
|
349
|
fossil sql -R main.fossil "REPLACE INTO config(name,value,mtime) |
|
350
|
VALUES('main-branch','primary',now())" |
|
351
|
set rebuildRoot [rebuild_sql "SELECT uuid FROM blob WHERE rid=(SELECT pid |
|
352
|
FROM plink AS x WHERE NOT EXISTS(SELECT 1 FROM plink |
|
353
|
WHERE cid=x.pid))" main.fossil] |
|
354
|
fossil rebuild main.fossil |
|
355
|
test rebuild-main-branch {$CODE == 0} |
|
356
|
test_eq rebuild-main-branch-tagged [rebuild_sql "SELECT count(*) |
|
357
|
FROM tagxref JOIN tag USING(tagid) JOIN blob USING(rid) |
|
358
|
WHERE tagname='sym-primary' AND tagtype=2 AND srcid>0 |
|
359
|
AND uuid='$rebuildRoot'" main.fossil] 1 |
|
360
|
# The two artifacts that carry the new tags are all that is added. |
|
361
|
set rebuildAdded [repository_state_diff [join $rebuildAll \n] \ |
|
362
|
[join [rebuild_hashes main.fossil] \n]] |
|
363
|
test rebuild-main-branch-kept {[regexp -all -line {^\+ } $rebuildAdded] == 2 && |
|
364
|
[regexp -all -line {^- } $rebuildAdded] == 0} |
|
365
|
repository_sound rebuild-main-branch main.fossil |
|
366
|
# A second rebuild finds the branch and adds nothing. |
|
367
|
set rebuildCount [rebuild_sql "SELECT count(*) FROM blob" main.fossil] |
|
368
|
fossil rebuild main.fossil |
|
369
|
test_eq rebuild-main-branch-once [rebuild_sql "SELECT count(*) FROM blob" \ |
|
370
|
main.fossil] $rebuildCount |
|
371
|
|
|
372
|
############################################################################### |
|
373
|
# Rebuild of a repository damaged with SQL: an artifact stored as a delta |
|
374
|
# whose own row is gone, or has become a phantom. The rebuild finishes, |
|
375
|
# every check-in is still in the timeline, and the artifact is listed as |
|
376
|
# a phantom. |
|
377
|
|
|
378
|
set rebuildDeltaFile "(SELECT delta.rid FROM delta JOIN mlink |
|
379
|
ON mlink.fid=delta.rid JOIN filename USING(fnid) |
|
380
|
WHERE name='a.txt' ORDER BY delta.rid LIMIT 1)" |
|
381
|
foreach {rebuildName rebuildDamage} [list \ |
|
382
|
delta-row-gone \ |
|
383
|
"DELETE FROM blob WHERE rid=$rebuildDeltaFile" \ |
|
384
|
delta-is-a-phantom \ |
|
385
|
"UPDATE blob SET size=-1, content=NULL WHERE rid=$rebuildDeltaFile" \ |
|
386
|
] { |
|
387
|
file copy -force full.fossil damaged.fossil |
|
388
|
fossil sql -R damaged.fossil $rebuildDamage |
|
389
|
fossil rebuild damaged.fossil |
|
390
|
test rebuild-damage-$rebuildName {$CODE == 0} |
|
391
|
test_eq rebuild-damage-$rebuildName-checkins [rebuild_sql "SELECT count(*) |
|
392
|
FROM event WHERE type='ci'" damaged.fossil] $rebuildCheckins |
|
393
|
test_eq rebuild-damage-$rebuildName-phantoms [rebuild_sql "SELECT count(*) |
|
394
|
FROM phantom" damaged.fossil] 1 |
|
395
|
fossil cat a.txt -r [lindex $rebuildTrunk 6] -R damaged.fossil |
|
396
|
test_eq rebuild-damage-$rebuildName-newest-readable "$RESULT\n" \ |
|
397
|
$rebuildText |
|
398
|
} |
|
399
|
file delete damaged.fossil |
|
400
|
|
|
401
|
############################################################################### |
|
402
|
# The full-text search index. Rebuild drops it and builds it again; |
|
403
|
# --noindex leaves it out; --index adds one; --compress-only leaves it |
|
404
|
# alone. |
|
405
|
|
|
406
|
file copy full.fossil fts.fossil |
|
407
|
proc rebuild_indexed {repo} { |
|
408
|
if {[rebuild_sql "SELECT count(*) FROM sqlite_schema |
|
409
|
WHERE name='ftsdocs'" $repo] == 0} {return none} |
|
410
|
return [rebuild_sql "SELECT count(*) FROM ftsdocs" $repo] |
|
411
|
} |
|
412
|
test_eq rebuild-index-setup-none [rebuild_indexed fts.fossil] none |
|
413
|
fossil rebuild fts.fossil --index |
|
414
|
test rebuild-index {$CODE == 0} |
|
415
|
set rebuildDocs [rebuild_indexed fts.fossil] |
|
416
|
test rebuild-index-made {$rebuildDocs ne "none"} |
|
417
|
fossil fts-config enable cdtwe -R fts.fossil |
|
418
|
fossil rebuild fts.fossil |
|
419
|
test rebuild-index-kept {$CODE == 0} |
|
420
|
set rebuildDocs [rebuild_indexed fts.fossil] |
|
421
|
test rebuild-index-kept-filled {$rebuildDocs ne "none" && $rebuildDocs > 0} |
|
422
|
fossil sql -R fts.fossil "DELETE FROM ftsdocs" |
|
423
|
fossil rebuild fts.fossil --compress-only |
|
424
|
test rebuild-index-compress-only {$CODE == 0} |
|
425
|
test_eq rebuild-index-compress-only-untouched [rebuild_indexed fts.fossil] 0 |
|
426
|
fossil rebuild fts.fossil |
|
427
|
test_eq rebuild-index-refilled [rebuild_indexed fts.fossil] $rebuildDocs |
|
428
|
fossil search rebuild-side-1 -R fts.fossil |
|
429
|
test rebuild-index-search {[string match "*rebuild-side-1*" $RESULT]} |
|
430
|
# --compress-only with --index, when there is an index already, builds it |
|
431
|
# again. |
|
432
|
fossil sql -R fts.fossil "DELETE FROM ftsdocs" |
|
433
|
fossil rebuild fts.fossil --compress-only --index |
|
434
|
test rebuild-index-compress-only-index {$CODE == 0} |
|
435
|
test_eq rebuild-index-compress-only-index-filled \ |
|
436
|
[rebuild_indexed fts.fossil] $rebuildDocs |
|
437
|
fossil rebuild fts.fossil --noindex |
|
438
|
test rebuild-noindex {$CODE == 0} |
|
439
|
test_eq rebuild-noindex-gone [rebuild_indexed fts.fossil] none |
|
440
|
test_eq rebuild-index-state \ |
|
441
|
[repository_state_diff $rebuildStart [repository_state fts.fossil]] "" |
|
442
|
# --compress-only with --index on a repository that has no index makes one. |
|
443
|
fossil rebuild fts.fossil --compress-only --index |
|
444
|
test rebuild-compress-only-index-new {$CODE == 0 && |
|
445
|
[rebuild_indexed fts.fossil] ne "none"} |
|
446
|
|
|
447
|
############################################################################### |
|
448
|
# Extra compression. "fossil repack" and "rebuild --compress-only" store |
|
449
|
# more artifacts as deltas and say how many; what the artifacts are does |
|
450
|
# not change. One or two file versions are stored whole again before |
|
451
|
# each run, so that there is that much to find. |
|
452
|
|
|
453
|
fossil repack r.fossil full.fossil -expectError |
|
454
|
test rebuild-repack-usage {$CODE != 0 && [string match "*Usage:*" $RESULT]} |
|
455
|
fossil repack |
|
456
|
test rebuild-repack-checkout {$CODE == 0} |
|
457
|
fossil repack |
|
458
|
test rebuild-repack-nothing {$CODE == 0 && |
|
459
|
[string match "*no new compression opportunities found*" $RESULT] && |
|
460
|
![string match "*Vacuuming*" $RESULT]} |
|
461
|
fossil rebuild --compress |
|
462
|
test rebuild-compress-nothing {$CODE == 0 && |
|
463
|
[string match "*Extra delta compression... none found*" $RESULT]} |
|
464
|
proc rebuild_store_whole {count} { |
|
465
|
foreach rid [split [rebuild_sql "SELECT delta.rid FROM delta JOIN mlink |
|
466
|
ON mlink.fid=delta.rid JOIN filename USING(fnid) |
|
467
|
WHERE name='a.txt' GROUP BY delta.rid ORDER BY delta.rid |
|
468
|
LIMIT $count"] \n] { |
|
469
|
fossil test-content-undelta $rid |
|
470
|
} |
|
471
|
} |
|
472
|
foreach {rebuildName rebuildCmd rebuildCount rebuildOut} { |
|
473
|
repack-one {repack} 1 "*1 new delta saves *Vacuuming*" |
|
474
|
repack-two {repack} 2 "*2 new deltas save *Vacuuming*" |
|
475
|
compress-one {rebuild --compress-only} 1 "*1 new delta saves *Vacuuming*" |
|
476
|
compress-two {rebuild --compress-only} 2 "*2 new deltas save *Vacuuming*" |
|
477
|
} { |
|
478
|
set rebuildDeltas [rebuild_sql "SELECT count(*) FROM delta"] |
|
479
|
rebuild_store_whole $rebuildCount |
|
480
|
test_eq rebuild-$rebuildName-setup [rebuild_sql "SELECT count(*) |
|
481
|
FROM delta"] [expr {$rebuildDeltas - $rebuildCount}] |
|
482
|
fossil {*}$rebuildCmd |
|
483
|
test rebuild-$rebuildName {$CODE == 0 && |
|
484
|
[string match $rebuildOut $RESULT]} |
|
485
|
test_eq rebuild-$rebuildName-deltas [rebuild_sql "SELECT count(*) |
|
486
|
FROM delta"] $rebuildDeltas |
|
487
|
test_eq rebuild-$rebuildName-state \ |
|
488
|
[repository_state_diff $rebuildStart [repository_state]] "" |
|
489
|
repository_sound rebuild-$rebuildName |
|
490
|
} |
|
491
|
for {set rebuildI 1} {$rebuildI <= 7} {incr rebuildI} { |
|
492
|
fossil cat n.txt -r [lindex $rebuildTrunk [expr {$rebuildI-1}]] |
|
493
|
test_eq rebuild-compress-content-$rebuildI "$RESULT\n" \ |
|
494
|
[rebuild_noise $rebuildI 1500] |
|
495
|
} |
|
496
|
|
|
497
|
############################################################################### |
|
498
|
# Detach asks first. "n" changes nothing; a capital Y is a yes. |
|
499
|
|
|
500
|
file copy full.fossil detach.fossil |
|
501
|
fossil_raw -input "n\n" detach detach.fossil |
|
502
|
test rebuild-detach-declined {$CODE == 0} |
|
503
|
test_eq rebuild-detach-declined-same-code [rebuild_sql "SELECT value |
|
504
|
FROM config WHERE name='project-code'" detach.fossil] $rebuildCode |
|
505
|
fossil_raw -input "Y\n" detach detach.fossil |
|
506
|
test rebuild-detach-capital {$CODE == 0 && |
|
507
|
[string match "*New project code: *" $RESULT]} |
|
508
|
test rebuild-detach-capital-new-code {[rebuild_sql "SELECT value FROM config |
|
509
|
WHERE name='project-code'" detach.fossil] ne $rebuildCode} |
|
510
|
test_eq rebuild-detach-capital-parent [rebuild_sql "SELECT value FROM config |
|
511
|
WHERE name='parent-project-code'" detach.fossil] $rebuildCode |
|
512
|
test_eq rebuild-detach-capital-state \ |
|
513
|
[repository_state_diff $rebuildStart [repository_state detach.fossil]] "" |
|
514
|
|
|
515
|
############################################################################### |
|
516
|
# Scrub asks first. "y" and "Y" are both a yes. |
|
517
|
|
|
518
|
foreach {rebuildName rebuildAnswer} {small y capital Y} { |
|
519
|
file copy -force full.fossil scrub.fossil |
|
520
|
test rebuild-scrub-$rebuildName-setup {[password_count scrub.fossil] > 0} |
|
521
|
fossil_raw -input "$rebuildAnswer\n" scrub scrub.fossil |
|
522
|
test rebuild-scrub-$rebuildName {$CODE == 0} |
|
523
|
test_eq rebuild-scrub-$rebuildName-passwords [password_count scrub.fossil] 0 |
|
524
|
test_eq rebuild-scrub-$rebuildName-state \ |
|
525
|
[repository_state_diff $rebuildStart [repository_state scrub.fossil]] "" |
|
526
|
} |
|
527
|
|
|
528
|
############################################################################### |
|
529
|
# Deconstruct writes each artifact to a file named by its hash; private |
|
530
|
# ones only when asked. Reconstruct makes a repository of the same |
|
531
|
# artifacts from the files. |
|
532
|
|
|
533
|
file mkdir d-public |
|
534
|
fossil deconstruct -R full.fossil d-public |
|
535
|
test rebuild-deconstruct {$CODE == 0} |
|
536
|
test_eq rebuild-deconstruct-public-only [rebuild_names d-public] $rebuildPublic |
|
537
|
test rebuild-deconstruct-two-letter-directories {[lsearch -not -regexp \ |
|
538
|
[rebuild_files d-public] {^[0-9a-f]{2}/[0-9a-f]+$}] < 0} |
|
539
|
test_eq rebuild-deconstruct-no-lists \ |
|
540
|
[glob -nocomplain -directory d-public .rid1 .private] "" |
|
541
|
fossil artifact [lindex $rebuildTrunk 0] -R full.fossil one.txt |
|
542
|
test rebuild-deconstruct-content {[same_file one.txt [file join d-public \ |
|
543
|
[string range [lindex $rebuildTrunk 0] 0 1] \ |
|
544
|
[string range [lindex $rebuildTrunk 0] 2 end]]]} |
|
545
|
fossil reconstruct r-public.fossil d-public |
|
546
|
test rebuild-reconstruct {$CODE == 0 && |
|
547
|
[string match "*project-id: *server-id: *admin-user: *" $RESULT]} |
|
548
|
test_eq rebuild-reconstruct-artifacts [rebuild_hashes r-public.fossil] \ |
|
549
|
$rebuildPublic |
|
550
|
test_eq rebuild-reconstruct-checkins [rebuild_sql "SELECT count(*) FROM event |
|
551
|
WHERE type='ci'" r-public.fossil] [expr {$rebuildCheckins - 2}] |
|
552
|
test_eq rebuild-reconstruct-none-private [rebuild_sql "SELECT count(*) |
|
553
|
FROM private" r-public.fossil] 0 |
|
554
|
repository_sound rebuild-reconstruct r-public.fossil |
|
555
|
|
|
556
|
# --quiet says nothing. |
|
557
|
file mkdir d-quiet |
|
558
|
fossil deconstruct -R full.fossil d-quiet --quiet |
|
559
|
test rebuild-deconstruct-quiet {$CODE == 0 && $RESULT eq ""} |
|
560
|
test_eq rebuild-deconstruct-quiet-files [rebuild_names d-quiet] $rebuildPublic |
|
561
|
|
|
562
|
# --private writes the private artifacts too. A repository made from the |
|
563
|
# files has them all, and none is private. |
|
564
|
file mkdir d-private |
|
565
|
fossil deconstruct -R full.fossil d-private --private |
|
566
|
test rebuild-deconstruct-private {$CODE == 0} |
|
567
|
test_eq rebuild-deconstruct-private-all [rebuild_names d-private] $rebuildAll |
|
568
|
test_eq rebuild-deconstruct-private-no-lists \ |
|
569
|
[glob -nocomplain -directory d-private .rid1 .private] "" |
|
570
|
|
|
571
|
# -P writes them and lists them in .private; -K names the file of the |
|
572
|
# first artifact in .rid1. Reconstruct with -P and -K reads both lists: |
|
573
|
# the same artifacts are private, the first artifact is the first again, |
|
574
|
# and everything else is as it was. An empty line, a comment and a line |
|
575
|
# that is not a hash are added to the lists first, and are passed over. |
|
576
|
file mkdir d-keep |
|
577
|
fossil deconstruct -R full.fossil d-keep -P -K |
|
578
|
test rebuild-deconstruct-keep {$CODE == 0} |
|
579
|
test_eq rebuild-deconstruct-keep-all [rebuild_names d-keep] $rebuildAll |
|
580
|
set rebuildFirst [rebuild_sql "SELECT uuid FROM blob WHERE rid=1" full.fossil] |
|
581
|
test_eq rebuild-deconstruct-keep-rid1 \ |
|
582
|
[lindex [split [string trim [read_file d-keep/.rid1]] \n] end] \ |
|
583
|
"[string range $rebuildFirst 0 1]/[string range $rebuildFirst 2 end]" |
|
584
|
set rebuildPrivate [rebuild_hashes full.fossil "rid IN private"] |
|
585
|
test_eq rebuild-deconstruct-keep-private [lsort [lrange [split \ |
|
586
|
[string trim [read_file d-keep/.private]] \n] 1 end]] $rebuildPrivate |
|
587
|
write_file d-keep/.private \ |
|
588
|
"\n# one more comment\nnot-a-hash\n[read_file d-keep/.private]" |
|
589
|
write_file d-keep/.rid1 "\n[read_file d-keep/.rid1]" |
|
590
|
fossil reconstruct r-keep.fossil d-keep -K -P |
|
591
|
test rebuild-reconstruct-keep {$CODE == 0} |
|
592
|
test_eq rebuild-reconstruct-keep-rid1 [rebuild_sql "SELECT uuid FROM blob |
|
593
|
WHERE rid=1" r-keep.fossil] $rebuildFirst |
|
594
|
test_eq rebuild-reconstruct-keep-private \ |
|
595
|
[rebuild_hashes r-keep.fossil "rid IN private"] $rebuildPrivate |
|
596
|
test_eq rebuild-reconstruct-keep-state \ |
|
597
|
[repository_state_diff $rebuildStart [repository_state r-keep.fossil]] "" |
|
598
|
repository_sound rebuild-reconstruct-keep r-keep.fossil |
|
599
|
|
|
600
|
# Without -P every artifact in the directory becomes public. |
|
601
|
fossil reconstruct r-private.fossil d-private |
|
602
|
test rebuild-reconstruct-private {$CODE == 0} |
|
603
|
test_eq rebuild-reconstruct-private-all [rebuild_hashes r-private.fossil] \ |
|
604
|
$rebuildAll |
|
605
|
test_eq rebuild-reconstruct-private-none-private [rebuild_sql "SELECT count(*) |
|
606
|
FROM private" r-private.fossil] 0 |
|
607
|
repository_sound rebuild-reconstruct-private r-private.fossil |
|
608
|
|
|
609
|
# -L sets how many letters of the hash name the directory: none, or five. |
|
610
|
# With none, .rid1 names a file in the directory itself. |
|
611
|
file mkdir d-flat d-five |
|
612
|
fossil deconstruct -R full.fossil d-flat -L 0 -K |
|
613
|
test rebuild-deconstruct-flat {$CODE == 0} |
|
614
|
test_eq rebuild-deconstruct-flat-files [rebuild_files d-flat] $rebuildPublic |
|
615
|
test_eq rebuild-deconstruct-flat-rid1 \ |
|
616
|
[lindex [split [string trim [read_file d-flat/.rid1]] \n] end] \ |
|
617
|
$rebuildFirst |
|
618
|
fossil reconstruct r-flat.fossil d-flat -K |
|
619
|
test rebuild-reconstruct-flat {$CODE == 0} |
|
620
|
test_eq rebuild-reconstruct-flat-artifacts [rebuild_hashes r-flat.fossil] \ |
|
621
|
$rebuildPublic |
|
622
|
test_eq rebuild-reconstruct-flat-rid1 [rebuild_sql "SELECT uuid FROM blob |
|
623
|
WHERE rid=1" r-flat.fossil] $rebuildFirst |
|
624
|
fossil deconstruct -R full.fossil d-five --prefixlength 5 |
|
625
|
test rebuild-deconstruct-five {$CODE == 0} |
|
626
|
test_eq rebuild-deconstruct-five-names [rebuild_names d-five] $rebuildPublic |
|
627
|
test rebuild-deconstruct-five-directories {[lsearch -not -regexp \ |
|
628
|
[rebuild_files d-five] {^[0-9a-f]{5}/[0-9a-f]+$}] < 0} |
|
629
|
|
|
630
|
# What deconstruct refuses: a prefix length that is not one digit, no |
|
631
|
# destination or two, and a destination that is empty or missing. |
|
632
|
file mkdir d-none |
|
633
|
foreach {rebuildName rebuildArgs rebuildOut} { |
|
634
|
prefix-below-digits {d-none -L /} "*not a valid prefix length*" |
|
635
|
prefix-letter {d-none -L x} "*not a valid prefix length*" |
|
636
|
prefix-two-digits {d-none -L 10} "*not a valid prefix length*" |
|
637
|
no-destination {} "*Usage:*" |
|
638
|
two-destinations {d-none d-flat} "*Usage:*" |
|
639
|
empty-destination {{}} "*is not a directory*" |
|
640
|
missing-destination {d-missing} "*is not a directory*" |
|
641
|
} { |
|
642
|
fossil deconstruct -R full.fossil {*}$rebuildArgs -expectError |
|
643
|
test rebuild-deconstruct-$rebuildName {$CODE != 0 && |
|
644
|
[string match $rebuildOut $RESULT]} |
|
645
|
} |
|
646
|
test_eq rebuild-deconstruct-refused-wrote-nothing [rebuild_files d-none] "" |
|
647
|
|
|
648
|
# A destination that is a file is refused, and the file is kept. |
|
649
|
write_file d-file.txt "a file, not a directory\n" |
|
650
|
fossil deconstruct -R full.fossil d-file.txt -expectError |
|
651
|
test rebuild-deconstruct-file-destination {$CODE != 0 && |
|
652
|
[string match "*is not a directory*" $RESULT]} |
|
653
|
test rebuild-deconstruct-file-destination-kept \ |
|
654
|
{[file isfile d-file.txt]} |
|
655
|
|
|
656
|
# A destination that cannot be written to, where the system can make one. |
|
657
|
catch {file attributes d-none -permissions 0555} |
|
658
|
if {![file writable d-none]} { |
|
659
|
fossil deconstruct -R full.fossil d-none -expectError |
|
660
|
test rebuild-deconstruct-not-writable {$CODE != 0 && |
|
661
|
[string match "*is not writeable*" $RESULT]} |
|
662
|
} |
|
663
|
catch {file attributes d-none -permissions 0755} |
|
664
|
|
|
665
|
# What reconstruct refuses: too few names, and a directory that is not one. |
|
666
|
fossil reconstruct r-none.fossil -expectError |
|
667
|
test rebuild-reconstruct-usage {$CODE != 0 && |
|
668
|
[string match "*Usage:*" $RESULT]} |
|
669
|
fossil reconstruct r-none.fossil one.txt -expectError |
|
670
|
test rebuild-reconstruct-not-a-directory {$CODE != 0 && |
|
671
|
[string match "*is not a directory*Usage:*" $RESULT]} |
|
672
|
test rebuild-reconstruct-refused-made-nothing {![file exists r-none.fossil]} |
|
673
|
|
|
674
|
# -K when .rid1 names no file, and when there is no .rid1. |
|
675
|
write_file d-flat/.rid1 "# nothing but a comment\n\n" |
|
676
|
fossil reconstruct r-rid1-empty.fossil d-flat -K -expectError |
|
677
|
test rebuild-reconstruct-rid1-empty {$CODE != 0 && |
|
678
|
[string match "*error occurred while reading or parsing*" $RESULT]} |
|
679
|
file delete d-flat/.rid1 |
|
680
|
fossil reconstruct r-rid1-missing.fossil d-flat -K -expectError |
|
681
|
test rebuild-reconstruct-rid1-missing {$CODE != 0 && |
|
682
|
[string match "*no such file*" $RESULT]} |
|
683
|
|
|
684
|
# A directory below that cannot be read, where the system can make one. |
|
685
|
file mkdir d-five/locked |
|
686
|
write_file d-five/locked/file.txt "out of reach\n" |
|
687
|
catch {file attributes d-five/locked -permissions 0000} |
|
688
|
if {![file readable d-five/locked]} { |
|
689
|
fossil reconstruct r-locked.fossil d-five -expectError |
|
690
|
test rebuild-reconstruct-unreadable-directory {$CODE != 0 && |
|
691
|
[string match "*encountered error*while trying to open*" $RESULT]} |
|
692
|
} |
|
693
|
catch {file attributes d-five/locked -permissions 0755} |
|
694
|
|
|
695
|
############################################################################### |
|
696
|
# Artifacts named by SHA1. Reconstruct stores each file under the kind |
|
697
|
# of hash its name has; a file whose name is no hash is stored as well. |
|
698
|
|
|
699
|
fossil init --sha1 sha1.fossil |
|
700
|
write_file sha1-content.txt "content stored under a SHA1 hash\n" |
|
701
|
fossil test-content-put sha1-content.txt -R sha1.fossil |
|
702
|
set rebuildSha1 [rebuild_hashes sha1.fossil] |
|
703
|
test rebuild-sha1-setup {[llength $rebuildSha1] >= 2 && |
|
704
|
[lsearch -not -regexp $rebuildSha1 {^[0-9a-f]{40}$}] < 0} |
|
705
|
file mkdir d-sha1 |
|
706
|
fossil deconstruct -R sha1.fossil d-sha1 |
|
707
|
test_eq rebuild-sha1-deconstruct [rebuild_names d-sha1] $rebuildSha1 |
|
708
|
write_file d-sha1/notes "a file whose name is not a hash\n" |
|
709
|
fossil sha1sum d-sha1/notes |
|
710
|
set rebuildNote1 [lindex $RESULT 0] |
|
711
|
fossil sha3sum d-sha1/notes |
|
712
|
set rebuildNote3 [lindex $RESULT 0] |
|
713
|
fossil reconstruct r-sha1.fossil d-sha1 |
|
714
|
test rebuild-sha1-reconstruct {$CODE == 0} |
|
715
|
test_eq rebuild-sha1-reconstruct-same-hashes [rebuild_hashes r-sha1.fossil \ |
|
716
|
"length(uuid)=40 AND uuid<>'$rebuildNote1'"] $rebuildSha1 |
|
717
|
test_eq rebuild-sha1-reconstruct-other-file [rebuild_sql "SELECT count(*) |
|
718
|
FROM blob WHERE uuid IN ('$rebuildNote1','$rebuildNote3')" r-sha1.fossil] 1 |
|
719
|
test_eq rebuild-sha1-reconstruct-count [llength [rebuild_hashes \ |
|
720
|
r-sha1.fossil]] [expr {[llength $rebuildSha1] + 1}] |
|
721
|
|
|
722
|
############################################################################### |
|
723
|
# Deconstruct of repositories that lack content. |
|
724
|
|
|
725
|
# A check-in whose parent and files are not there: they are phantoms, and |
|
726
|
# only what has content is written. |
|
727
|
fossil init phantom.fossil |
|
728
|
fossil artifact $rebuildSide -R full.fossil side.txt |
|
729
|
fossil test-content-put --crosslink side.txt -R phantom.fossil |
|
730
|
test rebuild-phantom-setup {[rebuild_sql "SELECT count(*) FROM phantom" \ |
|
731
|
phantom.fossil] > 0} |
|
732
|
file mkdir d-phantom |
|
733
|
fossil deconstruct -R phantom.fossil d-phantom |
|
734
|
test rebuild-deconstruct-phantom {$CODE == 0} |
|
735
|
test_eq rebuild-deconstruct-phantom-files [rebuild_names d-phantom] \ |
|
736
|
[rebuild_hashes phantom.fossil] |
|
737
|
test rebuild-deconstruct-phantom-has-checkin \ |
|
738
|
{[lsearch -exact [rebuild_names d-phantom] $rebuildSide] >= 0} |
|
739
|
|
|
740
|
# A public artifact stored as a delta from a private one, which "fossil |
|
741
|
# publish" of the older of two private check-ins leaves. Without |
|
742
|
# --private the public one is written and the private one is not. |
|
743
|
file copy full.fossil publish.fossil |
|
744
|
fossil publish $rebuildSecret1 -R publish.fossil |
|
745
|
test rebuild-public-from-private-setup {[rebuild_sql "SELECT count(*) |
|
746
|
FROM delta |
|
747
|
WHERE rid=(SELECT rid FROM blob WHERE uuid='$rebuildSecretFile1') |
|
748
|
AND srcid=(SELECT rid FROM blob WHERE uuid='$rebuildSecretFile2') |
|
749
|
AND rid NOT IN private AND srcid IN private" publish.fossil] == 1} |
|
750
|
file mkdir d-publish |
|
751
|
fossil deconstruct -R publish.fossil d-publish |
|
752
|
test rebuild-deconstruct-public-from-private {$CODE == 0} |
|
753
|
test_eq rebuild-deconstruct-public-from-private-files \ |
|
754
|
[rebuild_names d-publish] \ |
|
755
|
[rebuild_hashes publish.fossil "rid NOT IN private"] |
|
756
|
test rebuild-deconstruct-public-from-private-written \ |
|
757
|
{[lsearch -exact [rebuild_names d-publish] $rebuildSecretFile1] >= 0 && |
|
758
|
[lsearch -exact [rebuild_names d-publish] $rebuildSecretFile2] < 0} |
|
759
|
|
|
760
|
# A repository damaged with SQL: the artifact that others are deltas of |
|
761
|
# is gone. Deconstruct finishes; it writes what can still be read and |
|
762
|
# nothing for what cannot. |
|
763
|
file copy full.fossil damaged.fossil |
|
764
|
set rebuildSource [rebuild_sql "SELECT uuid FROM blob WHERE rid=(SELECT srcid |
|
765
|
FROM delta JOIN mlink ON mlink.fid=delta.rid JOIN filename USING(fnid) |
|
766
|
WHERE name='a.txt' AND srcid NOT IN (SELECT rid FROM delta))" \ |
|
767
|
damaged.fossil] |
|
768
|
set rebuildLost [rebuild_sql "WITH RECURSIVE lost(rid) AS ( |
|
769
|
SELECT rid FROM blob WHERE uuid='$rebuildSource' |
|
770
|
UNION SELECT delta.rid FROM delta, lost WHERE delta.srcid=lost.rid) |
|
771
|
SELECT group_concat(uuid, ' ') FROM blob WHERE rid IN lost" \ |
|
772
|
damaged.fossil] |
|
773
|
test rebuild-damage-source-setup {[llength $rebuildLost] > 1} |
|
774
|
fossil sql -R damaged.fossil "DELETE FROM blob WHERE uuid='$rebuildSource'" |
|
775
|
file mkdir d-damaged |
|
776
|
fossil deconstruct -R damaged.fossil d-damaged |
|
777
|
test rebuild-deconstruct-damage-source-gone {$CODE == 0} |
|
778
|
set rebuildWant {} |
|
779
|
foreach rebuildH $rebuildPublic { |
|
780
|
if {[lsearch -exact $rebuildLost $rebuildH] < 0} { |
|
781
|
lappend rebuildWant $rebuildH |
|
782
|
} |
|
783
|
} |
|
784
|
test_eq rebuild-deconstruct-damage-source-gone-files \ |
|
785
|
[rebuild_names d-damaged] $rebuildWant |
|
786
|
|
|
787
|
############################################################################### |
|
788
|
# Clusters. test-create-clusters makes one when a hundred or more |
|
789
|
# artifacts are in no cluster yet; test-clusters says whether every |
|
790
|
# artifact can be reached through them. |
|
791
|
|
|
792
|
proc rebuild_clusters {{repo .rep.fossil}} { |
|
793
|
return [rebuild_sql "SELECT count(*) FROM tagxref WHERE tagid=(SELECT tagid |
|
794
|
FROM tag WHERE tagname='cluster')" $repo] |
|
795
|
} |
|
796
|
proc rebuild_many_files {dir} { |
|
797
|
file mkdir $dir |
|
798
|
for {set i 0} {$i < 110} {incr i} { |
|
799
|
write_file $dir/f$i.txt "file $i in $dir\n" |
|
800
|
} |
|
801
|
fossil add $dir |
|
802
|
fossil commit -m rebuild-$dir --no-warnings |
|
803
|
} |
|
804
|
fossil test-create-clusters r.fossil full.fossil -expectError |
|
805
|
test rebuild-create-clusters-usage {$CODE != 0 && |
|
806
|
[string match "*Usage:*" $RESULT]} |
|
807
|
fossil test-create-clusters |
|
808
|
test rebuild-create-clusters-too-few {$CODE == 0} |
|
809
|
test_eq rebuild-create-clusters-too-few-none [rebuild_clusters] 0 |
|
810
|
fossil test-clusters |
|
811
|
test rebuild-clusters-none {$CODE == 0 && |
|
812
|
[string match "*all artifacts reachable through clusters*" $RESULT]} |
|
813
|
rebuild_many_files many1 |
|
814
|
fossil test-create-clusters .rep.fossil |
|
815
|
test rebuild-create-clusters {$CODE == 0} |
|
816
|
test_eq rebuild-create-clusters-one [rebuild_clusters] 1 |
|
817
|
test_eq rebuild-create-clusters-one-left [rebuild_sql "SELECT count(*) |
|
818
|
FROM unclustered"] 1 |
|
819
|
fossil test-clusters |
|
820
|
test rebuild-clusters-one {$CODE == 0 && |
|
821
|
[string match "*all artifacts reachable through clusters*" $RESULT]} |
|
822
|
# A second cluster lists the first. |
|
823
|
rebuild_many_files many2 |
|
824
|
fossil test-create-clusters .rep.fossil |
|
825
|
test_eq rebuild-create-clusters-two [rebuild_clusters] 2 |
|
826
|
fossil test-clusters -R .rep.fossil |
|
827
|
test rebuild-clusters-two {$CODE == 0 && |
|
828
|
[string match "*all artifacts reachable through clusters*" $RESULT]} |
|
829
|
repository_sound rebuild-clusters |
|
830
|
|
|
831
|
# When the newest cluster is purged, what it listed is in no cluster and |
|
832
|
# test-clusters lists each such artifact. |
|
833
|
set rebuildNewest [rebuild_sql "SELECT uuid FROM blob WHERE rid=(SELECT |
|
834
|
max(rid) FROM tagxref WHERE tagid=(SELECT tagid FROM tag |
|
835
|
WHERE tagname='cluster'))"] |
|
836
|
file copy .rep.fossil cluster.fossil |
|
837
|
fossil purge artifacts $rebuildNewest -R cluster.fossil |
|
838
|
fossil test-clusters -R cluster.fossil |
|
839
|
set rebuildCount 0 |
|
840
|
regexp {(\d+) unreachable artifacts:} $RESULT -> rebuildCount |
|
841
|
test rebuild-clusters-unreachable {$CODE == 0 && $rebuildCount > 100} |
|
842
|
test_eq rebuild-clusters-unreachable-listed \ |
|
843
|
[regexp -all -line {^ +\d+ [0-9a-f]{64}$} $RESULT] $rebuildCount |
|
844
|
|
|
845
|
# A cluster whose content has been replaced with SQL by that of a file. |
|
846
|
file copy -force .rep.fossil cluster.fossil |
|
847
|
fossil sql -R cluster.fossil "UPDATE blob |
|
848
|
SET content=(SELECT content FROM blob WHERE uuid='[checkin_file_hash \ |
|
849
|
$rebuildSide b.txt]') |
|
850
|
WHERE uuid='$rebuildNewest'" |
|
851
|
fossil test-clusters -R cluster.fossil -expectError |
|
852
|
test rebuild-clusters-bad-cluster {$CODE != 0 && |
|
853
|
[string match "*bad cluster: rid=*" $RESULT]} |
|
854
|
|
|
855
|
############################################################################### |
|
856
|
|
|
857
|
test_cleanup |
|
858
|
|