@@ -236,27 +236,38 @@ hello_size=$(strlen "$hello_content")
236
236
hello_oid=$( echo_without_newline " $hello_content " | git hash-object --stdin)
237
237
238
238
test_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 &&
239
242
echo_without_newline "$hello_content" > hello &&
240
243
git update-index --add hello
241
244
'
242
245
243
- run_tests ' blob' $hello_oid $hello_size " $hello_content " " $hello_content "
246
+ run_blob_tests () {
247
+ oid=$1
244
248
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" |
248
254
GIT_TEST_CAT_FILE_NO_FLUSH_ON_EXIT=1 \
249
255
git cat-file --batch-command --buffer >actual &&
250
256
test_cmp expect actual
251
- '
257
+ '
252
258
253
- test_expect_success ' --batch-command --buffer without flush for blob info' '
259
+ test_expect_success ' --batch-command --buffer without flush for blob info' '
254
260
touch output &&
255
- test_write_lines "info $hello_oid " |
261
+ test_write_lines "info $oid " |
256
262
GIT_TEST_CAT_FILE_NO_FLUSH_ON_EXIT=1 \
257
263
git cat-file --batch-command --buffer >>output &&
258
264
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
260
271
261
272
test_expect_success ' --batch-check without %(rest) considers whole line' '
262
273
echo "$hello_oid blob $hello_size" >expect &&
@@ -267,73 +278,102 @@ test_expect_success '--batch-check without %(rest) considers whole line' '
267
278
'
268
279
269
280
tree_oid=$( git write-tree)
281
+ tree_compat_oid=$( git rev-parse --output-object-format=$test_compat_hash_algo $tree_oid )
270
282
tree_size=$(( $(test_oid rawsz) + 13 ))
283
+ tree_compat_size=$(( $(test_oid -- hash= compat rawsz) + 13 ))
271
284
tree_pretty_content=" 100644 blob $hello_oid hello${LF} "
285
+ tree_compat_pretty_content=" 100644 blob $hello_compat_oid hello${LF} "
272
286
273
287
run_tests ' tree' $tree_oid $tree_size " " " $tree_pretty_content "
288
+ run_tests ' tree' $tree_compat_oid $tree_compat_size " " " $tree_compat_pretty_content "
274
289
275
290
commit_message=" Initial commit"
276
291
commit_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 )
277
293
commit_size=$(( $(test_oid hexsz) + 137 ))
294
+ commit_compat_size=$(( $(test_oid -- hash= compat hexsz) + 137 ))
278
295
commit_content=" tree $tree_oid
279
296
author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL > $GIT_AUTHOR_DATE
280
297
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL > $GIT_COMMITTER_DATE
281
298
282
299
$commit_message "
283
300
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
+
284
307
run_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 "
285
309
286
- tag_header_without_timestamp=" object $hello_oid
287
- type blob
310
+ tag_header_without_oid=" type blob
288
311
tag hellotag
289
312
tagger $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 "
290
317
tag_description=" This is a tag"
291
318
tag_content=" $tag_header_without_timestamp 0 +0000
292
319
320
+ $tag_description "
321
+ tag_compat_content=" $tag_compat_header_without_timestamp 0 +0000
322
+
293
323
$tag_description "
294
324
295
325
tag_oid=$( echo_without_newline " $tag_content " | git hash-object -t tag --stdin -w)
296
326
tag_size=$( strlen " $tag_content " )
297
327
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
+
298
331
run_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 "
299
333
300
334
test_expect_success " Reach a blob from a tag pointing to it" '
301
335
echo_without_newline "$hello_content" >expect &&
302
336
git cat-file blob $tag_oid >actual &&
303
337
test_cmp expect actual
304
338
'
305
339
306
- for batch in batch batch-check batch-command
340
+ for oid in $hello_oid $hello_compat_oid
307
341
do
308
- for opt in t s e p
342
+ for batch in batch batch-check batch-command
309
343
do
344
+ for opt in t s e p
345
+ do
310
346
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
312
348
'
313
349
314
350
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
316
352
'
317
- done
353
+ done
318
354
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
+ '
322
358
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
+ '
326
362
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
330
367
done
331
368
332
- for opt in t s e p
369
+ for oid in $hello_oid $hello_compat_oid
333
370
do
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
336
375
'
376
+ done
337
377
done
338
378
339
379
test_expect_success " --batch-check for a non-existent named object" '
@@ -386,112 +426,102 @@ test_expect_success 'empty --batch-check notices missing object' '
386
426
test_cmp expect actual
387
427
'
388
428
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
392
443
deadbeef
393
444
394
445
"
395
446
396
- printf " %s\0" \
397
- " $hello_oid blob $hello_size " \
447
+ printf " %s\0" \
448
+ " $boid blob $hello_size " \
398
449
" $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 " \
403
454
" deadbeef missing" \
404
455
" missing" > batch_output
405
456
406
- test_expect_success ' --batch with multiple oids gives correct format' '
457
+ test_expect_success ' --batch with multiple oids gives correct format' '
407
458
tr "\0" "\n" <batch_output >expect &&
408
459
echo_without_newline "$batch_input" >in &&
409
460
git cat-file --batch <in >actual &&
410
461
test_cmp expect actual
411
- '
462
+ '
412
463
413
- test_expect_success ' --batch, -z with multiple oids gives correct format' '
464
+ test_expect_success ' --batch, -z with multiple oids gives correct format' '
414
465
echo_without_newline_nul "$batch_input" >in &&
415
466
tr "\0" "\n" <batch_output >expect &&
416
467
git cat-file --batch -z <in >actual &&
417
468
test_cmp expect actual
418
- '
469
+ '
419
470
420
- test_expect_success ' --batch, -Z with multiple oids gives correct format' '
471
+ test_expect_success ' --batch, -Z with multiple oids gives correct format' '
421
472
echo_without_newline_nul "$batch_input" >in &&
422
473
git cat-file --batch -Z <in >actual &&
423
474
test_cmp batch_output actual
424
- '
475
+ '
425
476
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
430
481
deadbeef
431
482
432
483
"
433
484
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 " \
439
490
" deadbeef missing" \
440
491
" missing" > batch_check_output
441
492
442
- test_expect_success " --batch-check with multiple oids gives correct format" '
493
+ test_expect_success " --batch-check with multiple oids gives correct format" '
443
494
tr "\0" "\n" <batch_check_output >expect &&
444
495
echo_without_newline "$batch_check_input" >in &&
445
496
git cat-file --batch-check <in >actual &&
446
497
test_cmp expect actual
447
- '
498
+ '
448
499
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" '
450
501
tr "\0" "\n" <batch_check_output >expect &&
451
502
echo_without_newline_nul "$batch_check_input" >in &&
452
503
git cat-file --batch-check -z <in >actual &&
453
504
test_cmp expect actual
454
- '
505
+ '
455
506
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" '
457
508
echo_without_newline_nul "$batch_check_input" >in &&
458
509
git cat-file --batch-check -Z <in >actual &&
459
510
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
+ '
482
512
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
487
517
info deadbeef"
488
518
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' '
490
520
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
495
525
deadbeef missing
496
526
EOF
497
527
@@ -510,22 +540,22 @@ test_expect_success '--batch-command with multiple info calls gives correct form
510
540
git cat-file --batch-command --buffer -Z <in >actual &&
511
541
512
542
test_cmp expect_nul actual
513
- '
543
+ '
514
544
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
518
548
contents deadbeef
519
549
flush"
520
550
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' '
522
552
printf "%s\0" \
523
- "$hello_oid blob $hello_size" \
553
+ "$boid blob $hello_size" \
524
554
"$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 " \
529
559
"deadbeef missing" >expect_nul &&
530
560
tr "\0" "\n" <expect_nul >expect &&
531
561
@@ -543,6 +573,33 @@ test_expect_success '--batch-command with multiple command calls gives correct f
543
573
git cat-file --batch-command --buffer -Z <in >actual &&
544
574
545
575
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
546
603
'
547
604
548
605
test_expect_success ' setup blobs which are likely to delta' '
0 commit comments