@ -422,10 +422,10 @@ func RepoIDAssignment() func(ctx *Context) {
}
}
// RepoAssignment returns a middleware to handle repository assignment
// RepoAssignment returns a middleware to handle repository assignment
func RepoAssignment ( ctx * Context ) ( cancel context . CancelFunc ) {
func RepoAssignment ( ctx * Context ) context . CancelFunc {
if _ , repoAssignmentOnce := ctx . Data [ "repoAssignmentExecuted" ] ; repoAssignmentOnce {
if _ , repoAssignmentOnce := ctx . Data [ "repoAssignmentExecuted" ] ; repoAssignmentOnce {
log . Trace ( "RepoAssignment was exec already, skipping second call ..." )
log . Trace ( "RepoAssignment was exec already, skipping second call ..." )
return
return nil
}
}
ctx . Data [ "repoAssignmentExecuted" ] = true
ctx . Data [ "repoAssignmentExecuted" ] = true
@ -453,7 +453,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
// https://github.com/golang/go/issues/19760
// https://github.com/golang/go/issues/19760
if ctx . FormString ( "go-get" ) == "1" {
if ctx . FormString ( "go-get" ) == "1" {
EarlyResponseForGoGetMeta ( ctx )
EarlyResponseForGoGetMeta ( ctx )
return
return nil
}
}
if redirectUserID , err := user_model . LookupUserRedirect ( userName ) ; err == nil {
if redirectUserID , err := user_model . LookupUserRedirect ( userName ) ; err == nil {
@ -466,7 +466,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
} else {
} else {
ctx . ServerError ( "GetUserByName" , err )
ctx . ServerError ( "GetUserByName" , err )
}
}
return
return nil
}
}
}
}
ctx . Repo . Owner = owner
ctx . Repo . Owner = owner
@ -490,7 +490,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
redirectPath += "?" + ctx . Req . URL . RawQuery
redirectPath += "?" + ctx . Req . URL . RawQuery
}
}
ctx . Redirect ( path . Join ( setting . AppSubURL , redirectPath ) )
ctx . Redirect ( path . Join ( setting . AppSubURL , redirectPath ) )
return
return nil
}
}
// Get repository.
// Get repository.
@ -503,7 +503,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
} else if repo_model . IsErrRedirectNotExist ( err ) {
} else if repo_model . IsErrRedirectNotExist ( err ) {
if ctx . FormString ( "go-get" ) == "1" {
if ctx . FormString ( "go-get" ) == "1" {
EarlyResponseForGoGetMeta ( ctx )
EarlyResponseForGoGetMeta ( ctx )
return
return nil
}
}
ctx . NotFound ( "GetRepositoryByName" , nil )
ctx . NotFound ( "GetRepositoryByName" , nil )
} else {
} else {
@ -512,13 +512,13 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
} else {
} else {
ctx . ServerError ( "GetRepositoryByName" , err )
ctx . ServerError ( "GetRepositoryByName" , err )
}
}
return
return nil
}
}
repo . Owner = owner
repo . Owner = owner
repoAssignment ( ctx , repo )
repoAssignment ( ctx , repo )
if ctx . Written ( ) {
if ctx . Written ( ) {
return
return nil
}
}
ctx . Repo . RepoLink = repo . Link ( )
ctx . Repo . RepoLink = repo . Link ( )
@ -542,12 +542,12 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
} )
} )
if err != nil {
if err != nil {
ctx . ServerError ( "GetReleaseCountByRepoID" , err )
ctx . ServerError ( "GetReleaseCountByRepoID" , err )
return
return nil
}
}
ctx . Data [ "NumReleases" ] , err = repo_model . GetReleaseCountByRepoID ( ctx , ctx . Repo . Repository . ID , repo_model . FindReleasesOptions { } )
ctx . Data [ "NumReleases" ] , err = repo_model . GetReleaseCountByRepoID ( ctx , ctx . Repo . Repository . ID , repo_model . FindReleasesOptions { } )
if err != nil {
if err != nil {
ctx . ServerError ( "GetReleaseCountByRepoID" , err )
ctx . ServerError ( "GetReleaseCountByRepoID" , err )
return
return nil
}
}
ctx . Data [ "Title" ] = owner . Name + "/" + repo . Name
ctx . Data [ "Title" ] = owner . Name + "/" + repo . Name
@ -563,14 +563,14 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
canSignedUserFork , err := repo_module . CanUserForkRepo ( ctx . Doer , ctx . Repo . Repository )
canSignedUserFork , err := repo_module . CanUserForkRepo ( ctx . Doer , ctx . Repo . Repository )
if err != nil {
if err != nil {
ctx . ServerError ( "CanUserForkRepo" , err )
ctx . ServerError ( "CanUserForkRepo" , err )
return
return nil
}
}
ctx . Data [ "CanSignedUserFork" ] = canSignedUserFork
ctx . Data [ "CanSignedUserFork" ] = canSignedUserFork
userAndOrgForks , err := repo_model . GetForksByUserAndOrgs ( ctx , ctx . Doer , ctx . Repo . Repository )
userAndOrgForks , err := repo_model . GetForksByUserAndOrgs ( ctx , ctx . Doer , ctx . Repo . Repository )
if err != nil {
if err != nil {
ctx . ServerError ( "GetForksByUserAndOrgs" , err )
ctx . ServerError ( "GetForksByUserAndOrgs" , err )
return
return nil
}
}
ctx . Data [ "UserAndOrgForks" ] = userAndOrgForks
ctx . Data [ "UserAndOrgForks" ] = userAndOrgForks
@ -604,14 +604,14 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
if repo . IsFork {
if repo . IsFork {
RetrieveBaseRepo ( ctx , repo )
RetrieveBaseRepo ( ctx , repo )
if ctx . Written ( ) {
if ctx . Written ( ) {
return
return nil
}
}
}
}
if repo . IsGenerated ( ) {
if repo . IsGenerated ( ) {
RetrieveTemplateRepo ( ctx , repo )
RetrieveTemplateRepo ( ctx , repo )
if ctx . Written ( ) {
if ctx . Written ( ) {
return
return nil
}
}
}
}
@ -623,7 +623,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
if ! isHomeOrSettings {
if ! isHomeOrSettings {
ctx . Redirect ( ctx . Repo . RepoLink )
ctx . Redirect ( ctx . Repo . RepoLink )
}
}
return
return nil
}
}
gitRepo , err := git . OpenRepository ( ctx , repo_model . RepoPath ( userName , repoName ) )
gitRepo , err := git . OpenRepository ( ctx , repo_model . RepoPath ( userName , repoName ) )
@ -636,10 +636,10 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
if ! isHomeOrSettings {
if ! isHomeOrSettings {
ctx . Redirect ( ctx . Repo . RepoLink )
ctx . Redirect ( ctx . Repo . RepoLink )
}
}
return
return nil
}
}
ctx . ServerError ( "RepoAssignment Invalid repo " + repo_model . RepoPath ( userName , repoName ) , err )
ctx . ServerError ( "RepoAssignment Invalid repo " + repo_model . RepoPath ( userName , repoName ) , err )
return
return nil
}
}
if ctx . Repo . GitRepo != nil {
if ctx . Repo . GitRepo != nil {
ctx . Repo . GitRepo . Close ( )
ctx . Repo . GitRepo . Close ( )
@ -647,7 +647,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
ctx . Repo . GitRepo = gitRepo
ctx . Repo . GitRepo = gitRepo
// We opened it, we should close it
// We opened it, we should close it
cancel = func ( ) {
cancel : = func ( ) {
// If it's been set to nil then assume someone else has closed it.
// If it's been set to nil then assume someone else has closed it.
if ctx . Repo . GitRepo != nil {
if ctx . Repo . GitRepo != nil {
ctx . Repo . GitRepo . Close ( )
ctx . Repo . GitRepo . Close ( )
@ -657,13 +657,13 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
// Stop at this point when the repo is empty.
// Stop at this point when the repo is empty.
if ctx . Repo . Repository . IsEmpty {
if ctx . Repo . Repository . IsEmpty {
ctx . Data [ "BranchName" ] = ctx . Repo . Repository . DefaultBranch
ctx . Data [ "BranchName" ] = ctx . Repo . Repository . DefaultBranch
return
return cancel
}
}
tags , err := repo_model . GetTagNamesByRepoID ( ctx , ctx . Repo . Repository . ID )
tags , err := repo_model . GetTagNamesByRepoID ( ctx , ctx . Repo . Repository . ID )
if err != nil {
if err != nil {
ctx . ServerError ( "GetTagNamesByRepoID" , err )
ctx . ServerError ( "GetTagNamesByRepoID" , err )
return
return cancel
}
}
ctx . Data [ "Tags" ] = tags
ctx . Data [ "Tags" ] = tags
@ -677,7 +677,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
branchesTotal , err := git_model . CountBranches ( ctx , branchOpts )
branchesTotal , err := git_model . CountBranches ( ctx , branchOpts )
if err != nil {
if err != nil {
ctx . ServerError ( "CountBranches" , err )
ctx . ServerError ( "CountBranches" , err )
return
return cancel
}
}
// non empty repo should have at least 1 branch, so this repository's branches haven't been synced yet
// non empty repo should have at least 1 branch, so this repository's branches haven't been synced yet
@ -685,7 +685,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
branchesTotal , err = repo_module . SyncRepoBranches ( ctx , ctx . Repo . Repository . ID , 0 )
branchesTotal , err = repo_module . SyncRepoBranches ( ctx , ctx . Repo . Repository . ID , 0 )
if err != nil {
if err != nil {
ctx . ServerError ( "SyncRepoBranches" , err )
ctx . ServerError ( "SyncRepoBranches" , err )
return
return cancel
}
}
}
}
@ -694,7 +694,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
brs , err := git_model . FindBranchNames ( ctx , branchOpts )
brs , err := git_model . FindBranchNames ( ctx , branchOpts )
if err != nil {
if err != nil {
ctx . ServerError ( "GetBranches" , err )
ctx . ServerError ( "GetBranches" , err )
return
return cancel
}
}
// always put default branch on the top
// always put default branch on the top
ctx . Data [ "Branches" ] = append ( branchOpts . ExcludeBranchNames , brs ... )
ctx . Data [ "Branches" ] = append ( branchOpts . ExcludeBranchNames , brs ... )
@ -741,12 +741,12 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
repoTransfer , err := models . GetPendingRepositoryTransfer ( ctx , ctx . Repo . Repository )
repoTransfer , err := models . GetPendingRepositoryTransfer ( ctx , ctx . Repo . Repository )
if err != nil {
if err != nil {
ctx . ServerError ( "GetPendingRepositoryTransfer" , err )
ctx . ServerError ( "GetPendingRepositoryTransfer" , err )
return
return cancel
}
}
if err := repoTransfer . LoadAttributes ( ctx ) ; err != nil {
if err := repoTransfer . LoadAttributes ( ctx ) ; err != nil {
ctx . ServerError ( "LoadRecipient" , err )
ctx . ServerError ( "LoadRecipient" , err )
return
return cancel
}
}
ctx . Data [ "RepoTransfer" ] = repoTransfer
ctx . Data [ "RepoTransfer" ] = repoTransfer
@ -894,7 +894,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
ctx . Repo . IsViewBranch = true
ctx . Repo . IsViewBranch = true
ctx . Repo . BranchName = ctx . Repo . Repository . DefaultBranch
ctx . Repo . BranchName = ctx . Repo . Repository . DefaultBranch
ctx . Data [ "TreePath" ] = ""
ctx . Data [ "TreePath" ] = ""
return
return nil
}
}
var (
var (
@ -907,7 +907,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
ctx . Repo . GitRepo , err = git . OpenRepository ( ctx , repoPath )
ctx . Repo . GitRepo , err = git . OpenRepository ( ctx , repoPath )
if err != nil {
if err != nil {
ctx . ServerError ( "RepoRef Invalid repo " + repoPath , err )
ctx . ServerError ( "RepoRef Invalid repo " + repoPath , err )
return
return nil
}
}
// We opened it, we should close it
// We opened it, we should close it
cancel = func ( ) {
cancel = func ( ) {
@ -944,7 +944,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
ctx . Repo . Repository . MarkAsBrokenEmpty ( )
ctx . Repo . Repository . MarkAsBrokenEmpty ( )
} else {
} else {
ctx . ServerError ( "GetBranchCommit" , err )
ctx . ServerError ( "GetBranchCommit" , err )
return
return cancel
}
}
ctx . Repo . IsViewBranch = true
ctx . Repo . IsViewBranch = true
} else {
} else {
@ -956,7 +956,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
ctx . Flash . Info ( ctx . Tr ( "repo.branch.renamed" , refName , renamedBranchName ) )
ctx . Flash . Info ( ctx . Tr ( "repo.branch.renamed" , refName , renamedBranchName ) )
link := setting . AppSubURL + strings . Replace ( ctx . Req . URL . EscapedPath ( ) , util . PathEscapeSegments ( refName ) , util . PathEscapeSegments ( renamedBranchName ) , 1 )
link := setting . AppSubURL + strings . Replace ( ctx . Req . URL . EscapedPath ( ) , util . PathEscapeSegments ( refName ) , util . PathEscapeSegments ( renamedBranchName ) , 1 )
ctx . Redirect ( link )
ctx . Redirect ( link )
return
return cancel
}
}
if refType . RefTypeIncludesBranches ( ) && ctx . Repo . GitRepo . IsBranchExist ( refName ) {
if refType . RefTypeIncludesBranches ( ) && ctx . Repo . GitRepo . IsBranchExist ( refName ) {
@ -966,7 +966,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
ctx . Repo . Commit , err = ctx . Repo . GitRepo . GetBranchCommit ( refName )
ctx . Repo . Commit , err = ctx . Repo . GitRepo . GetBranchCommit ( refName )
if err != nil {
if err != nil {
ctx . ServerError ( "GetBranchCommit" , err )
ctx . ServerError ( "GetBranchCommit" , err )
return
return cancel
}
}
ctx . Repo . CommitID = ctx . Repo . Commit . ID . String ( )
ctx . Repo . CommitID = ctx . Repo . Commit . ID . String ( )
@ -978,10 +978,10 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
if err != nil {
if err != nil {
if git . IsErrNotExist ( err ) {
if git . IsErrNotExist ( err ) {
ctx . NotFound ( "GetTagCommit" , err )
ctx . NotFound ( "GetTagCommit" , err )
return
return cancel
}
}
ctx . ServerError ( "GetTagCommit" , err )
ctx . ServerError ( "GetTagCommit" , err )
return
return cancel
}
}
ctx . Repo . CommitID = ctx . Repo . Commit . ID . String ( )
ctx . Repo . CommitID = ctx . Repo . Commit . ID . String ( )
} else if len ( refName ) >= 7 && len ( refName ) <= git . SHAFullLength {
} else if len ( refName ) >= 7 && len ( refName ) <= git . SHAFullLength {
@ -991,7 +991,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
ctx . Repo . Commit , err = ctx . Repo . GitRepo . GetCommit ( refName )
ctx . Repo . Commit , err = ctx . Repo . GitRepo . GetCommit ( refName )
if err != nil {
if err != nil {
ctx . NotFound ( "GetCommit" , err )
ctx . NotFound ( "GetCommit" , err )
return
return cancel
}
}
// If short commit ID add canonical link header
// If short commit ID add canonical link header
if len ( refName ) < git . SHAFullLength {
if len ( refName ) < git . SHAFullLength {
@ -1000,10 +1000,10 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
}
}
} else {
} else {
if len ( ignoreNotExistErr ) > 0 && ignoreNotExistErr [ 0 ] {
if len ( ignoreNotExistErr ) > 0 && ignoreNotExistErr [ 0 ] {
return
return cancel
}
}
ctx . NotFound ( "RepoRef invalid repo" , fmt . Errorf ( "branch or tag not exist: %s" , refName ) )
ctx . NotFound ( "RepoRef invalid repo" , fmt . Errorf ( "branch or tag not exist: %s" , refName ) )
return
return cancel
}
}
if refType == RepoRefLegacy {
if refType == RepoRefLegacy {
@ -1015,7 +1015,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
util . PathEscapeSegments ( prefix ) ,
util . PathEscapeSegments ( prefix ) ,
ctx . Repo . BranchNameSubURL ( ) ,
ctx . Repo . BranchNameSubURL ( ) ,
util . PathEscapeSegments ( ctx . Repo . TreePath ) ) )
util . PathEscapeSegments ( ctx . Repo . TreePath ) ) )
return
return cancel
}
}
}
}
@ -1033,7 +1033,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
ctx . Repo . CommitsCount , err = ctx . Repo . GetCommitsCount ( )
ctx . Repo . CommitsCount , err = ctx . Repo . GetCommitsCount ( )
if err != nil {
if err != nil {
ctx . ServerError ( "GetCommitsCount" , err )
ctx . ServerError ( "GetCommitsCount" , err )
return
return cancel
}
}
ctx . Data [ "CommitsCount" ] = ctx . Repo . CommitsCount
ctx . Data [ "CommitsCount" ] = ctx . Repo . CommitsCount
ctx . Repo . GitRepo . LastCommitCache = git . NewLastCommitCache ( ctx . Repo . CommitsCount , ctx . Repo . Repository . FullName ( ) , ctx . Repo . GitRepo , cache . GetCache ( ) )
ctx . Repo . GitRepo . LastCommitCache = git . NewLastCommitCache ( ctx . Repo . CommitsCount , ctx . Repo . Repository . FullName ( ) , ctx . Repo . GitRepo , cache . GetCache ( ) )