Pass gitRepo down to GetRawDiff, since its used for main repo and wiki (#19461)
as per https://github.com/go-gitea/gitea/pull/19449#issuecomment-1105283931 pass gitRepo down to GetRawDiff, since its used for main repo and wiki
This commit is contained in:
parent
7c164d5a91
commit
1ebb30e41b
4 changed files with 23 additions and 31 deletions
|
@ -28,8 +28,8 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetRawDiff dumps diff results of repository in given commit ID to io.Writer.
|
// GetRawDiff dumps diff results of repository in given commit ID to io.Writer.
|
||||||
func GetRawDiff(ctx context.Context, repoPath, commitID string, diffType RawDiffType, writer io.Writer) error {
|
func GetRawDiff(repo *Repository, commitID string, diffType RawDiffType, writer io.Writer) error {
|
||||||
return GetRawDiffForFile(ctx, repoPath, "", commitID, diffType, "", writer)
|
return GetRepoRawDiffForFile(repo, "", commitID, diffType, "", writer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetReverseRawDiff dumps the reverse diff results of repository in given commit ID to io.Writer.
|
// GetReverseRawDiff dumps the reverse diff results of repository in given commit ID to io.Writer.
|
||||||
|
@ -46,17 +46,6 @@ func GetReverseRawDiff(ctx context.Context, repoPath, commitID string, writer io
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRawDiffForFile dumps diff results of file in given commit ID to io.Writer.
|
|
||||||
func GetRawDiffForFile(ctx context.Context, repoPath, startCommit, endCommit string, diffType RawDiffType, file string, writer io.Writer) error {
|
|
||||||
repo, closer, err := RepositoryFromContextOrOpen(ctx, repoPath)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("RepositoryFromContextOrOpen: %v", err)
|
|
||||||
}
|
|
||||||
defer closer.Close()
|
|
||||||
|
|
||||||
return GetRepoRawDiffForFile(repo, startCommit, endCommit, diffType, file, writer)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRepoRawDiffForFile dumps diff results of file in given commit ID to io.Writer according given repository
|
// GetRepoRawDiffForFile dumps diff results of file in given commit ID to io.Writer according given repository
|
||||||
func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diffType RawDiffType, file string, writer io.Writer) error {
|
func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diffType RawDiffType, file string, writer io.Writer) error {
|
||||||
commit, err := repo.GetCommit(endCommit)
|
commit, err := repo.GetCommit(endCommit)
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/convert"
|
"code.gitea.io/gitea/modules/convert"
|
||||||
|
@ -268,17 +267,12 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/string"
|
// "$ref": "#/responses/string"
|
||||||
// "404":
|
// "404":
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
sha := ctx.Params(":sha")
|
||||||
// TODO: use gitRepo from context
|
diffType := git.RawDiffType(ctx.Params(":diffType"))
|
||||||
if err := git.GetRawDiff(
|
|
||||||
ctx,
|
if err := git.GetRawDiff(ctx.Repo.GitRepo, sha, diffType, ctx.Resp); err != nil {
|
||||||
repoPath,
|
|
||||||
ctx.Params(":sha"),
|
|
||||||
git.RawDiffType(ctx.Params(":diffType")),
|
|
||||||
ctx.Resp,
|
|
||||||
); err != nil {
|
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
ctx.NotFound(ctx.Params(":sha"))
|
ctx.NotFound(sha)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "DownloadCommitDiffOrPatch", err)
|
ctx.Error(http.StatusInternalServerError, "DownloadCommitDiffOrPatch", err)
|
||||||
|
|
|
@ -151,7 +151,7 @@ func CherryPickPost(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := git.GetRawDiff(ctx, ctx.Repo.Repository.RepoPath(), sha, git.RawDiffType("patch"), buf); err != nil {
|
if err := git.GetRawDiff(ctx.Repo.GitRepo, sha, git.RawDiffType("patch"), buf); err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
ctx.NotFound("GetRawDiff", errors.New("commit "+ctx.Params(":sha")+" does not exist."))
|
ctx.NotFound("GetRawDiff", errors.New("commit "+ctx.Params(":sha")+" does not exist."))
|
||||||
return
|
return
|
||||||
|
|
|
@ -7,13 +7,13 @@ package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/charset"
|
"code.gitea.io/gitea/modules/charset"
|
||||||
|
@ -381,15 +381,24 @@ func Diff(ctx *context.Context) {
|
||||||
|
|
||||||
// RawDiff dumps diff results of repository in given commit ID to io.Writer
|
// RawDiff dumps diff results of repository in given commit ID to io.Writer
|
||||||
func RawDiff(ctx *context.Context) {
|
func RawDiff(ctx *context.Context) {
|
||||||
var repoPath string
|
var gitRepo *git.Repository
|
||||||
if ctx.Data["PageIsWiki"] != nil {
|
if ctx.Data["PageIsWiki"] != nil {
|
||||||
repoPath = ctx.Repo.Repository.WikiPath()
|
wikiRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath())
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("OpenRepository", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer wikiRepo.Close()
|
||||||
|
gitRepo = wikiRepo
|
||||||
} else {
|
} else {
|
||||||
repoPath = repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
gitRepo = ctx.Repo.GitRepo
|
||||||
|
if gitRepo == nil {
|
||||||
|
ctx.ServerError("GitRepo not open", fmt.Errorf("no open git repo for '%s'", ctx.Repo.Repository.FullName()))
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err := git.GetRawDiff(
|
if err := git.GetRawDiff(
|
||||||
ctx,
|
gitRepo,
|
||||||
repoPath,
|
|
||||||
ctx.Params(":sha"),
|
ctx.Params(":sha"),
|
||||||
git.RawDiffType(ctx.Params(":ext")),
|
git.RawDiffType(ctx.Params(":ext")),
|
||||||
ctx.Resp,
|
ctx.Resp,
|
||||||
|
|
Reference in a new issue