From 67426534ef9f0ceba49330cbc0b7676f4009a6e1 Mon Sep 17 00:00:00 2001
From: Unknown <joe2010xtmf@163.com>
Date: Tue, 15 Apr 2014 17:43:25 -0400
Subject: [PATCH] Add view by tag support

---
 README.md                  |  4 ++--
 README_ZH.md               |  6 +++---
 modules/middleware/repo.go | 39 +++++++++++++++++++++++---------------
 3 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/README.md b/README.md
index 715521c362..b0b8c0b1d5 100644
--- a/README.md
+++ b/README.md
@@ -24,7 +24,7 @@ More importantly, Gogs only needs one binary to setup your own project hosting o
 
 ## Overview
 
-- Please see [Wiki](https://github.com/gogits/gogs/wiki) for project design, known issues, change log and road map.
+- Please see [Wiki](https://github.com/gogits/gogs/wiki) for project design, known issues, and change log.
 - See [Trello Board](https://trello.com/b/uxAoeLUl/gogs-go-git-service) to follow the develop team.
 - Try it before anything? Do it [online](http://try.gogits.org/Unknown/gogs) or go down to **Installation -> Install from binary** section!
 - Having troubles? Get help from [Troubleshooting](https://github.com/gogits/gogs/wiki/Troubleshooting).
@@ -64,7 +64,7 @@ There are 3 ways to install Gogs:
 
 ## Contributors
 
-This project was launched by [Unknown](https://github.com/Unknwon) and [lunny](https://github.com/lunny); [fuxiaohei](https://github.com/fuxiaohei), [slene](https://github.com/slene) and [skyblue](https://github.com/shxsun) joined the team soon after. See [contributors page](https://github.com/gogits/gogs/graphs/contributors) for full list of contributors.
+This project was launched by [Unknown](https://github.com/Unknwon) and [lunny](https://github.com/lunny); [fuxiaohei](https://github.com/fuxiaohei), [slene](https://github.com/slene) and [codeskyblue](https://github.com/codeskyblue) joined the team soon after. See [contributors page](https://github.com/gogits/gogs/graphs/contributors) for full list of contributors.
 
 ## License
 
diff --git a/README_ZH.md b/README_ZH.md
index 3494876837..be191bc04e 100644
--- a/README_ZH.md
+++ b/README_ZH.md
@@ -15,7 +15,7 @@ Gogs 完全使用 Go 语言来实现对 Git 数据的操作,实现 **零** 依
 
 ## 项目概览
 
-- 有关项目设计、已知问题、变更日志和路线图,请通过  [Wiki](https://github.com/gogits/gogs/wiki) 查看。
+- 有关项目设计、已知问题和变更日志,请通过  [Wiki](https://github.com/gogits/gogs/wiki) 查看。
 - 您可以到 [Trello Board](https://trello.com/b/uxAoeLUl/gogs-go-git-service) 跟随开发团队的脚步。
 - 想要先睹为快?通过 [在线体验](http://try.gogits.org/Unknown/gogs) 或查看 **安装部署 -> 二进制安装** 小节。
 - 使用过程中遇到问题?尝试从 [故障排查](https://github.com/gogits/gogs/wiki/Troubleshooting) 页面获取帮助。
@@ -30,7 +30,7 @@ Gogs 完全使用 Go 语言来实现对 Git 数据的操作,实现 **零** 依
 - Gravatar 以及缓存支持
 - 邮件服务(注册、Issue)
 - 管理员面板
-- 支持 MySQL、PostgreSQL 以及 SQLite3
+- 支持 MySQL、PostgreSQL 以及 SQLite3 数据库
 - 社交帐号登录(GitHub、Google、QQ、微博)
 
 ## 安装部署
@@ -55,7 +55,7 @@ Gogs 完全使用 Go 语言来实现对 Git 数据的操作,实现 **零** 依
 
 ## 贡献成员
 
-本项目最初由 [Unknown](https://github.com/Unknwon) 和 [lunny](https://github.com/lunny) 发起,随后 [fuxiaohei](https://github.com/fuxiaohei)、[slene](https://github.com/slene) 以及 [skyblue](https://github.com/shxsun) 加入到开发团队。您可以通过查看 [贡献者页面](https://github.com/gogits/gogs/graphs/contributors) 获取完整的贡献者列表。
+本项目最初由 [Unknown](https://github.com/Unknwon) 和 [lunny](https://github.com/lunny) 发起,随后 [fuxiaohei](https://github.com/fuxiaohei)、[slene](https://github.com/slene) 以及 [codeskyblue](https://github.com/codeskyblue) 加入到开发团队。您可以通过查看 [贡献者页面](https://github.com/gogits/gogs/graphs/contributors) 获取完整的贡献者列表。
 
 ## 授权许可
 
diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go
index 82c1c2dbf6..07395df96a 100644
--- a/modules/middleware/repo.go
+++ b/modules/middleware/repo.go
@@ -40,7 +40,7 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
 
 		userName := params["username"]
 		repoName := params["reponame"]
-		branchName := params["branchname"]
+		refName := params["branchname"]
 
 		// get repository owner
 		ctx.Repo.IsOwner = ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName)
@@ -149,26 +149,35 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
 		// when repo is bare, not valid branch
 		if !ctx.Repo.Repository.IsBare && validBranch {
 		detect:
-			if len(branchName) > 0 {
-				// TODO check tag
-				if gitRepo.IsBranchExist(branchName) {
+			if len(refName) > 0 {
+				if gitRepo.IsBranchExist(refName) {
 					ctx.Repo.IsBranch = true
-					ctx.Repo.BranchName = branchName
+					ctx.Repo.BranchName = refName
 
-					ctx.Repo.Commit, err = gitRepo.GetCommitOfBranch(branchName)
+					ctx.Repo.Commit, err = gitRepo.GetCommitOfBranch(refName)
 					if err != nil {
 						ctx.Handle(404, "RepoAssignment invalid branch", nil)
 						return
 					}
-
 					ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
 
-				} else if len(branchName) == 40 {
-					ctx.Repo.IsCommit = true
-					ctx.Repo.CommitId = branchName
-					ctx.Repo.BranchName = branchName
+				} else if gitRepo.IsTagExist(refName) {
+					ctx.Repo.IsBranch = true
+					ctx.Repo.BranchName = refName
 
-					ctx.Repo.Commit, err = gitRepo.GetCommit(branchName)
+					ctx.Repo.Commit, err = gitRepo.GetCommitOfTag(refName)
+					if err != nil {
+						ctx.Handle(404, "RepoAssignment invalid tag", nil)
+						return
+					}
+					ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
+
+				} else if len(refName) == 40 {
+					ctx.Repo.IsCommit = true
+					ctx.Repo.CommitId = refName
+					ctx.Repo.BranchName = refName
+
+					ctx.Repo.Commit, err = gitRepo.GetCommit(refName)
 					if err != nil {
 						ctx.Handle(404, "RepoAssignment invalid commit", nil)
 						return
@@ -179,9 +188,9 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
 				}
 
 			} else {
-				branchName = ctx.Repo.Repository.DefaultBranch
-				if len(branchName) == 0 {
-					branchName = "master"
+				refName = ctx.Repo.Repository.DefaultBranch
+				if len(refName) == 0 {
+					refName = "master"
 				}
 				goto detect
 			}