@@ -236,27 +236,38 @@ hello_size=$(strlen "$hello_content")
236236hello_oid=$( echo_without_newline " $hello_content " | git hash-object --stdin)
237237
238238test_expect_success " setup" '
239+ git config core.repositoryformatversion 1 &&
240+ git config extensions.objectformat $test_hash_algo &&
241+ git config extensions.compatobjectformat $test_compat_hash_algo &&
239242 echo_without_newline "$hello_content" > hello &&
240243 git update-index --add hello
241244'
242245
243- run_tests ' blob' $hello_oid $hello_size " $hello_content " " $hello_content "
246+ run_blob_tests () {
247+ oid=$1
244248
245- test_expect_success ' --batch-command --buffer with flush for blob info' '
246- echo "$hello_oid blob $hello_size" >expect &&
247- test_write_lines "info $hello_oid" "flush" |
249+ run_tests ' blob' $oid $hello_size " $hello_content " " $hello_content "
250+
251+ test_expect_success ' --batch-command --buffer with flush for blob info' '
252+ echo "$oid blob $hello_size" >expect &&
253+ test_write_lines "info $oid" "flush" |
248254 GIT_TEST_CAT_FILE_NO_FLUSH_ON_EXIT=1 \
249255 git cat-file --batch-command --buffer >actual &&
250256 test_cmp expect actual
251- '
257+ '
252258
253- test_expect_success ' --batch-command --buffer without flush for blob info' '
259+ test_expect_success ' --batch-command --buffer without flush for blob info' '
254260 touch output &&
255- test_write_lines "info $hello_oid " |
261+ test_write_lines "info $oid " |
256262 GIT_TEST_CAT_FILE_NO_FLUSH_ON_EXIT=1 \
257263 git cat-file --batch-command --buffer >>output &&
258264 test_must_be_empty output
259- '
265+ '
266+ }
267+
268+ hello_compat_oid=$( git rev-parse --output-object-format=$test_compat_hash_algo $hello_oid )
269+ run_blob_tests $hello_oid
270+ run_blob_tests $hello_compat_oid
260271
261272test_expect_success ' --batch-check without %(rest) considers whole line' '
262273 echo "$hello_oid blob $hello_size" >expect &&
@@ -267,73 +278,102 @@ test_expect_success '--batch-check without %(rest) considers whole line' '
267278'
268279
269280tree_oid=$( git write-tree)
281+ tree_compat_oid=$( git rev-parse --output-object-format=$test_compat_hash_algo $tree_oid )
270282tree_size=$(( $(test_oid rawsz) + 13 ))
283+ tree_compat_size=$(( $(test_oid -- hash= compat rawsz) + 13 ))
271284tree_pretty_content=" 100644 blob $hello_oid hello${LF} "
285+ tree_compat_pretty_content=" 100644 blob $hello_compat_oid hello${LF} "
272286
273287run_tests ' tree' $tree_oid $tree_size " " " $tree_pretty_content "
288+ run_tests ' tree' $tree_compat_oid $tree_compat_size " " " $tree_compat_pretty_content "
274289
275290commit_message=" Initial commit"
276291commit_oid=$( echo_without_newline " $commit_message " | git commit-tree $tree_oid )
292+ commit_compat_oid=$( git rev-parse --output-object-format=$test_compat_hash_algo $commit_oid )
277293commit_size=$(( $(test_oid hexsz) + 137 ))
294+ commit_compat_size=$(( $(test_oid -- hash= compat hexsz) + 137 ))
278295commit_content=" tree $tree_oid
279296author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL > $GIT_AUTHOR_DATE
280297committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL > $GIT_COMMITTER_DATE
281298
282299$commit_message "
283300
301+ commit_compat_content=" tree $tree_compat_oid
302+ author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL > $GIT_AUTHOR_DATE
303+ committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL > $GIT_COMMITTER_DATE
304+
305+ $commit_message "
306+
284307run_tests ' commit' $commit_oid $commit_size " $commit_content " " $commit_content "
308+ run_tests ' commit' $commit_compat_oid $commit_compat_size " $commit_compat_content " " $commit_compat_content "
285309
286- tag_header_without_timestamp=" object $hello_oid
287- type blob
310+ tag_header_without_oid=" type blob
288311tag hellotag
289312tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL >"
313+ tag_header_without_timestamp=" object $hello_oid
314+ $tag_header_without_oid "
315+ tag_compat_header_without_timestamp=" object $hello_compat_oid
316+ $tag_header_without_oid "
290317tag_description=" This is a tag"
291318tag_content=" $tag_header_without_timestamp 0 +0000
292319
320+ $tag_description "
321+ tag_compat_content=" $tag_compat_header_without_timestamp 0 +0000
322+
293323$tag_description "
294324
295325tag_oid=$( echo_without_newline " $tag_content " | git hash-object -t tag --stdin -w)
296326tag_size=$( strlen " $tag_content " )
297327
328+ tag_compat_oid=$( git rev-parse --output-object-format=$test_compat_hash_algo $tag_oid )
329+ tag_compat_size=$( strlen " $tag_compat_content " )
330+
298331run_tests ' tag' $tag_oid $tag_size " $tag_content " " $tag_content "
332+ run_tests ' tag' $tag_compat_oid $tag_compat_size " $tag_compat_content " " $tag_compat_content "
299333
300334test_expect_success " Reach a blob from a tag pointing to it" '
301335 echo_without_newline "$hello_content" >expect &&
302336 git cat-file blob $tag_oid >actual &&
303337 test_cmp expect actual
304338'
305339
306- for batch in batch batch-check batch-command
340+ for oid in $hello_oid $hello_compat_oid
307341do
308- for opt in t s e p
342+ for batch in batch batch-check batch-command
309343 do
344+ for opt in t s e p
345+ do
310346 test_expect_success " Passing -$opt with --$batch fails" '
311- test_must_fail git cat-file --$batch -$opt $hello_oid
347+ test_must_fail git cat-file --$batch -$opt $oid
312348 '
313349
314350 test_expect_success " Passing --$batch with -$opt fails" '
315- test_must_fail git cat-file -$opt --$batch $hello_oid
351+ test_must_fail git cat-file -$opt --$batch $oid
316352 '
317- done
353+ done
318354
319- test_expect_success " Passing <type> with --$batch fails" '
320- test_must_fail git cat-file --$batch blob $hello_oid
321- '
355+ test_expect_success " Passing <type> with --$batch fails" '
356+ test_must_fail git cat-file --$batch blob $oid
357+ '
322358
323- test_expect_success " Passing --$batch with <type> fails" '
324- test_must_fail git cat-file blob --$batch $hello_oid
325- '
359+ test_expect_success " Passing --$batch with <type> fails" '
360+ test_must_fail git cat-file blob --$batch $oid
361+ '
326362
327- test_expect_success " Passing oid with --$batch fails" '
328- test_must_fail git cat-file --$batch $hello_oid
329- '
363+ test_expect_success " Passing oid with --$batch fails" '
364+ test_must_fail git cat-file --$batch $oid
365+ '
366+ done
330367done
331368
332- for opt in t s e p
369+ for oid in $hello_oid $hello_compat_oid
333370do
334- test_expect_success " Passing -$opt with --follow-symlinks fails" '
335- test_must_fail git cat-file --follow-symlinks -$opt $hello_oid
371+ for opt in t s e p
372+ do
373+ test_expect_success " Passing -$opt with --follow-symlinks fails" '
374+ test_must_fail git cat-file --follow-symlinks -$opt $oid
336375 '
376+ done
337377done
338378
339379test_expect_success " --batch-check for a non-existent named object" '
@@ -386,112 +426,102 @@ test_expect_success 'empty --batch-check notices missing object' '
386426 test_cmp expect actual
387427'
388428
389- batch_input=" $hello_oid
390- $commit_oid
391- $tag_oid
429+ batch_tests () {
430+ boid=$1
431+ loid=$2
432+ lsize=$3
433+ coid=$4
434+ csize=$5
435+ ccontent=$6
436+ toid=$7
437+ tsize=$8
438+ tcontent=$9
439+
440+ batch_input=" $boid
441+ $coid
442+ $toid
392443deadbeef
393444
394445"
395446
396- printf " %s\0" \
397- " $hello_oid blob $hello_size " \
447+ printf " %s\0" \
448+ " $boid blob $hello_size " \
398449 " $hello_content " \
399- " $commit_oid commit $commit_size " \
400- " $commit_content " \
401- " $tag_oid tag $tag_size " \
402- " $tag_content " \
450+ " $coid commit $csize " \
451+ " $ccontent " \
452+ " $toid tag $tsize " \
453+ " $tcontent " \
403454 " deadbeef missing" \
404455 " missing" > batch_output
405456
406- test_expect_success ' --batch with multiple oids gives correct format' '
457+ test_expect_success ' --batch with multiple oids gives correct format' '
407458 tr "\0" "\n" <batch_output >expect &&
408459 echo_without_newline "$batch_input" >in &&
409460 git cat-file --batch <in >actual &&
410461 test_cmp expect actual
411- '
462+ '
412463
413- test_expect_success ' --batch, -z with multiple oids gives correct format' '
464+ test_expect_success ' --batch, -z with multiple oids gives correct format' '
414465 echo_without_newline_nul "$batch_input" >in &&
415466 tr "\0" "\n" <batch_output >expect &&
416467 git cat-file --batch -z <in >actual &&
417468 test_cmp expect actual
418- '
469+ '
419470
420- test_expect_success ' --batch, -Z with multiple oids gives correct format' '
471+ test_expect_success ' --batch, -Z with multiple oids gives correct format' '
421472 echo_without_newline_nul "$batch_input" >in &&
422473 git cat-file --batch -Z <in >actual &&
423474 test_cmp batch_output actual
424- '
475+ '
425476
426- batch_check_input=" $hello_oid
427- $tree_oid
428- $commit_oid
429- $tag_oid
477+ batch_check_input=" $boid
478+ $loid
479+ $coid
480+ $toid
430481deadbeef
431482
432483"
433484
434- printf " %s\0" \
435- " $hello_oid blob $hello_size " \
436- " $tree_oid tree $tree_size " \
437- " $commit_oid commit $commit_size " \
438- " $tag_oid tag $tag_size " \
485+ printf " %s\0" \
486+ " $boid blob $hello_size " \
487+ " $loid tree $lsize " \
488+ " $coid commit $csize " \
489+ " $toid tag $tsize " \
439490 " deadbeef missing" \
440491 " missing" > batch_check_output
441492
442- test_expect_success " --batch-check with multiple oids gives correct format" '
493+ test_expect_success " --batch-check with multiple oids gives correct format" '
443494 tr "\0" "\n" <batch_check_output >expect &&
444495 echo_without_newline "$batch_check_input" >in &&
445496 git cat-file --batch-check <in >actual &&
446497 test_cmp expect actual
447- '
498+ '
448499
449- test_expect_success " --batch-check, -z with multiple oids gives correct format" '
500+ test_expect_success " --batch-check, -z with multiple oids gives correct format" '
450501 tr "\0" "\n" <batch_check_output >expect &&
451502 echo_without_newline_nul "$batch_check_input" >in &&
452503 git cat-file --batch-check -z <in >actual &&
453504 test_cmp expect actual
454- '
505+ '
455506
456- test_expect_success " --batch-check, -Z with multiple oids gives correct format" '
507+ test_expect_success " --batch-check, -Z with multiple oids gives correct format" '
457508 echo_without_newline_nul "$batch_check_input" >in &&
458509 git cat-file --batch-check -Z <in >actual &&
459510 test_cmp batch_check_output actual
460- '
461-
462- test_expect_success FUNNYNAMES ' setup with newline in input' '
463- touch -- "newline${LF}embedded" &&
464- git add -- "newline${LF}embedded" &&
465- git commit -m "file with newline embedded" &&
466- test_tick &&
467-
468- printf "HEAD:newline${LF}embedded" >in
469- '
470-
471- test_expect_success FUNNYNAMES ' --batch-check, -z with newline in input' '
472- git cat-file --batch-check -z <in >actual &&
473- echo "$(git rev-parse "HEAD:newline${LF}embedded") blob 0" >expect &&
474- test_cmp expect actual
475- '
476-
477- test_expect_success FUNNYNAMES ' --batch-check, -Z with newline in input' '
478- git cat-file --batch-check -Z <in >actual &&
479- printf "%s\0" "$(git rev-parse "HEAD:newline${LF}embedded") blob 0" >expect &&
480- test_cmp expect actual
481- '
511+ '
482512
483- batch_command_multiple_info=" info $hello_oid
484- info $tree_oid
485- info $commit_oid
486- info $tag_oid
513+ batch_command_multiple_info=" info $boid
514+ info $loid
515+ info $coid
516+ info $toid
487517info deadbeef"
488518
489- test_expect_success ' --batch-command with multiple info calls gives correct format' '
519+ test_expect_success ' --batch-command with multiple info calls gives correct format' '
490520 cat >expect <<-EOF &&
491- $hello_oid blob $hello_size
492- $tree_oid tree $tree_size
493- $commit_oid commit $commit_size
494- $tag_oid tag $tag_size
521+ $boid blob $hello_size
522+ $loid tree $lsize
523+ $coid commit $csize
524+ $toid tag $tsize
495525 deadbeef missing
496526 EOF
497527
@@ -510,22 +540,22 @@ test_expect_success '--batch-command with multiple info calls gives correct form
510540 git cat-file --batch-command --buffer -Z <in >actual &&
511541
512542 test_cmp expect_nul actual
513- '
543+ '
514544
515- batch_command_multiple_contents=" contents $hello_oid
516- contents $commit_oid
517- contents $tag_oid
545+ batch_command_multiple_contents=" contents $boid
546+ contents $coid
547+ contents $toid
518548contents deadbeef
519549flush"
520550
521- test_expect_success ' --batch-command with multiple command calls gives correct format' '
551+ test_expect_success ' --batch-command with multiple command calls gives correct format' '
522552 printf "%s\0" \
523- "$hello_oid blob $hello_size" \
553+ "$boid blob $hello_size" \
524554 "$hello_content" \
525- "$commit_oid commit $commit_size " \
526- "$commit_content " \
527- "$tag_oid tag $tag_size " \
528- "$tag_content " \
555+ "$coid commit $csize " \
556+ "$ccontent " \
557+ "$toid tag $tsize " \
558+ "$tcontent " \
529559 "deadbeef missing" >expect_nul &&
530560 tr "\0" "\n" <expect_nul >expect &&
531561
@@ -543,6 +573,33 @@ test_expect_success '--batch-command with multiple command calls gives correct f
543573 git cat-file --batch-command --buffer -Z <in >actual &&
544574
545575 test_cmp expect_nul actual
576+ '
577+
578+ }
579+
580+ batch_tests $hello_oid $tree_oid $tree_size $commit_oid $commit_size " $commit_content " $tag_oid $tag_size " $tag_content "
581+ batch_tests $hello_compat_oid $tree_compat_oid $tree_compat_size $commit_compat_oid $commit_compat_size " $commit_compat_content " $tag_compat_oid $tag_compat_size " $tag_compat_content "
582+
583+
584+ test_expect_success FUNNYNAMES ' setup with newline in input' '
585+ touch -- "newline${LF}embedded" &&
586+ git add -- "newline${LF}embedded" &&
587+ git commit -m "file with newline embedded" &&
588+ test_tick &&
589+
590+ printf "HEAD:newline${LF}embedded" >in
591+ '
592+
593+ test_expect_success FUNNYNAMES ' --batch-check, -z with newline in input' '
594+ git cat-file --batch-check -z <in >actual &&
595+ echo "$(git rev-parse "HEAD:newline${LF}embedded") blob 0" >expect &&
596+ test_cmp expect actual
597+ '
598+
599+ test_expect_success FUNNYNAMES ' --batch-check, -Z with newline in input' '
600+ git cat-file --batch-check -Z <in >actual &&
601+ printf "%s\0" "$(git rev-parse "HEAD:newline${LF}embedded") blob 0" >expect &&
602+ test_cmp expect actual
546603'
547604
548605test_expect_success ' setup blobs which are likely to delta' '
0 commit comments