@ -53,20 +53,20 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) {
}
}
func Single ( ctx * middleware . Context , params martini . Params ) {
func Single ( ctx * middleware . Context , params martini . Params ) {
if ! ctx . Repo . IsValid {
branchName := ctx . Repo . BranchName
return
commitId := ctx . Repo . CommitId
}
userName := ctx . Repo . Owner . Name
repoName := ctx . Repo . Repository . Name
b ranchNam e := params [ "branchname" ]
repoLink := ctx . Repo . RepoLink
userName := params [ "username" ]
branchLink := ctx . Repo . RepoLink + "/src/" + branchName
repoName := params [ "reponame" ]
rawLink := ctx . Repo . RepoLink + "/raw/" + branchName
// Get tree path
// Get tree path
treename := params [ "_1" ]
treename := params [ "_1" ]
if len ( treename ) > 0 && treename [ len ( treename ) - 1 ] == '/' {
if len ( treename ) > 0 && treename [ len ( treename ) - 1 ] == '/' {
ctx . Redirect ( "/" + ctx . Repo . Owner . LowerName + "/" +
ctx . Redirect ( repoLink + "/src/" + branchName + "/" + treename [ : len ( treename ) - 1 ] )
ctx . Repo . Repository . Name + "/src/" + branchName + "/" + treename [ : len ( treename ) - 1 ] )
return
return
}
}
@ -84,23 +84,17 @@ func Single(ctx *middleware.Context, params martini.Params) {
}
}
ctx . Data [ "Branches" ] = brs
ctx . Data [ "Branches" ] = brs
var commitId string
isViewBranch := ctx . Repo . IsBranch
isViewBranch := models . IsBranchExist ( userName , repoName , branchName )
if ! isViewBranch {
commitId = branchName
}
ctx . Data [ "IsViewBranch" ] = isViewBranch
ctx . Data [ "IsViewBranch" ] = isViewBranch
repoFile , err := models . GetTargetFile ( userName , repoName ,
repoFile , err := models . GetTargetFile ( userName , repoName ,
branchName , commitId , treename )
branchName , commitId , treename )
if err != nil && err != models . ErrRepoFileNotExist {
if err != nil && err != models . ErrRepoFileNotExist {
ctx . Handle ( 404 , "repo.Single(GetTargetFile)" , err )
ctx . Handle ( 404 , "repo.Single(GetTargetFile)" , err )
return
return
}
}
branchLink := "/" + ctx . Repo . Owner . LowerName + "/" + ctx . Repo . Repository . Name + "/src/" + branchName
rawLink := "/" + ctx . Repo . Owner . LowerName + "/" + ctx . Repo . Repository . Name + "/raw/" + branchName
if len ( treename ) != 0 && repoFile == nil {
if len ( treename ) != 0 && repoFile == nil {
ctx . Handle ( 404 , "repo.Single" , nil )
ctx . Handle ( 404 , "repo.Single" , nil )
return
return
@ -142,8 +136,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
} else {
} else {
// Directory and file list.
// Directory and file list.
files , err := models . GetReposFiles ( userName , repoName ,
files , err := models . GetReposFiles ( userName , repoName , ctx . Repo . CommitId , treename )
branchName , commitId , treename )
if err != nil {
if err != nil {
ctx . Handle ( 404 , "repo.Single(GetReposFiles)" , err )
ctx . Handle ( 404 , "repo.Single(GetReposFiles)" , err )
return
return
@ -200,18 +193,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
}
}
}
}
// Get latest commit according username and repo name.
ctx . Data [ "LastCommit" ] = ctx . Repo . Commit
commit , err := models . GetCommit ( userName , repoName ,
branchName , commitId )
if err != nil {
log . Error ( "repo.Single(GetCommit): %v" , err )
ctx . Handle ( 404 , "repo.Single(GetCommit)" , err )
return
}
ctx . Data [ "LastCommit" ] = commit
ctx . Data [ "CommitId" ] = commitId
ctx . Data [ "Paths" ] = Paths
ctx . Data [ "Paths" ] = Paths
ctx . Data [ "Treenames" ] = treenames
ctx . Data [ "Treenames" ] = treenames
ctx . Data [ "BranchLink" ] = branchLink
ctx . Data [ "BranchLink" ] = branchLink
@ -219,11 +201,6 @@ func Single(ctx *middleware.Context, params martini.Params) {
}
}
func SingleDownload ( ctx * middleware . Context , params martini . Params ) {
func SingleDownload ( ctx * middleware . Context , params martini . Params ) {
if ! ctx . Repo . IsValid {
ctx . Handle ( 404 , "repo.SingleDownload" , nil )
return
}
// Get tree path
// Get tree path
treename := params [ "_1" ]
treename := params [ "_1" ]
@ -263,10 +240,6 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) {
}
}
func Http ( ctx * middleware . Context , params martini . Params ) {
func Http ( ctx * middleware . Context , params martini . Params ) {
/ * if ! ctx . Repo . IsValid {
return
} * /
// TODO: access check
// TODO: access check
username := params [ "username" ]
username := params [ "username" ]