summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-09-22 17:01:19 -0400
committerUnknwon <joe2010xtmf@163.com>2014-09-22 17:01:19 -0400
commit3f707b3f3265c4b3e64e47ee172cc878f3325248 (patch)
tree254264c45395a6c908e249c94e02efa0860c6d79 /modules
parent063aacd436da24c2616d68a838959300978afaa5 (diff)
downloadgitea-3f707b3f3265c4b3e64e47ee172cc878f3325248.tar.gz
gitea-3f707b3f3265c4b3e64e47ee172cc878f3325248.zip
Add basic submodule support
Diffstat (limited to 'modules')
-rw-r--r--modules/git/submodule.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/modules/git/submodule.go b/modules/git/submodule.go
index 28b5b9f375..6927f8cbad 100644
--- a/modules/git/submodule.go
+++ b/modules/git/submodule.go
@@ -1,6 +1,58 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
package git
+import (
+ "strings"
+)
+
type SubModule struct {
Name string
Url string
}
+
+// SubModuleFile represents a file with submodule type.
+type SubModuleFile struct {
+ *Commit
+
+ refUrl string
+ refId string
+}
+
+func NewSubModuleFile(c *Commit, refUrl, refId string) *SubModuleFile {
+ return &SubModuleFile{
+ Commit: c,
+ refUrl: refUrl,
+ refId: refId,
+ }
+}
+
+// RefUrl guesses and returns reference URL.
+func (sf *SubModuleFile) RefUrl() string {
+ url := strings.TrimSuffix(sf.refUrl, ".git")
+
+ // git://xxx/user/repo
+ if strings.HasPrefix(url, "git://") {
+ return "http://" + strings.TrimPrefix(url, "git://")
+ }
+
+ // http[s]://xxx/user/repo
+ if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
+ return url
+ }
+
+ // sysuser@xxx:user/repo
+ i := strings.Index(url, "@")
+ j := strings.LastIndex(url, ":")
+ if i > -1 && j > -1 {
+ return "http://" + url[i+1:j] + "/" + url[j+1:]
+ }
+ return url
+}
+
+// RefId returns reference ID.
+func (sf *SubModuleFile) RefId() string {
+ return sf.refId
+}