mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Less naked returns (#25713)
just a step towards #25655 and some related refactoring
This commit is contained in:
		@@ -219,7 +219,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
 | 
			
		||||
	common.ServeContentByReadSeeker(ctx.Base, ctx.Repo.TreePath, lastModified, lfsDataRc)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEntry, lastModified time.Time) {
 | 
			
		||||
func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEntry, lastModified *time.Time) {
 | 
			
		||||
	entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if git.IsErrNotExist(err) {
 | 
			
		||||
@@ -227,23 +227,23 @@ func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEn
 | 
			
		||||
		} else {
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "GetTreeEntryByPath", err)
 | 
			
		||||
		}
 | 
			
		||||
		return
 | 
			
		||||
		return nil, nil, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if entry.IsDir() || entry.IsSubModule() {
 | 
			
		||||
		ctx.NotFound("getBlobForEntry", nil)
 | 
			
		||||
		return
 | 
			
		||||
		return nil, nil, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	info, _, err := git.Entries([]*git.TreeEntry{entry}).GetCommitsInfo(ctx, ctx.Repo.Commit, path.Dir("/" + ctx.Repo.TreePath)[1:])
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "GetCommitsInfo", err)
 | 
			
		||||
		return
 | 
			
		||||
		return nil, nil, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(info) == 1 {
 | 
			
		||||
		// Not Modified
 | 
			
		||||
		lastModified = info[0].Commit.Committer.When
 | 
			
		||||
		lastModified = &info[0].Commit.Committer.When
 | 
			
		||||
	}
 | 
			
		||||
	blob = entry.Blob()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -298,26 +298,26 @@ func ClearIssueLabels(ctx *context.APIContext) {
 | 
			
		||||
	ctx.Status(http.StatusNoContent)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) (issue *issues_model.Issue, labels []*issues_model.Label, err error) {
 | 
			
		||||
	issue, err = issues_model.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
 | 
			
		||||
func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) (*issues_model.Issue, []*issues_model.Label, error) {
 | 
			
		||||
	issue, err := issues_model.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if issues_model.IsErrIssueNotExist(err) {
 | 
			
		||||
			ctx.NotFound()
 | 
			
		||||
		} else {
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
 | 
			
		||||
		}
 | 
			
		||||
		return
 | 
			
		||||
		return nil, nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	labels, err = issues_model.GetLabelsByIDs(form.Labels)
 | 
			
		||||
	labels, err := issues_model.GetLabelsByIDs(form.Labels)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "GetLabelsByIDs", err)
 | 
			
		||||
		return
 | 
			
		||||
		return nil, nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
 | 
			
		||||
		ctx.Status(http.StatusForbidden)
 | 
			
		||||
		return
 | 
			
		||||
		return nil, nil, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return issue, labels, err
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user