Skip to content

Commit 1dad976

Browse files
committed
Minor fix for #14
- Refactor some name
1 parent c61be78 commit 1dad976

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111
)
1212

13-
const _VERSION = "0.2.9"
13+
const _VERSION = "0.3.0"
1414

1515
func Version() string {
1616
return _VERSION

submodule.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,32 @@ import "strings"
88

99
type SubModule struct {
1010
Name string
11-
Url string
11+
URL string
1212
}
1313

1414
// SubModuleFile represents a file with submodule type.
1515
type SubModuleFile struct {
1616
*Commit
1717

18-
refUrl string
19-
refId string
18+
refURL string
19+
refID string
2020
}
2121

22-
func NewSubModuleFile(c *Commit, refUrl, refId string) *SubModuleFile {
22+
func NewSubModuleFile(c *Commit, refURL, refID string) *SubModuleFile {
2323
return &SubModuleFile{
2424
Commit: c,
25-
refUrl: refUrl,
26-
refId: refId,
25+
refURL: refURL,
26+
refID: refID,
2727
}
2828
}
2929

30-
// FIXME: remove import of setting
31-
// RefUrl guesses and returns reference URL.
32-
func (sf *SubModuleFile) RefUrl(urlPrefix string, parentPath string) string {
33-
if sf.refUrl == "" {
30+
// RefURL guesses and returns reference URL.
31+
func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string {
32+
if sf.refURL == "" {
3433
return ""
3534
}
3635

37-
url := strings.TrimSuffix(sf.refUrl, ".git")
36+
url := strings.TrimSuffix(sf.refURL, ".git")
3837

3938
// git://xxx/user/repo
4039
if strings.HasPrefix(url, "git://") {
@@ -46,12 +45,14 @@ func (sf *SubModuleFile) RefUrl(urlPrefix string, parentPath string) string {
4645
return url
4746
}
4847

49-
// relative url prefix check (according to git submodule documentation)
48+
// Relative url prefix check (according to git submodule documentation)
5049
if strings.HasPrefix(url, "./") || strings.HasPrefix(url, "../") {
5150
// ...construct and return correct submodule url here...
52-
idx := strings.LastIndex(parentPath, "/src/")
53-
rel_url := strings.TrimSuffix(urlPrefix, "/") + parentPath[:idx] + "/" + url
54-
return rel_url
51+
idx := strings.Index(parentPath, "/src/")
52+
if idx == -1 {
53+
return url
54+
}
55+
return strings.TrimSuffix(urlPrefix, "/") + parentPath[:idx] + "/" + url
5556
}
5657

5758
// sysuser@xxx:user/repo
@@ -71,7 +72,7 @@ func (sf *SubModuleFile) RefUrl(urlPrefix string, parentPath string) string {
7172
return url
7273
}
7374

74-
// RefId returns reference ID.
75-
func (sf *SubModuleFile) RefId() string {
76-
return sf.refId
75+
// RefID returns reference ID.
76+
func (sf *SubModuleFile) RefID() string {
77+
return sf.refID
7778
}

tree_entry.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,16 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string) ([][]interfac
181181
return
182182
}
183183

184-
smUrl := ""
184+
smURL := ""
185185
if sm != nil {
186-
smUrl = sm.Url
186+
smURL = sm.URL
187187
}
188188

189189
c, err := commit.GetCommitByPath(filepath.Join(treePath, tes[i].Name()))
190190
if err != nil {
191191
cinfo.err = fmt.Errorf("GetCommitByPath (%s/%s): %v", treePath, tes[i].Name(), err)
192192
} else {
193-
cinfo.infos = []interface{}{tes[i], NewSubModuleFile(c, smUrl, tes[i].ID.String())}
193+
cinfo.infos = []interface{}{tes[i], NewSubModuleFile(c, smURL, tes[i].ID.String())}
194194
}
195195
revChan <- cinfo
196196
<-taskChan

0 commit comments

Comments
 (0)