aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/diff.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-01-19 23:26:57 +0000
committerGitHub <noreply@github.com>2022-01-19 23:26:57 +0000
commit5cb0c9aa0d7eed087055b1efca79628957207d36 (patch)
treed117a514e1f17e5f6bfcda1be273f6a971112663 /modules/git/diff.go
parent4563148a61ba892e8f2bb66342f00a950bcd5315 (diff)
downloadgitea-5cb0c9aa0d7eed087055b1efca79628957207d36.tar.gz
gitea-5cb0c9aa0d7eed087055b1efca79628957207d36.zip
Propagate context and ensure git commands run in request context (#17868)
This PR continues the work in #17125 by progressively ensuring that git commands run within the request context. This now means that the if there is a git repo already open in the context it will be used instead of reopening it. Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/git/diff.go')
-rw-r--r--modules/git/diff.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/modules/git/diff.go b/modules/git/diff.go
index f90f911be0..02ed2c60c4 100644
--- a/modules/git/diff.go
+++ b/modules/git/diff.go
@@ -30,17 +30,17 @@ const (
)
// GetRawDiff dumps diff results of repository in given commit ID to io.Writer.
-func GetRawDiff(repoPath, commitID string, diffType RawDiffType, writer io.Writer) error {
- return GetRawDiffForFile(repoPath, "", commitID, diffType, "", writer)
+func GetRawDiff(ctx context.Context, repoPath, commitID string, diffType RawDiffType, writer io.Writer) error {
+ return GetRawDiffForFile(ctx, repoPath, "", commitID, diffType, "", writer)
}
// GetRawDiffForFile dumps diff results of file in given commit ID to io.Writer.
-func GetRawDiffForFile(repoPath, startCommit, endCommit string, diffType RawDiffType, file string, writer io.Writer) error {
- repo, err := OpenRepository(repoPath)
+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("OpenRepository: %v", err)
}
- defer repo.Close()
+ defer closer.Close()
return GetRepoRawDiffForFile(repo, startCommit, endCommit, diffType, file, writer)
}
@@ -276,7 +276,7 @@ func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLi
}
// GetAffectedFiles returns the affected files between two commits
-func GetAffectedFiles(oldCommitID, newCommitID string, env []string, repo *Repository) ([]string, error) {
+func GetAffectedFiles(repo *Repository, oldCommitID, newCommitID string, env []string) ([]string, error) {
stdoutReader, stdoutWriter, err := os.Pipe()
if err != nil {
log.Error("Unable to create os.Pipe for %s", repo.Path)
@@ -290,7 +290,7 @@ func GetAffectedFiles(oldCommitID, newCommitID string, env []string, repo *Repos
affectedFiles := make([]string, 0, 32)
// Run `git diff --name-only` to get the names of the changed files
- err = NewCommand("diff", "--name-only", oldCommitID, newCommitID).
+ err = NewCommandContext(repo.Ctx, "diff", "--name-only", oldCommitID, newCommitID).
RunInDirTimeoutEnvFullPipelineFunc(env, -1, repo.Path,
stdoutWriter, nil, nil,
func(ctx context.Context, cancel context.CancelFunc) error {