@@ -17,6 +17,8 @@ import (
17
17
18
18
"code.gitea.io/gitea/modules/log"
19
19
"code.gitea.io/gitea/modules/util"
20
+
21
+ "github.com/go-git/go-git/v5/config"
20
22
)
21
23
22
24
// Commit represents a git commit.
@@ -371,37 +373,32 @@ func (c *Commit) GetSubModules() (*ObjectCache, error) {
371
373
return nil , err
372
374
}
373
375
374
- rd , err := entry .Blob ().DataAsync ( )
376
+ content , err := entry .Blob ().GetBlobContent ( 10 * 1024 )
375
377
if err != nil {
376
378
return nil , err
377
379
}
378
380
379
- defer rd .Close ()
380
- scanner := bufio .NewScanner (rd )
381
- c .submoduleCache = newObjectCache ()
382
- var ismodule bool
383
- var path string
384
- for scanner .Scan () {
385
- if strings .HasPrefix (scanner .Text (), "[submodule" ) {
386
- ismodule = true
387
- continue
388
- }
389
- if ismodule {
390
- fields := strings .Split (scanner .Text (), "=" )
391
- k := strings .TrimSpace (fields [0 ])
392
- if k == "path" {
393
- path = strings .TrimSpace (fields [1 ])
394
- } else if k == "url" {
395
- c .submoduleCache .Set (path , & SubModule {path , strings .TrimSpace (fields [1 ])})
396
- ismodule = false
397
- }
398
- }
381
+ c .submoduleCache , err = parseSubmoduleContent ([]byte (content ))
382
+ if err != nil {
383
+ return nil , err
399
384
}
400
- if err = scanner .Err (); err != nil {
401
- return nil , fmt .Errorf ("GetSubModules scan: %w" , err )
385
+ return c .submoduleCache , nil
386
+ }
387
+
388
+ func parseSubmoduleContent (bs []byte ) (* ObjectCache , error ) {
389
+ cfg := config .NewModules ()
390
+ if err := cfg .Unmarshal (bs ); err != nil {
391
+ return nil , err
392
+ }
393
+ submoduleCache := newObjectCache ()
394
+ if len (cfg .Submodules ) == 0 {
395
+ return nil , fmt .Errorf ("no submodules found" )
396
+ }
397
+ for _ , subModule := range cfg .Submodules {
398
+ submoduleCache .Set (subModule .Path , subModule .URL )
402
399
}
403
400
404
- return c . submoduleCache , nil
401
+ return submoduleCache , nil
405
402
}
406
403
407
404
// GetSubModule get the sub module according entryname
0 commit comments