@@ -9,11 +9,12 @@ import (
9
9
"time"
10
10
11
11
"github.com/github/git-sizer/counts"
12
+ "github.com/github/git-sizer/git"
12
13
"github.com/github/git-sizer/meter"
13
14
)
14
15
15
16
func ScanRepositoryUsingGraph (
16
- repo * Repository , filter ReferenceFilter , nameStyle NameStyle , progress bool ,
17
+ repo * git. Repository , filter git. ReferenceFilter , nameStyle NameStyle , progress bool ,
17
18
) (HistorySize , error ) {
18
19
graph := NewGraph (nameStyle )
19
20
var progressMeter meter.Progress
@@ -44,7 +45,7 @@ func ScanRepositoryUsingGraph(
44
45
}()
45
46
46
47
errChan := make (chan error , 1 )
47
- var refs []Reference
48
+ var refs []git. Reference
48
49
// Feed the references that we want into the stdin of the object
49
50
// iterator:
50
51
go func () {
@@ -82,13 +83,13 @@ func ScanRepositoryUsingGraph(
82
83
}()
83
84
84
85
type ObjectHeader struct {
85
- oid Oid
86
+ oid git. Oid
86
87
objectSize counts.Count32
87
88
}
88
89
89
90
type CommitHeader struct {
90
91
ObjectHeader
91
- tree Oid
92
+ tree git. Oid
92
93
}
93
94
94
95
// We process the blobs right away, but record these other types
@@ -151,7 +152,7 @@ func ScanRepositoryUsingGraph(
151
152
case "tree" :
152
153
trees = append (trees , ObjectHeader {oid , objectSize })
153
154
case "commit" :
154
- commits = append (commits , CommitHeader {ObjectHeader {oid , objectSize }, NullOid })
155
+ commits = append (commits , CommitHeader {ObjectHeader {oid , objectSize }, git . NullOid })
155
156
case "tag" :
156
157
tags = append (tags , ObjectHeader {oid , objectSize })
157
158
default :
@@ -242,7 +243,7 @@ func ScanRepositoryUsingGraph(
242
243
return HistorySize {}, fmt .Errorf ("expected tree; read %#v" , objectType )
243
244
}
244
245
progressMeter .Inc ()
245
- tree , err := ParseTree (oid , data )
246
+ tree , err := git . ParseTree (oid , data )
246
247
if err != nil {
247
248
return HistorySize {}, err
248
249
}
@@ -268,7 +269,7 @@ func ScanRepositoryUsingGraph(
268
269
if objectType != "commit" {
269
270
return HistorySize {}, fmt .Errorf ("expected commit; read %#v" , objectType )
270
271
}
271
- commit , err := ParseCommit (oid , data )
272
+ commit , err := git . ParseCommit (oid , data )
272
273
if err != nil {
273
274
return HistorySize {}, err
274
275
}
@@ -304,7 +305,7 @@ func ScanRepositoryUsingGraph(
304
305
if objectType != "tag" {
305
306
return HistorySize {}, fmt .Errorf ("expected tag; read %#v" , objectType )
306
307
}
307
- tag , err := ParseTag (oid , data )
308
+ tag , err := git . ParseTag (oid , data )
308
309
if err != nil {
309
310
return HistorySize {}, err
310
311
}
@@ -336,21 +337,21 @@ func ScanRepositoryUsingGraph(
336
337
337
338
// An object graph that is being built up.
338
339
type Graph struct {
339
- repo * Repository
340
+ repo * git. Repository
340
341
341
342
blobLock sync.Mutex
342
- blobSizes map [Oid ]BlobSize
343
+ blobSizes map [git. Oid ]BlobSize
343
344
344
345
treeLock sync.Mutex
345
- treeRecords map [Oid ]* treeRecord
346
- treeSizes map [Oid ]TreeSize
346
+ treeRecords map [git. Oid ]* treeRecord
347
+ treeSizes map [git. Oid ]TreeSize
347
348
348
349
commitLock sync.Mutex
349
- commitSizes map [Oid ]CommitSize
350
+ commitSizes map [git. Oid ]CommitSize
350
351
351
352
tagLock sync.Mutex
352
- tagRecords map [Oid ]* tagRecord
353
- tagSizes map [Oid ]TagSize
353
+ tagRecords map [git. Oid ]* tagRecord
354
+ tagSizes map [git. Oid ]TagSize
354
355
355
356
// Statistics about the overall history size:
356
357
historyLock sync.Mutex
@@ -361,21 +362,21 @@ type Graph struct {
361
362
362
363
func NewGraph (nameStyle NameStyle ) * Graph {
363
364
return & Graph {
364
- blobSizes : make (map [Oid ]BlobSize ),
365
+ blobSizes : make (map [git. Oid ]BlobSize ),
365
366
366
- treeRecords : make (map [Oid ]* treeRecord ),
367
- treeSizes : make (map [Oid ]TreeSize ),
367
+ treeRecords : make (map [git. Oid ]* treeRecord ),
368
+ treeSizes : make (map [git. Oid ]TreeSize ),
368
369
369
- commitSizes : make (map [Oid ]CommitSize ),
370
+ commitSizes : make (map [git. Oid ]CommitSize ),
370
371
371
- tagRecords : make (map [Oid ]* tagRecord ),
372
- tagSizes : make (map [Oid ]TagSize ),
372
+ tagRecords : make (map [git. Oid ]* tagRecord ),
373
+ tagSizes : make (map [git. Oid ]TagSize ),
373
374
374
375
pathResolver : NewPathResolver (nameStyle ),
375
376
}
376
377
}
377
378
378
- func (g * Graph ) RegisterReference (ref Reference ) {
379
+ func (g * Graph ) RegisterReference (ref git. Reference ) {
379
380
g .historyLock .Lock ()
380
381
g .historySize .recordReference (g , ref )
381
382
g .historyLock .Unlock ()
@@ -400,7 +401,7 @@ func (g *Graph) HistorySize() HistorySize {
400
401
}
401
402
402
403
// Record that the specified `oid` is a blob with the specified size.
403
- func (g * Graph ) RegisterBlob (oid Oid , objectSize counts.Count32 ) {
404
+ func (g * Graph ) RegisterBlob (oid git. Oid , objectSize counts.Count32 ) {
404
405
size := BlobSize {Size : objectSize }
405
406
// There are no listeners. Since this is a blob, we know all that
406
407
// we need to know about it. So skip the record and just fill in
@@ -423,7 +424,7 @@ func (g *Graph) RegisterBlob(oid Oid, objectSize counts.Count32) {
423
424
// listener to be informed some time in the future when the size is
424
425
// known. In this case, return false as the second value.
425
426
426
- func (g * Graph ) GetBlobSize (oid Oid ) BlobSize {
427
+ func (g * Graph ) GetBlobSize (oid git. Oid ) BlobSize {
427
428
// See if we already know the size:
428
429
size , ok := g .blobSizes [oid ]
429
430
if ! ok {
@@ -432,7 +433,7 @@ func (g *Graph) GetBlobSize(oid Oid) BlobSize {
432
433
return size
433
434
}
434
435
435
- func (g * Graph ) RequireTreeSize (oid Oid , listener func (TreeSize )) (TreeSize , bool ) {
436
+ func (g * Graph ) RequireTreeSize (oid git. Oid , listener func (TreeSize )) (TreeSize , bool ) {
436
437
g .treeLock .Lock ()
437
438
438
439
size , ok := g .treeSizes [oid ]
@@ -454,7 +455,7 @@ func (g *Graph) RequireTreeSize(oid Oid, listener func(TreeSize)) (TreeSize, boo
454
455
return TreeSize {}, false
455
456
}
456
457
457
- func (g * Graph ) GetTreeSize (oid Oid ) TreeSize {
458
+ func (g * Graph ) GetTreeSize (oid git. Oid ) TreeSize {
458
459
g .treeLock .Lock ()
459
460
460
461
size , ok := g .treeSizes [oid ]
@@ -466,7 +467,7 @@ func (g *Graph) GetTreeSize(oid Oid) TreeSize {
466
467
}
467
468
468
469
// Record that the specified `oid` is the specified `tree`.
469
- func (g * Graph ) RegisterTree (oid Oid , tree * Tree ) error {
470
+ func (g * Graph ) RegisterTree (oid git. Oid , tree * git. Tree ) error {
470
471
g .treeLock .Lock ()
471
472
472
473
if _ , ok := g .treeSizes [oid ]; ok {
@@ -487,7 +488,7 @@ func (g *Graph) RegisterTree(oid Oid, tree *Tree) error {
487
488
}
488
489
489
490
func (g * Graph ) finalizeTreeSize (
490
- oid Oid , size TreeSize , objectSize counts.Count32 , treeEntries counts.Count32 ,
491
+ oid git. Oid , size TreeSize , objectSize counts.Count32 , treeEntries counts.Count32 ,
491
492
) {
492
493
g .treeLock .Lock ()
493
494
g .treeSizes [oid ] = size
@@ -500,7 +501,7 @@ func (g *Graph) finalizeTreeSize(
500
501
}
501
502
502
503
type treeRecord struct {
503
- oid Oid
504
+ oid git. Oid
504
505
505
506
// Limit to only one mutator at a time.
506
507
lock sync.Mutex
@@ -527,7 +528,7 @@ type treeRecord struct {
527
528
listeners []func (TreeSize )
528
529
}
529
530
530
- func newTreeRecord (oid Oid ) * treeRecord {
531
+ func newTreeRecord (oid git. Oid ) * treeRecord {
531
532
return & treeRecord {
532
533
oid : oid ,
533
534
size : TreeSize {ExpandedTreeCount : 1 },
@@ -536,11 +537,11 @@ func newTreeRecord(oid Oid) *treeRecord {
536
537
}
537
538
538
539
// Initialize `r` (which is empty) based on `tree`.
539
- func (r * treeRecord ) initialize (g * Graph , oid Oid , tree * Tree ) error {
540
+ func (r * treeRecord ) initialize (g * Graph , oid git. Oid , tree * git. Tree ) error {
540
541
r .lock .Lock ()
541
542
defer r .lock .Unlock ()
542
543
543
- r .objectSize = counts . NewCount32 ( uint64 ( len ( tree .data )) )
544
+ r .objectSize = tree .Size ( )
544
545
r .pending = 0
545
546
546
547
iter := tree .Iter ()
@@ -624,7 +625,7 @@ func (r *treeRecord) addListener(listener func(TreeSize)) {
624
625
r .listeners = append (r .listeners , listener )
625
626
}
626
627
627
- func (g * Graph ) GetCommitSize (oid Oid ) CommitSize {
628
+ func (g * Graph ) GetCommitSize (oid git. Oid ) CommitSize {
628
629
g .commitLock .Lock ()
629
630
630
631
size , ok := g .commitSizes [oid ]
@@ -637,7 +638,7 @@ func (g *Graph) GetCommitSize(oid Oid) CommitSize {
637
638
}
638
639
639
640
// Record that the specified `oid` is the specified `commit`.
640
- func (g * Graph ) RegisterCommit (oid Oid , commit * Commit ) {
641
+ func (g * Graph ) RegisterCommit (oid git. Oid , commit * git. Commit ) {
641
642
g .commitLock .Lock ()
642
643
if _ , ok := g .commitSizes [oid ]; ok {
643
644
panic (fmt .Sprintf ("commit %s registered twice!" , oid ))
@@ -671,7 +672,7 @@ func (g *Graph) RegisterCommit(oid Oid, commit *Commit) {
671
672
g .historyLock .Unlock ()
672
673
}
673
674
674
- func (g * Graph ) RequireTagSize (oid Oid , listener func (TagSize )) (TagSize , bool ) {
675
+ func (g * Graph ) RequireTagSize (oid git. Oid , listener func (TagSize )) (TagSize , bool ) {
675
676
g .tagLock .Lock ()
676
677
677
678
size , ok := g .tagSizes [oid ]
@@ -694,7 +695,7 @@ func (g *Graph) RequireTagSize(oid Oid, listener func(TagSize)) (TagSize, bool)
694
695
}
695
696
696
697
// Record that the specified `oid` is the specified `tag`.
697
- func (g * Graph ) RegisterTag (oid Oid , tag * Tag ) {
698
+ func (g * Graph ) RegisterTag (oid git. Oid , tag * git. Tag ) {
698
699
g .tagLock .Lock ()
699
700
700
701
if _ , ok := g .tagSizes [oid ]; ok {
@@ -714,7 +715,7 @@ func (g *Graph) RegisterTag(oid Oid, tag *Tag) {
714
715
record .initialize (g , oid , tag )
715
716
}
716
717
717
- func (g * Graph ) finalizeTagSize (oid Oid , size TagSize , objectSize counts.Count32 ) {
718
+ func (g * Graph ) finalizeTagSize (oid git. Oid , size TagSize , objectSize counts.Count32 ) {
718
719
g .tagLock .Lock ()
719
720
g .tagSizes [oid ] = size
720
721
delete (g .tagRecords , oid )
@@ -726,7 +727,7 @@ func (g *Graph) finalizeTagSize(oid Oid, size TagSize, objectSize counts.Count32
726
727
}
727
728
728
729
type tagRecord struct {
729
- oid Oid
730
+ oid git. Oid
730
731
731
732
// Limit to only one mutator at a time.
732
733
lock sync.Mutex
@@ -744,15 +745,15 @@ type tagRecord struct {
744
745
listeners []func (TagSize )
745
746
}
746
747
747
- func newTagRecord (oid Oid ) * tagRecord {
748
+ func newTagRecord (oid git. Oid ) * tagRecord {
748
749
return & tagRecord {
749
750
oid : oid ,
750
751
pending : - 1 ,
751
752
}
752
753
}
753
754
754
755
// Initialize `r` (which is empty) based on `tag`.
755
- func (r * tagRecord ) initialize (g * Graph , oid Oid , tag * Tag ) {
756
+ func (r * tagRecord ) initialize (g * Graph , oid git. Oid , tag * git. Tag ) {
756
757
r .lock .Lock ()
757
758
defer r .lock .Unlock ()
758
759
0 commit comments