@@ -57,11 +57,6 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
5757
5858 tree := commit .Tree
5959
60- entries , err := tree .ListEntriesRecursiveWithSize ()
61- if err != nil {
62- return nil , err
63- }
64-
6560 checker , deferable := repo .CheckAttributeReader (commitID )
6661 defer deferable ()
6762
@@ -77,18 +72,18 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
7772 firstExcludedLanguage := ""
7873 firstExcludedLanguageSize := int64 (0 )
7974
80- for _ , f := range entries {
75+ if err := tree . IterateEntriesWithSize ( func ( f * TreeEntry ) error {
8176 select {
8277 case <- repo .Ctx .Done ():
83- return sizes , repo .Ctx .Err ()
78+ return repo .Ctx .Err ()
8479 default :
8580 }
8681
8782 contentBuf .Reset ()
8883 content = contentBuf .Bytes ()
8984
9085 if f .Size () == 0 {
91- continue
86+ return nil
9287 }
9388
9489 isVendored := optional .None [bool ]()
@@ -101,22 +96,22 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
10196 if err == nil {
10297 isVendored = AttributeToBool (attrs , AttributeLinguistVendored )
10398 if isVendored .ValueOrDefault (false ) {
104- continue
99+ return nil
105100 }
106101
107102 isGenerated = AttributeToBool (attrs , AttributeLinguistGenerated )
108103 if isGenerated .ValueOrDefault (false ) {
109- continue
104+ return nil
110105 }
111106
112107 isDocumentation = AttributeToBool (attrs , AttributeLinguistDocumentation )
113108 if isDocumentation .ValueOrDefault (false ) {
114- continue
109+ return nil
115110 }
116111
117112 isDetectable = AttributeToBool (attrs , AttributeLinguistDetectable )
118113 if ! isDetectable .ValueOrDefault (true ) {
119- continue
114+ return nil
120115 }
121116
122117 hasLanguage := TryReadLanguageAttribute (attrs )
@@ -131,7 +126,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
131126
132127 // this language will always be added to the size
133128 sizes [language ] += f .Size ()
134- continue
129+ return nil
135130 }
136131 }
137132 }
@@ -140,19 +135,19 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
140135 enry .IsDotFile (f .Name ()) ||
141136 (! isDocumentation .Has () && enry .IsDocumentation (f .Name ())) ||
142137 enry .IsConfiguration (f .Name ()) {
143- continue
138+ return nil
144139 }
145140
146141 // If content can not be read or file is too big just do detection by filename
147142
148143 if f .Size () <= bigFileSize {
149144 if err := writeID (f .ID .String ()); err != nil {
150- return nil , err
145+ return err
151146 }
152147 _ , _ , size , err := ReadBatchLine (batchReader )
153148 if err != nil {
154149 log .Debug ("Error reading blob: %s Err: %v" , f .ID .String (), err )
155- return nil , err
150+ return err
156151 }
157152
158153 sizeToRead := size
@@ -164,22 +159,22 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
164159
165160 _ , err = contentBuf .ReadFrom (io .LimitReader (batchReader , sizeToRead ))
166161 if err != nil {
167- return nil , err
162+ return err
168163 }
169164 content = contentBuf .Bytes ()
170165 if err := DiscardFull (batchReader , discard ); err != nil {
171- return nil , err
166+ return err
172167 }
173168 }
174169 if ! isGenerated .Has () && enry .IsGenerated (f .Name (), content ) {
175- continue
170+ return nil
176171 }
177172
178173 // FIXME: Why can't we split this and the IsGenerated tests to avoid reading the blob unless absolutely necessary?
179174 // - eg. do the all the detection tests using filename first before reading content.
180175 language := analyze .GetCodeLanguage (f .Name (), content )
181176 if language == "" {
182- continue
177+ return nil
183178 }
184179
185180 // group languages, such as Pug -> HTML; SCSS -> CSS
@@ -200,6 +195,9 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
200195 firstExcludedLanguage = language
201196 firstExcludedLanguageSize += f .Size ()
202197 }
198+ return nil
199+ }); err != nil {
200+ return sizes , err
203201 }
204202
205203 // If there are no included languages add the first excluded language
0 commit comments