]> source.dussan.org Git - gitea.git/commitdiff
Add basic submodule support
authorUnknwon <joe2010xtmf@163.com>
Mon, 22 Sep 2014 21:01:19 +0000 (17:01 -0400)
committerUnknwon <joe2010xtmf@163.com>
Mon, 22 Sep 2014 21:01:19 +0000 (17:01 -0400)
README.md
README_ZH.md
gogs.go
modules/git/submodule.go
routers/repo/view.go
templates/.VERSION

index 232aa92a84d91334fec537557a6b058bf2fd8e63..a2aed3afad8d57a902f76da6de5492977956146a 100644 (file)
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ Gogs(Go Git Service) is a painless self-hosted Git Service written in Go.
 
 ![Demo](https://gowalker.org/public/gogs_demo.gif)
 
-##### Current version: 0.5.3 Beta
+##### Current version: 0.5.4 Beta
 
 ### NOTICES
 
index fcc8b496946c6ce81d065f10f36f9734d7c9af10..817110b375f65a01def9d4521405c00ffe21da34 100644 (file)
@@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个基于 Go 语言的自助 Git 服务。
 
 ![Demo](https://gowalker.org/public/gogs_demo.gif)
 
-##### 当前版本:0.5.3 Beta
+##### 当前版本:0.5.4 Beta
 
 ## 开发目的
 
diff --git a/gogs.go b/gogs.go
index b1b9fe60d562ad873809d89b151f2f2ff72f7774..d565d7bbb190fdb8e2ad3cccecb40729ff85e0a8 100644 (file)
--- a/gogs.go
+++ b/gogs.go
@@ -17,7 +17,7 @@ import (
        "github.com/gogits/gogs/modules/setting"
 )
 
-const APP_VER = "0.5.3.0922 Beta"
+const APP_VER = "0.5.4.0922 Beta"
 
 func init() {
        runtime.GOMAXPROCS(runtime.NumCPU())
index 28b5b9f37564cf76d59a568fbaaa9be5c49a0502..6927f8cbadf09af83f8016f148290e5e9dcbeac8 100644 (file)
@@ -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
+}
index 77f17e7ae0965ee0e5bf81803d70e3f1cc86feee..4e4a7b18ce4b6249d2ee36fd2c1072b0d821373e 100644 (file)
@@ -21,13 +21,6 @@ const (
        HOME base.TplName = "repo/home"
 )
 
-type fakeCommit struct {
-       *git.Commit
-
-       RefUrl string
-       RefId  string
-}
-
 func Home(ctx *middleware.Context) {
        ctx.Data["Title"] = ctx.Repo.Repository.Name
 
@@ -153,14 +146,7 @@ func Home(ctx *middleware.Context) {
                                        ctx.Handle(404, "GetCommitOfRelPath", err)
                                        return
                                }
-
-                               commit := fakeCommit{
-                                       Commit: c,
-                                       RefUrl: strings.TrimRight(sm.Url, ".git"),
-                                       RefId:  te.Id.String(),
-                               }
-
-                               files = append(files, []interface{}{te, &commit})
+                               files = append(files, []interface{}{te, git.NewSubModuleFile(c, sm.Url, te.Id.String())})
                        }
                }
 
index 19d8171e8fff5eb018586d26e2097d30f27faffc..8a713df0428fcb47ec6811ed2c6207599b818a6a 100644 (file)
@@ -1 +1 @@
-0.5.3.0922 Beta
\ No newline at end of file
+0.5.4.0922 Beta
\ No newline at end of file