aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-09-18 01:54:15 +0100
committerGitHub <noreply@github.com>2021-09-17 20:54:15 -0400
commit25533657f6a3edd2d12c8b8112d009559a136201 (patch)
treebdab2bd70e3fb4156728f2e81bfc5dfdc2a46c38 /modules/git
parent693bea9780be8c9ecc40bc751e6fafbeaea07743 (diff)
downloadgitea-25533657f6a3edd2d12c8b8112d009559a136201.tar.gz
gitea-25533657f6a3edd2d12c8b8112d009559a136201.zip
Add caller to cat-file batch calls (#17082)
Some people still appear to report unclosed cat-files. This PR simply adds the caller to the process descriptor for the CatFileBatch and CatFileBatchCheck calls. Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/batch_reader.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/modules/git/batch_reader.go b/modules/git/batch_reader.go
index 164e643812..8e3c23251b 100644
--- a/modules/git/batch_reader.go
+++ b/modules/git/batch_reader.go
@@ -8,8 +8,10 @@ import (
"bufio"
"bytes"
"context"
+ "fmt"
"io"
"math"
+ "runtime"
"strconv"
"strings"
@@ -40,9 +42,14 @@ func CatFileBatchCheck(repoPath string) (WriteCloserError, *bufio.Reader, func()
<-closed
}
+ _, filename, line, _ := runtime.Caller(2)
+ filename = strings.TrimPrefix(filename, callerPrefix)
+
go func() {
stderr := strings.Builder{}
- err := NewCommandContext(ctx, "cat-file", "--batch-check").RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
+ err := NewCommandContext(ctx, "cat-file", "--batch-check").
+ SetDescription(fmt.Sprintf("%s cat-file --batch-check [repo_path: %s] (%s:%d)", GitExecutable, repoPath, filename, line)).
+ RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
if err != nil {
_ = batchStdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
_ = batchStdinReader.CloseWithError(ConcatenateError(err, (&stderr).String()))
@@ -76,9 +83,14 @@ func CatFileBatch(repoPath string) (WriteCloserError, *bufio.Reader, func()) {
<-closed
}
+ _, filename, line, _ := runtime.Caller(2)
+ filename = strings.TrimPrefix(filename, callerPrefix)
+
go func() {
stderr := strings.Builder{}
- err := NewCommandContext(ctx, "cat-file", "--batch").RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
+ err := NewCommandContext(ctx, "cat-file", "--batch").
+ SetDescription(fmt.Sprintf("%s cat-file --batch [repo_path: %s] (%s:%d)", GitExecutable, repoPath, filename, line)).
+ RunInDirFullPipeline(repoPath, batchStdoutWriter, &stderr, batchStdinReader)
if err != nil {
_ = batchStdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
_ = batchStdinReader.CloseWithError(ConcatenateError(err, (&stderr).String()))
@@ -292,3 +304,10 @@ func ParseTreeLine(rd *bufio.Reader, modeBuf, fnameBuf, shaBuf []byte) (mode, fn
sha = shaBuf
return
}
+
+var callerPrefix string
+
+func init() {
+ _, filename, _, _ := runtime.Caller(0)
+ callerPrefix = strings.TrimSuffix(filename, "modules/git/batch_reader.go")
+}