|
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 import --svn" and "fossil import --git". The dumps and the |
|
15
|
# streams are written here, byte by byte: first dumps whose file contents |
|
16
|
# are svndiff0 deltas (Text-delta: true), as "svnadmin dump --deltas" |
|
17
|
# writes them, then git streams, then dumps of whole histories. Where |
|
18
|
# Subversion or git is installed, a history that it wrote is imported too. |
|
19
|
# |
|
20
|
|
|
21
|
# The first sections run at every level, and the rest need |
|
22
|
# -assurance stress. |
|
23
|
test_setup |
|
24
|
|
|
25
|
# A number in the variable-length form of svndiff0: seven bits a byte, |
|
26
|
# most significant first, the high bit set on every byte but the last. |
|
27
|
# |
|
28
|
proc import_varint {n} { |
|
29
|
set out [list [expr {$n & 0x7f}]] |
|
30
|
set n [expr {$n >> 7}] |
|
31
|
while {$n} { |
|
32
|
set out [linsert $out 0 [expr {0x80 | ($n & 0x7f)}]] |
|
33
|
set n [expr {$n >> 7}] |
|
34
|
} |
|
35
|
return [binary format c* $out] |
|
36
|
} |
|
37
|
|
|
38
|
# One window: source offset and length, target length, instructions and |
|
39
|
# new data. INSTR is a list of byte values. |
|
40
|
# |
|
41
|
proc import_window {srcoff srclen tgtlen instr data} { |
|
42
|
set i [binary format c* $instr] |
|
43
|
return \ |
|
44
|
"[import_varint $srcoff][import_varint $srclen][import_varint $tgtlen][import_varint [string length $i]][import_varint [string length $data]]$i$data" |
|
45
|
} |
|
46
|
|
|
47
|
proc import_props {pairs} { |
|
48
|
set b "" |
|
49
|
foreach {k v} $pairs { |
|
50
|
append b "K [string length $k]\n$k\nV [string length $v]\n$v\n" |
|
51
|
} |
|
52
|
return "${b}PROPS-END\n" |
|
53
|
} |
|
54
|
|
|
55
|
proc import_rev {n log} { |
|
56
|
set p [import_props [list svn:log $log svn:author dan \ |
|
57
|
svn:date 2026-01-0[expr {$n+1}]T00:00:00.000000Z]] |
|
58
|
set len [string length $p] |
|
59
|
return \ |
|
60
|
[join [list \ |
|
61
|
"Revision-number: $n\nProp-content-length: $len\n" \ |
|
62
|
"Content-length: $len\n\n$p\n"] ""] |
|
63
|
} |
|
64
|
|
|
65
|
proc import_node {path kind action {text ""} {delta 0}} { |
|
66
|
set p "PROPS-END\n" |
|
67
|
set h "Node-path: $path\nNode-kind: $kind\nNode-action: $action\n" |
|
68
|
if {$kind eq "dir"} { |
|
69
|
return "${h}Prop-content-length: 10\nContent-length: 10\n\n$p\n\n" |
|
70
|
} |
|
71
|
if {$delta} { append h "Text-delta: true\n" } |
|
72
|
set n [string length $text] |
|
73
|
return \ |
|
74
|
[join [list \ |
|
75
|
"${h}Prop-content-length: 10\nText-content-length: $n\n" \ |
|
76
|
"Content-length: [expr {$n+10}]\n\n$p$text\n\n"] ""] |
|
77
|
} |
|
78
|
|
|
79
|
# Revision 1 adds trunk/a.txt, "hello world\n", as a delta from nothing. |
|
80
|
# Revision 2 changes it by the delta in WINDOWS. |
|
81
|
# |
|
82
|
proc import_dump {windows {magic "SVN\000"}} { |
|
83
|
set d \ |
|
84
|
[join [list \ |
|
85
|
"SVN-fs-dump-format-version: 3\n\n" \ |
|
86
|
"UUID: 00000000-0000-0000-0000-000000000000\n\n"] ""] |
|
87
|
append d [import_rev 0 zero] |
|
88
|
append d [import_rev 1 one] |
|
89
|
append d [import_node trunk dir add] |
|
90
|
append d [import_node trunk/a.txt file add \ |
|
91
|
"SVN\000[import_window 0 0 12 {0x8c} "hello world\n"]" 1] |
|
92
|
append d [import_rev 2 two] |
|
93
|
append d [import_node trunk/a.txt file change "$magic$windows" 1] |
|
94
|
return $d |
|
95
|
} |
|
96
|
|
|
97
|
# Import WINDOWS as revision 2 and return the file it makes, or the error. |
|
98
|
# |
|
99
|
proc import_try {name windows {magic "SVN\000"}} { |
|
100
|
write_file $name.dump [import_dump $windows $magic] |
|
101
|
fossil_raw -seconds 60 import --svn $name.fossil $name.dump |
|
102
|
if {$::CODE != 0} { return "error: [string trim $::RESULT]" } |
|
103
|
fossil_raw cat a.txt -R $name.fossil -r trunk |
|
104
|
return $::RESULT |
|
105
|
} |
|
106
|
|
|
107
|
############################################################################### |
|
108
|
# Sound deltas give the file they describe. |
|
109
|
|
|
110
|
# Twelve bytes from the source, then five new ones. |
|
111
|
test_eq import-svn-source-and-data [import_try sound \ |
|
112
|
[import_window 0 12 17 {0x0c 0 0x85} "more\n"]] "hello world\nmore\n" |
|
113
|
|
|
114
|
# A copy from the target that overlaps itself repeats what was written. |
|
115
|
test_eq import-svn-target-overlap [import_try rle \ |
|
116
|
[import_window 0 12 8 {0x82 0x46 0} ab]] abababab |
|
117
|
|
|
118
|
# Two windows, each from its own part of the source. |
|
119
|
test_eq import-svn-two-windows [import_try two \ |
|
120
|
"[import_window 0 5 5 {0x05 0} {}][import_window 6 6 6 {0x05 0 0x81} !]"] \ |
|
121
|
helloworld! |
|
122
|
|
|
123
|
# A length that does not fit in the instruction byte follows it. |
|
124
|
test_eq import-svn-long-length [import_try long \ |
|
125
|
[import_window 0 12 70 {0x80 70} [string repeat z 70]]] \ |
|
126
|
[string repeat z 70] |
|
127
|
|
|
128
|
# A copy of no bytes from the target may name any offset. |
|
129
|
test_eq import-svn-empty-target-copy [import_try emptycopy \ |
|
130
|
[import_window 0 12 2 {0x40 0 0 0x82} ab]] ab |
|
131
|
|
|
132
|
############################################################################### |
|
133
|
# Malformed deltas are refused, with nothing read or written outside the |
|
134
|
# buffers and no byte of the new file left unwritten. |
|
135
|
|
|
136
|
foreach {importName importWindows} [list \ |
|
137
|
write-past-target [import_window 0 12 4 {0x80 100} [string repeat x 100]] \ |
|
138
|
source-offset [import_window 0 12 10 {0x0a 0x87 0x68} {}] \ |
|
139
|
source-length [import_window 0 12 10 {0x0a 5} {}] \ |
|
140
|
bad-instruction [import_window 0 12 1 {0xc1 0} {}] \ |
|
141
|
source-window [import_window 1000 12 10 {0x0a 0} {}] \ |
|
142
|
target-offset [import_window 0 12 10 {0x82 0x48 0x87 0x68} ab] \ |
|
143
|
target-unwritten [import_window 0 12 4 {0x44 0} {}] \ |
|
144
|
data-past-end [import_window 0 12 50 {0xb2} abcde] \ |
|
145
|
huge-instr-len \ |
|
146
|
"[import_varint 0][import_varint 12][import_varint 5][import_varint 100000][import_varint 5]\x85abcde" \ |
|
147
|
huge-data-len \ |
|
148
|
"[import_varint 0][import_varint 12][import_varint 5][import_varint 1][import_varint 100000]\x85abcde" \ |
|
149
|
truncated-varint "\x80\x80" \ |
|
150
|
truncated-length [binary format c* {0 12 5 1 5 0x80}] \ |
|
151
|
target-unfilled [import_window 0 12 4000 {0x85} abcde] \ |
|
152
|
] { |
|
153
|
set importResult [import_try $importName $importWindows] |
|
154
|
test import-svn-$importName {$CODE == 1 && |
|
155
|
[string match "*Invalid svndiff0*" $importResult]} |
|
156
|
} |
|
157
|
|
|
158
|
# Not an svndiff0 delta at all. |
|
159
|
test import-svn-not-svndiff {[string match "*Invalid svndiff0*" \ |
|
160
|
[import_try not abc "XYZ\000"]]} |
|
161
|
|
|
162
|
if {[test_assurance] ne "stress"} { |
|
163
|
test_skip "the tests after the first sections need -assurance stress" |
|
164
|
} |
|
165
|
|
|
166
|
############################################################################### |
|
167
|
# A dump written by Subversion itself, with deltas of several windows. |
|
168
|
# Every version that Fossil imports must be byte for byte the one that |
|
169
|
# Subversion holds. |
|
170
|
|
|
171
|
if {[catch {exec svnadmin --version --quiet}] || [catch \ |
|
172
|
{exec svn --version --quiet}]} { |
|
173
|
test_skip_part "svnadmin and svn are not installed" |
|
174
|
} else { |
|
175
|
set importRepo [file join [pwd] svnrepo] |
|
176
|
exec svnadmin create $importRepo |
|
177
|
exec svn checkout -q file://$importRepo svnwc |
|
178
|
file mkdir svnwc/trunk |
|
179
|
set importBase "" |
|
180
|
for {set importI 0} {$importI < 6000} {incr importI} { |
|
181
|
append importBase \ |
|
182
|
"line $importI of a file that spans several delta windows\n" |
|
183
|
} |
|
184
|
set importVersions [list $importBase] |
|
185
|
set importNext "" |
|
186
|
for {set importI 0} {$importI < [string length $importBase]} \ |
|
187
|
{incr importI 20000} { |
|
188
|
append importNext [string range $importBase $importI \ |
|
189
|
[expr {$importI+19999}]] |
|
190
|
append importNext [string repeat x 3000] \ |
|
191
|
[string repeat "pattern $importI " 300] |
|
192
|
} |
|
193
|
lappend importVersions $importNext |
|
194
|
lappend importVersions "[string repeat {repeated line of text} 20000]\n" |
|
195
|
write_file svnwc/trunk/a.txt [lindex $importVersions 0] |
|
196
|
exec svn add -q svnwc/trunk |
|
197
|
exec svn commit -q -m one svnwc |
|
198
|
write_file svnwc/trunk/a.txt [lindex $importVersions 1] |
|
199
|
exec svn commit -q -m two svnwc |
|
200
|
write_file svnwc/trunk/a.txt [lindex $importVersions 2] |
|
201
|
exec svn commit -q -m three svnwc |
|
202
|
exec svnadmin dump -q --deltas $importRepo > real.dump |
|
203
|
fossil import --svn real.fossil real.dump |
|
204
|
test import-svn-real {$CODE == 0} |
|
205
|
set importI 0 |
|
206
|
foreach importComment {one two three} { |
|
207
|
fossil sql -R real.fossil "SELECT uuid FROM blob, event |
|
208
|
WHERE objid=rid AND type='ci' AND comment LIKE '$importComment%'" |
|
209
|
set importHash [string trim $RESULT "'\n "] |
|
210
|
fossil cat a.txt -R real.fossil -r $importHash -o real-$importComment.txt |
|
211
|
test_eq import-svn-real-$importComment [read_file real-$importComment.txt] \ |
|
212
|
[lindex $importVersions $importI] |
|
213
|
incr importI |
|
214
|
} |
|
215
|
} |
|
216
|
|
|
217
|
############################################################################### |
|
218
|
# "fossil import --git" of a commit holding a file whose content is a |
|
219
|
# Fossil check-in artifact, one whose second card is a P card that names no |
|
220
|
# parent. The file is imported as a file: the repository holds one |
|
221
|
# check-in, the imported commit, and the file reads back with a line added |
|
222
|
# at its end that stops it being an artifact. |
|
223
|
|
|
224
|
set importArt \ |
|
225
|
"D 2026-03-08T10:01:00.000\nP\nR d41d8cd98f00b204e9800998ecf8427e\n" |
|
226
|
append importArt "T *branch * planted\nT *sym-planted *\nU mallory\n" |
|
227
|
write_file git-artifact-body.txt $importArt |
|
228
|
fossil md5sum git-artifact-body.txt |
|
229
|
append importArt "Z [lindex $RESULT 0]\n" |
|
230
|
set importStream "blob\nmark :1\ndata [string length $importArt]\n$importArt\n" |
|
231
|
append importStream "commit refs/heads/master\nmark :2\n" |
|
232
|
append importStream "committer A <[email protected]> 1700000000 +0000\n" |
|
233
|
append importStream "data 4\nimp\nM 100644 :1 f.txt\n\n" |
|
234
|
write_file git-artifact.fi $importStream |
|
235
|
fossil_raw -seconds 60 import --git git-artifact.fossil git-artifact.fi |
|
236
|
test import-git-artifact-file {$CODE == 0} |
|
237
|
fossil sql -R git-artifact.fossil "SELECT count(*) FROM event WHERE type='ci'" |
|
238
|
test_eq import-git-artifact-one-checkin [string trim $RESULT] 1 |
|
239
|
fossil sql -R git-artifact.fossil \ |
|
240
|
"SELECT count(*) FROM tag WHERE tagname='sym-planted'" |
|
241
|
test_eq import-git-artifact-no-branch [string trim $RESULT] 0 |
|
242
|
fossil_raw cat f.txt -R git-artifact.fossil -r trunk |
|
243
|
test_eq import-git-artifact-content $RESULT \ |
|
244
|
[join [list \ |
|
245
|
"${importArt}# Remove this line to create a well-formed " \ |
|
246
|
"Fossil control artifact.\n"] ""] |
|
247
|
|
|
248
|
############################################################################### |
|
249
|
# Input that "fossil import" must refuse with an error and exit code 1. |
|
250
|
|
|
251
|
# Each row: a git stream. The length of a data command is negative, too |
|
252
|
# large to hold, or not a number; the time of a committer is past the |
|
253
|
# year 9999, has thirteen digits, or has no space before it. |
|
254
|
# |
|
255
|
set importWho "committer C <[email protected]>" |
|
256
|
foreach {importName importStream} [list \ |
|
257
|
data-negative \ |
|
258
|
"blob\nmark :1\ndata -1\nhello world, and more than one byte\n" \ |
|
259
|
data-huge "blob\nmark :1\ndata 2147483647\nhello\n" \ |
|
260
|
data-not-number "blob\nmark :1\ndata <<EOF\nhello\nEOF\n" \ |
|
261
|
time-past-9999 \ |
|
262
|
[join [list \ |
|
263
|
"commit refs/heads/master\nmark :1\n" \ |
|
264
|
"$importWho 253402300800 +0000\ndata 1\nx\n"] ""] \ |
|
265
|
time-13-digits \ |
|
266
|
[join [list \ |
|
267
|
"commit refs/heads/master\nmark :1\n" \ |
|
268
|
"$importWho 9999999999999 +0000\ndata 1\nx\n"] ""] \ |
|
269
|
time-no-space \ |
|
270
|
[join [list \ |
|
271
|
"commit refs/heads/master\nmark :1\n" \ |
|
272
|
"${importWho}1700000000 +0000\ndata 1\nx\n"] ""] \ |
|
273
|
] { |
|
274
|
write_file refuse-$importName.fi $importStream |
|
275
|
fossil_raw -seconds 60 import --git refuse-$importName.fossil \ |
|
276
|
refuse-$importName.fi |
|
277
|
test import-refuse-git-$importName {$CODE == 1 && |
|
278
|
[string first "bad fast-import line" $RESULT] >= 0} |
|
279
|
} |
|
280
|
|
|
281
|
# A commit command whose name is 992 bytes long, with no slash after its |
|
282
|
# fifth byte and no newline, is read within the name. The commit has no |
|
283
|
# data and is not made. |
|
284
|
write_file git-ref-long.fi "commit [string repeat a 992]" |
|
285
|
fossil_raw -seconds 60 import --git git-ref-long.fossil git-ref-long.fi |
|
286
|
test import-git-ref-long {$CODE == 0} |
|
287
|
|
|
288
|
# Each row: an svn dump. A header line has no newline after its value, |
|
289
|
# because the dump ends there, a zero byte comes first, or the line is |
|
290
|
# longer than the importer reads at once; a file on the trunk has no |
|
291
|
# Node-action. |
|
292
|
# |
|
293
|
set importStart "SVN-fs-dump-format-version: 2\n\nUUID: 0000\n\n" |
|
294
|
append importStart "Revision-number: 1\nProp-content-length: 10\n" |
|
295
|
append importStart "Content-length: 10\n\nPROPS-END\n\n" |
|
296
|
foreach {importName importDump} [list \ |
|
297
|
header-cut "SVN-fs-dump-format-version: 2\nUUID: 0000" \ |
|
298
|
header-zero "SVN-fs-dump-format-version: 2\nUUID: 00\00000\n\n" \ |
|
299
|
header-long \ |
|
300
|
"SVN-fs-dump-format-version: 2\nUUID: [string repeat 0 1200]\n\n" \ |
|
301
|
no-action \ |
|
302
|
[join [list \ |
|
303
|
"${importStart}Node-path: trunk/a\nNode-kind: file\n" \ |
|
304
|
"Text-content-length: 1\nContent-length: 1\n\nx\n\n"] ""] \ |
|
305
|
] { |
|
306
|
write_file refuse-$importName.dump $importDump |
|
307
|
fossil_raw -seconds 60 import --svn refuse-$importName.fossil \ |
|
308
|
refuse-$importName.dump |
|
309
|
test import-refuse-svn-$importName {$CODE == 1 && |
|
310
|
[string first "svn-dump data format broken" $RESULT] >= 0} |
|
311
|
} |
|
312
|
|
|
313
|
# A file outside trunk, branches and tags is passed over even when it has |
|
314
|
# no Node-action. |
|
315
|
# |
|
316
|
write_file outside.dump \ |
|
317
|
[join [list \ |
|
318
|
"${importStart}Node-path: other/a\nNode-kind: file\n" \ |
|
319
|
"Text-content-length: 1\nContent-length: 1\n\nx\n\n"] ""] |
|
320
|
fossil_raw -seconds 60 import --svn outside.fossil outside.dump |
|
321
|
test import-svn-outside-no-action {$CODE == 0} |
|
322
|
|
|
323
|
# An empty --trunk, --branches or --tags is refused unless --base names a |
|
324
|
# directory; with one, an empty --trunk makes the base itself the trunk. |
|
325
|
# |
|
326
|
write_file base.dump \ |
|
327
|
[join [list \ |
|
328
|
"${importStart}Node-path: proj/a\nNode-kind: file\n" \ |
|
329
|
"Node-action: add\nText-content-length: 1\n" \ |
|
330
|
"Content-length: 1\n\nx\n\n"] ""] |
|
331
|
foreach importName {trunk branches tags} { |
|
332
|
fossil_raw -seconds 60 import --svn --$importName "" \ |
|
333
|
refuse-$importName.fossil base.dump |
|
334
|
test import-refuse-svn-empty-$importName {$CODE == 1 && [string first \ |
|
335
|
"may be empty only with a non-empty --base" $RESULT] >= 0} |
|
336
|
} |
|
337
|
fossil_raw -seconds 60 import --svn --base proj --trunk "" base.fossil base.dump |
|
338
|
test import-svn-base-empty-trunk {$CODE == 0} |
|
339
|
fossil sql -R base.fossil "SELECT group_concat(f.filename, ' ') |
|
340
|
FROM event e, blob b, files_of_checkin(b.uuid) f WHERE b.rid=e.objid" |
|
341
|
test_eq import-svn-base-empty-trunk-files $RESULT a |
|
342
|
|
|
343
|
############################################################################### |
|
344
|
# "fossil import --git" of streams written here, command by command. |
|
345
|
|
|
346
|
proc import_blob {mark text} { |
|
347
|
return "blob\nmark :$mark\ndata [string length $text]\n$text\n" |
|
348
|
} |
|
349
|
|
|
350
|
# A commit on REF with mark MARK and comment COMMENT, made by C, MARK |
|
351
|
# minutes after 2023-11-14 22:13:20 UTC. BODY is the lines that follow |
|
352
|
# the comment. |
|
353
|
# |
|
354
|
proc import_commit {ref mark comment {body ""}} { |
|
355
|
set when [expr {1700000000+60*$mark}] |
|
356
|
return \ |
|
357
|
[join [list \ |
|
358
|
"commit $ref\nmark :$mark\n" \ |
|
359
|
"committer C <[email protected]> $when +0000\n" \ |
|
360
|
"data [string length $comment]\n$comment\n$body\n"] ""] |
|
361
|
} |
|
362
|
|
|
363
|
proc import_git {name stream args} { |
|
364
|
write_file $name.fi $stream |
|
365
|
fossil_raw -seconds 60 import --git {*}$args $name.fossil $name.fi |
|
366
|
} |
|
367
|
|
|
368
|
# What repository NAME answers to QUERY. |
|
369
|
# |
|
370
|
proc import_sql {name query} { |
|
371
|
return [fossil_sql $query $name.fossil] |
|
372
|
} |
|
373
|
|
|
374
|
# The files of the check-in of NAME whose comment is COMMENT, in name |
|
375
|
# order: the name, the permission and the former name of each. |
|
376
|
# |
|
377
|
proc import_files {name comment} { |
|
378
|
return [import_sql $name \ |
|
379
|
"SELECT group_concat(trim(f.filename||' '||coalesce(f.perm,'')||' '||coalesce(f.previousName,'')), ', ') |
|
380
|
FROM event e, blob b, files_of_checkin(b.uuid) f |
|
381
|
WHERE e.type='ci' AND e.comment='$comment' AND b.rid=e.objid"] |
|
382
|
} |
|
383
|
|
|
384
|
# The branch and tag names that hold for the check-in with comment COMMENT. |
|
385
|
# |
|
386
|
proc import_tags {name comment} { |
|
387
|
return [import_sql $name "SELECT group_concat(substr(tagname,5), ' ') FROM ( |
|
388
|
SELECT tagname FROM tag, tagxref, event |
|
389
|
WHERE tag.tagid=tagxref.tagid AND tagxref.rid=event.objid |
|
390
|
AND tagxref.tagtype>0 AND tagname LIKE 'sym-%' |
|
391
|
AND event.type='ci' AND event.comment='$comment' ORDER BY tagname)"] |
|
392
|
} |
|
393
|
|
|
394
|
# The comments of the parents of the check-in with comment COMMENT, the |
|
395
|
# primary parent first. |
|
396
|
# |
|
397
|
proc import_parents {name comment} { |
|
398
|
return [import_sql $name "SELECT group_concat(comment, ' ') FROM ( |
|
399
|
SELECT p.comment FROM plink, event c, event p |
|
400
|
WHERE c.comment='$comment' AND plink.cid=c.objid AND p.objid=plink.pid |
|
401
|
ORDER BY plink.isprim DESC, p.comment)"] |
|
402
|
} |
|
403
|
|
|
404
|
proc import_checkins {name} { |
|
405
|
return [import_sql $name "SELECT group_concat(comment, ' ') FROM |
|
406
|
(SELECT comment FROM event WHERE type='ci' ORDER BY mtime, comment)"] |
|
407
|
} |
|
408
|
|
|
409
|
# A stream with every command that the importer knows. Commit one holds |
|
410
|
# plain, executable, link, empty and inline files, a file whose mark is |
|
411
|
# not defined and an M line with no mark and no name. Commit two has no |
|
412
|
# "from" and follows one on the same branch. Commit three begins another |
|
413
|
# branch. Commit four has a parent on another branch and three merge |
|
414
|
# lines, one of them for a mark that is not defined. Commits five and six |
|
415
|
# are on the same tag ref. |
|
416
|
# |
|
417
|
set importStream "# a comment line\nfeature done\noption git quiet\n" |
|
418
|
append importStream "progress halfway there\n" |
|
419
|
append importStream [import_blob 1 "hello\n"] |
|
420
|
append importStream "blob\ndata 6\nhello\n\n" |
|
421
|
append importStream "blob\nmark :2\ndata 0\n\n" |
|
422
|
append importStream [import_blob 3 "exec\n"] |
|
423
|
append importStream "reset refs/heads/master\n" |
|
424
|
append importStream "commit refs/heads/master\nmark :10\n" |
|
425
|
append importStream "author Au Thor <[email protected]> 1600000000 +0000\n" |
|
426
|
append importStream "committer C <[email protected]> 1700000600 +0000\n" |
|
427
|
append importStream "data 3\none\n" |
|
428
|
append importStream "M 100644 :1 a.txt\nM 100755 :3 run.sh\nM 120000 :1 link\n" |
|
429
|
append importStream "M 100644 :2 empty\n" |
|
430
|
append importStream "M 100644 inline in.txt\ndata 7\ninline\n\n" |
|
431
|
append importStream "M 100644 :99 missing.txt\n" |
|
432
|
append importStream "M 100644 :1 dir/x\nM 100644 :1 dir/y\n" |
|
433
|
append importStream \ |
|
434
|
"M 100644 :1 tmp/p\nM 100644 :1 tmp/q\nM 100644 :1 tmpfile\n" |
|
435
|
append importStream "M 100644\nN :1 :10\ncheckpoint\n" |
|
436
|
append importStream [import_commit refs/heads/master 11 two \ |
|
437
|
"D run.sh\nD tmp\nC a.txt b.txt\nR link link2\n"] |
|
438
|
append importStream [import_commit refs/heads/dev 12 three \ |
|
439
|
"M 100644 :1 d.txt\n"] |
|
440
|
append importStream [import_commit refs/heads/dev 13 four \ |
|
441
|
"from :11\nmerge :12\nmerge :10\nmerge :98\nC dir dir2\nR dir dir3\n"] |
|
442
|
append importStream [import_commit refs/tags/v1 14 five \ |
|
443
|
"from :13\nM 100644 :1 five.txt\n"] |
|
444
|
append importStream [import_commit refs/tags/v1 15 six \ |
|
445
|
"from :14\nM 100644 :1 six.txt\n"] |
|
446
|
set importTagger "tagger T <[email protected]> 1700009999 +0000" |
|
447
|
append importStream "tag v2\nfrom :13\n$importTagger\ndata 8\nthe tag\n\n" |
|
448
|
append importStream "tag v3\nfrom :13\n$importTagger\n" |
|
449
|
append importStream "tag nodate\nfrom :13\ndata 1\nx\n" |
|
450
|
append importStream "tag nofrom\n$importTagger\ndata 1\nx\n" |
|
451
|
append importStream "tag unknown\nfrom :97\n$importTagger\n" |
|
452
|
append importStream "tag v4\n$importTagger\nfrom :13" |
|
453
|
|
|
454
|
import_git all $importStream |
|
455
|
test import-git-all {$CODE == 0} |
|
456
|
test import-git-all-progress \ |
|
457
|
{[holds_strings $RESULT {"halfway there" 2023-11-14}]} |
|
458
|
test_eq import-git-all-checkins [import_checkins all] \ |
|
459
|
"one two three four five six" |
|
460
|
test_eq import-git-all-user [import_sql all \ |
|
461
|
"SELECT user||' '||date(mtime) FROM event WHERE comment='one'"] \ |
|
462
|
"[email protected] 2023-11-14" |
|
463
|
test_eq import-git-all-one [import_files all one] \ |
|
464
|
[join [list \ |
|
465
|
"a.txt w, dir/x w, dir/y w, empty w, in.txt w, link l, " \ |
|
466
|
"run.sh x, tmp/p w, tmp/q w, tmpfile w"] ""] |
|
467
|
fossil_raw cat in.txt -R all.fossil -r [import_sql all \ |
|
468
|
"SELECT uuid FROM blob, event WHERE rid=objid AND comment='one'"] |
|
469
|
test_eq import-git-all-inline $RESULT "inline\n" |
|
470
|
test_eq import-git-all-two [import_files all two] \ |
|
471
|
[join [list \ |
|
472
|
"a.txt w, b.txt w, dir/x w, dir/y w, empty w, in.txt w, " \ |
|
473
|
"link2 l link, tmpfile w"] ""] |
|
474
|
test_eq import-git-all-two-parent [import_parents all two] one |
|
475
|
test_eq import-git-all-two-tags [import_tags all two] "master trunk" |
|
476
|
test_eq import-git-all-three-parent [import_parents all three] "" |
|
477
|
test_eq import-git-all-three-tags [import_tags all three] "dev trunk" |
|
478
|
test_eq import-git-all-four [import_files all four] \ |
|
479
|
[join [list \ |
|
480
|
"a.txt w, b.txt w, dir2/x w, dir2/y w, dir3/x w dir/x, " \ |
|
481
|
"dir3/y w dir/y, empty w, in.txt w, link2 l, tmpfile w"] ""] |
|
482
|
test_eq import-git-all-four-parents [import_parents all four] "two one three" |
|
483
|
test_eq import-git-all-four-tags [import_tags all four] "dev trunk v2 v3 v4" |
|
484
|
test_eq import-git-all-tag-comment [import_sql all "SELECT value FROM tagxref |
|
485
|
WHERE tagid=(SELECT tagid FROM tag WHERE tagname='sym-v2')"] "the tag" |
|
486
|
test_eq import-git-all-five-tags [import_tags all five] "dev trunk" |
|
487
|
test_eq import-git-all-six-tags [import_tags all six] "dev trunk v1" |
|
488
|
test_eq import-git-all-no-other-tags [import_sql all "SELECT count(*) FROM tag |
|
489
|
WHERE tagname IN ('sym-nodate','sym-nofrom','sym-unknown')"] 0 |
|
490
|
|
|
491
|
# With --quiet the dates of the commits are not printed. |
|
492
|
import_git quiet $importStream --quiet |
|
493
|
test import-git-quiet {$CODE == 0 && [holds_strings $RESULT {!2023-11-14}]} |
|
494
|
test_eq import-git-quiet-checkins [import_checkins quiet] \ |
|
495
|
"one two three four five six" |
|
496
|
|
|
497
|
|
|
498
|
# File names in quotes, as git writes names that hold unusual bytes. Each |
|
499
|
# row is the name as the stream gives it and the name the file must get. |
|
500
|
# A backslash and three octal digits stand for one byte unless the byte |
|
501
|
# would be zero; a backslash and a letter for a control character; a |
|
502
|
# backslash and anything else for that character. A name that begins |
|
503
|
# with a quote and does not end with one is kept as it is. |
|
504
|
# |
|
505
|
set importNames [list \ |
|
506
|
{plain name} "plain name" \ |
|
507
|
{"all\a\b\f\n\r\t\v\\\"end"} "all\a\b\f\n\r\t\v\\\"end" \ |
|
508
|
{"oct\303\251"} "oct\xc3\xa9" \ |
|
509
|
{"tail\\"} "tail\\" \ |
|
510
|
{"c3\777"} "c3777" \ |
|
511
|
{"c4\1.5"} "c41.5" \ |
|
512
|
{"c5\1895"} "c51895" \ |
|
513
|
{"c6\11.5"} "c611.5" \ |
|
514
|
{"c7\1185"} "c71185" \ |
|
515
|
{"c8\0005"} "c80005" \ |
|
516
|
{"noend} "\"noend" \ |
|
517
|
] |
|
518
|
set importStream [import_blob 1 "hello\n"] |
|
519
|
set importBody "" |
|
520
|
set importWant [list] |
|
521
|
foreach {importGiven importName} $importNames { |
|
522
|
append importBody "M 100644 :1 $importGiven\n" |
|
523
|
lappend importWant [binary encode hex $importName] |
|
524
|
} |
|
525
|
append importStream [import_commit refs/heads/master 2 names $importBody] |
|
526
|
append importStream [import_commit refs/heads/master 3 fewer \ |
|
527
|
"D \"oct\\303\\251\"\nD plain name\n"] |
|
528
|
import_git names $importStream |
|
529
|
test import-git-names {$CODE == 0} |
|
530
|
test_eq import-git-names-files \ |
|
531
|
[import_sql names "SELECT group_concat(lower(hex(f.filename)), ' ') |
|
532
|
FROM event e, blob b, files_of_checkin(b.uuid) f |
|
533
|
WHERE e.comment='names' AND b.rid=e.objid"] [lsort $importWant] |
|
534
|
test_eq import-git-names-deleted [import_sql names "SELECT count(*) |
|
535
|
FROM event e, blob b, files_of_checkin(b.uuid) f |
|
536
|
WHERE e.comment='fewer' AND b.rid=e.objid"] 9 |
|
537
|
|
|
538
|
# A line that ends in a carriage return and a newline gives the name |
|
539
|
# before them. A carriage return with no newline after it ends the name. |
|
540
|
# |
|
541
|
set importStream [import_blob 1 "hello\n"] |
|
542
|
append importStream [import_commit refs/heads/master 2 returns \ |
|
543
|
"M 100644 :1 cr.txt\r\nM 100644 :1 cut\rtail\n"] |
|
544
|
import_git returns $importStream |
|
545
|
test_eq import-git-returns [import_files returns returns] "cr.txt w, cut w" |
|
546
|
|
|
547
|
# A ref with nothing after its last slash, and one with no slash after |
|
548
|
# "refs/", name the branch as they stand. "property branch-nick" names the |
|
549
|
# branch of its commit; "property rebase-of" changes nothing. |
|
550
|
# |
|
551
|
set importStream [import_blob 1 "hello\n"] |
|
552
|
append importStream [import_commit refs/heads/ 2 slash "M 100644 :1 a\n"] |
|
553
|
append importStream [import_commit refs/x 3 short "M 100644 :1 a\n"] |
|
554
|
append importStream [import_commit refs/heads/master 4 nick \ |
|
555
|
"property branch-nick 7 nicked\nproperty rebase-of abc\nM 100644 :1 a\n"] |
|
556
|
import_git refs $importStream |
|
557
|
test_eq import-git-refs [import_sql refs \ |
|
558
|
"SELECT group_concat(comment||'='||value, ' ') |
|
559
|
FROM (SELECT comment, value FROM event, tagxref |
|
560
|
WHERE rid=objid AND tagxref.tagid=8 ORDER BY event.mtime)"] \ |
|
561
|
"slash=refs/heads/ short=refs/x nick=nicked" |
|
562
|
|
|
563
|
# A commit on a tag ref that has no parent gets no tag, and a commit with |
|
564
|
# no committer line makes no check-in. |
|
565
|
# |
|
566
|
set importStream [import_blob 1 "hello\n"] |
|
567
|
append importStream [import_commit refs/tags/t0 2 rootless "M 100644 :1 a\n"] |
|
568
|
append importStream "commit refs/tags/t1\nmark :3\ndata 6\nnobody\nfrom :2\n" |
|
569
|
import_git tagrefs $importStream |
|
570
|
test import-git-tagrefs {$CODE == 0} |
|
571
|
test_eq import-git-tagrefs-checkins [import_checkins tagrefs] rootless |
|
572
|
test_eq import-git-tagrefs-tags [import_tags tagrefs rootless] trunk |
|
573
|
|
|
574
|
# With --use-author the author of a commit is its user and the author's |
|
575
|
# time its date, and the committer counts only where there is no author. |
|
576
|
# Without the option the author line is passed over. |
|
577
|
# |
|
578
|
set importStream [import_blob 1 "hello\n"] |
|
579
|
append importStream "commit refs/heads/master\nmark :2\n" |
|
580
|
append importStream "author Au Thor <[email protected]> 1600000000 +0000\n" |
|
581
|
append importStream "committer C <[email protected]> 1700000000 +0000\n" |
|
582
|
append importStream "data 4\nboth\nM 100644 :1 a\n\n" |
|
583
|
append importStream [import_commit refs/heads/master 3 alone "M 100644 :1 b\n"] |
|
584
|
import_git author $importStream --use-author |
|
585
|
test_eq import-git-use-author [import_sql author "SELECT group_concat( |
|
586
|
comment||' '||user||' '||date(mtime), ', ') FROM event"] \ |
|
587
|
"both [email protected] 2020-09-13, alone [email protected] 2023-11-14" |
|
588
|
import_git noauthor $importStream |
|
589
|
test_eq import-git-no-use-author [import_sql noauthor "SELECT group_concat( |
|
590
|
comment||' '||user||' '||date(mtime), ', ') FROM event"] \ |
|
591
|
"both [email protected] 2023-11-14, alone [email protected] 2023-11-14" |
|
592
|
|
|
593
|
# The --rename options: master and trunk get the names given, and each |
|
594
|
# branch and tag name is put into its pattern in place of the "%". |
|
595
|
# |
|
596
|
set importStream [import_blob 1 "hello\n"] |
|
597
|
append importStream [import_commit refs/heads/master 2 first "M 100644 :1 a\n"] |
|
598
|
append importStream [import_commit refs/heads/side 3 second \ |
|
599
|
"from :2\nM 100644 :1 b\n"] |
|
600
|
append importStream "tag rel\nfrom :3\n$importTagger\n" |
|
601
|
import_git renamed $importStream --rename-master chief --rename-trunk stem \ |
|
602
|
--rename-branch "b-%-e" --rename-tag "t-%" |
|
603
|
test_eq import-git-rename-first [import_tags renamed first] "b-chief-e stem" |
|
604
|
test_eq import-git-rename-second [import_tags renamed second] \ |
|
605
|
"b-side-e stem t-rel" |
|
606
|
test_eq import-git-rename-main-branch [import_sql renamed \ |
|
607
|
"SELECT value FROM config WHERE name='main-branch'"] stem |
|
608
|
|
|
609
|
# Each row: the options and the error they must give. A rename pattern |
|
610
|
# needs exactly one "%"; --rename-rev belongs to --svn; the command takes |
|
611
|
# a repository and at most one input file; the input file must exist. |
|
612
|
# |
|
613
|
foreach {importName importOptions importError} { |
|
614
|
rename-no-percent {--rename-branch plain new.fossil names.fi} |
|
615
|
"missing '%' in argument to --rename-branch" |
|
616
|
rename-two-percent {--rename-tag a%b%c new.fossil names.fi} |
|
617
|
"multiple '%' in argument to --rename-tag" |
|
618
|
rename-rev {--rename-rev r% new.fossil names.fi} |
|
619
|
"unrecognized command-line option" |
|
620
|
no-repository {} |
|
621
|
"Usage: " |
|
622
|
three-arguments {new.fossil names.fi more} |
|
623
|
"Usage: " |
|
624
|
no-input-file {new.fossil no-such-file.fi} |
|
625
|
"cannot open input file" |
|
626
|
import-marks-missing {--import-marks no-such-file new.fossil names.fi} |
|
627
|
"cannot open no-such-file for reading" |
|
628
|
export-marks-directory {--export-marks . new.fossil names.fi} |
|
629
|
"cannot open . for writing" |
|
630
|
} { |
|
631
|
fossil_raw -seconds 60 import --git {*}$importOptions |
|
632
|
test import-git-option-$importName {$CODE == 1 && |
|
633
|
[string first $importError $RESULT] >= 0 && ![file exists new.fossil]} |
|
634
|
} |
|
635
|
|
|
636
|
# Each row: a stream and the error it must give. |
|
637
|
# |
|
638
|
foreach {importName importStream importError} [list \ |
|
639
|
unknown-command "bogus line\n" {bad fast-import line: [bogus line]} \ |
|
640
|
no-angle-bracket "commit refs/heads/master\ncommitter C 1700000000 +0000\n" \ |
|
641
|
{bad fast-import line: [committer C 1700000000 +0000]} \ |
|
642
|
no-open-bracket \ |
|
643
|
"commit refs/heads/master\ncommitter C [email protected]> 17 +0000\n" \ |
|
644
|
{bad fast-import line: [committer C [email protected]>} \ |
|
645
|
short-data "blob\nmark :1\ndata 50\nabc" \ |
|
646
|
{short read: got 3 of 50 bytes} \ |
|
647
|
] { |
|
648
|
import_git bad-$importName $importStream |
|
649
|
test import-git-bad-$importName {$CODE == 1 && |
|
650
|
[string first $importError $RESULT] >= 0} |
|
651
|
} |
|
652
|
|
|
653
|
# Without --force an existing repository is not written over, and the |
|
654
|
# command says so rather than give an error from the database. |
|
655
|
# |
|
656
|
fossil_raw -seconds 60 import --git names.fossil names.fi |
|
657
|
test import-git-exists {$CODE == 1 && [holds_strings $RESULT {!SQLITE_ERROR}]} |
|
658
|
test_eq import-git-exists-untouched [import_checkins names] "names fewer" |
|
659
|
|
|
660
|
# With --force an existing repository is replaced. The stream comes on |
|
661
|
# standard input when no file is named. |
|
662
|
# |
|
663
|
set importStream [import_blob 1 "hello\n"] |
|
664
|
append importStream [import_commit refs/heads/master 2 forced "M 100644 :1 a\n"] |
|
665
|
fossil_raw -seconds 60 -input $importStream import --git --force names.fossil |
|
666
|
test import-git-force {$CODE == 0} |
|
667
|
test_eq import-git-force-checkins [import_checkins names] forced |
|
668
|
|
|
669
|
# With --no-rebuild the check-ins are there and nothing is rebuilt or |
|
670
|
# vacuumed. |
|
671
|
# |
|
672
|
import_git norebuild $importStream --no-rebuild |
|
673
|
test import-git-no-rebuild {$CODE == 0 && |
|
674
|
[holds_strings $RESULT {!Rebuilding !Vacuuming}]} |
|
675
|
test_eq import-git-no-rebuild-checkins [import_checkins norebuild] forced |
|
676
|
|
|
677
|
|
|
678
|
# --attribute gives the user name for an email address, --export-marks |
|
679
|
# writes one line for each check-in and none for a file, and a later |
|
680
|
# import with --incremental and --import-marks goes on from those marks |
|
681
|
# and still knows the names. There, a committer whose name and address |
|
682
|
# are the contact information of a user is that user. |
|
683
|
# |
|
684
|
set importStream [import_blob 1 "hello\n"] |
|
685
|
append importStream [import_commit refs/heads/master 2 base "M 100644 :1 a\n"] |
|
686
|
import_git incr $importStream --attribute "[email protected] carol" \ |
|
687
|
--attribute [email protected] --export-marks incr.marks |
|
688
|
test import-git-attribute {$CODE == 0} |
|
689
|
test_eq import-git-attribute-user [import_sql incr \ |
|
690
|
"SELECT user FROM event WHERE comment='base'"] carol |
|
691
|
test_eq import-git-attribute-table [import_sql incr \ |
|
692
|
"SELECT group_concat(email||'='||user, ' ') FROM |
|
693
|
(SELECT email, user FROM fx_git ORDER BY email)"] \ |
|
694
|
"[email protected]=carol [email protected]=" |
|
695
|
test_eq import-git-export-marks [read_file incr.marks] "[import_sql incr \ |
|
696
|
"SELECT 'c'||rid||' :2 '||uuid FROM blob, event WHERE rid=objid"]\n" |
|
697
|
|
|
698
|
fossil sql -R incr.fossil "INSERT INTO user(login, pw, cap, info) |
|
699
|
VALUES('dee', '', 'i', 'Dee <[email protected]>')" |
|
700
|
set importStream [import_blob 1 "more\n"] |
|
701
|
append importStream "commit refs/heads/master\nmark :3\n" |
|
702
|
append importStream "committer Dee <[email protected]> 1700000180 +0000\n" |
|
703
|
append importStream "data 5\nlater\nfrom :2\nM 100644 :1 b\n\n" |
|
704
|
append importStream [import_commit refs/heads/master 4 last "M 100644 :1 c\n"] |
|
705
|
fossil_raw -seconds 60 -input $importStream import --git --incremental \ |
|
706
|
--import-marks incr.marks --export-marks incr2.marks incr.fossil |
|
707
|
test import-git-incremental {$CODE == 0 && |
|
708
|
[holds_strings $RESULT {!project-id !admin-user}]} |
|
709
|
test_eq import-git-incremental-parents \ |
|
710
|
"[import_parents incr later], [import_parents incr last]" "base, later" |
|
711
|
test_eq import-git-incremental-users [import_sql incr "SELECT group_concat( |
|
712
|
comment||'='||user, ' ') FROM (SELECT * FROM event ORDER BY mtime)"] \ |
|
713
|
"base=carol later=dee last=carol" |
|
714
|
test_eq import-git-incremental-files [import_files incr last] "a w, b w, c w" |
|
715
|
test_eq import-git-incremental-marks [lsort [split [string trim \ |
|
716
|
[read_file incr2.marks]] \n]] [lsort [split [import_sql incr \ |
|
717
|
"SELECT 'c'||rid||' :'||(1+(SELECT count(*) FROM event x |
|
718
|
WHERE x.mtime<=event.mtime))||' '||uuid FROM blob, event WHERE rid=objid"] \n]] |
|
719
|
|
|
720
|
# A third import adds another name to the ones kept in the repository. |
|
721
|
# |
|
722
|
set importStream "commit refs/heads/master\nmark :5\n" |
|
723
|
append importStream "committer E <[email protected]> 1700000500 +0000\n" |
|
724
|
append importStream "data 5\nthird\nfrom :4\n\n" |
|
725
|
fossil_raw -seconds 60 -input $importStream import --git --incremental \ |
|
726
|
--import-marks incr2.marks --attribute "[email protected] eve" incr.fossil |
|
727
|
test import-git-incremental-attribute {$CODE == 0} |
|
728
|
test_eq import-git-incremental-attribute-user [import_sql incr \ |
|
729
|
"SELECT user FROM event WHERE comment='third'"] eve |
|
730
|
test_eq import-git-incremental-attribute-table [import_sql incr \ |
|
731
|
"SELECT count(*) FROM fx_git"] 3 |
|
732
|
|
|
733
|
# A marks file whose hash is not the one of its artifact is refused. |
|
734
|
# |
|
735
|
write_file wrong.marks "c1 :2 [string repeat 0 40]\n" |
|
736
|
fossil_raw -seconds 60 -input $importStream import --git --incremental \ |
|
737
|
--import-marks wrong.marks incr.fossil |
|
738
|
test import-git-import-marks-wrong {$CODE == 1 && |
|
739
|
[string first "error importing marks from file: wrong.marks" $RESULT] >= 0} |
|
740
|
|
|
741
|
# A marks file that gives record number 0 to a hash the repository does |
|
742
|
# not hold is refused. |
|
743
|
# |
|
744
|
write_file zero.marks "c0 :5 [string repeat a 40]\n" |
|
745
|
set importStream [import_blob 1 "hello\n"] |
|
746
|
append importStream [import_commit refs/heads/master 2 orphan \ |
|
747
|
"from :5\nM 100644 :1 a\n"] |
|
748
|
fossil_raw -seconds 60 -input $importStream import --git \ |
|
749
|
--import-marks zero.marks zero.fossil |
|
750
|
test import-git-import-marks-zero {$CODE == 1 && |
|
751
|
[string first "error importing marks from file: zero.marks" $RESULT] >= 0} |
|
752
|
|
|
753
|
# Each row: a marks line that is not a commit or file mark of Fossil's, |
|
754
|
# which "fossil export --import-marks" refuses. |
|
755
|
# |
|
756
|
fossil init marks-export.fossil |
|
757
|
foreach {importName importLine} [list \ |
|
758
|
other-type "x5 junk" \ |
|
759
|
git-style ":1 [string repeat a 40]" \ |
|
760
|
other-zero "x0 junk" \ |
|
761
|
] { |
|
762
|
write_file bad-$importName.marks "$importLine\n" |
|
763
|
fossil_raw -seconds 60 export --git --import-marks bad-$importName.marks \ |
|
764
|
-R marks-export.fossil |
|
765
|
test import-export-marks-$importName {$CODE == 1 && [string first \ |
|
766
|
"error importing marks from file: bad-$importName.marks" $RESULT] >= 0} |
|
767
|
} |
|
768
|
|
|
769
|
# Marks may name a check-in made by "fossil commit", whose files carry no |
|
770
|
# permission, and the files of such a parent are kept. A commit whose |
|
771
|
# "from" is the mark of a file keeps nothing from it. |
|
772
|
# |
|
773
|
commit_file plain.txt "plain\n" committed |
|
774
|
fossil sql "SELECT 'c'||rid||' :7 '||uuid FROM blob |
|
775
|
WHERE rid=(SELECT objid FROM event WHERE comment='committed')" |
|
776
|
set importMarks "$RESULT\n" |
|
777
|
fossil sql "SELECT 'b'||rid||' :8 '||uuid FROM blob |
|
778
|
WHERE rid=(SELECT fid FROM mlink)" |
|
779
|
append importMarks "$RESULT\n" |
|
780
|
write_file plain.marks $importMarks |
|
781
|
set importStream [import_blob 1 "more\n"] |
|
782
|
append importStream [import_commit refs/heads/trunk 9 onto \ |
|
783
|
"from :7\nM 100644 :1 new.txt\n"] |
|
784
|
append importStream [import_commit refs/heads/other 10 onfile \ |
|
785
|
"from :8\nM 100644 :1 only.txt\n"] |
|
786
|
fossil_raw -seconds 60 -input $importStream import --git --incremental \ |
|
787
|
--import-marks plain.marks .rep.fossil |
|
788
|
test import-git-marks-commit {$CODE == 0} |
|
789
|
fossil sql "SELECT group_concat(f.filename||':'||f.perm, ' ') |
|
790
|
FROM event e, blob b, files_of_checkin(b.uuid) f |
|
791
|
WHERE e.comment='onto' AND b.rid=e.objid" |
|
792
|
test_eq import-git-marks-commit-files $RESULT "new.txt:w plain.txt:w" |
|
793
|
fossil sql "SELECT group_concat(f.filename, ' ') |
|
794
|
FROM event e, blob b, files_of_checkin(b.uuid) f |
|
795
|
WHERE e.comment='onfile' AND b.rid=e.objid" |
|
796
|
test_eq import-git-marks-file-files $RESULT only.txt |
|
797
|
|
|
798
|
# With neither --git nor --svn the input is a git stream, and its master |
|
799
|
# branch keeps its name. |
|
800
|
# |
|
801
|
set importStream [import_blob 1 "hello\n"] |
|
802
|
append importStream [import_commit refs/heads/master 2 first "M 100644 :1 a\n"] |
|
803
|
write_file default.fi $importStream |
|
804
|
fossil_raw -seconds 60 import default.fossil default.fi |
|
805
|
test import-default-format {$CODE == 0} |
|
806
|
test_eq import-default-format-checkins [import_checkins default] first |
|
807
|
test_eq import-default-format-tags [import_tags default first] "master trunk" |
|
808
|
|
|
809
|
# A ref of fewer than five bytes names its branch. |
|
810
|
# |
|
811
|
set importStream [import_blob 1 "hello\n"] |
|
812
|
append importStream [import_commit refs/heads/master 2 first \ |
|
813
|
"M 100644 :1 a-long-name-for-a-file\n"] |
|
814
|
append importStream [import_commit x 3 second "M 100644 :1 b\n"] |
|
815
|
import_git shortref $importStream |
|
816
|
test_eq import-git-short-ref [import_sql shortref "SELECT value |
|
817
|
FROM event, tagxref WHERE rid=objid AND tagxref.tagid=8 |
|
818
|
AND comment='second'"] x |
|
819
|
|
|
820
|
# A file command acts on a file that an earlier line of the same commit |
|
821
|
# made: D removes it, C copies it and R renames it. Fossil applies D, C |
|
822
|
# and R only to the files of the parent check-in: gone and old stay, dst |
|
823
|
# and new are not made. |
|
824
|
# |
|
825
|
set importStream [import_blob 1 "hello\n"] |
|
826
|
append importStream [import_commit refs/heads/master 2 ordered \ |
|
827
|
[join [list \ |
|
828
|
"M 100644 :1 gone\nD gone\nM 100644 :1 src\nC src dst\n" \ |
|
829
|
"M 100644 :1 old\nR old new\n"] ""]] |
|
830
|
import_git ordered $importStream |
|
831
|
test_eq import-git-ordered [import_files ordered ordered] \ |
|
832
|
"dst w, new w, src w" knownBug |
|
833
|
|
|
834
|
############################################################################### |
|
835
|
# "fossil import --svn" of dumps written here, record by record. |
|
836
|
|
|
837
|
# One record of a dump. HEADERS is a list of header names and values. |
|
838
|
# PROPS, unless it is "-", is a list of property names and values, and |
|
839
|
# TEXT, unless it is "-", is the content. |
|
840
|
# |
|
841
|
proc import_record {headers {props -} {text -}} { |
|
842
|
set h "" |
|
843
|
foreach {k v} $headers { append h "$k: $v\n" } |
|
844
|
set body "" |
|
845
|
if {$props ne "-"} { |
|
846
|
set body [import_props $props] |
|
847
|
append h "Prop-content-length: [string length $body]\n" |
|
848
|
} |
|
849
|
if {$text ne "-"} { |
|
850
|
append h "Text-content-length: [string length $text]\n" |
|
851
|
append body $text |
|
852
|
} |
|
853
|
return "${h}Content-length: [string length $body]\n\n$body\n\n" |
|
854
|
} |
|
855
|
|
|
856
|
# Revision N, made by dan on day N+1 of 2026, with LOG as its comment. |
|
857
|
# |
|
858
|
proc import_r {n log} { |
|
859
|
return [import_record [list Revision-number $n] [list svn:log $log \ |
|
860
|
svn:author dan svn:date [format 2026-01-%02dT00:00:00.000000Z \ |
|
861
|
[expr {$n+1}]]]] |
|
862
|
} |
|
863
|
proc import_file {action path text {props -}} { |
|
864
|
return [import_record \ |
|
865
|
[list Node-path $path Node-kind file Node-action $action] $props $text] |
|
866
|
} |
|
867
|
proc import_dir {path} { |
|
868
|
return [import_record [list Node-path $path Node-kind dir Node-action add]] |
|
869
|
} |
|
870
|
proc import_copy {kind path from rev {props -} {text -}} { |
|
871
|
return [import_record [list Node-path $path Node-kind $kind Node-action add \ |
|
872
|
Node-copyfrom-rev $rev Node-copyfrom-path $from] $props $text] |
|
873
|
} |
|
874
|
proc import_delete {path} { |
|
875
|
return [import_record [list Node-path $path Node-action delete]] |
|
876
|
} |
|
877
|
proc import_svn {name dump args} { |
|
878
|
write_file $name.dump $dump |
|
879
|
fossil_raw -seconds 60 import --svn {*}$args $name.fossil $name.dump |
|
880
|
} |
|
881
|
set importHead "SVN-fs-dump-format-version: 2\n\n" |
|
882
|
append importHead "UUID: 00000000-0000-0000-0000-000000000000\n\n" |
|
883
|
|
|
884
|
# A history in the usual layout. |
|
885
|
# 1 trunk gets a plain file, an executable, a link and a file in a |
|
886
|
# directory; two paths outside trunk, branches and tags are passed over |
|
887
|
# 2 no log and no author; a file changes, the executable changes with |
|
888
|
# no properties given, a directory has content and a file has a |
|
889
|
# change of properties only |
|
890
|
# 3 trunk is copied to branches/b1 |
|
891
|
# 4 a file changes on b1 |
|
892
|
# 5 trunk is copied to tags/v1 and to tags/v2 |
|
893
|
# 6 on trunk, a file is copied from b1, one from trunk, one from trunk |
|
894
|
# with a delta and one from trunk with new content |
|
895
|
# 7 a directory and a file are deleted and the executable is replaced |
|
896
|
# 8 a directory of trunk and the whole of trunk are copied into b1 |
|
897
|
# 9 a directory of trunk is copied to branches/b2 |
|
898
|
# 10 branches/b2 is deleted |
|
899
|
# 11 tags/v1 is deleted |
|
900
|
# 12 a file that does not exist is deleted |
|
901
|
# 13 a file gets the executable property and the content it had |
|
902
|
# 14 a file is added that sorts after every other |
|
903
|
# 15 branches/b3 is copied from trunk as of revision 0, and gets a file |
|
904
|
# |
|
905
|
set importDump $importHead |
|
906
|
append importDump [import_record {Revision-number 0} \ |
|
907
|
{svn:date 2026-01-01T00:00:00.000000Z}] |
|
908
|
append importDump [import_r 1 one] [import_dir trunk] [import_dir branches] \ |
|
909
|
[import_dir tags] [import_dir trunk/sub] \ |
|
910
|
[import_file add trunk/a.txt "alpha\n"] \ |
|
911
|
[import_file add trunk/run.sh "run\n" {svn:executable *}] \ |
|
912
|
[import_file add trunk/link "link a.txt" {svn:special *}] \ |
|
913
|
[import_file add trunk/sub/s.txt "sub\n"] \ |
|
914
|
[import_file add other/x "x\n"] [import_file add trunkx/y "y\n"] |
|
915
|
append importDump [import_record {Revision-number 2} \ |
|
916
|
{svn:date 2026-01-03T00:00:00.000000Z}] \ |
|
917
|
[import_file change trunk/a.txt "alpha2\n"] \ |
|
918
|
[import_file change trunk/run.sh "run2\n"] \ |
|
919
|
[import_record {Node-path trunk Node-kind dir Node-action change} - xyz] \ |
|
920
|
[import_file change trunk/sub/s.txt - {svn:eol-style native}] |
|
921
|
append importDump [import_r 3 three] [import_copy dir branches/b1 trunk 2] |
|
922
|
append importDump [import_r 4 four] \ |
|
923
|
[import_file change branches/b1/a.txt "beta\n"] |
|
924
|
append importDump [import_r 5 five] [import_copy dir tags/v1 trunk 4] \ |
|
925
|
[import_copy dir tags/v2 trunk 4] |
|
926
|
append importDump [import_r 6 six] \ |
|
927
|
[import_copy file trunk/b-copy.txt branches/b1/a.txt 4] \ |
|
928
|
[import_copy file trunk/a2.txt trunk/a.txt 2] \ |
|
929
|
[import_record {Node-path trunk/d.txt Node-kind file Node-action add |
|
930
|
Node-copyfrom-rev 2 Node-copyfrom-path trunk/a.txt Text-delta true} \ |
|
931
|
- "SVN\000[import_window 0 7 12 {0x07 0 0x85} "more\n"]"] \ |
|
932
|
[import_copy file trunk/e.txt trunk/a.txt 2 - "fresh\n"] |
|
933
|
append importDump [import_r 7 seven] [import_delete trunk/sub] \ |
|
934
|
[import_delete trunk/a.txt] [import_file replace trunk/run.sh "new run\n"] |
|
935
|
append importDump [import_r 8 eight] \ |
|
936
|
[import_copy dir branches/b1/sub2 trunk/sub 6] \ |
|
937
|
[import_copy dir branches/b1/tcopy trunk 7] |
|
938
|
append importDump [import_r 9 nine] [import_copy dir branches/b2 trunk/sub 6] |
|
939
|
append importDump [import_r 10 ten] [import_delete branches/b2] |
|
940
|
append importDump [import_r 11 eleven] [import_delete tags/v1] |
|
941
|
append importDump [import_r 12 twelve] [import_delete trunk/nothing] |
|
942
|
append importDump [import_r 13 thirteen] \ |
|
943
|
[import_file change trunk/run.sh "new run\n" {svn:executable *}] |
|
944
|
append importDump [import_r 14 fourteen] [import_file add trunk/zz.txt "z\n"] |
|
945
|
append importDump [import_r 15 fifteen] [import_copy dir branches/b3 trunk 0] \ |
|
946
|
[import_file add branches/b3/f.txt "f\n"] |
|
947
|
|
|
948
|
# The content of file PATH in the check-in of NAME with comment COMMENT. |
|
949
|
# |
|
950
|
proc import_cat {name comment path} { |
|
951
|
fossil_raw cat $path -R $name.fossil -r [import_sql $name "SELECT uuid |
|
952
|
FROM blob, event WHERE rid=objid AND type='ci' AND comment='$comment'"] |
|
953
|
return $::RESULT |
|
954
|
} |
|
955
|
|
|
956
|
import_svn layout $importDump |
|
957
|
test import-svn-layout {$CODE == 0} |
|
958
|
regexp {admin-user: (\S+)} $RESULT importAll importAdmin |
|
959
|
test_eq import-svn-layout-checkins [import_checkins layout] "one (no comment)\ |
|
960
|
three four six seven eight nine thirteen fourteen fifteen" |
|
961
|
test_eq import-svn-layout-users [import_sql layout "SELECT group_concat( |
|
962
|
user, ' ') FROM (SELECT user FROM event WHERE type='ci' |
|
963
|
ORDER BY mtime LIMIT 2)"] "dan $importAdmin" |
|
964
|
test_eq import-svn-layout-one [import_files layout one] \ |
|
965
|
"a.txt, link l, run.sh x, sub/s.txt" |
|
966
|
test_eq import-svn-layout-link [import_cat layout one link] a.txt |
|
967
|
test_eq import-svn-layout-two [import_files layout "(no comment)"] \ |
|
968
|
"a.txt, link l, run.sh x, sub/s.txt" |
|
969
|
test_eq import-svn-layout-two-content \ |
|
970
|
"[import_cat layout {(no comment)} a.txt][import_cat layout {(no comment)} run.sh]" \ |
|
971
|
"alpha2\nrun2\n" |
|
972
|
test_eq import-svn-layout-two-tags [import_tags layout "(no comment)"] \ |
|
973
|
"trunk v2" |
|
974
|
test_eq import-svn-layout-three [import_files layout three] \ |
|
975
|
"a.txt, link l, run.sh x, sub/s.txt" |
|
976
|
test_eq import-svn-layout-three-parent [import_parents layout three] \ |
|
977
|
"(no comment)" |
|
978
|
test_eq import-svn-layout-three-tags [import_tags layout three] b1 |
|
979
|
test_eq import-svn-layout-four [import_cat layout four a.txt] "beta\n" |
|
980
|
test_eq import-svn-layout-four-tags [import_tags layout four] b1 |
|
981
|
test_eq import-svn-layout-six [import_files layout six] \ |
|
982
|
"a.txt, a2.txt, b-copy.txt, d.txt, e.txt, link l, run.sh x, sub/s.txt" |
|
983
|
test_eq import-svn-layout-six-content \ |
|
984
|
"[import_cat layout six b-copy.txt][import_cat \ |
|
985
|
layout six a2.txt][import_cat layout six d.txt][import_cat layout six e.txt]" \ |
|
986
|
"beta\nalpha2\nalpha2\nmore\nfresh\n" |
|
987
|
test_eq import-svn-layout-six-parents [import_parents layout six] \ |
|
988
|
"(no comment) four" |
|
989
|
test_eq import-svn-layout-seven [import_files layout seven] \ |
|
990
|
"a2.txt, b-copy.txt, d.txt, e.txt, link l, run.sh" |
|
991
|
test_eq import-svn-layout-seven-content [import_cat layout seven run.sh] \ |
|
992
|
"new run\n" |
|
993
|
test_eq import-svn-layout-eight [import_files layout eight] "a.txt, link l,\ |
|
994
|
run.sh x, sub/s.txt, sub2/s.txt, tcopy/a2.txt, tcopy/b-copy.txt,\ |
|
995
|
tcopy/d.txt, tcopy/e.txt, tcopy/link l, tcopy/run.sh" |
|
996
|
test_eq import-svn-layout-eight-parents [import_parents layout eight] \ |
|
997
|
"four seven" |
|
998
|
test_eq import-svn-layout-nine [import_files layout nine] s.txt |
|
999
|
test_eq import-svn-layout-nine-parent [import_parents layout nine] six |
|
1000
|
test_eq import-svn-layout-nine-tags [import_tags layout nine] b2 |
|
1001
|
test_eq import-svn-layout-nine-closed [import_sql layout "SELECT count(*) |
|
1002
|
FROM tagxref, tag, event WHERE tag.tagid=tagxref.tagid AND tagname='closed' |
|
1003
|
AND tagxref.rid=objid AND comment='nine' AND tagtype>0"] 1 |
|
1004
|
test_eq import-svn-layout-thirteen [import_files layout thirteen] \ |
|
1005
|
"a2.txt, b-copy.txt, d.txt, e.txt, link l, run.sh x" |
|
1006
|
test_eq import-svn-layout-thirteen-parent [import_parents layout thirteen] seven |
|
1007
|
test_eq import-svn-layout-fourteen [import_files layout fourteen] \ |
|
1008
|
"a2.txt, b-copy.txt, d.txt, e.txt, link l, run.sh x, zz.txt" |
|
1009
|
test_eq import-svn-layout-fifteen [import_files layout fifteen] f.txt |
|
1010
|
test_eq import-svn-layout-fifteen-parent [import_parents layout fifteen] "" |
|
1011
|
test_eq import-svn-layout-fifteen-tags [import_tags layout fifteen] b3 |
|
1012
|
|
|
1013
|
|
|
1014
|
# The same history with --rev-tags and the --rename options. The trunk |
|
1015
|
# and every branch and tag get their names from the patterns, and a |
|
1016
|
# check-in that begins a branch or has two parents gets a tag made from |
|
1017
|
# its revision number and the --rename-rev pattern. |
|
1018
|
# |
|
1019
|
import_svn revtags $importDump --rev-tags --rename-rev R%x \ |
|
1020
|
--rename-branch br-% --rename-tag tg-% --rename-trunk main |
|
1021
|
test import-svn-revtags {$CODE == 0} |
|
1022
|
test import-svn-revtags-root {[holds_strings [import_tags revtags one] \ |
|
1023
|
{R1x br-main}]} |
|
1024
|
test import-svn-revtags-merge {[holds_strings [import_tags revtags six] \ |
|
1025
|
{R6x br-main}]} |
|
1026
|
test import-svn-revtags-new-root {[holds_strings \ |
|
1027
|
[import_tags revtags fifteen] {R15x br-b3 !br-main}]} |
|
1028
|
test_eq import-svn-revtags-main-branch [import_sql revtags \ |
|
1029
|
"SELECT value FROM config WHERE name='main-branch'"] main |
|
1030
|
set importTags [import_tags revtags "(no comment)"] |
|
1031
|
test import-svn-revtags-tag {"tg-v2" in $importTags} |
|
1032
|
|
|
1033
|
# Every other check-in gets such a tag too. Fossil adds none to them. |
|
1034
|
test import-svn-revtags-ordinary {"R2x" in $importTags} knownBug |
|
1035
|
test import-svn-revtags-branch {"R3x" in [import_tags revtags three]} knownBug |
|
1036
|
|
|
1037
|
# A tag whose directory is deleted is taken off its check-in. Fossil leaves |
|
1038
|
# tg-v1 on it. |
|
1039
|
test import-svn-revtags-tag-deleted {"tg-v1" ni $importTags} knownBug |
|
1040
|
|
|
1041
|
# A history under proj/ with other names for the three directories: trunk |
|
1042
|
# is proj/main, branches are in proj/br and tags in proj/tg. Revision 1 |
|
1043
|
# adds a file and an executable to the trunk and two files elsewhere, 2 |
|
1044
|
# copies the trunk to branch b1 and changes the file there, 3 copies b1 |
|
1045
|
# to tag v1, and 4 copies the executable on the trunk, and the file with |
|
1046
|
# the executable property set on the copy. |
|
1047
|
# |
|
1048
|
set importDump $importHead |
|
1049
|
append importDump [import_r 1 one] [import_dir proj] [import_dir proj/main] \ |
|
1050
|
[import_file add proj/main/a "a\n"] \ |
|
1051
|
[import_file add proj/main/run "run\n" {svn:executable *}] \ |
|
1052
|
[import_file add proj/other/x "x\n"] [import_file add elsewhere/y "y\n"] |
|
1053
|
append importDump [import_r 2 two] [import_copy dir proj/br/b1 proj/main 1] \ |
|
1054
|
[import_file change proj/br/b1/a "b\n"] |
|
1055
|
append importDump [import_r 3 three] [import_copy dir proj/tg/v1 proj/br/b1 2] |
|
1056
|
append importDump [import_r 4 four] \ |
|
1057
|
[import_copy file proj/main/run2 proj/main/run 1] \ |
|
1058
|
[import_copy file proj/main/run3 proj/main/a 1 {svn:executable *}] |
|
1059
|
|
|
1060
|
# The permission of file PATH in the check-in with comment COMMENT. |
|
1061
|
# |
|
1062
|
proc import_perm {name comment path} { |
|
1063
|
return [import_sql $name "SELECT coalesce(f.perm,'') |
|
1064
|
FROM event e, blob b, files_of_checkin(b.uuid) f WHERE e.type='ci' |
|
1065
|
AND e.comment='$comment' AND b.rid=e.objid AND f.filename='$path'"] |
|
1066
|
} |
|
1067
|
|
|
1068
|
# The directories are named with and without a slash at the end. |
|
1069
|
foreach {importName importOptions} { |
|
1070
|
named {--base proj --trunk main --branches br --tags tg} |
|
1071
|
named-slash {--base proj/ --trunk main/ --branches br/ --tags tg/} |
|
1072
|
} { |
|
1073
|
import_svn $importName $importDump {*}$importOptions |
|
1074
|
test import-svn-$importName {$CODE == 0} |
|
1075
|
test_eq import-svn-$importName-checkins [import_checkins $importName] \ |
|
1076
|
"one two four" |
|
1077
|
test_eq import-svn-$importName-one [import_files $importName one] "a, run x" |
|
1078
|
test_eq import-svn-$importName-two "[import_files $importName two];\ |
|
1079
|
[import_tags $importName two]; [import_cat $importName two a]" \ |
|
1080
|
"a, run x; b1 v1; b\n" |
|
1081
|
} |
|
1082
|
|
|
1083
|
test_eq import-svn-named-copy-props [import_perm named four run3] x |
|
1084
|
|
|
1085
|
# A file that is copied keeps the permission of the file it comes from. |
|
1086
|
test_eq import-svn-named-copy-perm [import_perm named four run2] x |
|
1087
|
|
|
1088
|
# With --flat every path is a file of the trunk. |
|
1089
|
import_svn flat $importDump --flat |
|
1090
|
test import-svn-flat {$CODE == 0} |
|
1091
|
test_eq import-svn-flat-files [import_files flat two] "elsewhere/y,\ |
|
1092
|
proj/br/b1/a, proj/br/b1/run x, proj/main/a, proj/main/run x, proj/other/x" |
|
1093
|
test_eq import-svn-flat-tags [import_tags flat two] trunk |
|
1094
|
test_eq import-svn-flat-copy-perm [import_perm flat four proj/main/run2] x |
|
1095
|
|
|
1096
|
# With --flat and --base the trunk holds the paths under the base, and |
|
1097
|
# the paths outside it are passed over. Fossil also puts a check-in on a |
|
1098
|
# branch "elsewhere". |
|
1099
|
import_svn flatbase $importDump --flat --base proj |
|
1100
|
test import-svn-flat-base {$CODE == 0} |
|
1101
|
test_eq import-svn-flat-base-files [import_files flatbase two] \ |
|
1102
|
"br/b1/a, br/b1/run x, main/a, main/run x, other/x" |
|
1103
|
test_eq import-svn-flat-base-branches [import_sql flatbase "SELECT |
|
1104
|
group_concat(DISTINCT value) FROM tagxref WHERE tagid=8"] trunk knownBug |
|
1105
|
|
|
1106
|
# A revision that copies a directory to another place on the same branch, |
|
1107
|
# and does nothing else, is a check-in with the files of the copy. |
|
1108
|
# |
|
1109
|
import_svn dircopy \ |
|
1110
|
"$importHead[import_r 1 one][import_file add trunk/d/f "f\n"][import_r \ |
|
1111
|
2 two][import_copy dir trunk/d2 trunk/d 1]" |
|
1112
|
test import-svn-dir-copy {$CODE == 0} |
|
1113
|
test_eq import-svn-dir-copy-files [import_files dircopy two] "d/f, d2/f" |
|
1114
|
|
|
1115
|
# --ignore-tree leaves out a directory and what is in it, on the trunk |
|
1116
|
# and on a branch, and no other path that begins with the same letters. |
|
1117
|
# An empty --ignore-tree names nothing. |
|
1118
|
# |
|
1119
|
set importDump $importHead |
|
1120
|
append importDump [import_r 1 one] [import_dir trunk] \ |
|
1121
|
[import_file add trunk/keep.txt "k\n"] [import_dir trunk/old] \ |
|
1122
|
[import_file add trunk/old/f.txt "f\n"] \ |
|
1123
|
[import_file add trunk/older.txt "o\n"] \ |
|
1124
|
[import_file add branches/dead/x.txt "x\n"] |
|
1125
|
import_svn ignore $importDump --ignore-tree trunk/old --ignore-tree "" \ |
|
1126
|
--ignore-tree branches/dead |
|
1127
|
test import-svn-ignore-tree {$CODE == 0} |
|
1128
|
test_eq import-svn-ignore-tree-files [import_files ignore one] \ |
|
1129
|
"keep.txt, older.txt" |
|
1130
|
test_eq import-svn-ignore-tree-checkins [import_sql ignore \ |
|
1131
|
"SELECT count(*) FROM event"] 1 |
|
1132
|
|
|
1133
|
# --incremental adds to a repository that exists, and tags each new |
|
1134
|
# check-in with its revision number unless --no-rev-tags is given. |
|
1135
|
# |
|
1136
|
import_svn sincr "$importHead[import_r 1 one][import_file add trunk/a "a\n"]" |
|
1137
|
write_file sincr2.dump \ |
|
1138
|
"$importHead[import_r 2 two][import_file add trunk/b "b\n"]" |
|
1139
|
fossil_raw -seconds 60 import --svn --incremental sincr.fossil sincr2.dump |
|
1140
|
test import-svn-incremental \ |
|
1141
|
{$CODE == 0 && [holds_strings $RESULT {!project-id}]} |
|
1142
|
fossil_raw -seconds 60 -input \ |
|
1143
|
"$importHead[import_r 3 three][import_file add trunk/c "c\n"]" \ |
|
1144
|
import --svn --incremental --no-rev-tags sincr.fossil |
|
1145
|
test import-svn-incremental-no-rev-tags {$CODE == 0} |
|
1146
|
test_eq import-svn-incremental-checkins [import_checkins sincr] "one two three" |
|
1147
|
test_eq import-svn-incremental-tags "[import_tags sincr one];\ |
|
1148
|
[import_tags sincr two]; [import_tags sincr three]" \ |
|
1149
|
"trunk; svn-rev-2 trunk; trunk" |
|
1150
|
|
|
1151
|
# A revision with no date gets the time of the import. A property block |
|
1152
|
# may hold the name of a deleted property. The record after the version |
|
1153
|
# need not be the UUID. |
|
1154
|
# |
|
1155
|
set importProps "D 3\nfoo\nK 7\nsvn:log\nV 7\nundated\nPROPS-END\n" |
|
1156
|
set importDump "SVN-fs-dump-format-version: 3\n\nOther: 1\n\n" |
|
1157
|
append importDump "Revision-number: 1\n" |
|
1158
|
append importDump "Prop-content-length: [string length $importProps]\n" |
|
1159
|
append importDump \ |
|
1160
|
"Content-length: [string length $importProps]\n\n$importProps\n" |
|
1161
|
append importDump [import_file add trunk/a "a\n"] |
|
1162
|
import_svn undated $importDump |
|
1163
|
test import-svn-undated {$CODE == 0} |
|
1164
|
test_eq import-svn-undated-checkin [import_sql undated "SELECT comment||' '|| |
|
1165
|
(mtime>julianday('now','-1 day')) FROM event"] "undated 1" |
|
1166
|
|
|
1167
|
# A dump that is the version record and nothing else has no check-in. |
|
1168
|
import_svn version-only "SVN-fs-dump-format-version: 2\n\n" |
|
1169
|
test import-svn-version-only {$CODE == 0} |
|
1170
|
test_eq import-svn-version-only-checkins [import_sql version-only \ |
|
1171
|
"SELECT count(*) FROM event"] 0 |
|
1172
|
|
|
1173
|
# Each row: a dump and the error it must give. |
|
1174
|
# |
|
1175
|
set importR1 "$importHead[import_r 1 one]" |
|
1176
|
set importA "$importR1[import_file add trunk/a "a\n"]" |
|
1177
|
foreach {importName importDump importError} [list \ |
|
1178
|
empty "" "Input is not an svn-dump!" \ |
|
1179
|
no-version "Other: 1\n\n" "Input is not an svn-dump!" \ |
|
1180
|
version-4 "SVN-fs-dump-format-version: 4\n\n" \ |
|
1181
|
"Unknown svn-dump format version: 4" \ |
|
1182
|
no-colon "${importHead}no colon here\n\n" {bad header line: [no colon here]} \ |
|
1183
|
ends-in-headers "${importHead}Revision-number: 1\n" \ |
|
1184
|
"svn-dump data ended unexpectedly" \ |
|
1185
|
props-short \ |
|
1186
|
"${importHead}Revision-number: 1\nProp-content-length: 50\n\nPROPS-END\n" \ |
|
1187
|
"short read: got 10 of 50 bytes" \ |
|
1188
|
props-no-end \ |
|
1189
|
[join [list \ |
|
1190
|
"${importHead}Revision-number: 1\nProp-content-length: 12\n\n" \ |
|
1191
|
"K 1\na\nV 1\nb\n"] ""] \ |
|
1192
|
"svn-dump data ended unexpectedly" \ |
|
1193
|
props-negative \ |
|
1194
|
"${importHead}Revision-number: 1\nProp-content-length: -5\n\n" \ |
|
1195
|
"svn-dump data format broken" \ |
|
1196
|
text-short \ |
|
1197
|
[join [list \ |
|
1198
|
"${importR1}Node-path: trunk/a\nNode-kind: file\n" \ |
|
1199
|
"Node-action: add\nText-content-length: 9\n\nabc"] ""] \ |
|
1200
|
"short read: got 3 of 9 bytes" \ |
|
1201
|
unknown-record "${importHead}Other: 1\n\n" "Unknown record type" \ |
|
1202
|
rev-over-31-bits "$importHead[import_record {Revision-number 2147483648}]" \ |
|
1203
|
"svn-dump data format broken" \ |
|
1204
|
rev-eleven-digits "$importHead[import_record {Revision-number 21474836480}]" \ |
|
1205
|
"svn-dump data format broken" \ |
|
1206
|
node-before-revision "$importHead[import_file add trunk/a "a\n"]" \ |
|
1207
|
"svn-dump data format broken" \ |
|
1208
|
no-copyfrom-rev "$importA[import_record {Node-path trunk/b Node-kind file |
|
1209
|
Node-action add Node-copyfrom-path trunk/a}]" "Missing copyfrom-rev" \ |
|
1210
|
copy-from-outside "$importA[import_copy file trunk/b other/a 1]" \ |
|
1211
|
"Copy from path outside the import paths" \ |
|
1212
|
add-no-kind \ |
|
1213
|
"$importR1[import_record {Node-path trunk/a Node-action add} - x]" \ |
|
1214
|
"Missing Node-kind" \ |
|
1215
|
change-no-kind \ |
|
1216
|
"$importA[import_record {Node-path trunk/a Node-action change} - x]" \ |
|
1217
|
"Missing Node-kind" \ |
|
1218
|
unknown-action "$importR1[import_record {Node-path trunk/a Node-kind file |
|
1219
|
Node-action frobnicate}]" "Unknown Node-action" \ |
|
1220
|
short-link "$importR1[import_file add trunk/l "link " {svn:special *}]" \ |
|
1221
|
"Too short symbolic link path" \ |
|
1222
|
delta-too-short "$importR1[import_record {Node-path trunk/a Node-kind file |
|
1223
|
Node-action add Text-delta true} - SVN]" "Invalid svndiff0 format" \ |
|
1224
|
delta-no-source "$importR1[import_record {Node-path trunk/a Node-kind file |
|
1225
|
Node-action add Text-delta true} - \ |
|
1226
|
"SVN\000[import_window 0 5 5 {0x05 0} {}]"]" \ |
|
1227
|
"Don't know how to handle NULL input" \ |
|
1228
|
] { |
|
1229
|
import_svn bad-$importName $importDump |
|
1230
|
test import-svn-bad-$importName {$CODE == 1 && |
|
1231
|
[string first $importError $RESULT] >= 0} |
|
1232
|
} |
|
1233
|
|
|
1234
|
# Each row: the bytes of a property block before its end mark, which make |
|
1235
|
# the block malformed. A length may be negative, reach past the block or |
|
1236
|
# not be followed by a newline, a zero byte may come before the newline |
|
1237
|
# or stand in place of the space after the letter, and a line may begin |
|
1238
|
# with a letter other than D, K and V. |
|
1239
|
# |
|
1240
|
foreach {importName importProps} [list \ |
|
1241
|
d-zero-byte "D 1\000\000" \ |
|
1242
|
d-zero-space "D\0001\na\n" \ |
|
1243
|
d-no-newline "D 1" \ |
|
1244
|
d-negative "D -1\nab\n" \ |
|
1245
|
d-too-long "D 99\nab\n" \ |
|
1246
|
not-k "X 1\na\n" \ |
|
1247
|
k-zero-space "K\0001\na\nV 1\nb\n" \ |
|
1248
|
k-no-newline "K 1" \ |
|
1249
|
k-negative "K -1\na\n" \ |
|
1250
|
k-no-end "K 2\nabcd\nV 1\nb\n" \ |
|
1251
|
not-v "K 1\na\nX 1\nb\n" \ |
|
1252
|
v-zero-byte "K 1\na\nV 1\000\000" \ |
|
1253
|
v-zero-space "K 1\na\nV\0001\nb\n" \ |
|
1254
|
v-no-newline "K 1\na\nV 1" \ |
|
1255
|
v-no-end "K 1\na\nV 1\nbcd\n" \ |
|
1256
|
] { |
|
1257
|
append importProps "PROPS-END\n" |
|
1258
|
set importLength [string length $importProps] |
|
1259
|
import_svn props-$importName \ |
|
1260
|
[join [list \ |
|
1261
|
"${importHead}Revision-number: 1\n" \ |
|
1262
|
"Prop-content-length: $importLength\n" \ |
|
1263
|
"Content-length: $importLength\n\n$importProps\n"] ""] |
|
1264
|
test import-svn-props-$importName {$CODE == 1 && |
|
1265
|
[string first "svn-dump data format broken" $RESULT] >= 0} |
|
1266
|
} |
|
1267
|
|
|
1268
|
# A history with nodes that make no check-in of their own. |
|
1269
|
# 1 trunk gets a file and an executable; a file named "branches", and |
|
1270
|
# a file directly in branches and one directly in tags, are passed over |
|
1271
|
# 2 the executable is copied four times: with its properties given in |
|
1272
|
# full and none of them svn:executable, with a property delta that |
|
1273
|
# changes nothing, with "Prop-delta: false", and with no properties |
|
1274
|
# 3 a tag and a branch that were never made are deleted, and so is a |
|
1275
|
# file of another tag that was never made |
|
1276
|
# 4 trunk is deleted |
|
1277
|
# 5 trunk is copied from trunk as of revision 1 |
|
1278
|
# 6 a file of trunk changes |
|
1279
|
# |
|
1280
|
set importDump $importHead |
|
1281
|
append importDump [import_r 1 one] [import_dir trunk] [import_dir branches] \ |
|
1282
|
[import_dir tags] [import_file add trunk/a.txt "a\n"] \ |
|
1283
|
[import_file add trunk/run.sh "run\n" {svn:executable *}] \ |
|
1284
|
[import_file add branches "a file\n"] \ |
|
1285
|
[import_file add branches/README "a file\n"] \ |
|
1286
|
[import_file add tags/README "a file\n"] |
|
1287
|
append importDump [import_r 2 two] \ |
|
1288
|
[import_copy file trunk/full trunk/run.sh 1 {}] \ |
|
1289
|
[import_record {Node-path trunk/delta Node-kind file Node-action add |
|
1290
|
Node-copyfrom-rev 1 Node-copyfrom-path trunk/run.sh |
|
1291
|
Prop-delta true} {}] \ |
|
1292
|
[import_record {Node-path trunk/nodelta Node-kind file Node-action add |
|
1293
|
Node-copyfrom-rev 1 Node-copyfrom-path trunk/run.sh |
|
1294
|
Prop-delta false} {}] \ |
|
1295
|
[import_copy file trunk/none trunk/run.sh 1] |
|
1296
|
append importDump [import_r 3 three] [import_delete tags/never] \ |
|
1297
|
[import_delete tags/never2/file] [import_delete branches/never] |
|
1298
|
append importDump [import_r 4 four] [import_delete trunk] |
|
1299
|
append importDump [import_r 5 five] [import_copy dir trunk trunk 1] |
|
1300
|
append importDump [import_r 6 six] [import_file change trunk/a.txt "b\n"] |
|
1301
|
import_svn quiet-nodes $importDump |
|
1302
|
test import-svn-quiet-nodes {$CODE == 0} |
|
1303
|
test_eq import-svn-quiet-nodes-checkins [import_checkins quiet-nodes] \ |
|
1304
|
"one two six" |
|
1305
|
test_eq import-svn-quiet-nodes-one [import_files quiet-nodes one] \ |
|
1306
|
"a.txt, run.sh x" |
|
1307
|
|
|
1308
|
# A copied file keeps the executable permission of its source when the |
|
1309
|
# node gives no properties or only a property delta. |
|
1310
|
test_eq import-svn-copy-props [import_files quiet-nodes two] \ |
|
1311
|
"a.txt, delta x, full, nodelta, none x, run.sh x" |
|
1312
|
|
|
1313
|
# Nothing is left of the tags and the branch that were never made: the |
|
1314
|
# timeline holds the three check-ins and the tag that closes trunk when |
|
1315
|
# it is deleted. |
|
1316
|
test_eq import-svn-never-made [import_sql quiet-nodes "SELECT count(*) |
|
1317
|
FROM tag WHERE tagname GLOB 'sym-never*' OR tagname GLOB 'sym-README*'"] 0 |
|
1318
|
test_eq import-svn-never-made-events [import_sql quiet-nodes "SELECT |
|
1319
|
group_concat(type, ' ') FROM (SELECT type FROM event ORDER BY mtime)"] \ |
|
1320
|
"ci ci g ci" |
|
1321
|
|
|
1322
|
# Trunk as copied from revision 1 has the files of revision 1 again, and |
|
1323
|
# the next check-in on it follows the last one made there. |
|
1324
|
test_eq import-svn-trunk-copied "[import_files quiet-nodes six];\ |
|
1325
|
[import_cat quiet-nodes six a.txt]; [import_parents quiet-nodes six];\ |
|
1326
|
[import_tags quiet-nodes six]" "a.txt, run.sh x; b\n; two; trunk" |
|
1327
|
|
|
1328
|
# A path that a check-in cannot hold is refused, or else every revision |
|
1329
|
# becomes a check-in. |
|
1330
|
# |
|
1331
|
import_svn odd-path "$importR1[import_file add trunk/./a "a\n"][import_r 2 \ |
|
1332
|
two][import_file add trunk/b "b\n"]" |
|
1333
|
test import-svn-odd-path {$CODE == 1 && |
|
1334
|
[string first "svn path is not a valid file name" $RESULT] >= 0} |
|
1335
|
|
|
1336
|
# So is a file that is added with no content and no source. |
|
1337
|
# |
|
1338
|
import_svn no-content "$importR1[import_file add trunk/a "a\n"][import_record \ |
|
1339
|
{Node-path trunk/n Node-kind file Node-action add}]" |
|
1340
|
test import-svn-no-content {$CODE == 1 && |
|
1341
|
[string first "svn file has no content and no source" $RESULT] >= 0} |
|
1342
|
|
|
1343
|
############################################################################### |
|
1344
|
# A history made by Subversion, dumped with and without deltas: files, an |
|
1345
|
# executable and a link on the trunk, a branch and a tag copied from it, |
|
1346
|
# a change, a renamed file, and the branch deleted. |
|
1347
|
|
|
1348
|
if {$::is_windows} { |
|
1349
|
test_skip_part "the history made by Subversion needs links and file modes" |
|
1350
|
} elseif {[catch {exec svnadmin --version --quiet}] || [catch \ |
|
1351
|
{exec svn --version --quiet}]} { |
|
1352
|
test_skip_part "svnadmin and svn are not installed" |
|
1353
|
} else { |
|
1354
|
set importRepo [file join [pwd] svnrepo2] |
|
1355
|
set importUrl file://$importRepo |
|
1356
|
exec svnadmin create $importRepo |
|
1357
|
exec svn mkdir -q -m layout $importUrl/trunk $importUrl/branches \ |
|
1358
|
$importUrl/tags |
|
1359
|
exec svn checkout -q $importUrl/trunk svnwc2 |
|
1360
|
write_file svnwc2/a.txt "alpha\n" |
|
1361
|
write_file svnwc2/run.sh "run\n" |
|
1362
|
file link -symbolic svnwc2/link a.txt |
|
1363
|
exec svn add -q svnwc2/a.txt svnwc2/run.sh svnwc2/link |
|
1364
|
exec svn propset -q svn:executable on svnwc2/run.sh |
|
1365
|
exec svn commit -q -m one svnwc2 |
|
1366
|
exec svn copy -q -m two $importUrl/trunk $importUrl/branches/b1 |
|
1367
|
exec svn copy -q -m three $importUrl/trunk $importUrl/tags/v1 |
|
1368
|
write_file svnwc2/a.txt "alpha2\n" |
|
1369
|
exec svn move -q svnwc2/run.sh svnwc2/moved.sh |
|
1370
|
exec svn commit -q -m four svnwc2 |
|
1371
|
exec svn delete -q -m five $importUrl/branches/b1 |
|
1372
|
foreach {importName importOption} {plain {} deltas --deltas} { |
|
1373
|
exec svnadmin dump -q {*}$importOption $importRepo > svn-$importName.dump |
|
1374
|
fossil_raw -seconds 60 import --svn svn-$importName.fossil \ |
|
1375
|
svn-$importName.dump |
|
1376
|
test import-svn-made-$importName {$CODE == 0} |
|
1377
|
set importName svn-$importName |
|
1378
|
test_eq import-$importName-checkins [import_checkins $importName] \ |
|
1379
|
"one two four" |
|
1380
|
test_eq import-$importName-one "[import_files $importName one];\ |
|
1381
|
[import_cat $importName one link]; [import_tags $importName one]" \ |
|
1382
|
"a.txt, link l, run.sh x; a.txt; trunk v1" |
|
1383
|
test_eq import-$importName-two "[import_parents $importName two];\ |
|
1384
|
[import_tags $importName two]; [import_sql $importName "SELECT count(*) |
|
1385
|
FROM tagxref, tag, event WHERE tag.tagid=tagxref.tagid |
|
1386
|
AND tagname='closed' AND tagxref.rid=objid AND comment='two'"]" \ |
|
1387
|
"one; b1; 1" |
|
1388
|
test_eq import-$importName-four "[import_sql $importName "SELECT |
|
1389
|
group_concat(f.filename, ' ') FROM event e, blob b, |
|
1390
|
files_of_checkin(b.uuid) f WHERE e.comment='four' AND b.rid=e.objid"];\ |
|
1391
|
[import_cat $importName four a.txt]" "a.txt link moved.sh; alpha2\n" |
|
1392
|
test_eq import-$importName-four-perm \ |
|
1393
|
[import_perm $importName four moved.sh] x |
|
1394
|
} |
|
1395
|
} |
|
1396
|
|
|
1397
|
############################################################################### |
|
1398
|
# A history made by git and written by "git fast-export": files whose |
|
1399
|
# names git puts in quotes, an executable and a link, a branch, a renamed |
|
1400
|
# file, a merge, a tag with a message, and a file removed. |
|
1401
|
|
|
1402
|
if {$::is_windows} { |
|
1403
|
test_skip_part "the history made by git needs links and file modes" |
|
1404
|
} elseif {[catch {exec git --version}]} { |
|
1405
|
test_skip_part "git is not installed" |
|
1406
|
} else { |
|
1407
|
# Run git in the repository as if on day DAY of January 2026. |
|
1408
|
proc import_git_run {day args} { |
|
1409
|
set ::env(GIT_AUTHOR_DATE) "2026-01-0$day 00:00:00 +0000" |
|
1410
|
set ::env(GIT_COMMITTER_DATE) $::env(GIT_AUTHOR_DATE) |
|
1411
|
set out [exec git -C gitrepo -c user.name=Tester \ |
|
1412
|
-c [email protected] {*}$args 2>@1] |
|
1413
|
unset ::env(GIT_AUTHOR_DATE) ::env(GIT_COMMITTER_DATE) |
|
1414
|
return $out |
|
1415
|
} |
|
1416
|
exec git -c init.defaultBranch=master init -q gitrepo 2>@1 |
|
1417
|
foreach importName [list a.txt run.sh "sp ace.txt" "q\"uote.txt" \ |
|
1418
|
"t\tab.txt"] { |
|
1419
|
write_file [file join gitrepo $importName] "content of $importName\n" |
|
1420
|
} |
|
1421
|
file attributes gitrepo/run.sh -permissions 0755 |
|
1422
|
file link -symbolic gitrepo/link a.txt |
|
1423
|
import_git_run 1 add -A |
|
1424
|
import_git_run 1 commit -q -m one |
|
1425
|
import_git_run 2 checkout -q -b side |
|
1426
|
write_file gitrepo/side.txt "side\n" |
|
1427
|
import_git_run 2 add side.txt |
|
1428
|
import_git_run 2 commit -q -m two |
|
1429
|
import_git_run 3 checkout -q master |
|
1430
|
import_git_run 3 mv a.txt moved.txt |
|
1431
|
import_git_run 3 commit -q -m three |
|
1432
|
import_git_run 4 merge -q --no-ff -m four side |
|
1433
|
import_git_run 5 tag -a -m "tag message" v1 |
|
1434
|
import_git_run 6 rm -q run.sh |
|
1435
|
import_git_run 6 commit -q -m five |
|
1436
|
write_file made.fi [import_git_run 7 fast-export --all -M] |
|
1437
|
fossil_raw -seconds 60 import --git made.fossil made.fi |
|
1438
|
test import-git-made {$CODE == 0} |
|
1439
|
test_eq import-git-made-checkins [import_checkins made] \ |
|
1440
|
"one two three four five" |
|
1441
|
test_eq import-git-made-one [import_files made one] "a.txt w, link l,\ |
|
1442
|
q\"uote.txt w, run.sh x, sp ace.txt w, t\tab.txt w" |
|
1443
|
test_eq import-git-made-one-content \ |
|
1444
|
"[import_cat made one link]; [import_cat made one {sp ace.txt}]" \ |
|
1445
|
"a.txt; content of sp ace.txt\n" |
|
1446
|
test_eq import-git-made-three [import_files made three] "link l,\ |
|
1447
|
moved.txt w a.txt, q\"uote.txt w, run.sh x, sp ace.txt w, t\tab.txt w" |
|
1448
|
test_eq import-git-made-four "[import_parents made four];\ |
|
1449
|
[import_sql made "SELECT user FROM event WHERE comment='four'"]" \ |
|
1450
|
"three two; [email protected]" |
|
1451
|
test import-git-made-four-tag {"v1" in [import_tags made four]} |
|
1452
|
test_eq import-git-made-tag-message [import_sql made "SELECT value |
|
1453
|
FROM tagxref WHERE tagid=(SELECT tagid FROM tag WHERE tagname='sym-v1') |
|
1454
|
AND tagtype=1 AND value IS NOT NULL"] "tag message" |
|
1455
|
test_eq import-git-made-five [import_files made five] "link l,\ |
|
1456
|
moved.txt w, q\"uote.txt w, side.txt w, sp ace.txt w, t\tab.txt w" |
|
1457
|
test_eq import-git-made-five-tags [import_tags made five] "master trunk" |
|
1458
|
} |
|
1459
|
|
|
1460
|
############################################################################### |
|
1461
|
|
|
1462
|
test_cleanup |
|
1463
|
|