@ -29,12 +29,16 @@ func NewCommitSubmoduleFile(repoLink, fullPath, refURL, refID string) *CommitSub
return & CommitSubmoduleFile { repoLink : repoLink , fullPath : fullPath , refURL : refURL , refID : refID }
}
// RefID returns the commit ID of the submodule, it returns empty string for nil receiver
func ( sf * CommitSubmoduleFile ) RefID ( ) string {
if sf == nil {
return ""
}
return sf . refID
}
func ( sf * CommitSubmoduleFile ) getWebLinkInTargetRepo ( ctx context . Context , moreLinkPath string ) * SubmoduleWebLink {
if sf == nil {
if sf == nil || sf . refURL == "" {
return nil
}
if strings . HasPrefix ( sf . refURL , "../" ) {
@ -53,14 +57,13 @@ func (sf *CommitSubmoduleFile) getWebLinkInTargetRepo(ctx context.Context, moreL
}
// SubmoduleWebLinkTree tries to make the submodule's tree link in its own repo, it also works on "nil" receiver
// It returns nil if the submodule does not have a valid URL or is nil
func ( sf * CommitSubmoduleFile ) SubmoduleWebLinkTree ( ctx context . Context , optCommitID ... string ) * SubmoduleWebLink {
if sf == nil {
return nil
}
return sf . getWebLinkInTargetRepo ( ctx , "/tree/" + util . OptionalArg ( optCommitID , sf . refID ) )
return sf . getWebLinkInTargetRepo ( ctx , "/tree/" + util . OptionalArg ( optCommitID , sf . RefID ( ) ) )
}
// SubmoduleWebLinkCompare tries to make the submodule's compare link in its own repo, it also works on "nil" receiver
// It returns nil if the submodule does not have a valid URL or is nil
func ( sf * CommitSubmoduleFile ) SubmoduleWebLinkCompare ( ctx context . Context , commitID1 , commitID2 string ) * SubmoduleWebLink {
return sf . getWebLinkInTargetRepo ( ctx , "/compare/" + commitID1 + "..." + commitID2 )
}