Skip to content

Commit 5c363af

Browse files
committed
simplify
1 parent 38fa21b commit 5c363af

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed

modules/git/commit_info.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@
33

44
package git
55

6+
import "path"
7+
68
// CommitInfo describes the first commit with the provided entry
79
type CommitInfo struct {
810
Entry *TreeEntry
911
Commit *Commit
1012
SubmoduleFile *CommitSubmoduleFile
1113
}
14+
15+
func getCommitInfoSubmoduleFile(repoLink string, entry *TreeEntry, commit *Commit, treePathDir string) (*CommitSubmoduleFile, error) {
16+
fullPath := path.Join(treePathDir, entry.Name())
17+
submodule, err := commit.GetSubModule(fullPath)
18+
if err != nil {
19+
return nil, err
20+
}
21+
return NewCommitSubmoduleFile(repoLink, fullPath, submodule.URL, entry.ID.String()), nil
22+
}

modules/git/commit_info_gogit.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,12 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *
7171
commitsInfo[i].Commit = entryCommit
7272
}
7373

74-
// If the entry is a submodule add a submodule file for this
74+
// If the entry is a submodule, add a submodule file for this
7575
if entry.IsSubModule() {
76-
subModuleURL := ""
77-
var fullPath string
78-
if len(treePath) > 0 {
79-
fullPath = treePath + "/" + entry.Name()
80-
} else {
81-
fullPath = entry.Name()
82-
}
83-
if subModule, err := commit.GetSubModule(fullPath); err != nil {
76+
commitsInfo[i].SubmoduleFile, err = getCommitInfoSubmoduleFile(repoLink, entry, commit, treePath)
77+
if err != nil {
8478
return nil, nil, err
85-
} else if subModule != nil {
86-
subModuleURL = subModule.URL
8779
}
88-
subModuleFile := NewCommitSubmoduleFile(repoLink, fullPath, subModuleURL, entry.ID.String())
89-
commitsInfo[i].SubmoduleFile = subModuleFile
9080
}
9181
}
9282

modules/git/commit_info_nogogit.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,12 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *
6262
log.Debug("missing commit for %s", entry.Name())
6363
}
6464

65-
// If the entry is a submodule add a submodule file for this
65+
// If the entry is a submodule, add a submodule file for this
6666
if entry.IsSubModule() {
67-
subModuleURL := ""
68-
var fullPath string
69-
if len(treePath) > 0 {
70-
fullPath = treePath + "/" + entry.Name()
71-
} else {
72-
fullPath = entry.Name()
73-
}
74-
if subModule, err := commit.GetSubModule(fullPath); err != nil {
67+
commitsInfo[i].SubmoduleFile, err = getCommitInfoSubmoduleFile(repoLink, entry, commit, treePath)
68+
if err != nil {
7569
return nil, nil, err
76-
} else if subModule != nil {
77-
subModuleURL = subModule.URL
7870
}
79-
subModuleFile := NewCommitSubmoduleFile(repoLink, fullPath, subModuleURL, entry.ID.String())
80-
commitsInfo[i].SubmoduleFile = subModuleFile
8171
}
8272
}
8373

0 commit comments

Comments
 (0)