chore: replace pkg/errors with cockroachdb/errors (#8098)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: unknwon <2946214+unknwon@users.noreply.github.com>
This commit is contained in:
Copilot
2026-01-22 08:20:53 -05:00
committed by GitHub
parent ae59787ff5
commit 4ee706b2bf
96 changed files with 605 additions and 564 deletions

View File

@@ -2,12 +2,12 @@ package gitutil
import (
"bytes"
"fmt"
"html"
"html/template"
"io"
"sync"
"github.com/cockroachdb/errors"
"github.com/sergi/go-diff/diffmatchpatch"
"golang.org/x/net/html/charset"
"golang.org/x/text/transform"
@@ -176,7 +176,7 @@ func ParseDiff(r io.Reader, maxFiles, maxFileLines, maxLineChars int) (*Diff, er
result := <-done
if result.Err != nil {
return nil, fmt.Errorf("stream parse diff: %v", result.Err)
return nil, errors.Newf("stream parse diff: %v", result.Err)
}
return NewDiff(result.Diff), nil
}
@@ -185,7 +185,7 @@ func ParseDiff(r io.Reader, maxFiles, maxFileLines, maxLineChars int) (*Diff, er
func RepoDiff(repo *git.Repository, rev string, maxFiles, maxFileLines, maxLineChars int, opts ...git.DiffOptions) (*Diff, error) {
diff, err := repo.Diff(rev, maxFiles, maxFileLines, maxLineChars, opts...)
if err != nil {
return nil, fmt.Errorf("get diff: %v", err)
return nil, errors.Newf("get diff: %v", err)
}
return NewDiff(diff), nil
}

View File

@@ -1,8 +1,8 @@
package gitutil
import (
"github.com/cockroachdb/errors"
"github.com/gogs/git-module"
"github.com/pkg/errors"
"gogs.io/gogs/internal/errutil"
)

View File

@@ -1,12 +1,11 @@
package gitutil
import (
"fmt"
"strconv"
"time"
"github.com/cockroachdb/errors"
"github.com/gogs/git-module"
"github.com/pkg/errors"
log "unknwon.dev/clog/v2"
)
@@ -28,7 +27,7 @@ func (module) PullRequestMeta(headPath, basePath, headBranch, baseBranch string)
tmpRemote := strconv.FormatInt(time.Now().UnixNano(), 10)
err := Module.RemoteAdd(headPath, tmpRemote, basePath, git.RemoteAddOptions{Fetch: true})
if err != nil {
return nil, fmt.Errorf("add remote: %v", err)
return nil, errors.Newf("add remote: %v", err)
}
defer func() {
err := Module.RemoteRemove(headPath, tmpRemote)

View File

@@ -1,11 +1,10 @@
package gitutil
import (
"fmt"
"testing"
"github.com/cockroachdb/errors"
"github.com/gogs/git-module"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
@@ -23,64 +22,64 @@ func TestModuler_PullRequestMeta(t *testing.T) {
SetMockModuleStore(t, &MockModuleStore{
remoteAdd: func(repoPath, name, url string, opts ...git.RemoteAddOptions) error {
if repoPath != headPath {
return fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath)
return errors.Newf("repoPath: want %q but got %q", headPath, repoPath)
} else if name == "" {
return errors.New("empty name")
} else if url != basePath {
return fmt.Errorf("url: want %q but got %q", basePath, url)
return errors.Newf("url: want %q but got %q", basePath, url)
}
if len(opts) == 0 {
return errors.New("no options")
} else if !opts[0].Fetch {
return fmt.Errorf("opts.Fetch: want %v but got %v", true, opts[0].Fetch)
return errors.Newf("opts.Fetch: want %v but got %v", true, opts[0].Fetch)
}
return nil
},
mergeBase: func(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) {
if repoPath != headPath {
return "", fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath)
return "", errors.Newf("repoPath: want %q but got %q", headPath, repoPath)
} else if base == "" {
return "", errors.New("empty base")
} else if head != headBranch {
return "", fmt.Errorf("head: want %q but got %q", headBranch, head)
return "", errors.Newf("head: want %q but got %q", headBranch, head)
}
return mergeBase, nil
},
log: func(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) {
if repoPath != headPath {
return nil, fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath)
return nil, errors.Newf("repoPath: want %q but got %q", headPath, repoPath)
}
expRev := mergeBase + "..." + headBranch
if rev != expRev {
return nil, fmt.Errorf("rev: want %q but got %q", expRev, rev)
return nil, errors.Newf("rev: want %q but got %q", expRev, rev)
}
return commits, nil
},
diffNameOnly: func(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) {
if repoPath != headPath {
return nil, fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath)
return nil, errors.Newf("repoPath: want %q but got %q", headPath, repoPath)
} else if base == "" {
return nil, errors.New("empty base")
} else if head != headBranch {
return nil, fmt.Errorf("head: want %q but got %q", headBranch, head)
return nil, errors.Newf("head: want %q but got %q", headBranch, head)
}
if len(opts) == 0 {
return nil, errors.New("no options")
} else if !opts[0].NeedsMergeBase {
return nil, fmt.Errorf("opts.NeedsMergeBase: want %v but got %v", true, opts[0].NeedsMergeBase)
return nil, errors.Newf("opts.NeedsMergeBase: want %v but got %v", true, opts[0].NeedsMergeBase)
}
return changedFiles, nil
},
remoteRemove: func(repoPath, name string, opts ...git.RemoteRemoveOptions) error {
if repoPath != headPath {
return fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath)
return errors.Newf("repoPath: want %q but got %q", headPath, repoPath)
} else if name == "" {
return errors.New("empty name")
}

View File

@@ -1,7 +1,7 @@
package gitutil
import (
"github.com/pkg/errors"
"github.com/cockroachdb/errors"
)
// TagsPage contains a list of tags and pagination information.