- Refactor some name
This commit is contained in:
Unknwon 2016-06-27 23:39:35 +08:00
Родитель c61be7813a
Коммит 1dad9765c0
4 изменённых файлов: 24 добавлений и 22 удалений

1
.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
.idea

2
git.go
Просмотреть файл

@ -10,7 +10,7 @@ import (
"time" "time"
) )
const _VERSION = "0.2.9" const _VERSION = "0.3.0"
func Version() string { func Version() string {
return _VERSION return _VERSION

Просмотреть файл

@ -8,33 +8,32 @@ import "strings"
type SubModule struct { type SubModule struct {
Name string Name string
Url string URL string
} }
// SubModuleFile represents a file with submodule type. // SubModuleFile represents a file with submodule type.
type SubModuleFile struct { type SubModuleFile struct {
*Commit *Commit
refUrl string refURL string
refId string refID string
} }
func NewSubModuleFile(c *Commit, refUrl, refId string) *SubModuleFile { func NewSubModuleFile(c *Commit, refURL, refID string) *SubModuleFile {
return &SubModuleFile{ return &SubModuleFile{
Commit: c, Commit: c,
refUrl: refUrl, refURL: refURL,
refId: refId, refID: refID,
} }
} }
// FIXME: remove import of setting // RefURL guesses and returns reference URL.
// RefUrl guesses and returns reference URL. func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string {
func (sf *SubModuleFile) RefUrl(urlPrefix string, parentPath string) string { if sf.refURL == "" {
if sf.refUrl == "" {
return "" return ""
} }
url := strings.TrimSuffix(sf.refUrl, ".git") url := strings.TrimSuffix(sf.refURL, ".git")
// git://xxx/user/repo // git://xxx/user/repo
if strings.HasPrefix(url, "git://") { if strings.HasPrefix(url, "git://") {
@ -46,12 +45,14 @@ func (sf *SubModuleFile) RefUrl(urlPrefix string, parentPath string) string {
return url return url
} }
// relative url prefix check (according to git submodule documentation) // Relative url prefix check (according to git submodule documentation)
if strings.HasPrefix(url, "./") || strings.HasPrefix(url, "../") { if strings.HasPrefix(url, "./") || strings.HasPrefix(url, "../") {
// ...construct and return correct submodule url here... // ...construct and return correct submodule url here...
idx := strings.LastIndex(parentPath, "/src/") idx := strings.Index(parentPath, "/src/")
rel_url := strings.TrimSuffix(urlPrefix, "/") + parentPath[:idx] + "/" + url if idx == -1 {
return rel_url return url
}
return strings.TrimSuffix(urlPrefix, "/") + parentPath[:idx] + "/" + url
} }
// sysuser@xxx:user/repo // sysuser@xxx:user/repo
@ -71,7 +72,7 @@ func (sf *SubModuleFile) RefUrl(urlPrefix string, parentPath string) string {
return url return url
} }
// RefId returns reference ID. // RefID returns reference ID.
func (sf *SubModuleFile) RefId() string { func (sf *SubModuleFile) RefID() string {
return sf.refId return sf.refID
} }

Просмотреть файл

@ -181,16 +181,16 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string) ([][]interfac
return return
} }
smUrl := "" smURL := ""
if sm != nil { if sm != nil {
smUrl = sm.Url smURL = sm.URL
} }
c, err := commit.GetCommitByPath(filepath.Join(treePath, tes[i].Name())) c, err := commit.GetCommitByPath(filepath.Join(treePath, tes[i].Name()))
if err != nil { if err != nil {
cinfo.err = fmt.Errorf("GetCommitByPath (%s/%s): %v", treePath, tes[i].Name(), err) cinfo.err = fmt.Errorf("GetCommitByPath (%s/%s): %v", treePath, tes[i].Name(), err)
} else { } else {
cinfo.infos = []interface{}{tes[i], NewSubModuleFile(c, smUrl, tes[i].ID.String())} cinfo.infos = []interface{}{tes[i], NewSubModuleFile(c, smURL, tes[i].ID.String())}
} }
revChan <- cinfo revChan <- cinfo
<-taskChan <-taskChan