|
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
|
# Commands that remove content from a repository: "fossil purge", with |
|
15
|
# its graveyard, undo and obliterate, and "fossil scrub". After each the |
|
16
|
# repository must still be sound, and an undo must give back exactly what |
|
17
|
# was removed. |
|
18
|
# |
|
19
|
|
|
20
|
# The first sections run at every level, and the rest need |
|
21
|
# -assurance stress. |
|
22
|
require_no_open_checkout |
|
23
|
|
|
24
|
test_setup |
|
25
|
|
|
26
|
proc purge_sql {sql {repo .rep.fossil}} { |
|
27
|
return [fossil_sql $sql $repo] |
|
28
|
} |
|
29
|
|
|
30
|
proc purge_commit {file content comment args} { |
|
31
|
set new [expr {![file exists $file]}] |
|
32
|
write_file $file $content |
|
33
|
if {$new} {fossil add $file} |
|
34
|
fossil commit -m $comment --no-warnings {*}$args |
|
35
|
return [checkin_hash $comment] |
|
36
|
} |
|
37
|
|
|
38
|
# The number of the newest purge event. |
|
39
|
proc purge_last_event {{repo .rep.fossil}} { |
|
40
|
return [purge_sql "SELECT max(peid) FROM purgeevent" $repo] |
|
41
|
} |
|
42
|
|
|
43
|
proc purge_has {repo hash} { |
|
44
|
return [purge_sql "SELECT count(*) FROM blob WHERE uuid='$hash' |
|
45
|
AND size>=0" $repo] |
|
46
|
} |
|
47
|
|
|
48
|
# The number of file and parent links whose artifact is not in the |
|
49
|
# repository at all. repository_state compares the links by hash, which also |
|
50
|
# shows a link to the wrong artifact. |
|
51
|
proc purge_dangling {repo} { |
|
52
|
return [purge_sql "SELECT (SELECT count(*) FROM mlink |
|
53
|
WHERE fid>0 AND fid NOT IN (SELECT rid FROM blob)) |
|
54
|
+ (SELECT count(*) FROM plink |
|
55
|
WHERE pid NOT IN (SELECT rid FROM blob) |
|
56
|
OR cid NOT IN (SELECT rid FROM blob))" $repo] |
|
57
|
} |
|
58
|
|
|
59
|
############################################################################### |
|
60
|
# A trunk of five check-ins, each a new version of one file, so that the |
|
61
|
# file is stored as deltas; a branch of two check-ins off the third; and a |
|
62
|
# second file that only the branch has. |
|
63
|
|
|
64
|
fossil settings autosync off |
|
65
|
set purgeText "" |
|
66
|
for {set purgeI 0} {$purgeI < 60} {incr purgeI} { |
|
67
|
append purgeText "line $purgeI of a file that is stored as deltas\n" |
|
68
|
} |
|
69
|
set purgeTrunk {} |
|
70
|
for {set purgeI 1} {$purgeI <= 5} {incr purgeI} { |
|
71
|
append purgeText "version $purgeI\n" |
|
72
|
lappend purgeTrunk [purge_commit a.txt $purgeText purge-trunk-$purgeI] |
|
73
|
set purgeTrunkText($purgeI) $purgeText |
|
74
|
} |
|
75
|
fossil update [lindex $purgeTrunk 2] |
|
76
|
fossil branch new side current |
|
77
|
fossil update side |
|
78
|
set purgeSide1 [purge_commit a.txt "${purgeTrunkText(3)}on the side\n" \ |
|
79
|
purge-side-1] |
|
80
|
set purgeSide2 [purge_commit b.txt "a file only the branch has\n" purge-side-2] |
|
81
|
set purgeSideB [checkin_file_hash $purgeSide2 b.txt] |
|
82
|
fossil update trunk |
|
83
|
|
|
84
|
repository_sound purge-start |
|
85
|
set purgeStart [repository_state] |
|
86
|
file copy .rep.fossil full.fossil |
|
87
|
|
|
88
|
############################################################################### |
|
89
|
# A trial run changes nothing. |
|
90
|
|
|
91
|
fossil purge checkins side --explain |
|
92
|
test purge-explain {$CODE == 0} |
|
93
|
test_eq purge-explain-no-change [repository_state] $purgeStart |
|
94
|
fossil purge checkins side --dry-run |
|
95
|
test_eq purge-dry-run-no-change [repository_state] $purgeStart |
|
96
|
|
|
97
|
# Either option may be given twice, or both together, with the same result. |
|
98
|
foreach {purgeName purgeArgs} { |
|
99
|
explain-twice {--explain --explain} |
|
100
|
explain-dry {--explain --dry-run} |
|
101
|
dry-twice {--dry-run --dry-run} |
|
102
|
} { |
|
103
|
fossil_raw purge checkins side {*}$purgeArgs |
|
104
|
test purge-$purgeName {$CODE == 0 && |
|
105
|
[string match "*check-in to side*file b.txt*" $RESULT]} |
|
106
|
test_eq purge-$purgeName-no-change [repository_state] $purgeStart |
|
107
|
} |
|
108
|
fossil purge list |
|
109
|
test_eq purge-explain-no-graveyard [string trim $RESULT] "" |
|
110
|
|
|
111
|
############################################################################### |
|
112
|
# Purge a branch. Its check-ins, and the files that only it uses, go; |
|
113
|
# everything on trunk can still be read. |
|
114
|
|
|
115
|
fossil purge checkins side |
|
116
|
test purge-checkins {$CODE == 0 && |
|
117
|
[string match "*artifacts purged*" $RESULT]} |
|
118
|
test_eq purge-checkins-gone [purge_sql "SELECT count(*) FROM blob |
|
119
|
WHERE uuid IN ('$purgeSide1','$purgeSide2','$purgeSideB')"] 0 |
|
120
|
test_eq purge-checkins-no-event [purge_sql "SELECT count(*) FROM event |
|
121
|
WHERE comment LIKE 'purge-side-%'"] 0 |
|
122
|
test_eq purge-checkins-trunk-kept [purge_sql "SELECT count(*) FROM event |
|
123
|
WHERE comment LIKE 'purge-trunk-%'"] 5 |
|
124
|
repository_sound purge-checkins |
|
125
|
for {set purgeI 1} {$purgeI <= 5} {incr purgeI} { |
|
126
|
fossil cat a.txt -r [lindex $purgeTrunk [expr {$purgeI-1}]] |
|
127
|
test_eq purge-checkins-trunk-$purgeI "$RESULT\n" $purgeTrunkText($purgeI) |
|
128
|
} |
|
129
|
set purgeEvent [purge_last_event] |
|
130
|
fossil purge list |
|
131
|
test purge-list {[string match "*$purgeEvent on *" $RESULT]} |
|
132
|
fossil purge list -l |
|
133
|
test purge-list-detail {[string first [string range $purgeSide2 0 9] \ |
|
134
|
$RESULT] >= 0} |
|
135
|
# "ls" is another name for "list". |
|
136
|
fossil purge ls |
|
137
|
test purge-ls {[string match "*$purgeEvent on *" $RESULT]} |
|
138
|
|
|
139
|
# The graveyard gives back the content, a delta among it included. |
|
140
|
fossil purge cat $purgeSideB |
|
141
|
test_eq purge-cat [string trim $RESULT] "a file only the branch has" |
|
142
|
fossil purge cat [purge_sql "SELECT uuid FROM purgeitem |
|
143
|
WHERE srcid IS NOT NULL LIMIT 1"] |
|
144
|
test purge-cat-delta {$CODE == 0} |
|
145
|
|
|
146
|
# A trial run of the undo restores nothing and keeps the purge. |
|
147
|
set purgeBefore [repository_state] |
|
148
|
fossil purge undo $purgeEvent --explain |
|
149
|
test purge-undo-explain {$CODE == 0} |
|
150
|
test_eq purge-undo-explain-no-change [repository_state] $purgeBefore |
|
151
|
test_eq purge-undo-explain-event-kept [purge_last_event] $purgeEvent |
|
152
|
fossil purge undo $purgeEvent --dry-run |
|
153
|
test_eq purge-undo-dry-run-event-kept [purge_last_event] $purgeEvent |
|
154
|
|
|
155
|
# Undo gives back exactly what was there. |
|
156
|
fossil purge undo $purgeEvent |
|
157
|
test purge-undo {$CODE == 0} |
|
158
|
test_eq purge-undo-state [repository_state_diff $purgeStart \ |
|
159
|
[repository_state]] "" |
|
160
|
repository_sound purge-undo |
|
161
|
fossil purge list |
|
162
|
test_eq purge-undo-graveyard-empty [string trim $RESULT] "" |
|
163
|
fossil cat b.txt -r $purgeSide2 |
|
164
|
test_eq purge-undo-content [string trim $RESULT] "a file only the branch has" |
|
165
|
|
|
166
|
############################################################################### |
|
167
|
# A record number that a purge frees can be given to the next artifact |
|
168
|
# stored. A kept check-in must never take that artifact for its parent, |
|
169
|
# before the undo or after it. The parent is made the newest record by |
|
170
|
# storing it last, and the repository is then rebuilt to link them. |
|
171
|
set purgeP [lindex $purgeTrunk 3] |
|
172
|
set purgeC [lindex $purgeTrunk 4] |
|
173
|
fossil init p5.fossil |
|
174
|
set purgeAll [purge_sql "SELECT group_concat(uuid,' ') FROM (SELECT uuid |
|
175
|
FROM blob WHERE size>=0 AND uuid<>'$purgeP' ORDER BY rid)" full.fossil] |
|
176
|
foreach purgeH [concat $purgeAll [list $purgeP]] { |
|
177
|
fossil artifact $purgeH -R full.fossil art.txt |
|
178
|
fossil test-content-put art.txt -R p5.fossil |
|
179
|
} |
|
180
|
fossil rebuild p5.fossil |
|
181
|
test purge-reuse-setup {[purge_sql "SELECT count(*) FROM plink |
|
182
|
WHERE cid=(SELECT rid FROM blob WHERE uuid='$purgeC') |
|
183
|
AND pid=(SELECT rid FROM blob WHERE uuid='$purgeP') |
|
184
|
AND pid=(SELECT max(rid) FROM blob)" p5.fossil] == 1} |
|
185
|
fossil purge artifacts $purgeP -R p5.fossil |
|
186
|
write_file other.txt "an artifact stored after the purge\n" |
|
187
|
fossil test-content-put other.txt -R p5.fossil |
|
188
|
proc purge_parent_of {repo child} { |
|
189
|
return [purge_sql "SELECT group_concat(p.uuid) FROM plink |
|
190
|
JOIN blob p ON p.rid=plink.pid |
|
191
|
WHERE plink.cid=(SELECT rid FROM blob WHERE uuid='$child')" $repo] |
|
192
|
} |
|
193
|
test purge-reuse-no-false-parent \ |
|
194
|
{[purge_parent_of p5.fossil $purgeC] in [list "" $purgeP]} |
|
195
|
fossil purge undo [purge_last_event p5.fossil] -R p5.fossil |
|
196
|
test purge-reuse-undo {$CODE == 0} |
|
197
|
test purge-reuse-undo-no-false-parent \ |
|
198
|
{[purge_parent_of p5.fossil $purgeC] in [list "" $purgeP]} |
|
199
|
|
|
200
|
# What is refused. |
|
201
|
|
|
202
|
fossil update side |
|
203
|
fossil purge checkins side -expectError |
|
204
|
test purge-current-checkout {$CODE != 0 && |
|
205
|
[string match "*cannot purge the current check-out*" $RESULT]} |
|
206
|
# The same when the repository is named with -R from inside the check-out. |
|
207
|
fossil purge checkins side -R [file join [pwd] .rep.fossil] -expectError |
|
208
|
test purge-current-checkout-repository {$CODE != 0 && |
|
209
|
[string match "*cannot purge the current check-out*" $RESULT]} |
|
210
|
# And when it is named by a symbolic link to it. |
|
211
|
if {$::tcl_platform(platform) eq "unix"} { |
|
212
|
file link -symbolic link.fossil [file join [pwd] .rep.fossil] |
|
213
|
fossil purge checkins side -R link.fossil -expectError |
|
214
|
test purge-current-checkout-link {$CODE != 0 && |
|
215
|
[string match "*cannot purge the current check-out*" $RESULT]} |
|
216
|
file delete link.fossil |
|
217
|
} |
|
218
|
fossil update trunk |
|
219
|
test_eq purge-current-checkout-no-change [repository_state] $purgeStart |
|
220
|
|
|
221
|
fossil purge cat [string repeat 0 40] -expectError |
|
222
|
test purge-cat-missing {$CODE != 0} |
|
223
|
fossil purge tickets x -expectError |
|
224
|
test purge-tickets-not-implemented {$CODE != 0} |
|
225
|
fossil purge wiki x -expectError |
|
226
|
test purge-wiki-not-implemented {$CODE != 0} |
|
227
|
fossil purge frobnicate -expectError |
|
228
|
test purge-unknown-subcommand {$CODE != 0} |
|
229
|
|
|
230
|
# Each of these lacks an argument and gets the usage message. |
|
231
|
foreach {purgeName purgeArgs} { |
|
232
|
nothing {} |
|
233
|
cat {cat} |
|
234
|
checkins {checkins} |
|
235
|
obliterate {obliterate --force} |
|
236
|
undo {undo} |
|
237
|
undo-two {undo 1 2} |
|
238
|
} { |
|
239
|
fossil purge {*}$purgeArgs -expectError |
|
240
|
test purge-usage-$purgeName {$CODE != 0 && |
|
241
|
[string match "*Usage:*" $RESULT]} |
|
242
|
} |
|
243
|
test_eq purge-usage-no-change [repository_state] $purgeStart |
|
244
|
|
|
245
|
if {[test_assurance] ne "stress"} { |
|
246
|
test_skip "the tests after the first sections need -assurance stress" |
|
247
|
} |
|
248
|
|
|
249
|
############################################################################### |
|
250
|
# Purging one file version that a kept version is a delta of, on a copy. |
|
251
|
# The kept version is stored whole first and can still be read. |
|
252
|
|
|
253
|
file copy full.fossil p1.fossil |
|
254
|
set purgeV2 [checkin_file_hash [lindex $purgeTrunk 1] a.txt] |
|
255
|
set purgeV3 [checkin_file_hash [lindex $purgeTrunk 2] a.txt] |
|
256
|
test purge-delta-setup {[purge_sql "SELECT count(*) FROM delta |
|
257
|
WHERE srcid=(SELECT rid FROM blob WHERE uuid='$purgeV3')" p1.fossil] > 0} |
|
258
|
fossil purge artifacts $purgeV3 -R p1.fossil |
|
259
|
test purge-artifact {$CODE == 0} |
|
260
|
test_eq purge-artifact-gone [purge_has p1.fossil $purgeV3] 0 |
|
261
|
fossil artifact $purgeV2 -R p1.fossil |
|
262
|
test_eq purge-artifact-neighbour-readable "$RESULT\n" $purgeTrunkText(2) |
|
263
|
fossil test-integrity -R p1.fossil |
|
264
|
test purge-artifact-integrity {$CODE == 0} |
|
265
|
# While it is purged, the check-in that holds it lacks a file, and |
|
266
|
# test-missing says so. |
|
267
|
fossil test-missing -R p1.fossil -expectError |
|
268
|
test purge-artifact-missing-reported {$CODE != 0} |
|
269
|
|
|
270
|
# After the undo the check-ins that hold the file point to it again, and |
|
271
|
# the history of the file has every version. |
|
272
|
fossil purge undo [purge_last_event p1.fossil] -R p1.fossil |
|
273
|
test purge-artifact-undo {$CODE == 0} |
|
274
|
test_eq purge-artifact-undo-back [purge_has p1.fossil $purgeV3] 1 |
|
275
|
test_eq purge-artifact-undo-links [purge_dangling p1.fossil] 0 |
|
276
|
test_eq purge-artifact-undo-state \ |
|
277
|
[repository_state_diff $purgeStart [repository_state p1.fossil]] "" |
|
278
|
repository_sound purge-artifact-undo p1.fossil |
|
279
|
fossil rebuild p1.fossil |
|
280
|
test_eq purge-artifact-rebuild-state \ |
|
281
|
[repository_state_diff $purgeStart [repository_state p1.fossil]] "" |
|
282
|
|
|
283
|
# Every version of a file, by name, on another copy. |
|
284
|
file copy full.fossil p2.fossil |
|
285
|
fossil purge files a.txt -R p2.fossil |
|
286
|
test purge-files {$CODE == 0} |
|
287
|
test_eq purge-files-gone [purge_sql "SELECT count(*) FROM blob |
|
288
|
WHERE uuid IN ('$purgeV2','$purgeV3')" p2.fossil] 0 |
|
289
|
fossil purge undo [purge_last_event p2.fossil] -R p2.fossil |
|
290
|
test purge-files-undo {$CODE == 0} |
|
291
|
test_eq purge-files-undo-back [purge_sql "SELECT count(*) FROM blob |
|
292
|
WHERE uuid IN ('$purgeV2','$purgeV3')" p2.fossil] 2 |
|
293
|
test_eq purge-files-undo-links [purge_dangling p2.fossil] 0 |
|
294
|
fossil rebuild p2.fossil |
|
295
|
test_eq purge-files-rebuild-state \ |
|
296
|
[repository_state_diff $purgeStart [repository_state p2.fossil]] "" |
|
297
|
|
|
298
|
# Purging check-ins takes a repository named with -R, as every command |
|
299
|
# can. |
|
300
|
file copy full.fossil p3.fossil |
|
301
|
fossil_raw purge checkins side --explain -R p3.fossil |
|
302
|
test purge-checkins-repository-explain {$CODE == 0} |
|
303
|
# The same from a directory that is not in any check-out. |
|
304
|
set purgeHere [pwd] |
|
305
|
cd [file dirname $purgeHere] |
|
306
|
fossil_raw purge checkins side --explain -R [file join $purgeHere p3.fossil] |
|
307
|
cd $purgeHere |
|
308
|
test purge-checkins-no-checkout-explain {$CODE == 0 && |
|
309
|
[string first [string range $purgeSide2 0 15] $RESULT] >= 0} |
|
310
|
fossil_raw purge checkins side -R p3.fossil |
|
311
|
test purge-checkins-repository {$CODE == 0} |
|
312
|
|
|
313
|
# One check-in in the middle of trunk, alone, on a copy. Its child keeps |
|
314
|
# its link to it, and after the undo the history is as it was. While it is |
|
315
|
# purged the child names a parent that is not there, and test-missing says |
|
316
|
# so. |
|
317
|
file copy full.fossil p4.fossil |
|
318
|
set purgeMiddle [lindex $purgeTrunk 3] |
|
319
|
fossil purge artifacts $purgeMiddle -R p4.fossil |
|
320
|
test purge-middle {$CODE == 0} |
|
321
|
test_eq purge-middle-gone [purge_has p4.fossil $purgeMiddle] 0 |
|
322
|
fossil test-integrity -R p4.fossil |
|
323
|
test purge-middle-integrity {$CODE == 0} |
|
324
|
fossil test-missing -R p4.fossil -expectError |
|
325
|
test purge-middle-missing-reported {$CODE != 0} |
|
326
|
fossil timeline -n 20 -R p4.fossil |
|
327
|
test purge-middle-timeline {$CODE == 0 && |
|
328
|
[string match "*purge-trunk-5*" $RESULT] && |
|
329
|
![string match "*purge-trunk-4*" $RESULT]} |
|
330
|
fossil purge undo [purge_last_event p4.fossil] -R p4.fossil |
|
331
|
test purge-middle-undo {$CODE == 0} |
|
332
|
test_eq purge-middle-undo-state \ |
|
333
|
[repository_state_diff $purgeStart [repository_state p4.fossil]] "" |
|
334
|
repository_sound purge-middle-undo p4.fossil |
|
335
|
|
|
336
|
# A ticket change. The ticket goes with its only change and comes back |
|
337
|
# with the undo. |
|
338
|
fossil ticket add title "a ticket to purge" status Open -R p4.fossil |
|
339
|
set purgeTicket [purge_sql "SELECT uuid FROM blob |
|
340
|
WHERE rid=(SELECT tkt_rid FROM ticketchng)" p4.fossil] |
|
341
|
test purge-ticket-setup {[purge_sql "SELECT count(*) FROM ticket |
|
342
|
WHERE title='a ticket to purge'" p4.fossil] == 1} |
|
343
|
set purgeBefore [repository_state p4.fossil] |
|
344
|
fossil purge artifacts $purgeTicket -R p4.fossil |
|
345
|
test purge-ticket {$CODE == 0} |
|
346
|
test_eq purge-ticket-gone [purge_sql "SELECT (SELECT count(*) FROM ticket) |
|
347
|
+ (SELECT count(*) FROM ticketchng)" p4.fossil] 0 |
|
348
|
fossil purge undo [purge_last_event p4.fossil] -R p4.fossil |
|
349
|
test purge-ticket-undo {$CODE == 0} |
|
350
|
test_eq purge-ticket-undo-back [purge_sql "SELECT count(*) FROM ticket |
|
351
|
WHERE title='a ticket to purge'" p4.fossil] 1 |
|
352
|
test_eq purge-ticket-undo-state \ |
|
353
|
[repository_state_diff $purgeBefore [repository_state p4.fossil]] "" |
|
354
|
|
|
355
|
# A repository whose plink table has no baseid column, as one made before |
|
356
|
# the 2014-11-28 schema change that was never rebuilt; the column is |
|
357
|
# dropped here with SQL. A purge works on it; a rebuild adds the column, |
|
358
|
# and the undo then restores what was purged. |
|
359
|
file copy full.fossil p6.fossil |
|
360
|
fossil sql -R p6.fossil "ALTER TABLE plink DROP COLUMN baseid" |
|
361
|
fossil purge artifacts $purgeMiddle -R p6.fossil |
|
362
|
test purge-old-plink {$CODE == 0} |
|
363
|
test_eq purge-old-plink-gone [purge_has p6.fossil $purgeMiddle] 0 |
|
364
|
fossil rebuild p6.fossil |
|
365
|
test purge-old-plink-rebuild {$CODE == 0} |
|
366
|
fossil purge undo [purge_last_event p6.fossil] -R p6.fossil |
|
367
|
test purge-old-plink-undo {$CODE == 0} |
|
368
|
test_eq purge-old-plink-undo-back [purge_has p6.fossil $purgeMiddle] 1 |
|
369
|
test_eq purge-old-plink-undo-state \ |
|
370
|
[repository_state_diff $purgeStart [repository_state p6.fossil]] "" |
|
371
|
repository_sound purge-old-plink-undo p6.fossil |
|
372
|
|
|
373
|
# "fossil bundle purge" removes the check-ins of a bundle without a |
|
374
|
# graveyard: there is no purge event, nothing is said about an undo, and |
|
375
|
# importing the bundle brings the branch back. |
|
376
|
file copy full.fossil p7.fossil |
|
377
|
fossil bundle export side.bundle --branch side -R p7.fossil |
|
378
|
test purge-bundle-export {$CODE == 0} |
|
379
|
fossil bundle purge side.bundle -R p7.fossil |
|
380
|
test purge-bundle {$CODE == 0 && ![string match "*undoable*" $RESULT] && |
|
381
|
![string match "*artifacts purged*" $RESULT]} |
|
382
|
test_eq purge-bundle-gone [purge_sql "SELECT count(*) FROM blob |
|
383
|
WHERE uuid IN ('$purgeSide1','$purgeSide2','$purgeSideB')" p7.fossil] 0 |
|
384
|
test_eq purge-bundle-no-graveyard [purge_sql "SELECT count(*) |
|
385
|
FROM sqlite_schema WHERE name IN ('purgeevent','purgeitem')" p7.fossil] 0 |
|
386
|
fossil test-integrity -R p7.fossil |
|
387
|
test purge-bundle-integrity {$CODE == 0} |
|
388
|
fossil bundle import side.bundle --publish -R p7.fossil |
|
389
|
test purge-bundle-import {$CODE == 0} |
|
390
|
test_eq purge-bundle-import-state \ |
|
391
|
[repository_state_diff $purgeStart [repository_state p7.fossil]] "" |
|
392
|
|
|
393
|
############################################################################### |
|
394
|
# A graveyard that has been damaged with SQL. Each command stops with a |
|
395
|
# message and restores nothing. In source-loop two items name each other |
|
396
|
# as delta source. In undo-record-zero the hash of an item is already in |
|
397
|
# the repository under record number 0; that undo stops with no message. |
|
398
|
|
|
399
|
file copy full.fossil p8.fossil |
|
400
|
fossil purge files a.txt -R p8.fossil |
|
401
|
set purgeEvent8 [purge_last_event p8.fossil] |
|
402
|
set purgeDeltaItem [purge_sql "SELECT uuid FROM purgeitem |
|
403
|
WHERE srcid IS NOT NULL LIMIT 1" p8.fossil] |
|
404
|
set purgeWholeItem [purge_sql "SELECT uuid FROM purgeitem |
|
405
|
WHERE srcid IS NULL LIMIT 1" p8.fossil] |
|
406
|
test purge-damage-setup {$purgeDeltaItem ne "" && $purgeWholeItem ne ""} |
|
407
|
set purgeOtherHash [string repeat a 64] |
|
408
|
foreach {purgeName purgeDamage purgeArgs purgeMessage} [list \ |
|
409
|
source-gone \ |
|
410
|
"DELETE FROM purgeitem WHERE piid=(SELECT srcid FROM purgeitem |
|
411
|
WHERE uuid='$purgeDeltaItem')" \ |
|
412
|
[list cat $purgeDeltaItem] \ |
|
413
|
"*missing purge-item*" \ |
|
414
|
cat-wrong-hash \ |
|
415
|
"UPDATE purgeitem SET uuid='$purgeOtherHash' |
|
416
|
WHERE uuid='$purgeWholeItem'" \ |
|
417
|
[list cat $purgeOtherHash] \ |
|
418
|
"*incorrect artifact hash on $purgeOtherHash*" \ |
|
419
|
undo-wrong-hash \ |
|
420
|
"UPDATE purgeitem SET uuid='$purgeOtherHash' |
|
421
|
WHERE uuid='$purgeWholeItem'" \ |
|
422
|
[list undo $purgeEvent8] \ |
|
423
|
"*incorrect hash on $purgeOtherHash*" \ |
|
424
|
cat-source-loop \ |
|
425
|
"UPDATE purgeitem SET srcid=(SELECT piid FROM purgeitem |
|
426
|
WHERE uuid='$purgeDeltaItem') |
|
427
|
WHERE piid=(SELECT srcid FROM purgeitem |
|
428
|
WHERE uuid='$purgeDeltaItem')" \ |
|
429
|
[list cat $purgeDeltaItem] \ |
|
430
|
"*is part of a delta cycle*" \ |
|
431
|
undo-record-zero \ |
|
432
|
"PRAGMA ignore_check_constraints=1; |
|
433
|
INSERT INTO blob(rid,rcvid,size,uuid) |
|
434
|
VALUES(0,0,1,'$purgeWholeItem')" \ |
|
435
|
[list undo $purgeEvent8] \ |
|
436
|
"*" \ |
|
437
|
] { |
|
438
|
file copy -force p8.fossil damaged.fossil |
|
439
|
fossil sql -R damaged.fossil $purgeDamage |
|
440
|
set purgeBefore [repository_state damaged.fossil] |
|
441
|
fossil_raw purge {*}$purgeArgs -R damaged.fossil |
|
442
|
test purge-damage-$purgeName {$CODE == 1 && |
|
443
|
[string match $purgeMessage $RESULT]} |
|
444
|
test_eq purge-damage-$purgeName-no-change [repository_state damaged.fossil] \ |
|
445
|
$purgeBefore |
|
446
|
test_eq purge-damage-$purgeName-event-kept \ |
|
447
|
[purge_last_event damaged.fossil] $purgeEvent8 |
|
448
|
} |
|
449
|
|
|
450
|
# An item with no record number is restored under a new one. |
|
451
|
file copy -force p8.fossil damaged.fossil |
|
452
|
fossil sql -R damaged.fossil "UPDATE purgeitem SET orid=NULL" |
|
453
|
fossil purge undo $purgeEvent8 -R damaged.fossil |
|
454
|
test purge-undo-no-record-number {$CODE == 0} |
|
455
|
fossil rebuild damaged.fossil |
|
456
|
test_eq purge-undo-no-record-number-state \ |
|
457
|
[repository_state_diff $purgeStart [repository_state damaged.fossil]] "" |
|
458
|
repository_sound purge-undo-no-record-number damaged.fossil |
|
459
|
|
|
460
|
# A check-in is purged and its child, which is kept, then loses its |
|
461
|
# content. The undo restores the purged check-in and does not link the |
|
462
|
# child to it. |
|
463
|
file copy -force full.fossil damaged.fossil |
|
464
|
fossil purge artifacts $purgeP -R damaged.fossil |
|
465
|
fossil sql -R damaged.fossil "UPDATE blob SET size=-1, content=NULL |
|
466
|
WHERE uuid='$purgeC'" |
|
467
|
fossil purge undo [purge_last_event damaged.fossil] -R damaged.fossil |
|
468
|
test purge-undo-child-without-content {$CODE == 0} |
|
469
|
test_eq purge-undo-child-without-content-back \ |
|
470
|
[purge_has damaged.fossil $purgeP] 1 |
|
471
|
test_eq purge-undo-child-without-content-not-linked \ |
|
472
|
[purge_parent_of damaged.fossil $purgeC] "" |
|
473
|
|
|
474
|
############################################################################### |
|
475
|
# Obliterate. Asked first, unless --force; afterwards the purge cannot |
|
476
|
# be undone. |
|
477
|
|
|
478
|
fossil purge checkins side |
|
479
|
set purgeEvent [purge_last_event] |
|
480
|
|
|
481
|
# The error for a missing item names the item that is missing. |
|
482
|
fossil_raw purge cat $purgeSideB [string repeat 0 40] |
|
483
|
test purge-cat-second-missing {$CODE != 0 && |
|
484
|
[string match "*a file only the branch has*" $RESULT]} |
|
485
|
test purge-cat-second-missing-named \ |
|
486
|
{[string first [string repeat 0 40] $RESULT] >= 0} |
|
487
|
|
|
488
|
fossil_raw -input "n\n" purge obliterate $purgeEvent |
|
489
|
test purge-obliterate-declined {$CODE == 1} |
|
490
|
test_eq purge-obliterate-declined-kept [purge_last_event] $purgeEvent |
|
491
|
fossil_raw -input "y\n" purge obliterate $purgeEvent |
|
492
|
test purge-obliterate {$CODE == 0} |
|
493
|
test_eq purge-obliterate-gone [purge_sql "SELECT count(*) FROM purgeitem"] 0 |
|
494
|
# A capital Y is a yes too. |
|
495
|
fossil purge artifacts $purgeMiddle -R p4.fossil |
|
496
|
set purgeEvent4 [purge_last_event p4.fossil] |
|
497
|
fossil_raw -input "Y\n" purge obliterate $purgeEvent4 -R p4.fossil |
|
498
|
test purge-obliterate-capital {$CODE == 0} |
|
499
|
test_eq purge-obliterate-capital-gone [purge_sql "SELECT count(*) |
|
500
|
FROM purgeevent WHERE peid=$purgeEvent4" p4.fossil] 0 |
|
501
|
fossil purge obliterate $purgeEvent --force -expectError |
|
502
|
test purge-obliterate-again {$CODE != 0 && |
|
503
|
[string match "*no such purge event*" $RESULT]} |
|
504
|
repository_sound purge-obliterate |
|
505
|
|
|
506
|
# An undo of a purge that does not exist is refused, as an obliterate of |
|
507
|
# one is. |
|
508
|
set purgeBefore [repository_state] |
|
509
|
fossil_raw purge undo $purgeEvent |
|
510
|
test purge-undo-missing-event {$CODE == 1} |
|
511
|
test_eq purge-undo-missing-event-no-change [repository_state] $purgeBefore |
|
512
|
|
|
513
|
# A repository that has never had a purge has no graveyard tables. Undo |
|
514
|
# and obliterate are refused there as for any unknown purge, the list is |
|
515
|
# empty, and a scrub of private content has nothing to take from it. |
|
516
|
fossil init nograve.fossil |
|
517
|
foreach {purgeName purgeArgs} { |
|
518
|
undo {undo 1} |
|
519
|
obliterate {obliterate 1 --force} |
|
520
|
} { |
|
521
|
fossil_raw purge {*}$purgeArgs -R nograve.fossil |
|
522
|
test purge-no-graveyard-$purgeName {$CODE == 1 && |
|
523
|
[string match "*no such purge event: 1*" $RESULT]} |
|
524
|
} |
|
525
|
fossil purge list -R nograve.fossil |
|
526
|
test_eq purge-no-graveyard-list [string trim $RESULT] "" |
|
527
|
fossil scrub --private --force nograve.fossil |
|
528
|
test purge-no-graveyard-scrub {$CODE == 0} |
|
529
|
test_eq purge-no-graveyard-none-made [purge_sql "SELECT count(*) |
|
530
|
FROM sqlite_schema WHERE name IN ('purgeevent','purgeitem')" \ |
|
531
|
nograve.fossil] 0 |
|
532
|
|
|
533
|
############################################################################### |
|
534
|
# A purge is local. A clone made afterwards lacks what was purged; a |
|
535
|
# pull from a repository that still holds it brings it back. |
|
536
|
|
|
537
|
fossil clone .rep.fossil c1.fossil |
|
538
|
test purge-clone {$CODE == 0} |
|
539
|
test_eq purge-clone-lacks [purge_sql "SELECT count(*) FROM blob |
|
540
|
WHERE uuid='$purgeSide2'" c1.fossil] 0 |
|
541
|
fossil pull [file join [pwd] full.fossil] |
|
542
|
test purge-pull-back {$CODE == 0} |
|
543
|
test_eq purge-pull-back-state \ |
|
544
|
[repository_state_diff $purgeStart [repository_state]] "" |
|
545
|
repository_sound purge-pull-back |
|
546
|
|
|
547
|
############################################################################### |
|
548
|
# Scrub. A private branch, a password and a purge in the graveyard, then |
|
549
|
# each kind of scrub on its own copy. |
|
550
|
|
|
551
|
set purgeSecretText "" |
|
552
|
for {set purgeI 0} {$purgeI < 60} {incr purgeI} { |
|
553
|
append purgeSecretText "line $purgeI of private content\n" |
|
554
|
} |
|
555
|
set purgeSecret [purge_commit secret.txt $purgeSecretText purge-secret \ |
|
556
|
--private --branch secret] |
|
557
|
set purgeSecretFile [checkin_file_hash $purgeSecret secret.txt] |
|
558
|
fossil update trunk |
|
559
|
fossil user new scrubuser [email protected] hunter2 |
|
560
|
set purgePublic [purge_sql "SELECT group_concat(uuid,' ') FROM (SELECT uuid |
|
561
|
FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid)"] |
|
562
|
foreach purgeCopy {s1 s2 s3 s4 s5 s7} { |
|
563
|
file copy .rep.fossil $purgeCopy.fossil |
|
564
|
} |
|
565
|
proc purge_public {repo} { |
|
566
|
return [purge_sql "SELECT group_concat(uuid,' ') FROM (SELECT uuid |
|
567
|
FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid)" $repo] |
|
568
|
} |
|
569
|
test purge-scrub-setup {[password_count s1.fossil] > 0 && |
|
570
|
[purge_has s1.fossil $purgeSecret] == 1} |
|
571
|
|
|
572
|
# Asked first; "n" changes nothing. |
|
573
|
fossil_raw -input "n\n" scrub s1.fossil |
|
574
|
test purge-scrub-declined {$CODE == 1} |
|
575
|
test purge-scrub-declined-kept {[password_count s1.fossil] > 0} |
|
576
|
|
|
577
|
# By default only passwords go. |
|
578
|
fossil scrub --force s1.fossil |
|
579
|
test purge-scrub {$CODE == 0} |
|
580
|
test_eq purge-scrub-passwords [password_count s1.fossil] 0 |
|
581
|
test_eq purge-scrub-keeps-private [purge_has s1.fossil $purgeSecret] 1 |
|
582
|
test_eq purge-scrub-keeps-public [purge_public s1.fossil] $purgePublic |
|
583
|
repository_sound purge-scrub s1.fossil |
|
584
|
|
|
585
|
# --private removes the private branch and nothing else. |
|
586
|
fossil scrub --private --force s2.fossil |
|
587
|
test purge-scrub-private {$CODE == 0} |
|
588
|
test_eq purge-scrub-private-gone [purge_has s2.fossil $purgeSecret] 0 |
|
589
|
test_eq purge-scrub-private-file-gone [purge_has s2.fossil $purgeSecretFile] 0 |
|
590
|
test_eq purge-scrub-private-none-left [purge_sql "SELECT count(*) |
|
591
|
FROM private" s2.fossil] 0 |
|
592
|
test_eq purge-scrub-private-no-event [purge_sql "SELECT count(*) FROM event |
|
593
|
WHERE comment='purge-secret'" s2.fossil] 0 |
|
594
|
test_eq purge-scrub-private-keeps-public [purge_public s2.fossil] $purgePublic |
|
595
|
test purge-scrub-private-keeps-passwords {[password_count s2.fossil] > 0} |
|
596
|
repository_sound purge-scrub-private s2.fossil |
|
597
|
|
|
598
|
# A private branch that was purged before the scrub is in the graveyard. |
|
599
|
fossil purge artifacts $purgeSecret $purgeSecretFile -R s3.fossil |
|
600
|
test purge-scrub-graveyard-setup {$CODE == 0 && |
|
601
|
[purge_has s3.fossil $purgeSecret] == 0} |
|
602
|
# The detailed list marks each private item with a P. |
|
603
|
fossil purge list -l -R s3.fossil |
|
604
|
test purge-list-private-mark {[regexp -line \ |
|
605
|
"^ +\\d+ [string range $purgeSecret 0 15] +P +\\d+ " $RESULT]} |
|
606
|
# Undo, on a copy, gives the private branch back, still private. |
|
607
|
file copy s3.fossil s8.fossil |
|
608
|
fossil purge undo [purge_last_event s8.fossil] -R s8.fossil |
|
609
|
test purge-undo-private {$CODE == 0} |
|
610
|
test_eq purge-undo-private-state \ |
|
611
|
[repository_state_diff [repository_state s7.fossil] \ |
|
612
|
[repository_state s8.fossil]] "" |
|
613
|
test_eq purge-undo-private-still-private [purge_sql "SELECT count(*) |
|
614
|
FROM private JOIN blob USING(rid) |
|
615
|
WHERE uuid IN ('$purgeSecret','$purgeSecretFile')" s8.fossil] 2 |
|
616
|
repository_sound purge-undo-private s8.fossil |
|
617
|
fossil scrub --private --force s3.fossil |
|
618
|
test purge-scrub-graveyard {$CODE == 0} |
|
619
|
# The private branch does not survive in the graveyard, so neither |
|
620
|
# "purge cat" nor "purge undo" can bring it back. |
|
621
|
test_eq purge-scrub-private-graveyard [purge_sql "SELECT count(*) |
|
622
|
FROM purgeitem WHERE isPrivate" s3.fossil] 0 |
|
623
|
fossil_raw purge cat $purgeSecretFile -R s3.fossil |
|
624
|
test purge-scrub-private-graveyard-cat {$CODE == 1} |
|
625
|
|
|
626
|
# A public item in the graveyard that is stored as a delta from a private |
|
627
|
# one is kept and can still be read. "fossil publish" leaves such deltas: |
|
628
|
# the older version of a file is stored as a delta from the newer, and |
|
629
|
# only the older is published. |
|
630
|
fossil update secret |
|
631
|
set purgeSecret2 [purge_commit secret.txt "${purgeSecretText}one more\n" \ |
|
632
|
purge-secret-2] |
|
633
|
set purgeSecretFile2 [checkin_file_hash $purgeSecret2 secret.txt] |
|
634
|
fossil update trunk |
|
635
|
file copy .rep.fossil s6.fossil |
|
636
|
fossil publish $purgeSecret -R s6.fossil |
|
637
|
test purge-scrub-publish {$CODE == 0} |
|
638
|
test purge-scrub-public-from-private {[purge_sql "SELECT count(*) FROM delta |
|
639
|
WHERE rid=(SELECT rid FROM blob WHERE uuid='$purgeSecretFile') |
|
640
|
AND srcid=(SELECT rid FROM blob WHERE uuid='$purgeSecretFile2') |
|
641
|
AND rid NOT IN private AND srcid IN private" s6.fossil] == 1} |
|
642
|
fossil purge artifacts $purgeSecretFile $purgeSecretFile2 -R s6.fossil |
|
643
|
test purge-scrub-delta-in-graveyard {[purge_sql "SELECT count(*) |
|
644
|
FROM purgeitem a JOIN purgeitem b ON a.srcid=b.piid |
|
645
|
WHERE NOT a.isPrivate AND b.isPrivate" s6.fossil] == 1} |
|
646
|
fossil scrub --private --force s6.fossil |
|
647
|
test purge-scrub-delta {$CODE == 0} |
|
648
|
test_eq purge-scrub-delta-private-gone [purge_sql "SELECT count(*) |
|
649
|
FROM purgeitem WHERE isPrivate" s6.fossil] 0 |
|
650
|
fossil purge cat $purgeSecretFile -R s6.fossil |
|
651
|
test_eq purge-scrub-delta-public-kept $RESULT [string trim $purgeSecretText] |
|
652
|
|
|
653
|
# --verily removes the graveyard too, and the private branch. |
|
654
|
fossil purge artifacts $purgeSecret $purgeSecretFile -R s4.fossil |
|
655
|
fossil scrub --verily --force s4.fossil |
|
656
|
test purge-scrub-verily {$CODE == 0} |
|
657
|
test_eq purge-scrub-verily-no-graveyard [purge_sql "SELECT count(*) |
|
658
|
FROM sqlite_schema WHERE name='purgeitem'" s4.fossil] 0 |
|
659
|
test_eq purge-scrub-verily-passwords [password_count s4.fossil] 0 |
|
660
|
test_eq purge-scrub-verily-keeps-public [purge_public s4.fossil] $purgePublic |
|
661
|
repository_sound purge-scrub-verily s4.fossil |
|
662
|
|
|
663
|
# A scrubbed repository still clones. |
|
664
|
fossil clone s2.fossil c2.fossil |
|
665
|
test purge-scrub-clone {$CODE == 0} |
|
666
|
test_eq purge-scrub-clone-public [purge_public c2.fossil] $purgePublic |
|
667
|
|
|
668
|
############################################################################### |
|
669
|
# repack changes how content is stored, never what it is. |
|
670
|
|
|
671
|
fossil repack s5.fossil |
|
672
|
test purge-repack {$CODE == 0} |
|
673
|
test_eq purge-repack-same \ |
|
674
|
[repository_state_diff [repository_state s7.fossil] \ |
|
675
|
[repository_state s5.fossil]] "" |
|
676
|
test_eq purge-repack-public [purge_public s5.fossil] $purgePublic |
|
677
|
test_eq purge-repack-private [purge_has s5.fossil $purgeSecret] 1 |
|
678
|
repository_sound purge-repack s5.fossil |
|
679
|
|
|
680
|
############################################################################### |
|
681
|
# A delta manifest names its baseline. A purge of the baseline alone is |
|
682
|
# refused; with the delta manifest it goes through, and the undo restores |
|
683
|
# both. |
|
684
|
|
|
685
|
fossil settings forbid-delta-manifests off |
|
686
|
set purgeBase [lindex $purgeTrunk 4] |
|
687
|
set purgeDeltaM [purge_commit a.txt "${purgeTrunkText(5)}one more line\n" \ |
|
688
|
purge-delta-manifest --delta] |
|
689
|
test purge-baseline-setup {[purge_sql "SELECT count(*) FROM plink |
|
690
|
WHERE cid=(SELECT rid FROM blob WHERE uuid='$purgeDeltaM') |
|
691
|
AND baseid=(SELECT rid FROM blob WHERE uuid='$purgeBase')"] == 1} |
|
692
|
fossil update [lindex $purgeTrunk 3] |
|
693
|
set purgeBefore [repository_state] |
|
694
|
fossil_raw purge artifacts $purgeBase |
|
695
|
test purge-baseline-alone-refused {$CODE ne "0" && |
|
696
|
[string match "*attempt to purge a baseline manifest*" $RESULT]} |
|
697
|
test_eq purge-baseline-alone-no-change [repository_state] $purgeBefore |
|
698
|
fossil purge artifacts $purgeBase $purgeDeltaM |
|
699
|
test purge-baseline-with-delta {$CODE == 0} |
|
700
|
test_eq purge-baseline-with-delta-gone [purge_sql "SELECT count(*) FROM blob |
|
701
|
WHERE uuid IN ('$purgeBase','$purgeDeltaM')"] 0 |
|
702
|
fossil purge undo [purge_last_event] |
|
703
|
test purge-baseline-undo {$CODE == 0} |
|
704
|
test_eq purge-baseline-undo-state \ |
|
705
|
[repository_state_diff $purgeBefore [repository_state]] "" |
|
706
|
repository_sound purge-baseline-undo |
|
707
|
|
|
708
|
############################################################################### |
|
709
|
|
|
710
|
test_cleanup |
|
711
|
|