mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-16 01:43:24 +09:00
refactor: remove unnecessary git command wrapper functions (#38531)
Removed `gitrepo.RunCmd*` functions, because gitcmd.Command works with Repository directly. Move some "local filesystem" related function into "localfs.go"
This commit is contained in:
@@ -138,7 +138,7 @@ func RestoreBranchPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := gitrepo.Push(ctx, ctx.Repo.Repository, ctx.Repo.Repository, git.PushOptions{
|
||||
if err := gitrepo.PushManaged(ctx, ctx.Repo.Repository, ctx.Repo.Repository, git.PushOptions{
|
||||
Branch: fmt.Sprintf("%s:%s%s", deletedBranch.CommitID, git.BranchPrefix, deletedBranch.Name),
|
||||
Env: repo_module.PushingEnvironment(ctx.Doer, ctx.Repo.Repository),
|
||||
}); err != nil {
|
||||
|
||||
@@ -288,13 +288,11 @@ func Diff(ctx *context.Context) {
|
||||
DiffStyle: GetDiffViewStyle(ctx),
|
||||
AfterCommitID: commitID,
|
||||
}
|
||||
gitRepo := ctx.Repo.GitRepo
|
||||
var gitRepoStore gitrepo.Repository = ctx.Repo.Repository
|
||||
gitRepo := ctx.Repo.GitRepo // don't access ctx.Repo.GitRepo anymore, because it might not be right for wiki repo
|
||||
|
||||
if ctx.Data["PageIsWiki"] != nil {
|
||||
var err error
|
||||
gitRepoStore = ctx.Repo.Repository.WikiStorageRepo()
|
||||
gitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, gitRepoStore)
|
||||
gitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository.WikiStorageRepo())
|
||||
if err != nil {
|
||||
ctx.ServerError("Repo.GitRepo.GetCommit", err)
|
||||
return
|
||||
@@ -334,7 +332,7 @@ func Diff(ctx *context.Context) {
|
||||
ctx.NotFound(err)
|
||||
return
|
||||
}
|
||||
diffShortStat, err := gitdiff.GetDiffShortStat(ctx, gitRepoStore, gitRepo, "", commitID)
|
||||
diffShortStat, err := gitdiff.GetDiffShortStat(ctx, gitRepo, "", commitID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetDiffShortStat", err)
|
||||
return
|
||||
@@ -410,7 +408,7 @@ func Diff(ctx *context.Context) {
|
||||
}
|
||||
|
||||
note := &git.Note{}
|
||||
err = git.GetNote(ctx, ctx.Repo.GitRepo, commitID, note)
|
||||
err = git.GetNote(ctx, gitRepo, commitID, note)
|
||||
if err == nil {
|
||||
ctx.Data["NoteCommit"] = note.Commit
|
||||
ctx.Data["NoteAuthor"] = user_model.GetUserByGitAuthor(ctx, note.Commit)
|
||||
|
||||
@@ -426,7 +426,7 @@ func (cpi *comparePageInfoType) prepareCompareDiff(ctx *context.Context, whitesp
|
||||
ctx.ServerError("GetDiff", err)
|
||||
return
|
||||
}
|
||||
diffShortStat, err := gitdiff.GetDiffShortStat(ctx, ci.HeadRepo, ci.HeadGitRepo, beforeCommitID, headCommitID)
|
||||
diffShortStat, err := gitdiff.GetDiffShortStat(ctx, ci.HeadGitRepo, beforeCommitID, headCommitID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetDiffShortStat", err)
|
||||
return
|
||||
|
||||
@@ -128,7 +128,7 @@ func getUniqueRepositoryName(ctx context.Context, ownerID int64, name string) st
|
||||
}
|
||||
|
||||
func editorPushBranchToForkedRepository(ctx context.Context, doer *user_model.User, baseRepo *repo_model.Repository, baseBranchName string, targetRepo *repo_model.Repository, targetBranchName string) error {
|
||||
return gitrepo.Push(ctx, baseRepo, targetRepo, git.PushOptions{
|
||||
return gitrepo.PushManaged(ctx, baseRepo, targetRepo, git.PushOptions{
|
||||
Branch: baseBranchName + ":" + targetBranchName,
|
||||
Env: repo_module.PushingEnvironment(doer, targetRepo),
|
||||
})
|
||||
|
||||
@@ -306,11 +306,11 @@ type serviceHandler struct {
|
||||
environ []string
|
||||
}
|
||||
|
||||
func (h *serviceHandler) getStorageRepo() gitrepo.Repository {
|
||||
func (h *serviceHandler) getStorageRepo() git.RepositoryFacade {
|
||||
if h.isWiki {
|
||||
return h.repo.WikiStorageRepo()
|
||||
}
|
||||
return h.repo
|
||||
return h.repo.CodeStorageRepo()
|
||||
}
|
||||
|
||||
func setHeaderNoCache(ctx *context.Context) {
|
||||
@@ -412,11 +412,12 @@ func serviceRPC(ctx *context.Context, service string) {
|
||||
h.environ = append(h.environ, "GIT_PROTOCOL="+protocol)
|
||||
}
|
||||
|
||||
if err := gitrepo.RunCmdWithStderr(ctx, h.getStorageRepo(), cmd.AddArguments(".").
|
||||
WithEnv(append(os.Environ(), h.environ...)).
|
||||
err := cmd.AddArguments(".").
|
||||
WithRepo(h.getStorageRepo()).WithEnv(append(os.Environ(), h.environ...)).
|
||||
WithStdinCopy(reqBody).
|
||||
WithStdoutCopy(ctx.Resp),
|
||||
); err != nil {
|
||||
WithStdoutCopy(ctx.Resp).
|
||||
RunWithStderr(ctx)
|
||||
if err != nil {
|
||||
if !gitcmd.IsErrorCanceledOrKilled(err) {
|
||||
repoLogName := h.repo.FullName() + util.Iif(h.isWiki, ".wiki", "")
|
||||
log.Error("Fail to serve RPC(%s) for repo %s: %v", service, repoLogName, err)
|
||||
@@ -482,7 +483,7 @@ func GetInfoRefs(ctx *context.Context) {
|
||||
h.environ = append(os.Environ(), h.environ...)
|
||||
|
||||
cmd = cmd.AddArguments("--stateless-rpc", "--advertise-refs", ".").WithEnv(h.environ)
|
||||
refs, _, err := gitrepo.RunCmdBytes(ctx, h.getStorageRepo(), cmd)
|
||||
refs, _, err := cmd.WithRepo(h.getStorageRepo()).RunStdBytes(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("RunGitServiceAdvertiseRefs", err)
|
||||
return
|
||||
|
||||
@@ -146,7 +146,7 @@ func NewComment(ctx *context.Context) {
|
||||
|
||||
if prHeadCommitID != headBranchCommitID {
|
||||
// force push to base repo
|
||||
err := gitrepo.Push(ctx, pull.HeadRepo, pull.BaseRepo, git.PushOptions{
|
||||
err := gitrepo.PushManaged(ctx, pull.HeadRepo, pull.BaseRepo, git.PushOptions{
|
||||
Branch: pull.HeadBranch + ":" + prHeadRef,
|
||||
Force: true,
|
||||
Env: repo_module.InternalPushingEnvironment(pull.Issue.Poster, pull.BaseRepo),
|
||||
|
||||
@@ -210,7 +210,7 @@ func GetPullDiffStats(ctx *context.Context) {
|
||||
log.Error("Failed to GetRefCommitID: %v, repo: %v", err, ctx.Repo.Repository.FullName())
|
||||
return
|
||||
}
|
||||
diffShortStat, err := gitdiff.GetDiffShortStat(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, mergeBaseCommitID, headCommitID)
|
||||
diffShortStat, err := gitdiff.GetDiffShortStat(ctx, ctx.Repo.GitRepo, mergeBaseCommitID, headCommitID)
|
||||
if err != nil {
|
||||
log.Error("Failed to GetDiffShortStat: %v, repo: %v", err, ctx.Repo.Repository.FullName())
|
||||
return
|
||||
@@ -243,8 +243,8 @@ func GetMergedBaseCommitID(ctx *context.Context, issue *issues_model.Issue) stri
|
||||
}
|
||||
if commitSHA != "" {
|
||||
// Get immediate parent of the first commit in the patch, grab history back
|
||||
parentCommit, _, err = gitrepo.RunCmdString(ctx, ctx.Repo.Repository,
|
||||
gitcmd.NewCommand("rev-list", "-1", "--skip=1").AddDynamicArguments(commitSHA))
|
||||
parentCommit, _, err = gitcmd.NewCommand("rev-list", "-1", "--skip=1").
|
||||
AddDynamicArguments(commitSHA).WithRepo(ctx.Repo.Repository).RunStdString(ctx)
|
||||
if err == nil {
|
||||
parentCommit = strings.TrimSpace(parentCommit)
|
||||
}
|
||||
@@ -811,7 +811,7 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) {
|
||||
}
|
||||
}
|
||||
|
||||
diffShortStat, err := gitdiff.GetDiffShortStat(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, beforeCommitID, afterCommitID)
|
||||
diffShortStat, err := gitdiff.GetDiffShortStat(ctx, ctx.Repo.GitRepo, beforeCommitID, afterCommitID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetDiffShortStat", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user