mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-22 14:25:18 +02:00
refactor: make git package handle all git operations (#38543)
before: gitrepo vs git packages after: git package fully handle all git operations by the way, use `WithRepo(repo)` instead of `WithDir(repo.Path)` to hide path details. benefits: 1. remove all unnecessary wrappers, developers no need to struggle with "which package should be used" 2. simplify code, RepositoryFacade can (will) be used everywhere, all "path" details are (will be) hidden
This commit is contained in:
@@ -29,7 +29,6 @@ import (
|
||||
"gitea.dev/modules/git"
|
||||
"gitea.dev/modules/git/attribute"
|
||||
"gitea.dev/modules/git/gitcmd"
|
||||
"gitea.dev/modules/gitrepo"
|
||||
"gitea.dev/modules/highlight"
|
||||
"gitea.dev/modules/htmlutil"
|
||||
"gitea.dev/modules/lfs"
|
||||
@@ -1322,8 +1321,6 @@ func guessBeforeCommitForDiff(ctx context.Context, gitRepo *git.Repository, befo
|
||||
// The whitespaceBehavior is either an empty string or a git flag
|
||||
// Returned beforeCommit could be nil if the afterCommit doesn't have parent commit
|
||||
func getDiffBasic(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, files ...string) (_ *Diff, beforeCommit, afterCommit *git.Commit, err error) {
|
||||
repoPath := gitRepo.Path
|
||||
|
||||
afterCommit, err = gitRepo.GetCommit(ctx, opts.AfterCommitID)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
@@ -1360,9 +1357,9 @@ func getDiffBasic(ctx context.Context, gitRepo *git.Repository, opts *DiffOption
|
||||
defer readerClose()
|
||||
go func() {
|
||||
if err := cmdDiff.
|
||||
WithDir(repoPath).
|
||||
WithRepo(gitRepo).
|
||||
RunWithStderr(cmdCtx); err != nil && !gitcmd.IsErrorCanceledOrKilled(err) {
|
||||
log.Error("error during GetDiff(git diff dir: %s): %v", repoPath, err)
|
||||
log.Error("error during GetDiff(git diff dir: %s): %v", gitRepo.Path, err)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -1503,7 +1500,7 @@ func GetDiffShortStat(ctx context.Context, gitRepo *git.Repository, beforeCommit
|
||||
}
|
||||
|
||||
diff := &DiffShortStat{}
|
||||
diff.NumFiles, diff.TotalAddition, diff.TotalDeletion, err = gitrepo.GetDiffShortStatByCmdArgs(ctx, gitRepo, nil, actualBeforeCommitID.String(), afterCommitID)
|
||||
diff.NumFiles, diff.TotalAddition, diff.TotalDeletion, err = git.GetDiffShortStatByCmdArgs(ctx, gitRepo, nil, actualBeforeCommitID.String(), afterCommitID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user