t98xx: fix Perforce tests with p4d r23 and newer

Some of the tests in t98xx modify the Perforce depot in ways that the tool wouldn't normally allow. This is done to test behaviour of git-p4 in certain edge cases that we have observed in the wild, but which should in theory not be possible. Naturally, modifying the depot on disk directly is quite intimate with the tool and thus prone to breakage when Perforce updates the way that data is stored. And indeed, those tests are broken nowadays with r23 of Perforce. While a file revision was previously stored as a plain file "depot/file,v", it is now stored in a directory "depot/file,d" with compression. Adapt those tests to handle both old- and new-style depot layouts. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 31, 2024 at 12:37 UTC 49f4fd901a97863c6458acaa0904b940dc827c40
3 files changed +48 -8
t/t9800-git-p4-basic.sh
+14 -2
@@ -297,8 +297,20 @@ test_expect_success 'exit when p4 fails to produce marshaled output' '
297 # p4 changes, files, or describe; just in p4 print. If P4CLIENT is unset, the
298 # message will include "Librarian checkout".
299 test_expect_success 'exit gracefully for p4 server errors' '
300 - test_when_finished "mv \"$db\"/depot/file1,v,hidden \"$db\"/depot/file1,v" &&
301 - mv "$db"/depot/file1,v "$db"/depot/file1,v,hidden &&
300 + # Note that newer Perforce versions started to store files
301 + # compressed in directories. The case statement handles both
302 + # old and new layout.
303 + case "$(echo "$db"/depot/file1*)" in
304 + *,v)
305 + test_when_finished "mv \"$db\"/depot/file1,v,hidden \"$db\"/depot/file1,v" &&
306 + mv "$db"/depot/file1,v "$db"/depot/file1,v,hidden;;
307 + *,d)
308 + path="$(echo "$db"/depot/file1,d/*.gz)" &&
309 + test_when_finished "mv \"$path\",hidden \"$path\"" &&
310 + mv "$path" "$path",hidden;;
311 + *)
312 + BUG "unhandled p4d layout";;
313 + esac &&
314 test_when_finished cleanup_git &&
315 test_expect_code 1 git p4 clone --dest="$git" //depot@1 >out 2>err &&
316 test_grep "Error from p4 print" err
t/t9802-git-p4-filetype.sh
+15 -3
@@ -300,10 +300,22 @@ test_expect_success SYMLINKS 'empty symlink target' '
300 # text
301 # @@
302 #
303 + # Note that newer Perforce versions started to store files
304 + # compressed in directories. The case statement handles both
305 + # old and new layout.
306 cd "$db/depot" &&
304 - sed "/@target1/{; s/target1/@/; n; d; }" \
305 - empty-symlink,v >empty-symlink,v.tmp &&
306 - mv empty-symlink,v.tmp empty-symlink,v
307 + case "$(echo empty-symlink*)" in
308 + empty-symlink,v)
309 + sed "/@target1/{; s/target1/@/; n; d; }" \
310 + empty-symlink,v >empty-symlink,v.tmp &&
311 + mv empty-symlink,v.tmp empty-symlink,v;;
312 + empty-symlink,d)
313 + path="empty-symlink,d/$(ls empty-symlink,d/ | tail -n1)" &&
314 + rm "$path" &&
315 + gzip </dev/null >"$path";;
316 + *)
317 + BUG "unhandled p4d layout";;
318 + esac
319 ) &&
320 (
321 # Make sure symlink really is empty. Asking
t/t9825-git-p4-handle-utf16-without-bom.sh
+19 -3
@@ -22,9 +22,25 @@ test_expect_success 'init depot with UTF-16 encoded file and artificially remove
22 cd db &&
23 p4d -jc &&
24 # P4D automatically adds a BOM. Remove it here to make the file invalid.
25 - sed -e "\$d" depot/file1,v >depot/file1,v.new &&
26 - mv depot/file1,v.new depot/file1,v &&
27 - printf "@$UTF16@" >>depot/file1,v &&
25 + #
26 + # Note that newer Perforce versions started to store files
27 + # compressed in directories. The case statement handles both
28 + # old and new layout.
29 + case "$(echo depot/file1*)" in
30 + depot/file1,v)
31 + sed -e "\$d" depot/file1,v >depot/file1,v.new &&
32 + mv depot/file1,v.new depot/file1,v &&
33 + printf "@$UTF16@" >>depot/file1,v;;
34 + depot/file1,d)
35 + path="$(echo depot/file1,d/*.gz)" &&
36 + gunzip -c "$path" >"$path.unzipped" &&
37 + sed -e "\$d" "$path.unzipped" >"$path.new" &&
38 + printf "$UTF16" >>"$path.new" &&
39 + gzip -c "$path.new" >"$path" &&
40 + rm "$path.unzipped" "$path.new";;
41 + *)
42 + BUG "unhandled p4d layout";;
43 + esac &&
44 p4d -jrF checkpoint.1
45 )
46 '