9
9
"bytes"
10
10
"context"
11
11
"errors"
12
- "fmt"
13
12
"io"
14
13
"os/exec"
15
14
"strconv"
@@ -29,7 +28,7 @@ type Commit struct {
29
28
Signature * CommitSignature
30
29
31
30
Parents []ObjectID // ID strings
32
- submoduleCache * ObjectCache
31
+ submoduleCache * ObjectCache [ * SubModule ]
33
32
}
34
33
35
34
// CommitSignature represents a git commit signature part.
@@ -357,69 +356,6 @@ func (c *Commit) GetFileContent(filename string, limit int) (string, error) {
357
356
return string (bytes ), nil
358
357
}
359
358
360
- // GetSubModules get all the sub modules of current revision git tree
361
- func (c * Commit ) GetSubModules () (* ObjectCache , error ) {
362
- if c .submoduleCache != nil {
363
- return c .submoduleCache , nil
364
- }
365
-
366
- entry , err := c .GetTreeEntryByPath (".gitmodules" )
367
- if err != nil {
368
- if _ , ok := err .(ErrNotExist ); ok {
369
- return nil , nil
370
- }
371
- return nil , err
372
- }
373
-
374
- rd , err := entry .Blob ().DataAsync ()
375
- if err != nil {
376
- return nil , err
377
- }
378
-
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
- }
399
- }
400
- if err = scanner .Err (); err != nil {
401
- return nil , fmt .Errorf ("GetSubModules scan: %w" , err )
402
- }
403
-
404
- return c .submoduleCache , nil
405
- }
406
-
407
- // GetSubModule get the sub module according entryname
408
- func (c * Commit ) GetSubModule (entryname string ) (* SubModule , error ) {
409
- modules , err := c .GetSubModules ()
410
- if err != nil {
411
- return nil , err
412
- }
413
-
414
- if modules != nil {
415
- module , has := modules .Get (entryname )
416
- if has {
417
- return module .(* SubModule ), nil
418
- }
419
- }
420
- return nil , nil
421
- }
422
-
423
359
// GetBranchName gets the closest branch name (as returned by 'git name-rev --name-only')
424
360
func (c * Commit ) GetBranchName () (string , error ) {
425
361
cmd := NewCommand (c .repo .Ctx , "name-rev" )
0 commit comments