|
|
|
|
@ -6,6 +6,7 @@ package git
@@ -6,6 +6,7 @@ package git
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"context" |
|
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
giturl "code.gitea.io/gitea/modules/git/url" |
|
|
|
|
) |
|
|
|
|
@ -13,10 +14,10 @@ import (
@@ -13,10 +14,10 @@ import (
|
|
|
|
|
// CommitSubmoduleFile represents a file with submodule type.
|
|
|
|
|
type CommitSubmoduleFile struct { |
|
|
|
|
refURL string |
|
|
|
|
parsedURL *giturl.RepositoryURL |
|
|
|
|
parsed bool |
|
|
|
|
refID string |
|
|
|
|
repoLink string |
|
|
|
|
|
|
|
|
|
parsed bool |
|
|
|
|
targetRepoLink string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewCommitSubmoduleFile create a new submodule file
|
|
|
|
|
@ -35,20 +36,27 @@ func (sf *CommitSubmoduleFile) SubmoduleWebLink(ctx context.Context, optCommitID
@@ -35,20 +36,27 @@ func (sf *CommitSubmoduleFile) SubmoduleWebLink(ctx context.Context, optCommitID
|
|
|
|
|
} |
|
|
|
|
if !sf.parsed { |
|
|
|
|
sf.parsed = true |
|
|
|
|
if strings.HasPrefix(sf.refURL, "../") { |
|
|
|
|
// FIXME: when handling relative path, this logic is not right. It needs to:
|
|
|
|
|
// 1. Remember the submodule's full path and its commit's repo home link
|
|
|
|
|
// 2. Resolve the relative path: targetRepoLink = path.Join(repoHomeLink, path.Dir(submoduleFullPath), refURL)
|
|
|
|
|
// Not an easy task and need to refactor related code a lot.
|
|
|
|
|
sf.targetRepoLink = sf.refURL |
|
|
|
|
} else { |
|
|
|
|
parsedURL, err := giturl.ParseRepositoryURL(ctx, sf.refURL) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
sf.parsedURL = parsedURL |
|
|
|
|
sf.repoLink = giturl.MakeRepositoryWebLink(sf.parsedURL) |
|
|
|
|
sf.targetRepoLink = giturl.MakeRepositoryWebLink(parsedURL) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
var commitLink string |
|
|
|
|
if len(optCommitID) == 2 { |
|
|
|
|
commitLink = sf.repoLink + "/compare/" + optCommitID[0] + "..." + optCommitID[1] |
|
|
|
|
commitLink = sf.targetRepoLink + "/compare/" + optCommitID[0] + "..." + optCommitID[1] |
|
|
|
|
} else if len(optCommitID) == 1 { |
|
|
|
|
commitLink = sf.repoLink + "/tree/" + optCommitID[0] |
|
|
|
|
commitLink = sf.targetRepoLink + "/tree/" + optCommitID[0] |
|
|
|
|
} else { |
|
|
|
|
commitLink = sf.repoLink + "/tree/" + sf.refID |
|
|
|
|
commitLink = sf.targetRepoLink + "/tree/" + sf.refID |
|
|
|
|
} |
|
|
|
|
return &SubmoduleWebLink{RepoWebLink: sf.repoLink, CommitWebLink: commitLink} |
|
|
|
|
return &SubmoduleWebLink{RepoWebLink: sf.targetRepoLink, CommitWebLink: commitLink} |
|
|
|
|
} |
|
|
|
|
|