mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Add basic submodule support
This commit is contained in:
		@@ -5,7 +5,7 @@ Gogs(Go Git Service) is a painless self-hosted Git Service written in Go.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||

 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
##### Current version: 0.5.3 Beta
 | 
					##### Current version: 0.5.4 Beta
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### NOTICES
 | 
					### NOTICES
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个基于 Go 语言的自助 Git 服务。
 | 
				
			|||||||
 | 
					
 | 
				
			||||||

 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
##### 当前版本:0.5.3 Beta
 | 
					##### 当前版本:0.5.4 Beta
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 开发目的
 | 
					## 开发目的
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							@@ -17,7 +17,7 @@ import (
 | 
				
			|||||||
	"github.com/gogits/gogs/modules/setting"
 | 
						"github.com/gogits/gogs/modules/setting"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const APP_VER = "0.5.3.0922 Beta"
 | 
					const APP_VER = "0.5.4.0922 Beta"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
	runtime.GOMAXPROCS(runtime.NumCPU())
 | 
						runtime.GOMAXPROCS(runtime.NumCPU())
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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
 | 
					package git
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type SubModule struct {
 | 
					type SubModule struct {
 | 
				
			||||||
	Name string
 | 
						Name string
 | 
				
			||||||
	Url  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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,13 +21,6 @@ const (
 | 
				
			|||||||
	HOME base.TplName = "repo/home"
 | 
						HOME base.TplName = "repo/home"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type fakeCommit struct {
 | 
					 | 
				
			||||||
	*git.Commit
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	RefUrl string
 | 
					 | 
				
			||||||
	RefId  string
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func Home(ctx *middleware.Context) {
 | 
					func Home(ctx *middleware.Context) {
 | 
				
			||||||
	ctx.Data["Title"] = ctx.Repo.Repository.Name
 | 
						ctx.Data["Title"] = ctx.Repo.Repository.Name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -153,14 +146,7 @@ func Home(ctx *middleware.Context) {
 | 
				
			|||||||
					ctx.Handle(404, "GetCommitOfRelPath", err)
 | 
										ctx.Handle(404, "GetCommitOfRelPath", err)
 | 
				
			||||||
					return
 | 
										return
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
									files = append(files, []interface{}{te, git.NewSubModuleFile(c, sm.Url, te.Id.String())})
 | 
				
			||||||
				commit := fakeCommit{
 | 
					 | 
				
			||||||
					Commit: c,
 | 
					 | 
				
			||||||
					RefUrl: strings.TrimRight(sm.Url, ".git"),
 | 
					 | 
				
			||||||
					RefId:  te.Id.String(),
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				files = append(files, []interface{}{te, &commit})
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1 +1 @@
 | 
				
			|||||||
0.5.3.0922 Beta
 | 
					0.5.4.0922 Beta
 | 
				
			||||||
		Reference in New Issue
	
	Block a user