Skip to content

Commit ace647d

Browse files
committed
Revert change of ConcatenateError
1 parent ce0ec3b commit ace647d

16 files changed

+27
-39
lines changed

modules/git/batch_reader.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"strings"
1414

1515
"code.gitea.io/gitea/modules/log"
16-
"code.gitea.io/gitea/modules/util"
1716

1817
"github.com/djherbis/buffer"
1918
"github.com/djherbis/nio/v3"
@@ -36,7 +35,7 @@ func ensureValidGitRepository(ctx context.Context, repoPath string) error {
3635
Stderr: &stderr,
3736
})
3837
if err != nil {
39-
return util.ConcatenateError(err, (&stderr).String())
38+
return ConcatenateError(err, (&stderr).String())
4039
}
4140
return nil
4241
}
@@ -72,8 +71,8 @@ func catFileBatchCheck(ctx context.Context, repoPath string) (WriteCloserError,
7271
UseContextTimeout: true,
7372
})
7473
if err != nil {
75-
_ = batchStdoutWriter.CloseWithError(util.ConcatenateError(err, (&stderr).String()))
76-
_ = batchStdinReader.CloseWithError(util.ConcatenateError(err, (&stderr).String()))
74+
_ = batchStdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
75+
_ = batchStdinReader.CloseWithError(ConcatenateError(err, (&stderr).String()))
7776
} else {
7877
_ = batchStdoutWriter.Close()
7978
_ = batchStdinReader.Close()
@@ -120,8 +119,8 @@ func catFileBatch(ctx context.Context, repoPath string) (WriteCloserError, *bufi
120119
UseContextTimeout: true,
121120
})
122121
if err != nil {
123-
_ = batchStdoutWriter.CloseWithError(util.ConcatenateError(err, (&stderr).String()))
124-
_ = batchStdinReader.CloseWithError(util.ConcatenateError(err, (&stderr).String()))
122+
_ = batchStdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
123+
_ = batchStdinReader.CloseWithError(ConcatenateError(err, (&stderr).String()))
125124
} else {
126125
_ = batchStdoutWriter.Close()
127126
_ = batchStdinReader.Close()

modules/git/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ type runStdError struct {
380380
func (r *runStdError) Error() string {
381381
// the stderr must be in the returned error text, some code only checks `strings.Contains(err.Error(), "git error")`
382382
if r.errMsg == "" {
383-
r.errMsg = util.ConcatenateError(r.err, r.stderr).Error()
383+
r.errMsg = ConcatenateError(r.err, r.stderr).Error()
384384
}
385385
return r.errMsg
386386
}

modules/git/commit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ func GetCommitFileStatus(ctx context.Context, repoPath, commitID string) (*Commi
448448
})
449449
w.Close() // Close writer to exit parsing goroutine
450450
if err != nil {
451-
return nil, util.ConcatenateError(err, stderr.String())
451+
return nil, ConcatenateError(err, stderr.String())
452452
}
453453

454454
<-done

modules/git/log_name_status.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"strings"
1515

1616
"code.gitea.io/gitea/modules/container"
17-
"code.gitea.io/gitea/modules/util"
1817

1918
"github.com/djherbis/buffer"
2019
"github.com/djherbis/nio/v3"
@@ -71,7 +70,7 @@ func LogNameStatusRepo(ctx context.Context, repository, head, treepath string, p
7170
Stderr: &stderr,
7271
})
7372
if err != nil {
74-
_ = stdoutWriter.CloseWithError(util.ConcatenateError(err, (&stderr).String()))
73+
_ = stdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
7574
return
7675
}
7776

modules/git/pipeline/lfs_nogogit.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"sync"
1515

1616
"code.gitea.io/gitea/modules/git"
17-
"code.gitea.io/gitea/modules/util"
1817
)
1918

2019
// FindLFSFile finds commits that contain a provided pointer file hash
@@ -39,7 +38,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
3938
Stderr: &stderr,
4039
})
4140
if err != nil {
42-
_ = revListWriter.CloseWithError(util.ConcatenateError(err, (&stderr).String()))
41+
_ = revListWriter.CloseWithError(git.ConcatenateError(err, (&stderr).String()))
4342
} else {
4443
_ = revListWriter.Close()
4544
}

modules/git/repo.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"time"
1919

2020
"code.gitea.io/gitea/modules/proxy"
21-
"code.gitea.io/gitea/modules/util"
2221
)
2322

2423
// GPGSettings represents the default GPG settings for this repository
@@ -177,7 +176,7 @@ func CloneWithArgs(ctx context.Context, args TrustedCmdArgs, from, to string, op
177176
Stdout: io.Discard,
178177
Stderr: stderr,
179178
}); err != nil {
180-
return util.ConcatenateError(err, stderr.String())
179+
return ConcatenateError(err, stderr.String())
181180
}
182181
return nil
183182
}

modules/git/repo_archive.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"io"
1111
"path/filepath"
1212
"strings"
13-
14-
"code.gitea.io/gitea/modules/util"
1513
)
1614

1715
// ArchiveType archive types
@@ -69,7 +67,7 @@ func (repo *Repository) CreateArchive(ctx context.Context, format ArchiveType, t
6967
Stderr: &stderr,
7068
})
7169
if err != nil {
72-
return util.ConcatenateError(err, stderr.String())
70+
return ConcatenateError(err, stderr.String())
7371
}
7472
return nil
7573
}

modules/git/repo_branch_nogogit.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"strings"
1515

1616
"code.gitea.io/gitea/modules/log"
17-
"code.gitea.io/gitea/modules/util"
1817
)
1918

2019
// IsObjectExist returns true if the given object exists in the repository.
@@ -120,7 +119,7 @@ func WalkShowRef(ctx context.Context, repoPath string, extraArgs TrustedCmdArgs,
120119
_ = stdoutWriter.Close()
121120
return
122121
}
123-
_ = stdoutWriter.CloseWithError(util.ConcatenateError(err, stderrBuilder.String()))
122+
_ = stdoutWriter.CloseWithError(ConcatenateError(err, stderrBuilder.String()))
124123
} else {
125124
_ = stdoutWriter.Close()
126125
}

modules/git/repo_commit.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"code.gitea.io/gitea/modules/cache"
1515
"code.gitea.io/gitea/modules/setting"
16-
"code.gitea.io/gitea/modules/util"
1716
)
1817

1918
// GetBranchCommitID returns last commit ID string of given branch.
@@ -240,7 +239,7 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
240239
Stderr: &stderr,
241240
})
242241
if err != nil {
243-
_ = stdoutWriter.CloseWithError(util.ConcatenateError(err, (&stderr).String()))
242+
_ = stdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String()))
244243
} else {
245244
_ = stdoutWriter.Close()
246245
}

modules/git/repo_ref_nogogit.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"bufio"
1010
"io"
1111
"strings"
12-
13-
"code.gitea.io/gitea/modules/util"
1412
)
1513

1614
// GetRefsFiltered returns all references of the repository that matches patterm exactly or starting with.
@@ -29,7 +27,7 @@ func (repo *Repository) GetRefsFiltered(pattern string) ([]*Reference, error) {
2927
Stderr: stderrBuilder,
3028
})
3129
if err != nil {
32-
_ = stdoutWriter.CloseWithError(util.ConcatenateError(err, stderrBuilder.String()))
30+
_ = stdoutWriter.CloseWithError(ConcatenateError(err, stderrBuilder.String()))
3331
} else {
3432
_ = stdoutWriter.Close()
3533
}

modules/git/repo_tag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (repo *Repository) GetTagInfos(page, pageSize int) ([]*Tag, int, error) {
121121
AddOptionFormat("--format=%s", forEachRefFmt.Flag()).
122122
AddArguments("--sort", "-*creatordate", "refs/tags").Run(repo.Ctx, rc)
123123
if err != nil {
124-
_ = stdoutWriter.CloseWithError(util.ConcatenateError(err, stderr.String()))
124+
_ = stdoutWriter.CloseWithError(ConcatenateError(err, stderr.String()))
125125
} else {
126126
_ = stdoutWriter.Close()
127127
}

modules/git/repo_tree.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"os"
1010
"strings"
1111
"time"
12-
13-
"code.gitea.io/gitea/modules/util"
1412
)
1513

1614
// CommitTreeOpts represents the possible options to CommitTree
@@ -63,7 +61,7 @@ func (repo *Repository) CommitTree(author, committer *Signature, tree *Tree, opt
6361
Stderr: stderr,
6462
})
6563
if err != nil {
66-
return nil, util.ConcatenateError(err, stderr.String())
64+
return nil, ConcatenateError(err, stderr.String())
6765
}
6866
return NewIDFromString(strings.TrimSpace(stdout.String()))
6967
}

modules/git/utils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package git
66
import (
77
"crypto/sha1"
88
"encoding/hex"
9+
"fmt"
910
"io"
1011
"strconv"
1112
"strings"
@@ -39,6 +40,14 @@ func (oc *ObjectCache[T]) Get(id string) (T, bool) {
3940
return obj, has
4041
}
4142

43+
// ConcatenateError concatenats an error with stderr string
44+
func ConcatenateError(err error, stderr string) error {
45+
if len(stderr) == 0 {
46+
return err
47+
}
48+
return fmt.Errorf("%w - %s", err, stderr)
49+
}
50+
4251
// ParseBool returns the boolean value represented by the string as per git's git_config_bool
4352
// true will be returned for the result if the string is empty, but valid will be false.
4453
// "true", "yes", "on" are all true, true

modules/util/error.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,3 @@ func ErrorAsLocale(err error) *LocaleWrapper {
9595
}
9696
return nil
9797
}
98-
99-
// ConcatenateError concatenats an error with stderr string
100-
func ConcatenateError(err error, stderr string) error {
101-
if len(stderr) == 0 {
102-
return err
103-
}
104-
return fmt.Errorf("%w - %s", err, stderr)
105-
}

services/pull/patch_unmerged.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515

1616
"code.gitea.io/gitea/modules/git"
1717
"code.gitea.io/gitea/modules/log"
18-
"code.gitea.io/gitea/modules/util"
1918
)
2019

2120
// lsFileLine is a Quadruplet struct (+error) representing a partially parsed line from ls-files
@@ -117,7 +116,7 @@ func readUnmergedLsFileLines(ctx context.Context, tmpBasePath string, outputChan
117116
},
118117
})
119118
if err != nil {
120-
outputChan <- &lsFileLine{err: fmt.Errorf("git ls-files -u -z: %w", util.ConcatenateError(err, stderr.String()))}
119+
outputChan <- &lsFileLine{err: fmt.Errorf("git ls-files -u -z: %w", git.ConcatenateError(err, stderr.String()))}
121120
}
122121
}
123122

services/pull/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ func checkIfPRContentChanged(ctx context.Context, pr *issues_model.PullRequest,
551551
if err == util.ErrNotEmpty {
552552
return true, nil
553553
}
554-
err = util.ConcatenateError(err, stderr.String())
554+
err = git.ConcatenateError(err, stderr.String())
555555

556556
log.Error("Unable to run diff on %s %s %s in tempRepo for PR[%d]%s/%s...%s/%s: Error: %v",
557557
newCommitID, oldCommitID, base,

0 commit comments

Comments
 (0)