3 test_description
='topgit_msg_prepare.awk functionality'
9 ap
="$(tg --awk-path)" && test -n "$ap" && test -d "$ap" || die
10 aptmp
="$ap/topgit_msg_prepare"
11 test -f "$aptmp" && test -r "$aptmp" && test -x "$aptmp" || die
13 # Example use of topgit_msg_prepare:
15 # $ printf "%s\n" "refs/heads/{top-bases}/t/sample" |
16 # awk -f "$(tg --awk-path)/ref_prepare" \
17 # -v "topbases=refs/heads/{top-bases}" \
18 # -v "chkblob=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" -v "depsblob=1" \
19 # -v "msgblob=1" | tee /dev/stderr |
20 # git cat-file --batch-check="%(objectname) %(objecttype) %(rest)" |
22 # awk -f "$(tg --awk-path)/topgit_msg_prepare" \
23 # -v "missing=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" \
26 # e69de29bb2d1d6434b8b29ae775ad8c2e48c5391^{blob} check ?
27 # refs/heads/{top-bases}/t/sample t/sample :
28 # refs/heads/{top-bases}/t/sample^0
29 # refs/heads/t/sample^0
30 # refs/heads/{top-bases}/t/sample^{tree}
31 # refs/heads/t/sample^{tree}
32 # refs/heads/t/sample^{tree}:.topdeps
33 # refs/heads/t/sample^{tree}:.topmsg
35 # e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 blob check ?
36 # 9769d34b6ee3d539e4152f2629ec16c56108f82c commit t/sample :
37 # 9769d34b6ee3d539e4152f2629ec16c56108f82c commit
38 # d95cc1ed8dc6dcee3002573ca94e1d07f23889d0 commit
39 # 1afd3b1f70a1155465d1635a76fa49f96d23db2f tree
40 # 59344164440d5f71cb204b464c45ae4a14416b54 tree
41 # 2466de6787619f47fe41ced8608998462317f209 blob
42 # 5e6bd1db23329803939ffa1e1f9052e678ea4a06 blob
44 # 5e6bd1db23329803939ffa1e1f9052e678ea4a06 0 t/sample
46 # Note that topgit_msg_prepare does not concern itself with the actual value
47 # of any of the hashes (other than for equality testing), but it does care
48 # about object types and whether things are "missing" or not.
50 # It also doesn't detect obviously corrupt input (both commits are the same
51 # but their trees are not).
61 cat <<-EOT >"$cmd0" || die
62 10000000 whatever cmd0 :
70 echo "10000006 0 cmd0" >"$cmd0.out0" || die
71 echo "10000007 0 cmd0" >"$cmd0.out1" || die
72 echo "cmd0" >"$cmd0.br" || die
75 cat <<-EOT >"$cmd1" || die
76 10000000 whatever cmd1 :
86 cat <<-EOT >"$cmd2" || die
87 10000000 whatever cmd2 :
97 cat <<-EOT >"$cmd3" || die
98 10000000 whatever cmd3 :
108 cat <<-EOT >"$cmd4" || die
109 10000000 whatever cmd4 :
119 cat <<-EOT >"$data1" || die
122 even more garbage here
124 20000001 whatever k0 :
130 30000001 whatever k1 :
136 40000001 whatever k2 :
142 50000001 whatever k3 :
148 60000001 whatever k4 :
157 cat <<-EOT >"$data2" || die
160 even more garbage here
162 20000001 whatever k0 :
169 30000001 whatever k1 :
176 40000001 whatever k2 :
183 50000001 whatever k3 :
190 60000001 whatever k4 :
200 cat <<-EOT >"$data3" || die
203 even more garbage here
205 20000001 whatever k0 :
212 30000001 whatever k1 :
219 40000001 whatever k2 :
226 50000001 whatever k3 :
233 60000001 whatever k4 :
241 cat <<-EOT >"$data3.d0"
248 cat <<-EOT >"$data3.d1"
255 cat <<-EOT >"$data3.d2"
264 cat <<-EOT >"$data3r" || die
267 even more garbage here
269 20000001 whatever k0 :
276 30000001 whatever k1 :
283 40000001 whatever k2 :
290 50000001 whatever k3 :
297 60000001 whatever k4 :
305 cat <<-EOT >"$data3r.d0"
312 cat <<-EOT >"$data3r.d1"
319 cat <<-EOT >"$data3r.d2"
327 mt_base
="one-rather-lengthy-and-unlikely-blob-name-for-sure"
329 test_expect_success
'test setup' '
330 branch_base="some-very-long-branch-base-name-goes-here-for-sure" &&
332 >biginput && >bigoutput && >bigbrfile &&
333 i=1 && while i=$(($i + 10)) && test $i -le 10000; do
334 printf "%08d whatever %s-%d :\n" $(( $bn + $i )) "$branch_base" $(( $bn + $i )) >>biginput &&
335 printf "%08d commit\n" $(( $bn + $i + 1 )) >>biginput &&
336 printf "%08d commit\n" $(( $bn + $i + 2 )) >>biginput &&
337 printf "%08d tree\n" $(( $bn + $i + 3 )) >>biginput &&
338 printf "%08d tree\n" $(( $bn + $i + 3 )) >>biginput &&
339 printf "%08d blob\n" $(( $bn + $i + 4 )) >>biginput &&
340 printf "%s-%d\n" "$branch_base" $(( $bn + $i )) >>bigbrfile &&
341 printf "%s^{blob} 2 %s-%d\n" "$mt_base" "$branch_base" $(( $bn + $i )) >>bigoutput
343 cat bigbrfile bigoutput >bigcombined
346 test_expect_success
'topgit_msg_prepare runs' '
347 # some stupid awks might not even compile it
348 awk -f "$aptmp" </dev/null &&
349 # and make sure various file arg combinations are accepted
350 awk -f "$aptmp" </dev/null -v brfile=brfile && rm -f brfile &&
351 awk -f "$aptmp" </dev/null -v anfile=anfile && rm -f anfile &&
352 awk -f "$aptmp" </dev/null -v brfile=brfile -v anfile=anfile
355 test_expect_success
'output files always truncated' '
356 echo brfile > brfile && test -s brfile &&
357 echo anfile > anfile && test -s anfile &&
358 awk -f "$aptmp" </dev/null -v brfile=brfile -v anfile=anfile &&
364 IFS
= read -r line ||
return &&
366 printf '%s\n' "$line" >>"$2" &&
370 test_expect_success
'output brfile ordering' '
372 awk -f "$aptmp" <biginput -v withan=1 -v missing="$mt_base" -v brfile=brfile | capture brfile result &&
373 test_cmp result bigcombined
376 test_expect_success
'output anfile ordering' '
378 awk -f "$aptmp" <biginput -v withan=1 -v missing="$mt_base" -v anfile=anfile | capture anfile result &&
379 test_cmp result bigcombined
382 test_expect_success
'anfile only' '
383 awk -f "$aptmp" <biginput -v anfile=anlist >out &&
384 test ! -s out && test_cmp anlist bigbrfile
387 test_expect_success
'anfile only one out' '
388 cat "$cmd0" biginput | awk -f "$aptmp" -v anfile=anlist >out &&
389 test_cmp out "$cmd0.out0" && test_cmp anlist bigbrfile
392 test_expect_success
'empty brfile only' '
393 awk -f "$aptmp" <biginput -v brfile=brlist >out &&
394 test ! -s out && test -e brlist && test ! -s brlist
397 test_expect_success
'one in brfile only' '
398 cat "$cmd0" biginput | awk -f "$aptmp" -v brfile=brlist >out &&
399 test_cmp out "$cmd0.out0" && test_cmp brlist "$cmd0.br"
402 test_expect_success
'withan=1 brfile only' '
403 awk -f "$aptmp" <biginput -v withan=1 -v brfile=brlist >out &&
404 test ! -s out && test_cmp brlist bigbrfile
407 test_expect_success
'anfile and empty brfile' '
408 awk -f "$aptmp" <biginput -v anfile=anlist -v brfile=brlist >out &&
409 test ! -s out && test_cmp anlist bigbrfile && test -e brlist && test ! -s brlist
412 test_expect_success
'anfile and one in brfile' '
413 cat "$cmd0" biginput | awk -f "$aptmp" -v anfile=anlist -v brfile=brlist >out &&
414 test_cmp out "$cmd0.out0" && test_cmp anlist bigbrfile && test_cmp brlist "$cmd0.br"
417 # The only kind of "bad" input that's detected is not enough lines after
418 # the starting 4-field ':' line
419 test_expect_success
'bad input detected' '
420 echo "0001 commit branch :" >input &&
421 test_must_fail awk -f "$aptmp" <input &&
422 echo "0002 commit" >>input &&
423 test_must_fail awk -f "$aptmp" <input &&
424 echo "0003 commit" >>input &&
425 test_must_fail awk -f "$aptmp" <input &&
426 echo "0004 tree" >>input &&
427 test_must_fail awk -f "$aptmp" <input &&
428 echo "0005 tree" >>input &&
429 test_must_fail awk -f "$aptmp" <input &&
430 echo "0006 blob" >>input &&
431 awk -f "$aptmp" <input &&
432 test_must_fail awk -f "$aptmp" <input -v depsblob=1 &&
433 test_must_fail awk -f "$aptmp" <input -v depsblob=2 &&
434 echo "0007 blob" >>input &&
435 awk -f "$aptmp" <input &&
436 awk -f "$aptmp" <input -v depsblob=1 &&
437 awk -f "$aptmp" <input -v depsblob=2
440 test_expect_success
'missing command does not run' '
442 awk -f "$aptmp" <"$cmd0" -v misscmd="echo r0>>run0" >out0 &&
443 awk -f "$aptmp" <"$cmd0" -v depsblob=1 -v misscmd="echo r0>>run0" >out1 &&
444 test_cmp "$cmd0.out0" out0 && test_cmp "$cmd0.out1" out1 && test ! -e run0 &&
445 awk -f "$aptmp" <"$cmd1" -v depsblob=1 -v misscmd="echo r1>>run1" >out &&
446 test ! -s out && test ! -e run1 &&
447 awk -f "$aptmp" <"$cmd2" -v misscmd="echo r2>>run2" >out &&
448 awk -f "$aptmp" <"$cmd2" -v missing=other -v misscmd="echo r2>>run2" >>out &&
449 awk -f "$aptmp" <"$cmd2" -v withmt=1 -v missing=other -v misscmd="echo r2>>run2" >>out &&
450 test ! -s out && test ! -e run2 &&
451 awk -f "$aptmp" <"$cmd3" -v misscmd="echo r3>>run3" >out &&
452 awk -f "$aptmp" <"$cmd3" -v missing=other -v misscmd="echo r3>>run3" >>out &&
453 awk -f "$aptmp" <"$cmd3" -v withan=1 -v withmt=0 -v missing=other -v misscmd="echo r3>>run3" >>out &&
454 test ! -s out && test ! -e run3 &&
455 awk -f "$aptmp" <"$cmd4" -v misscmd="echo r4>>run4" >out &&
456 test ! -s out && test ! -e run4 &&
457 cat "$chkmb" "$cmd0" | awk -f "$aptmp" -v missing=12345678 -v misscmd="echo r0>>run0" >out0a &&
458 cat "$chkmb" "$cmd0" | awk -f "$aptmp" -v missing=other -v misscmd="echo r0>>run0" >out0b &&
459 test_cmp "$cmd0.out0" out0a && test_cmp "$cmd0.out0" out0b &&
461 echo "12345678^{blob} 1 cmd1" >expected &&
462 cat "$chkmb" "$cmd1" | awk -f "$aptmp" -v depsblob=1 -v missing=12345678 -v misscmd="echo r1>>run1" >out &&
463 test ! -e run1 && test_cmp out expected &&
464 echo "12345678^{blob} 2 cmd2" >expected &&
465 cat "$chkmb" "$cmd2" | awk -f "$aptmp" -v withan=1 -v missing=12345678 -v misscmd="echo r2>>run2" >out &&
466 test ! -e run2 && test_cmp out expected &&
467 echo "12345678^{blob} 3 cmd3" >expected &&
468 cat "$chkmb" "$cmd3" | awk -f "$aptmp" -v withmt=1 -v missing=12345678 -v misscmd="echo r3>>run3" >out &&
469 test ! -e run3 && test_cmp out expected &&
470 echo "12345678^{blob} 1 cmd4" >expected &&
471 echo "12345678^{blob} 1 cmd4" >>expected &&
472 echo "12345678^{blob} 4 cmd4" >>expected &&
473 cat "$chkmb" "$cmd4" | awk -f "$aptmp" -v missing=12345678 -v misscmd="echo r4>>run4" >out &&
474 cat "$chkmb" "$cmd4" | awk -f "$aptmp" -v missing=12345678 -v misscmd="echo r4>>run4" -v depsblob=1 >>out &&
475 cat "$chkmb" "$cmd4" | awk -f "$aptmp" -v missing=12345678 -v misscmd="echo r4>>run4" -v depsblob=2 >>out &&
476 test ! -e run4 && test_cmp out expected
479 test_expect_success
'missing command does run' '
481 <"$cmd1" awk -f "$aptmp" -v depsblob=1 -v missing=12345678 -v misscmd="echo r1>>run1" &&
482 test -s run1 && read -r l <run1 && test "$l" = "r1" &&
483 <"$cmd2" awk -f "$aptmp" -v withan=1 -v withmt=0 -v missing=12345678 -v misscmd="echo r2>>run2" &&
484 test -s run2 && read -r l <run2 && test "$l" = "r2" &&
485 <"$cmd3" awk -f "$aptmp" -v withmt=1 -v missing=12345678 -v misscmd="echo r3>>run3" &&
486 test -s run3 && read -r l <run3 && test "$l" = "r3" &&
487 <"$cmd4" awk -f "$aptmp" -v missing=12345678 -v misscmd="echo r4a>>run4" &&
488 <"$cmd4" awk -f "$aptmp" -v missing=12345678 -v misscmd="echo r4b>>run4" -v depsblob=1 &&
489 <"$cmd4" awk -f "$aptmp" -v missing=12345678 -v misscmd="echo r4c>>run4" -v depsblob=2 &&
490 { read -r l1 && read -r l2 && read -r l3; } <run4 &&
491 test "$l1" = "r4a" && test "$l2" = "r4b" && test "$l3" = "r4c"
494 test_expect_success
'missing command runs once' '
496 cat "$cmd1" "$cmd2" "$cmd3" "$cmd4" |
497 awk -f "$aptmp" -v depsblob=2 -v withan=1 -v missing=12345678 -v misscmd="echo r1>>run1" &&
498 echo "r1" >expected &&
499 test -s run1 && test_cmp run1 expected
502 test_expect_success
'depsblob=0..2' '
503 <"$data3" awk -f "$aptmp" -v withan=1 -v missing=other >out &&
504 test_cmp out "$data3.d0" &&
505 <"$data3" awk -f "$aptmp" -v depsblob=0 -v withan=1 -v missing=other >out &&
506 test_cmp out "$data3.d0" &&
507 <"$data3" awk -f "$aptmp" -v depsblob=1 -v withan=1 -v missing=other >out &&
508 test_cmp out "$data3.d1" &&
509 <"$data3" awk -f "$aptmp" -v depsblob=2 -v withan=1 -v missing=other >out &&
510 test_cmp out "$data3.d2" &&
511 <"$data3r" awk -f "$aptmp" -v withan=1 -v missing=other >out &&
512 test_cmp out "$data3r.d0" &&
513 <"$data3r" awk -f "$aptmp" -v depsblob=0 -v withan=1 -v missing=other >out &&
514 test_cmp out "$data3r.d0" &&
515 <"$data3r" awk -f "$aptmp" -v depsblob=1 -v withan=1 -v missing=other >out &&
516 test_cmp out "$data3r.d1" &&
517 <"$data3r" awk -f "$aptmp" -v depsblob=2 -v withan=1 -v missing=other >out &&
518 test_cmp out "$data3r.d2"
521 test_expect_success
'no K=1..4 without -v missing' '
522 echo "20000007 0 k0" >expected &&
523 <"$data1" awk -f "$aptmp" >out &&
524 test_cmp out expected &&
525 <"$data1" awk -f "$aptmp" -v withan=1 >out &&
526 test_cmp out expected &&
527 <"$data1" awk -f "$aptmp" -v withmt=1 >out &&
528 test_cmp out expected &&
529 <"$data1" awk -f "$aptmp" -v withan=1 -v withmt=1 >out &&
530 test_cmp out expected
533 test_expect_success
'K=0,1 output' '
534 echo "20000007 0 k0" >expected &&
535 echo "other^{blob} 1 k1" >>expected &&
536 echo "other^{blob} 1 k4" >>expected &&
537 <"$data1" awk -f "$aptmp" -v missing=other >out &&
538 test_cmp out expected
541 test_expect_success
'K=0,1 output depsblob=1' '
542 echo "20000007 0 k0" >expected &&
543 echo "other^{blob} 1 k1" >>expected &&
544 echo "other^{blob} 1 k4" >>expected &&
545 <"$data2" awk -f "$aptmp" -v missing=other -v depsblob=1 >out &&
546 test_cmp out expected
549 test_expect_success
'K=0,1,4 output depsblob=2' '
550 echo "20000007 0 k0" >expected &&
551 echo "other^{blob} 1 k1" >>expected &&
552 echo "other^{blob} 4 k4" >>expected &&
553 <"$data2" awk -f "$aptmp" -v missing=other -v depsblob=2 >out &&
554 test_cmp out expected
556 test_expect_success
'K=0..3 output' '
557 echo "20000007 0 k0" >expected &&
558 echo "other^{blob} 1 k1" >>expected &&
559 echo "other^{blob} 2 k2" >>expected &&
560 echo "other^{blob} 3 k3" >>expected &&
561 echo "other^{blob} 1 k4" >>expected &&
562 <"$data1" awk -f "$aptmp" -v withan=1 -v missing=other >out &&
563 test_cmp out expected
566 test_expect_success
'K=0..3 output depsblob=1' '
567 echo "20000007 0 k0" >expected &&
568 echo "other^{blob} 1 k1" >>expected &&
569 echo "other^{blob} 2 k2" >>expected &&
570 echo "other^{blob} 3 k3" >>expected &&
571 echo "other^{blob} 1 k4" >>expected &&
572 <"$data2" awk -f "$aptmp" -v withan=1 -v missing=other -v depsblob=1 >out &&
573 test_cmp out expected
576 test_expect_success
'K=0..4 output depsblob=2' '
577 echo "20000007 0 k0" >expected &&
578 echo "other^{blob} 1 k1" >>expected &&
579 echo "other^{blob} 2 k2" >>expected &&
580 echo "other^{blob} 3 k3" >>expected &&
581 echo "other^{blob} 4 k4" >>expected &&
582 <"$data2" awk -f "$aptmp" -v withan=1 -v missing=other -v depsblob=4 >out &&
583 test_cmp out expected
586 test_expect_success
'K=0..2 output' '
587 echo "20000007 0 k0" >expected &&
588 echo "other^{blob} 1 k1" >>expected &&
589 echo "other^{blob} 2 k2" >>expected &&
590 echo "other^{blob} 1 k4" >>expected &&
591 <"$data1" awk -f "$aptmp" -v withan=1 -v withmt=0 -v missing=other >out &&
592 test_cmp out expected
595 test_expect_success
'K=0..2 output depsblob=1' '
596 echo "20000007 0 k0" >expected &&
597 echo "other^{blob} 1 k1" >>expected &&
598 echo "other^{blob} 2 k2" >>expected &&
599 echo "other^{blob} 1 k4" >>expected &&
600 <"$data2" awk -f "$aptmp" -v withan=1 -v withmt=0 -v missing=other -v depsblob=1 >out &&
601 test_cmp out expected
604 test_expect_success
'K=0..2,4 output depsblob=2' '
605 echo "20000007 0 k0" >expected &&
606 echo "other^{blob} 1 k1" >>expected &&
607 echo "other^{blob} 2 k2" >>expected &&
608 echo "other^{blob} 4 k4" >>expected &&
609 <"$data2" awk -f "$aptmp" -v withan=1 -v withmt=0 -v missing=other -v depsblob=2 >out &&
610 test_cmp out expected
613 test_expect_success
'K=0,1,3 output' '
614 echo "20000007 0 k0" >expected &&
615 echo "other^{blob} 1 k1" >>expected &&
616 echo "other^{blob} 3 k3" >>expected &&
617 echo "other^{blob} 1 k4" >>expected &&
618 <"$data1" awk -f "$aptmp" -v withmt=1 -v missing=other >out &&
619 test_cmp out expected
622 test_expect_success
'K=0,1,3 output depsblob=1' '
623 echo "20000007 0 k0" >expected &&
624 echo "other^{blob} 1 k1" >>expected &&
625 echo "other^{blob} 3 k3" >>expected &&
626 echo "other^{blob} 1 k4" >>expected &&
627 <"$data2" awk -f "$aptmp" -v withmt=1 -v missing=other -v depsblob=1 >out &&
628 test_cmp out expected
631 test_expect_success
'K=0,1,3,4 output depsblob=2' '
632 echo "20000007 0 k0" >expected &&
633 echo "other^{blob} 1 k1" >>expected &&
634 echo "other^{blob} 3 k3" >>expected &&
635 echo "other^{blob} 4 k4" >>expected &&
636 <"$data2" awk -f "$aptmp" -v withmt=1 -v missing=other -v depsblob=2 >out &&
637 test_cmp out expected