@@ -15,46 +15,59 @@ import (
15
15
16
16
type SubmoduleDiffInfo struct {
17
17
SubmoduleName string
18
- SubmoduleFile * git.CommitSubmoduleFile
18
+ SubmoduleFile * git.CommitSubmoduleFile // it might be nil if the submodule is not found or unable to parse
19
19
NewRefID string
20
20
PreviousRefID string
21
21
}
22
22
23
- func (si * SubmoduleDiffInfo ) PopulateURL (diffFile * DiffFile , leftCommit , rightCommit * git.Commit ) error {
23
+ func (si * SubmoduleDiffInfo ) PopulateURL (diffFile * DiffFile , leftCommit , rightCommit * git.Commit ) {
24
24
si .SubmoduleName = diffFile .Name
25
25
submoduleCommit := rightCommit // If the submodule is added or updated, check at the right commit
26
26
if diffFile .IsDeleted {
27
27
submoduleCommit = leftCommit // If the submodule is deleted, check at the left commit
28
28
}
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
+ }
40
41
}
41
42
42
43
func (si * SubmoduleDiffInfo ) PreviousRefIDLinkHTML (ctx context.Context ) template.HTML {
43
44
webLink := si .SubmoduleFile .SubmoduleWebLink (ctx , si .PreviousRefID )
45
+ if webLink == nil {
46
+ return htmlutil .HTMLFormat ("%s" , base .ShortSha (si .PreviousRefID ))
47
+ }
44
48
return htmlutil .HTMLFormat (`<a href="%s">%s</a>` , webLink .CommitWebLink , base .ShortSha (si .PreviousRefID ))
45
49
}
46
50
47
51
func (si * SubmoduleDiffInfo ) NewRefIDLinkHTML (ctx context.Context ) template.HTML {
48
52
webLink := si .SubmoduleFile .SubmoduleWebLink (ctx , si .NewRefID )
53
+ if webLink == nil {
54
+ return htmlutil .HTMLFormat ("%s" , base .ShortSha (si .NewRefID ))
55
+ }
49
56
return htmlutil .HTMLFormat (`<a href="%s">%s</a>` , webLink .CommitWebLink , base .ShortSha (si .NewRefID ))
50
57
}
51
58
52
59
func (si * SubmoduleDiffInfo ) CompareRefIDLinkHTML (ctx context.Context ) template.HTML {
53
60
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
+ }
54
64
return htmlutil .HTMLFormat (`<a href="%s">%s...%s</a>` , webLink .CommitWebLink , base .ShortSha (si .PreviousRefID ), base .ShortSha (si .NewRefID ))
55
65
}
56
66
57
67
func (si * SubmoduleDiffInfo ) SubmoduleRepoLinkHTML (ctx context.Context ) template.HTML {
58
68
webLink := si .SubmoduleFile .SubmoduleWebLink (ctx )
69
+ if webLink == nil {
70
+ return htmlutil .HTMLFormat ("%s" , si .SubmoduleName )
71
+ }
59
72
return htmlutil .HTMLFormat (`<a href="%s">%s</a>` , webLink .RepoWebLink , si .SubmoduleName )
60
73
}
0 commit comments