@@ -15,46 +15,59 @@ import (
1515
1616type SubmoduleDiffInfo struct {
1717 SubmoduleName string
18- SubmoduleFile * git.CommitSubmoduleFile
18+ SubmoduleFile * git.CommitSubmoduleFile // it might be nil if the submodule is not found or unable to parse
1919 NewRefID string
2020 PreviousRefID string
2121}
2222
23- func (si * SubmoduleDiffInfo ) PopulateURL (diffFile * DiffFile , leftCommit , rightCommit * git.Commit ) error {
23+ func (si * SubmoduleDiffInfo ) PopulateURL (diffFile * DiffFile , leftCommit , rightCommit * git.Commit ) {
2424 si .SubmoduleName = diffFile .Name
2525 submoduleCommit := rightCommit // If the submodule is added or updated, check at the right commit
2626 if diffFile .IsDeleted {
2727 submoduleCommit = leftCommit // If the submodule is deleted, check at the left commit
2828 }
29- if submoduleCommit != nil {
30- submodule , err := submoduleCommit .GetSubModule (diffFile .GetDiffFileName ())
31- if err != nil {
32- log .Error ("Unable to PopulateURL for submodule %q: GetSubModule: %v" , diffFile .GetDiffFileName (), err )
33- return nil // ignore the error, do not cause 500 errors for end users
34- }
35- if submodule != nil {
36- si .SubmoduleFile = git .NewCommitSubmoduleFile (submodule .URL , submoduleCommit .ID .String ())
37- }
38- }
39- return nil
29+ if submoduleCommit == nil {
30+ return
31+ }
32+
33+ submodule , err := submoduleCommit .GetSubModule (diffFile .GetDiffFileName ())
34+ if err != nil {
35+ log .Error ("Unable to PopulateURL for submodule %q: GetSubModule: %v" , diffFile .GetDiffFileName (), err )
36+ return // ignore the error, do not cause 500 errors for end users
37+ }
38+ if submodule != nil {
39+ si .SubmoduleFile = git .NewCommitSubmoduleFile (submodule .URL , submoduleCommit .ID .String ())
40+ }
4041}
4142
4243func (si * SubmoduleDiffInfo ) PreviousRefIDLinkHTML (ctx context.Context ) template.HTML {
4344 webLink := si .SubmoduleFile .SubmoduleWebLink (ctx , si .PreviousRefID )
45+ if webLink == nil {
46+ return htmlutil .HTMLFormat ("%s" , base .ShortSha (si .PreviousRefID ))
47+ }
4448 return htmlutil .HTMLFormat (`<a href="%s">%s</a>` , webLink .CommitWebLink , base .ShortSha (si .PreviousRefID ))
4549}
4650
4751func (si * SubmoduleDiffInfo ) NewRefIDLinkHTML (ctx context.Context ) template.HTML {
4852 webLink := si .SubmoduleFile .SubmoduleWebLink (ctx , si .NewRefID )
53+ if webLink == nil {
54+ return htmlutil .HTMLFormat ("%s" , base .ShortSha (si .NewRefID ))
55+ }
4956 return htmlutil .HTMLFormat (`<a href="%s">%s</a>` , webLink .CommitWebLink , base .ShortSha (si .NewRefID ))
5057}
5158
5259func (si * SubmoduleDiffInfo ) CompareRefIDLinkHTML (ctx context.Context ) template.HTML {
5360 webLink := si .SubmoduleFile .SubmoduleWebLink (ctx , si .PreviousRefID , si .NewRefID )
61+ if webLink == nil {
62+ return htmlutil .HTMLFormat ("%s...%s" , base .ShortSha (si .PreviousRefID ), base .ShortSha (si .NewRefID ))
63+ }
5464 return htmlutil .HTMLFormat (`<a href="%s">%s...%s</a>` , webLink .CommitWebLink , base .ShortSha (si .PreviousRefID ), base .ShortSha (si .NewRefID ))
5565}
5666
5767func (si * SubmoduleDiffInfo ) SubmoduleRepoLinkHTML (ctx context.Context ) template.HTML {
5868 webLink := si .SubmoduleFile .SubmoduleWebLink (ctx )
69+ if webLink == nil {
70+ return htmlutil .HTMLFormat ("%s" , si .SubmoduleName )
71+ }
5972 return htmlutil .HTMLFormat (`<a href="%s">%s</a>` , webLink .RepoWebLink , si .SubmoduleName )
6073}
0 commit comments