@@ -558,14 +558,21 @@ func (rg refGrouper) Groups() []sizes.RefGroup {
558
558
func TestBomb (t * testing.T ) {
559
559
t .Parallel ()
560
560
561
- repo := testutils .NewTestRepo (t , true , "bomb" )
562
- t .Cleanup (func () { repo .Remove (t ) })
561
+ ctx := context .Background ()
562
+
563
+ testRepo := testutils .NewTestRepo (t , true , "bomb" )
564
+ t .Cleanup (func () { testRepo .Remove (t ) })
565
+
566
+ newGitBomb (t , testRepo , 10 , 10 , "boom!\n " )
563
567
564
- newGitBomb (t , repo , 10 , 10 , "boom!\n " )
568
+ repo := testRepo .Repository (t )
569
+
570
+ refRoots , err := sizes .CollectReferences (ctx , repo , refGrouper {})
571
+ require .NoError (t , err )
565
572
566
573
h , err := sizes .ScanRepositoryUsingGraph (
567
- context . Background () , repo . Repository ( t ) ,
568
- refGrouper {} , sizes .NameStyleFull , meter .NoProgressMeter ,
574
+ ctx , repo ,
575
+ refRoots , sizes .NameStyleFull , meter .NoProgressMeter ,
569
576
)
570
577
require .NoError (t , err )
571
578
@@ -613,32 +620,39 @@ func TestBomb(t *testing.T) {
613
620
func TestTaggedTags (t * testing.T ) {
614
621
t .Parallel ()
615
622
616
- repo := testutils .NewTestRepo (t , false , "tagged-tags" )
617
- defer repo .Remove (t )
623
+ ctx := context .Background ()
624
+
625
+ testRepo := testutils .NewTestRepo (t , false , "tagged-tags" )
626
+ defer testRepo .Remove (t )
618
627
619
628
timestamp := time .Unix (1112911993 , 0 )
620
629
621
- cmd := repo .GitCommand (t , "commit" , "-m" , "initial" , "--allow-empty" )
630
+ cmd := testRepo .GitCommand (t , "commit" , "-m" , "initial" , "--allow-empty" )
622
631
testutils .AddAuthorInfo (cmd , & timestamp )
623
632
require .NoError (t , cmd .Run (), "creating commit" )
624
633
625
634
// The lexicographical order of these tags is important, hence
626
635
// their strange names.
627
- cmd = repo .GitCommand (t , "tag" , "-m" , "tag 1" , "tag" , "master" )
636
+ cmd = testRepo .GitCommand (t , "tag" , "-m" , "tag 1" , "tag" , "master" )
628
637
testutils .AddAuthorInfo (cmd , & timestamp )
629
638
require .NoError (t , cmd .Run (), "creating tag 1" )
630
639
631
- cmd = repo .GitCommand (t , "tag" , "-m" , "tag 2" , "bag" , "tag" )
640
+ cmd = testRepo .GitCommand (t , "tag" , "-m" , "tag 2" , "bag" , "tag" )
632
641
testutils .AddAuthorInfo (cmd , & timestamp )
633
642
require .NoError (t , cmd .Run (), "creating tag 2" )
634
643
635
- cmd = repo .GitCommand (t , "tag" , "-m" , "tag 3" , "wag" , "bag" )
644
+ cmd = testRepo .GitCommand (t , "tag" , "-m" , "tag 3" , "wag" , "bag" )
636
645
testutils .AddAuthorInfo (cmd , & timestamp )
637
646
require .NoError (t , cmd .Run (), "creating tag 3" )
638
647
648
+ repo := testRepo .Repository (t )
649
+
650
+ refRoots , err := sizes .CollectReferences (ctx , repo , refGrouper {})
651
+ require .NoError (t , err )
652
+
639
653
h , err := sizes .ScanRepositoryUsingGraph (
640
- context .Background (), repo . Repository ( t ) ,
641
- refGrouper {} , sizes .NameStyleNone , meter .NoProgressMeter ,
654
+ context .Background (), repo ,
655
+ refRoots , sizes .NameStyleNone , meter .NoProgressMeter ,
642
656
)
643
657
require .NoError (t , err , "scanning repository" )
644
658
assert .Equal (t , counts .Count32 (3 ), h .MaxTagDepth , "tag depth" )
@@ -647,20 +661,27 @@ func TestTaggedTags(t *testing.T) {
647
661
func TestFromSubdir (t * testing.T ) {
648
662
t .Parallel ()
649
663
650
- repo := testutils .NewTestRepo (t , false , "subdir" )
651
- defer repo .Remove (t )
664
+ ctx := context .Background ()
665
+
666
+ testRepo := testutils .NewTestRepo (t , false , "subdir" )
667
+ defer testRepo .Remove (t )
652
668
653
669
timestamp := time .Unix (1112911993 , 0 )
654
670
655
- repo .AddFile (t , "subdir/file.txt" , "Hello, world!\n " )
671
+ testRepo .AddFile (t , "subdir/file.txt" , "Hello, world!\n " )
656
672
657
- cmd := repo .GitCommand (t , "commit" , "-m" , "initial" )
673
+ cmd := testRepo .GitCommand (t , "commit" , "-m" , "initial" )
658
674
testutils .AddAuthorInfo (cmd , & timestamp )
659
675
require .NoError (t , cmd .Run (), "creating commit" )
660
676
677
+ repo := testRepo .Repository (t )
678
+
679
+ refRoots , err := sizes .CollectReferences (ctx , repo , refGrouper {})
680
+ require .NoError (t , err )
681
+
661
682
h , err := sizes .ScanRepositoryUsingGraph (
662
- context .Background (), repo .Repository (t ),
663
- refGrouper {} , sizes .NameStyleNone , meter .NoProgressMeter ,
683
+ context .Background (), testRepo .Repository (t ),
684
+ refRoots , sizes .NameStyleNone , meter .NoProgressMeter ,
664
685
)
665
686
require .NoError (t , err , "scanning repository" )
666
687
assert .Equal (t , counts .Count32 (2 ), h .MaxPathDepth , "max path depth" )
@@ -669,6 +690,8 @@ func TestFromSubdir(t *testing.T) {
669
690
func TestSubmodule (t * testing.T ) {
670
691
t .Parallel ()
671
692
693
+ ctx := context .Background ()
694
+
672
695
tmp , err := ioutil .TempDir ("" , "submodule" )
673
696
require .NoError (t , err , "creating temporary directory" )
674
697
@@ -678,55 +701,66 @@ func TestSubmodule(t *testing.T) {
678
701
679
702
timestamp := time .Unix (1112911993 , 0 )
680
703
681
- submRepo := testutils.TestRepo {
704
+ submTestRepo := testutils.TestRepo {
682
705
Path : filepath .Join (tmp , "subm" ),
683
706
}
684
- submRepo .Init (t , false )
685
- submRepo .AddFile (t , "submfile1.txt" , "Hello, submodule!\n " )
686
- submRepo .AddFile (t , "submfile2.txt" , "Hello again, submodule!\n " )
687
- submRepo .AddFile (t , "submfile3.txt" , "Hello again, submodule!\n " )
707
+ submTestRepo .Init (t , false )
708
+ submTestRepo .AddFile (t , "submfile1.txt" , "Hello, submodule!\n " )
709
+ submTestRepo .AddFile (t , "submfile2.txt" , "Hello again, submodule!\n " )
710
+ submTestRepo .AddFile (t , "submfile3.txt" , "Hello again, submodule!\n " )
688
711
689
- cmd := submRepo .GitCommand (t , "commit" , "-m" , "subm initial" )
712
+ cmd := submTestRepo .GitCommand (t , "commit" , "-m" , "subm initial" )
690
713
testutils .AddAuthorInfo (cmd , & timestamp )
691
714
require .NoError (t , cmd .Run (), "creating subm commit" )
692
715
693
- mainRepo := testutils.TestRepo {
716
+ mainTestRepo := testutils.TestRepo {
694
717
Path : filepath .Join (tmp , "main" ),
695
718
}
696
- mainRepo .Init (t , false )
719
+ mainTestRepo .Init (t , false )
697
720
698
- mainRepo .AddFile (t , "mainfile.txt" , "Hello, main!\n " )
721
+ mainTestRepo .AddFile (t , "mainfile.txt" , "Hello, main!\n " )
699
722
700
- cmd = mainRepo .GitCommand (t , "commit" , "-m" , "main initial" )
723
+ cmd = mainTestRepo .GitCommand (t , "commit" , "-m" , "main initial" )
701
724
testutils .AddAuthorInfo (cmd , & timestamp )
702
725
require .NoError (t , cmd .Run (), "creating main commit" )
703
726
704
727
// Make subm a submodule of main:
705
- cmd = mainRepo .GitCommand (t , "-c" , "protocol.file.allow=always" , "submodule" , "add" , submRepo .Path , "sub" )
706
- cmd .Dir = mainRepo .Path
728
+ cmd = mainTestRepo .GitCommand (t , "-c" , "protocol.file.allow=always" , "submodule" , "add" , submTestRepo .Path , "sub" )
729
+ cmd .Dir = mainTestRepo .Path
707
730
require .NoError (t , cmd .Run (), "adding submodule" )
708
731
709
- cmd = mainRepo .GitCommand (t , "commit" , "-m" , "add submodule" )
732
+ cmd = mainTestRepo .GitCommand (t , "commit" , "-m" , "add submodule" )
710
733
testutils .AddAuthorInfo (cmd , & timestamp )
711
734
require .NoError (t , cmd .Run (), "committing submodule to main" )
712
735
736
+ mainRepo := mainTestRepo .Repository (t )
737
+
738
+ mainRefRoots , err := sizes .CollectReferences (ctx , mainRepo , refGrouper {})
739
+ require .NoError (t , err )
740
+
713
741
// Analyze the main repo:
714
742
h , err := sizes .ScanRepositoryUsingGraph (
715
- context .Background (), mainRepo .Repository (t ),
716
- refGrouper {} , sizes .NameStyleNone , meter .NoProgressMeter ,
743
+ context .Background (), mainTestRepo .Repository (t ),
744
+ mainRefRoots , sizes .NameStyleNone , meter .NoProgressMeter ,
717
745
)
718
746
require .NoError (t , err , "scanning repository" )
719
747
assert .Equal (t , counts .Count32 (2 ), h .UniqueBlobCount , "unique blob count" )
720
748
assert .Equal (t , counts .Count32 (2 ), h .MaxExpandedBlobCount , "max expanded blob count" )
721
749
assert .Equal (t , counts .Count32 (1 ), h .MaxExpandedSubmoduleCount , "max expanded submodule count" )
722
750
723
751
// Analyze the submodule:
724
- submRepo2 := testutils.TestRepo {
725
- Path : filepath .Join (mainRepo .Path , "sub" ),
752
+ submTestRepo2 := testutils.TestRepo {
753
+ Path : filepath .Join (mainTestRepo .Path , "sub" ),
726
754
}
755
+
756
+ submRepo2 := submTestRepo2 .Repository (t )
757
+
758
+ submRefRoots2 , err := sizes .CollectReferences (ctx , submRepo2 , refGrouper {})
759
+ require .NoError (t , err )
760
+
727
761
h , err = sizes .ScanRepositoryUsingGraph (
728
- context .Background (), submRepo2 . Repository ( t ) ,
729
- refGrouper {} , sizes .NameStyleNone , meter .NoProgressMeter ,
762
+ context .Background (), submRepo2 ,
763
+ submRefRoots2 , sizes .NameStyleNone , meter .NoProgressMeter ,
730
764
)
731
765
require .NoError (t , err , "scanning repository" )
732
766
assert .Equal (t , counts .Count32 (2 ), h .UniqueBlobCount , "unique blob count" )
0 commit comments