0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-18 21:42:56 +02:00
This commit is contained in:
wxiaoguang 2025-07-12 15:27:26 +08:00
parent 38fa21b366
commit 5c363af83c
3 changed files with 17 additions and 26 deletions

View File

@ -3,9 +3,20 @@
package git package git
import "path"
// CommitInfo describes the first commit with the provided entry // CommitInfo describes the first commit with the provided entry
type CommitInfo struct { type CommitInfo struct {
Entry *TreeEntry Entry *TreeEntry
Commit *Commit Commit *Commit
SubmoduleFile *CommitSubmoduleFile SubmoduleFile *CommitSubmoduleFile
} }
func getCommitInfoSubmoduleFile(repoLink string, entry *TreeEntry, commit *Commit, treePathDir string) (*CommitSubmoduleFile, error) {
fullPath := path.Join(treePathDir, entry.Name())
submodule, err := commit.GetSubModule(fullPath)
if err != nil {
return nil, err
}
return NewCommitSubmoduleFile(repoLink, fullPath, submodule.URL, entry.ID.String()), nil
}

View File

@ -71,22 +71,12 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *
commitsInfo[i].Commit = entryCommit commitsInfo[i].Commit = entryCommit
} }
// If the entry is a submodule add a submodule file for this // If the entry is a submodule, add a submodule file for this
if entry.IsSubModule() { if entry.IsSubModule() {
subModuleURL := "" commitsInfo[i].SubmoduleFile, err = getCommitInfoSubmoduleFile(repoLink, entry, commit, treePath)
var fullPath string if err != nil {
if len(treePath) > 0 {
fullPath = treePath + "/" + entry.Name()
} else {
fullPath = entry.Name()
}
if subModule, err := commit.GetSubModule(fullPath); err != nil {
return nil, nil, err return nil, nil, err
} else if subModule != nil {
subModuleURL = subModule.URL
} }
subModuleFile := NewCommitSubmoduleFile(repoLink, fullPath, subModuleURL, entry.ID.String())
commitsInfo[i].SubmoduleFile = subModuleFile
} }
} }

View File

@ -62,22 +62,12 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *
log.Debug("missing commit for %s", entry.Name()) log.Debug("missing commit for %s", entry.Name())
} }
// If the entry is a submodule add a submodule file for this // If the entry is a submodule, add a submodule file for this
if entry.IsSubModule() { if entry.IsSubModule() {
subModuleURL := "" commitsInfo[i].SubmoduleFile, err = getCommitInfoSubmoduleFile(repoLink, entry, commit, treePath)
var fullPath string if err != nil {
if len(treePath) > 0 {
fullPath = treePath + "/" + entry.Name()
} else {
fullPath = entry.Name()
}
if subModule, err := commit.GetSubModule(fullPath); err != nil {
return nil, nil, err return nil, nil, err
} else if subModule != nil {
subModuleURL = subModule.URL
} }
subModuleFile := NewCommitSubmoduleFile(repoLink, fullPath, subModuleURL, entry.ID.String())
commitsInfo[i].SubmoduleFile = subModuleFile
} }
} }