From d318098ba47bc7d1d94a6aa67b614e2ba434763e Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 29 Oct 2025 14:08:14 +0800 Subject: [PATCH 01/14] restart from scratch --- modules/git/batch.go | 47 --------- modules/git/blob_nogogit.go | 33 +++---- modules/git/catfile_batch.go | 41 ++++++++ modules/git/catfile_batch_legacy.go | 73 ++++++++++++++ ...atch_reader.go => catfile_batch_reader.go} | 98 +++++++------------ .../languagestats/language_stats_nogogit.go | 12 +-- modules/git/parse_nogogit.go | 3 +- modules/git/pipeline/lfs_nogogit.go | 23 ++--- modules/git/repo_base_nogogit.go | 85 +++++++--------- modules/git/repo_branch_nogogit.go | 8 +- modules/git/repo_commit_nogogit.go | 27 +++-- modules/git/repo_tag_nogogit.go | 9 +- modules/git/repo_tree_nogogit.go | 11 ++- modules/git/tree_entry_nogogit.go | 4 +- modules/git/tree_nogogit.go | 16 ++- modules/indexer/code/bleve/bleve.go | 9 +- .../code/elasticsearch/elasticsearch.go | 9 +- routers/web/repo/compare.go | 4 +- 18 files changed, 263 insertions(+), 249 deletions(-) delete mode 100644 modules/git/batch.go create mode 100644 modules/git/catfile_batch.go create mode 100644 modules/git/catfile_batch_legacy.go rename modules/git/{batch_reader.go => catfile_batch_reader.go} (71%) diff --git a/modules/git/batch.go b/modules/git/batch.go deleted file mode 100644 index f9e1748b548f5..0000000000000 --- a/modules/git/batch.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2024 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -package git - -import ( - "bufio" - "context" -) - -type Batch struct { - cancel context.CancelFunc - Reader *bufio.Reader - Writer WriteCloserError -} - -// NewBatch creates a new batch for the given repository, the Close must be invoked before release the batch -func NewBatch(ctx context.Context, repoPath string) (*Batch, error) { - // Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first! - if err := ensureValidGitRepository(ctx, repoPath); err != nil { - return nil, err - } - - var batch Batch - batch.Writer, batch.Reader, batch.cancel = catFileBatch(ctx, repoPath) - return &batch, nil -} - -func NewBatchCheck(ctx context.Context, repoPath string) (*Batch, error) { - // Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first! - if err := ensureValidGitRepository(ctx, repoPath); err != nil { - return nil, err - } - - var check Batch - check.Writer, check.Reader, check.cancel = catFileBatchCheck(ctx, repoPath) - return &check, nil -} - -func (b *Batch) Close() { - if b.cancel != nil { - b.cancel() - b.Reader = nil - b.Writer = nil - b.cancel = nil - } -} diff --git a/modules/git/blob_nogogit.go b/modules/git/blob_nogogit.go index af3ce376d6a46..07d857cb51de1 100644 --- a/modules/git/blob_nogogit.go +++ b/modules/git/blob_nogogit.go @@ -6,8 +6,6 @@ package git import ( - "bufio" - "bytes" "io" "code.gitea.io/gitea/modules/log" @@ -25,35 +23,27 @@ type Blob struct { // DataAsync gets a ReadCloser for the contents of a blob without reading it all. // Calling the Close function on the result will discard all unread output. -func (b *Blob) DataAsync() (io.ReadCloser, error) { - wr, rd, cancel, err := b.repo.CatFileBatch(b.repo.Ctx) +func (b *Blob) DataAsync() (_ io.ReadCloser, retErr error) { + batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx) if err != nil { return nil, err } + defer func() { + if retErr != nil { + cancel() + } + }() - _, err = wr.Write([]byte(b.ID.String() + "\n")) + rd, err := batch.QueryContent(b.ID.String()) if err != nil { - cancel() return nil, err } _, _, size, err := ReadBatchLine(rd) if err != nil { - cancel() return nil, err } b.gotSize = true b.size = size - - if size < 4096 { - bs, err := io.ReadAll(io.LimitReader(rd, size)) - defer cancel() - if err != nil { - return nil, err - } - _, err = rd.Discard(1) - return io.NopCloser(bytes.NewReader(bs)), err - } - return &blobReader{ rd: rd, n: size, @@ -67,13 +57,13 @@ func (b *Blob) Size() int64 { return b.size } - wr, rd, cancel, err := b.repo.CatFileBatchCheck(b.repo.Ctx) + batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx) if err != nil { log.Debug("error whilst reading size for %s in %s. Error: %v", b.ID.String(), b.repo.Path, err) return 0 } defer cancel() - _, err = wr.Write([]byte(b.ID.String() + "\n")) + rd, err := batch.QueryInfo(b.ID.String()) if err != nil { log.Debug("error whilst reading size for %s in %s. Error: %v", b.ID.String(), b.repo.Path, err) return 0 @@ -85,12 +75,11 @@ func (b *Blob) Size() int64 { } b.gotSize = true - return b.size } type blobReader struct { - rd *bufio.Reader + rd BufferedReader n int64 cancel func() } diff --git a/modules/git/catfile_batch.go b/modules/git/catfile_batch.go new file mode 100644 index 0000000000000..72b54b48dee00 --- /dev/null +++ b/modules/git/catfile_batch.go @@ -0,0 +1,41 @@ +// Copyright 2025 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +import ( + "context" + "io" +) + +type BufferedReader interface { + io.Reader + Buffered() int + Peek(n int) ([]byte, error) + Discard(n int) (int, error) + ReadString(sep byte) (string, error) + ReadSlice(sep byte) ([]byte, error) + ReadBytes(sep byte) ([]byte, error) +} + +type CatFileBatchContent interface { + QueryContent(obj string) (BufferedReader, error) +} + +type CatFileBatchInfo interface { + QueryInfo(obj string) (BufferedReader, error) +} + +type CatFileBatch interface { + CatFileBatchInfo + CatFileBatchContent +} + +type CatFileBatchCloser interface { + CatFileBatch + Close() +} + +func NewBatch(ctx context.Context, repoPath string) (CatFileBatchCloser, error) { + return newCatFileBatchLegacy(ctx, repoPath) +} diff --git a/modules/git/catfile_batch_legacy.go b/modules/git/catfile_batch_legacy.go new file mode 100644 index 0000000000000..02d8beb0e8824 --- /dev/null +++ b/modules/git/catfile_batch_legacy.go @@ -0,0 +1,73 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +import ( + "context" + "io" + + "code.gitea.io/gitea/modules/git/gitcmd" +) + +// catFileBatchLegacy implements the CatFileBatch interface using the "cat-file --batch" command and "cat-file --batch-check" command +// for git version < 2.36 +// to align with "--batch-command", it creates the two commands for querying object contents and object info separately +// ref: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt---batch +type catFileBatchLegacy struct { + ctx context.Context + repoPath string + batchContent *catFileBatchCommunicator + batchCheck *catFileBatchCommunicator +} + +var _ CatFileBatchCloser = (*catFileBatchLegacy)(nil) + +// newCatFileBatchLegacy creates a new batch and a new batch check for the given repository, the Close must be invoked before release the batch +func newCatFileBatchLegacy(ctx context.Context, repoPath string) (*catFileBatchLegacy, error) { + if err := ensureValidGitRepository(ctx, repoPath); err != nil { + return nil, err + } + + return &catFileBatchLegacy{ + ctx: ctx, + repoPath: repoPath, + }, nil +} + +func (b *catFileBatchLegacy) getBatchContent() *catFileBatchCommunicator { + if b.batchContent != nil { + return b.batchContent + } + b.batchContent = newCatFileBatch(b.ctx, b.repoPath, gitcmd.NewCommand("cat-file", "--batch")) + return b.batchContent +} + +func (b *catFileBatchLegacy) getBatchCheck() *catFileBatchCommunicator { + if b.batchCheck != nil { + return b.batchCheck + } + b.batchCheck = newCatFileBatch(b.ctx, b.repoPath, gitcmd.NewCommand("cat-file", "--batch-check")) + return b.batchCheck +} + +func (b *catFileBatchLegacy) QueryContent(obj string) (BufferedReader, error) { + _, err := io.WriteString(b.getBatchContent().writer, obj+"\n") + return b.getBatchContent().reader, err +} + +func (b *catFileBatchLegacy) QueryInfo(obj string) (BufferedReader, error) { + _, err := io.WriteString(b.getBatchCheck().writer, obj+"\n") + return b.getBatchCheck().reader, err +} + +func (b *catFileBatchLegacy) Close() { + if b.batchContent != nil { + b.batchContent.Close() + b.batchContent = nil + } + if b.batchCheck != nil { + b.batchCheck.Close() + b.batchCheck = nil + } +} diff --git a/modules/git/batch_reader.go b/modules/git/catfile_batch_reader.go similarity index 71% rename from modules/git/batch_reader.go rename to modules/git/catfile_batch_reader.go index b5cec130d5e3a..9e631e488c80f 100644 --- a/modules/git/batch_reader.go +++ b/modules/git/catfile_batch_reader.go @@ -14,20 +14,35 @@ import ( "code.gitea.io/gitea/modules/git/gitcmd" "code.gitea.io/gitea/modules/log" - - "github.com/djherbis/buffer" - "github.com/djherbis/nio/v3" ) -// WriteCloserError wraps an io.WriteCloser with an additional CloseWithError function -type WriteCloserError interface { +// writeCloserError wraps an io.WriteCloser with an additional CloseWithError function (for nio.Pipe) +type writeCloserError interface { io.WriteCloser CloseWithError(err error) error } +type catFileBatchCommunicator struct { + cancel context.CancelFunc + reader *bufio.Reader + writer writeCloserError +} + +func (b *catFileBatchCommunicator) Close() { + if b.cancel != nil { + b.cancel() + b.reader = nil + b.writer = nil + b.cancel = nil + } +} + // ensureValidGitRepository runs git rev-parse in the repository path - thus ensuring that the repository is a valid repository. // Run before opening git cat-file. // This is needed otherwise the git cat-file will hang for invalid repositories. +// FIXME: the comment is from https://github.com/go-gitea/gitea/pull/17991 but it doesn't seem to be true. +// The real problem is that Golang's Cmd.Wait hangs because it waits for the pipes to be closed, but we can't close the pipes before Wait returns +// Need to refactor to use StdinPipe and StdoutPipe func ensureValidGitRepository(ctx context.Context, repoPath string) error { stderr := strings.Builder{} err := gitcmd.NewCommand("rev-parse"). @@ -40,56 +55,13 @@ func ensureValidGitRepository(ctx context.Context, repoPath string) error { return nil } -// catFileBatchCheck opens git cat-file --batch-check in the provided repo and returns a stdin pipe, a stdout reader and cancel function -func catFileBatchCheck(ctx context.Context, repoPath string) (WriteCloserError, *bufio.Reader, func()) { - batchStdinReader, batchStdinWriter := io.Pipe() - batchStdoutReader, batchStdoutWriter := io.Pipe() - ctx, ctxCancel := context.WithCancel(ctx) - closed := make(chan struct{}) - cancel := func() { - ctxCancel() - _ = batchStdoutReader.Close() - _ = batchStdinWriter.Close() - <-closed - } +// newCatFileBatch opens git cat-file --batch in the provided repo and returns a stdin pipe, a stdout reader and cancel function +func newCatFileBatch(ctx context.Context, repoPath string, cmdCatFile *gitcmd.Command) *catFileBatchCommunicator { + // We often want to feed the commits in order into cat-file --batch, followed by their trees and subtrees as necessary. - // Ensure cancel is called as soon as the provided context is cancelled - go func() { - <-ctx.Done() - cancel() - }() - - go func() { - stderr := strings.Builder{} - err := gitcmd.NewCommand("cat-file", "--batch-check"). - WithDir(repoPath). - WithStdin(batchStdinReader). - WithStdout(batchStdoutWriter). - WithStderr(&stderr). - WithUseContextTimeout(true). - Run(ctx) - if err != nil { - _ = batchStdoutWriter.CloseWithError(gitcmd.ConcatenateError(err, (&stderr).String())) - _ = batchStdinReader.CloseWithError(gitcmd.ConcatenateError(err, (&stderr).String())) - } else { - _ = batchStdoutWriter.Close() - _ = batchStdinReader.Close() - } - close(closed) - }() - - // For simplicities sake we'll use a buffered reader to read from the cat-file --batch-check - batchReader := bufio.NewReader(batchStdoutReader) - - return batchStdinWriter, batchReader, cancel -} - -// catFileBatch opens git cat-file --batch in the provided repo and returns a stdin pipe, a stdout reader and cancel function -func catFileBatch(ctx context.Context, repoPath string) (WriteCloserError, *bufio.Reader, func()) { - // We often want to feed the commits in order into cat-file --batch, followed by their trees and sub trees as necessary. // so let's create a batch stdin and stdout batchStdinReader, batchStdinWriter := io.Pipe() - batchStdoutReader, batchStdoutWriter := nio.Pipe(buffer.New(32 * 1024)) + batchStdoutReader, batchStdoutWriter := io.Pipe() ctx, ctxCancel := context.WithCancel(ctx) closed := make(chan struct{}) cancel := func() { @@ -107,7 +79,7 @@ func catFileBatch(ctx context.Context, repoPath string) (WriteCloserError, *bufi go func() { stderr := strings.Builder{} - err := gitcmd.NewCommand("cat-file", "--batch"). + err := cmdCatFile. WithDir(repoPath). WithStdin(batchStdinReader). WithStdout(batchStdoutWriter). @@ -124,16 +96,20 @@ func catFileBatch(ctx context.Context, repoPath string) (WriteCloserError, *bufi close(closed) }() - // For simplicities sake we'll us a buffered reader to read from the cat-file --batch + // use a buffered reader to read from the cat-file --batch (StringReader.ReadString) batchReader := bufio.NewReaderSize(batchStdoutReader, 32*1024) - return batchStdinWriter, batchReader, cancel + return &catFileBatchCommunicator{ + writer: batchStdinWriter, + reader: batchReader, + cancel: cancel, + } } // ReadBatchLine reads the header line from cat-file --batch // We expect: SP SP LF // then leaving the rest of the stream " LF" to be read -func ReadBatchLine(rd *bufio.Reader) (sha []byte, typ string, size int64, err error) { +func ReadBatchLine(rd BufferedReader) (sha []byte, typ string, size int64, err error) { typ, err = rd.ReadString('\n') if err != nil { return sha, typ, size, err @@ -165,7 +141,7 @@ func ReadBatchLine(rd *bufio.Reader) (sha []byte, typ string, size int64, err er } // ReadTagObjectID reads a tag object ID hash from a cat-file --batch stream, throwing away the rest of the stream. -func ReadTagObjectID(rd *bufio.Reader, size int64) (string, error) { +func ReadTagObjectID(rd BufferedReader, size int64) (string, error) { var id string var n int64 headerLoop: @@ -191,7 +167,7 @@ headerLoop: } // ReadTreeID reads a tree ID from a cat-file --batch stream, throwing away the rest of the stream. -func ReadTreeID(rd *bufio.Reader, size int64) (string, error) { +func ReadTreeID(rd BufferedReader, size int64) (string, error) { var id string var n int64 headerLoop: @@ -225,7 +201,7 @@ headerLoop: // constant hextable to help quickly convert between binary and hex representation const hextable = "0123456789abcdef" -// BinToHexHeash converts a binary Hash into a hex encoded one. Input and output can be the +// BinToHex converts a binary Hash into a hex encoded one. Input and output can be the // same byte slice to support in place conversion without allocations. // This is at least 100x quicker that hex.EncodeToString func BinToHex(objectFormat ObjectFormat, sha, out []byte) []byte { @@ -246,7 +222,7 @@ func BinToHex(objectFormat ObjectFormat, sha, out []byte) []byte { // SP NUL // // We don't attempt to convert the raw HASH to save a lot of time -func ParseCatFileTreeLine(objectFormat ObjectFormat, rd *bufio.Reader, modeBuf, fnameBuf, shaBuf []byte) (mode, fname, sha []byte, n int, err error) { +func ParseCatFileTreeLine(objectFormat ObjectFormat, rd BufferedReader, modeBuf, fnameBuf, shaBuf []byte) (mode, fname, sha []byte, n int, err error) { var readBytes []byte // Read the Mode & fname @@ -305,7 +281,7 @@ func ParseCatFileTreeLine(objectFormat ObjectFormat, rd *bufio.Reader, modeBuf, return mode, fname, sha, n, err } -func DiscardFull(rd *bufio.Reader, discard int64) error { +func DiscardFull(rd BufferedReader, discard int64) error { if discard > math.MaxInt32 { n, err := rd.Discard(math.MaxInt32) discard -= int64(n) diff --git a/modules/git/languagestats/language_stats_nogogit.go b/modules/git/languagestats/language_stats_nogogit.go index 94cf9fff8c129..33a3e3824c31a 100644 --- a/modules/git/languagestats/language_stats_nogogit.go +++ b/modules/git/languagestats/language_stats_nogogit.go @@ -22,18 +22,14 @@ import ( func GetLanguageStats(repo *git.Repository, commitID string) (map[string]int64, error) { // We will feed the commit IDs in order into cat-file --batch, followed by blobs as necessary. // so let's create a batch stdin and stdout - batchStdinWriter, batchReader, cancel, err := repo.CatFileBatch(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx) if err != nil { return nil, err } defer cancel() - writeID := func(id string) error { - _, err := batchStdinWriter.Write([]byte(id + "\n")) - return err - } - - if err := writeID(commitID); err != nil { + batchReader, err := batch.QueryContent(commitID) + if err != nil { return nil, err } shaBytes, typ, size, err := git.ReadBatchLine(batchReader) @@ -144,7 +140,7 @@ func GetLanguageStats(repo *git.Repository, commitID string) (map[string]int64, // If content can not be read or file is too big just do detection by filename if f.Size() <= bigFileSize { - if err := writeID(f.ID.String()); err != nil { + if _, err := batch.QueryContent(f.ID.String()); err != nil { return nil, err } _, _, size, err := git.ReadBatchLine(batchReader) diff --git a/modules/git/parse_nogogit.go b/modules/git/parse_nogogit.go index 78a016288986a..9ec9bee0fde35 100644 --- a/modules/git/parse_nogogit.go +++ b/modules/git/parse_nogogit.go @@ -6,7 +6,6 @@ package git import ( - "bufio" "bytes" "fmt" "io" @@ -49,7 +48,7 @@ func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) { return entries, nil } -func catBatchParseTreeEntries(objectFormat ObjectFormat, ptree *Tree, rd *bufio.Reader, sz int64) ([]*TreeEntry, error) { +func catBatchParseTreeEntries(objectFormat ObjectFormat, ptree *Tree, rd BufferedReader, sz int64) ([]*TreeEntry, error) { fnameBuf := make([]byte, 4096) modeBuf := make([]byte, 40) shaBuf := make([]byte, objectFormat.FullLength()) diff --git a/modules/git/pipeline/lfs_nogogit.go b/modules/git/pipeline/lfs_nogogit.go index 4881a2be64870..ee4ed1e3e9c83 100644 --- a/modules/git/pipeline/lfs_nogogit.go +++ b/modules/git/pipeline/lfs_nogogit.go @@ -47,7 +47,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err // Next feed the commits in order into cat-file --batch, followed by their trees and sub trees as necessary. // so let's create a batch stdin and stdout - batchStdinWriter, batchReader, cancel, err := repo.CatFileBatch(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx) if err != nil { return nil, err } @@ -64,14 +64,10 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err for scan.Scan() { // Get the next commit ID - commitID := scan.Bytes() + commitID := scan.Text() // push the commit to the cat-file --batch process - _, err := batchStdinWriter.Write(commitID) - if err != nil { - return nil, err - } - _, err = batchStdinWriter.Write([]byte{'\n'}) + batchReader, err := batch.QueryContent(commitID) if err != nil { return nil, err } @@ -93,14 +89,13 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err if err != nil { return nil, err } - _, err = batchStdinWriter.Write([]byte(id + "\n")) - if err != nil { + if _, err = batch.QueryContent(id); err != nil { return nil, err } continue case "commit": // Read in the commit to get its tree and in case this is one of the last used commits - curCommit, err = git.CommitFromReader(repo, git.MustIDFromString(string(commitID)), io.LimitReader(batchReader, size)) + curCommit, err = git.CommitFromReader(repo, git.MustIDFromString(commitID), io.LimitReader(batchReader, size)) if err != nil { return nil, err } @@ -108,7 +103,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err return nil, err } - if _, err := batchStdinWriter.Write([]byte(curCommit.Tree.ID.String() + "\n")); err != nil { + if _, err := batch.QueryContent(curCommit.Tree.ID.String()); err != nil { return nil, err } curPath = "" @@ -140,11 +135,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err return nil, err } if len(trees) > 0 { - _, err := batchStdinWriter.Write(trees[len(trees)-1]) - if err != nil { - return nil, err - } - _, err = batchStdinWriter.Write([]byte("\n")) + _, err := batch.QueryContent(string(trees[len(trees)-1])) if err != nil { return nil, err } diff --git a/modules/git/repo_base_nogogit.go b/modules/git/repo_base_nogogit.go index 4091e70846529..2021c3db32bf6 100644 --- a/modules/git/repo_base_nogogit.go +++ b/modules/git/repo_base_nogogit.go @@ -7,9 +7,9 @@ package git import ( - "bufio" "context" "path/filepath" + "sync" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/util" @@ -25,11 +25,9 @@ type Repository struct { gpgSettings *GPGSettings - batchInUse bool - batch *Batch - - checkInUse bool - check *Batch + mu sync.Mutex + catFileBatchCloser CatFileBatchCloser + catFileBatchInUse bool Ctx context.Context LastCommitCache *LastCommitCache @@ -58,69 +56,56 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) { }, nil } +// FIXME: for debugging purpose only +// At the moment, the old logic (debugTestAlwaysNewBatch=false: reuse the existing batch if not in use) +// causes random test failures: it makes the `t.Context()` occasionally canceled with unknown reasons. +// In theory, the `t.Context()` should never be affected by testing code and can never be canceled, but it does happen. +// The stranger thing is that the failure tests are almost around TestAPIPullUpdateByRebase, +// it almost are during MSSQL testing, sometimes PGSQL, never others. +var debugTestAlwaysNewBatch = false + // CatFileBatch obtains a CatFileBatch for this repository -func (repo *Repository) CatFileBatch(ctx context.Context) (WriteCloserError, *bufio.Reader, func(), error) { - if repo.batch == nil { - var err error - repo.batch, err = NewBatch(ctx, repo.Path) - if err != nil { - return nil, nil, nil, err - } - } +func (repo *Repository) CatFileBatch(ctx context.Context) (_ CatFileBatch, closeFunc func(), err error) { + repo.mu.Lock() + defer repo.mu.Unlock() - if !repo.batchInUse { - repo.batchInUse = true - return repo.batch.Writer, repo.batch.Reader, func() { - repo.batchInUse = false - }, nil + if debugTestAlwaysNewBatch { + b, err := NewBatch(ctx, repo.Path) + return b, b.Close, err } - log.Debug("Opening temporary cat file batch for: %s", repo.Path) - tempBatch, err := NewBatch(ctx, repo.Path) - if err != nil { - return nil, nil, nil, err - } - return tempBatch.Writer, tempBatch.Reader, tempBatch.Close, nil -} - -// CatFileBatchCheck obtains a CatFileBatchCheck for this repository -func (repo *Repository) CatFileBatchCheck(ctx context.Context) (WriteCloserError, *bufio.Reader, func(), error) { - if repo.check == nil { - var err error - repo.check, err = NewBatchCheck(ctx, repo.Path) + if repo.catFileBatchCloser == nil { + repo.catFileBatchCloser, err = NewBatch(ctx, repo.Path) if err != nil { - return nil, nil, nil, err + return nil, nil, err } } - if !repo.checkInUse { - repo.checkInUse = true - return repo.check.Writer, repo.check.Reader, func() { - repo.checkInUse = false + if !repo.catFileBatchInUse { + repo.catFileBatchInUse = true + return CatFileBatch(repo.catFileBatchCloser), func() { + repo.mu.Lock() + defer repo.mu.Unlock() + repo.catFileBatchInUse = false }, nil } - log.Debug("Opening temporary cat file batch-check for: %s", repo.Path) - tempBatchCheck, err := NewBatchCheck(ctx, repo.Path) + log.Debug("Opening temporary cat file batch for: %s", repo.Path) + tempBatch, err := NewBatch(ctx, repo.Path) if err != nil { - return nil, nil, nil, err + return nil, nil, err } - return tempBatchCheck.Writer, tempBatchCheck.Reader, tempBatchCheck.Close, nil + return tempBatch, tempBatch.Close, nil } func (repo *Repository) Close() error { if repo == nil { return nil } - if repo.batch != nil { - repo.batch.Close() - repo.batch = nil - repo.batchInUse = false - } - if repo.check != nil { - repo.check.Close() - repo.check = nil - repo.checkInUse = false + if repo.catFileBatchCloser != nil { + repo.catFileBatchCloser.Close() + repo.catFileBatchCloser = nil + repo.catFileBatchInUse = false } repo.LastCommitCache = nil repo.tagCache = nil diff --git a/modules/git/repo_branch_nogogit.go b/modules/git/repo_branch_nogogit.go index f1b26b06ab610..be8dc5bfa74d8 100644 --- a/modules/git/repo_branch_nogogit.go +++ b/modules/git/repo_branch_nogogit.go @@ -23,13 +23,13 @@ func (repo *Repository) IsObjectExist(name string) bool { return false } - wr, rd, cancel, err := repo.CatFileBatchCheck(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx) if err != nil { log.Debug("Error writing to CatFileBatchCheck %v", err) return false } defer cancel() - _, err = wr.Write([]byte(name + "\n")) + rd, err := batch.QueryInfo(name) if err != nil { log.Debug("Error writing to CatFileBatchCheck %v", err) return false @@ -44,13 +44,13 @@ func (repo *Repository) IsReferenceExist(name string) bool { return false } - wr, rd, cancel, err := repo.CatFileBatchCheck(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx) if err != nil { log.Debug("Error writing to CatFileBatchCheck %v", err) return false } defer cancel() - _, err = wr.Write([]byte(name + "\n")) + rd, err := batch.QueryInfo(name) if err != nil { log.Debug("Error writing to CatFileBatchCheck %v", err) return false diff --git a/modules/git/repo_commit_nogogit.go b/modules/git/repo_commit_nogogit.go index 3f27833fa6c62..9c94bdd0e275e 100644 --- a/modules/git/repo_commit_nogogit.go +++ b/modules/git/repo_commit_nogogit.go @@ -6,7 +6,6 @@ package git import ( - "bufio" "errors" "io" "strings" @@ -37,12 +36,12 @@ func (repo *Repository) ResolveReference(name string) (string, error) { // GetRefCommitID returns the last commit ID string of given reference (branch or tag). func (repo *Repository) GetRefCommitID(name string) (string, error) { - wr, rd, cancel, err := repo.CatFileBatchCheck(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx) if err != nil { return "", err } defer cancel() - _, err = wr.Write([]byte(name + "\n")) + rd, err := batch.QueryInfo(name) if err != nil { return "", err } @@ -68,18 +67,20 @@ func (repo *Repository) IsCommitExist(name string) bool { } func (repo *Repository) getCommit(id ObjectID) (*Commit, error) { - wr, rd, cancel, err := repo.CatFileBatch(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx) if err != nil { return nil, err } defer cancel() - _, _ = wr.Write([]byte(id.String() + "\n")) - - return repo.getCommitFromBatchReader(wr, rd, id) + rd, err := batch.QueryContent(id.String()) + if err != nil { + return nil, err + } + return repo.getCommitFromBatchReader(batch, rd, id) } -func (repo *Repository) getCommitFromBatchReader(wr WriteCloserError, rd *bufio.Reader, id ObjectID) (*Commit, error) { +func (repo *Repository) getCommitFromBatchReader(batchContent CatFileBatchContent, rd BufferedReader, id ObjectID) (*Commit, error) { _, typ, size, err := ReadBatchLine(rd) if err != nil { if errors.Is(err, io.EOF) || IsErrNotExist(err) { @@ -106,12 +107,10 @@ func (repo *Repository) getCommitFromBatchReader(wr WriteCloserError, rd *bufio. if err != nil { return nil, err } - - if _, err := wr.Write([]byte(tag.Object.String() + "\n")); err != nil { + if _, err := batchContent.QueryContent(tag.Object.String()); err != nil { return nil, err } - - commit, err := repo.getCommitFromBatchReader(wr, rd, tag.Object) + commit, err := repo.getCommitFromBatchReader(batchContent, rd, tag.Object) if err != nil { return nil, err } @@ -152,12 +151,12 @@ func (repo *Repository) ConvertToGitID(commitID string) (ObjectID, error) { } } - wr, rd, cancel, err := repo.CatFileBatchCheck(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx) if err != nil { return nil, err } defer cancel() - _, err = wr.Write([]byte(commitID + "\n")) + rd, err := batch.QueryInfo(commitID) if err != nil { return nil, err } diff --git a/modules/git/repo_tag_nogogit.go b/modules/git/repo_tag_nogogit.go index 5f79b68a9ae62..cb81e3434bf03 100644 --- a/modules/git/repo_tag_nogogit.go +++ b/modules/git/repo_tag_nogogit.go @@ -24,12 +24,12 @@ func (repo *Repository) IsTagExist(name string) bool { // GetTagType gets the type of the tag, either commit (simple) or tag (annotated) func (repo *Repository) GetTagType(id ObjectID) (string, error) { - wr, rd, cancel, err := repo.CatFileBatchCheck(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx) if err != nil { return "", err } defer cancel() - _, err = wr.Write([]byte(id.String() + "\n")) + rd, err := batch.QueryInfo(id.String()) if err != nil { return "", err } @@ -88,13 +88,14 @@ func (repo *Repository) getTag(tagID ObjectID, name string) (*Tag, error) { } // The tag is an annotated tag with a message. - wr, rd, cancel, err := repo.CatFileBatch(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx) if err != nil { return nil, err } defer cancel() - if _, err := wr.Write([]byte(tagID.String() + "\n")); err != nil { + rd, err := batch.QueryContent(tagID.String()) + if err != nil { return nil, err } _, typ, size, err := ReadBatchLine(rd) diff --git a/modules/git/repo_tree_nogogit.go b/modules/git/repo_tree_nogogit.go index 1954f8516219d..5501429498bef 100644 --- a/modules/git/repo_tree_nogogit.go +++ b/modules/git/repo_tree_nogogit.go @@ -10,13 +10,16 @@ import ( ) func (repo *Repository) getTree(id ObjectID) (*Tree, error) { - wr, rd, cancel, err := repo.CatFileBatch(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx) if err != nil { return nil, err } defer cancel() - _, _ = wr.Write([]byte(id.String() + "\n")) + rd, err := batch.QueryContent(id.String()) + if err != nil { + return nil, err + } // ignore the SHA _, typ, size, err := ReadBatchLine(rd) @@ -36,10 +39,10 @@ func (repo *Repository) getTree(id ObjectID) (*Tree, error) { return nil, err } - if _, err := wr.Write([]byte(tag.Object.String() + "\n")); err != nil { + if _, err := batch.QueryContent(tag.Object.String()); err != nil { return nil, err } - commit, err := repo.getCommitFromBatchReader(wr, rd, tag.Object) + commit, err := repo.getCommitFromBatchReader(batch, rd, tag.Object) if err != nil { return nil, err } diff --git a/modules/git/tree_entry_nogogit.go b/modules/git/tree_entry_nogogit.go index 8fad96cdf8924..4399b603add2a 100644 --- a/modules/git/tree_entry_nogogit.go +++ b/modules/git/tree_entry_nogogit.go @@ -36,13 +36,13 @@ func (te *TreeEntry) Size() int64 { return te.size } - wr, rd, cancel, err := te.ptree.repo.CatFileBatchCheck(te.ptree.repo.Ctx) + batch, cancel, err := te.ptree.repo.CatFileBatch(te.ptree.repo.Ctx) if err != nil { log.Debug("error whilst reading size for %s in %s. Error: %v", te.ID.String(), te.ptree.repo.Path, err) return 0 } defer cancel() - _, err = wr.Write([]byte(te.ID.String() + "\n")) + rd, err := batch.QueryInfo(te.ID.String()) if err != nil { log.Debug("error whilst reading size for %s in %s. Error: %v", te.ID.String(), te.ptree.repo.Path, err) return 0 diff --git a/modules/git/tree_nogogit.go b/modules/git/tree_nogogit.go index 956a5938f0f27..b4e1fcd796637 100644 --- a/modules/git/tree_nogogit.go +++ b/modules/git/tree_nogogit.go @@ -35,23 +35,33 @@ func (t *Tree) ListEntries() (Entries, error) { } if t.repo != nil { - wr, rd, cancel, err := t.repo.CatFileBatch(t.repo.Ctx) + batch, cancel, err := t.repo.CatFileBatch(t.repo.Ctx) if err != nil { return nil, err } defer cancel() - _, _ = wr.Write([]byte(t.ID.String() + "\n")) + rd, err := batch.QueryContent(t.ID.String()) + if err != nil { + return nil, err + } _, typ, sz, err := ReadBatchLine(rd) if err != nil { return nil, err } + if typ == "commit" { treeID, err := ReadTreeID(rd, sz) if err != nil && err != io.EOF { return nil, err } - _, _ = wr.Write([]byte(treeID + "\n")) + newRd, err := batch.QueryContent(treeID) + if err != nil { + return nil, err + } + if newRd != rd { + panic("abused batch reader") + } _, typ, sz, err = ReadBatchLine(rd) if err != nil { return nil, err diff --git a/modules/indexer/code/bleve/bleve.go b/modules/indexer/code/bleve/bleve.go index 0e2d0f879a5ea..10cbdae01ace0 100644 --- a/modules/indexer/code/bleve/bleve.go +++ b/modules/indexer/code/bleve/bleve.go @@ -4,7 +4,6 @@ package bleve import ( - "bufio" "context" "fmt" "io" @@ -151,7 +150,7 @@ func NewIndexer(indexDir string) *Indexer { } } -func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserError, batchReader *bufio.Reader, commitSha string, +func (b *Indexer) addUpdate(ctx context.Context, catFileBatch git.CatFileBatch, commitSha string, update internal.FileUpdate, repo *repo_model.Repository, batch *inner_bleve.FlushingBatch, ) error { // Ignore vendored files in code search @@ -177,7 +176,8 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro return b.addDelete(update.Filename, repo, batch) } - if _, err := batchWriter.Write([]byte(update.BlobSha + "\n")); err != nil { + batchReader, err := catFileBatch.QueryContent(update.BlobSha) + if err != nil { return err } @@ -225,11 +225,10 @@ func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha st defer gitBatch.Close() for _, update := range changes.Updates { - if err := b.addUpdate(ctx, gitBatch.Writer, gitBatch.Reader, sha, update, repo, batch); err != nil { + if err := b.addUpdate(ctx, gitBatch, sha, update, repo, batch); err != nil { return err } } - gitBatch.Close() } for _, filename := range changes.RemovedFilenames { if err := b.addDelete(filename, repo, batch); err != nil { diff --git a/modules/indexer/code/elasticsearch/elasticsearch.go b/modules/indexer/code/elasticsearch/elasticsearch.go index 012c57da291ab..cc9f1d0708dbb 100644 --- a/modules/indexer/code/elasticsearch/elasticsearch.go +++ b/modules/indexer/code/elasticsearch/elasticsearch.go @@ -4,7 +4,6 @@ package elasticsearch import ( - "bufio" "context" "fmt" "io" @@ -139,7 +138,7 @@ const ( }` ) -func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserError, batchReader *bufio.Reader, sha string, update internal.FileUpdate, repo *repo_model.Repository) ([]elastic.BulkableRequest, error) { +func (b *Indexer) addUpdate(ctx context.Context, catFileBatch git.CatFileBatch, sha string, update internal.FileUpdate, repo *repo_model.Repository) ([]elastic.BulkableRequest, error) { // Ignore vendored files in code search if setting.Indexer.ExcludeVendored && analyze.IsVendor(update.Filename) { return nil, nil @@ -162,7 +161,8 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro return []elastic.BulkableRequest{b.addDelete(update.Filename, repo)}, nil } - if _, err := batchWriter.Write([]byte(update.BlobSha + "\n")); err != nil { + batchReader, err := catFileBatch.QueryContent(update.BlobSha) + if err != nil { return nil, err } @@ -217,7 +217,7 @@ func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha st defer batch.Close() for _, update := range changes.Updates { - updateReqs, err := b.addUpdate(ctx, batch.Writer, batch.Reader, sha, update, repo) + updateReqs, err := b.addUpdate(ctx, batch, sha, update, repo) if err != nil { return err } @@ -225,7 +225,6 @@ func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha st reqs = append(reqs, updateReqs...) } } - batch.Close() } for _, filename := range changes.RemovedFilenames { diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index f3375e4898d33..0e60e11fa0984 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -150,9 +150,9 @@ func setCsvCompareContext(ctx *context.Context) { if err != nil { return nil, nil, err } - + var closer io.Closer = reader csvReader, err := csv_module.CreateReaderAndDetermineDelimiter(ctx, charset.ToUTF8WithFallbackReader(reader, charset.ConvertOpts{})) - return csvReader, reader, err + return csvReader, closer, err } baseReader, baseBlobCloser, err := csvReaderFromCommit(markup.NewRenderContext(ctx).WithRelativePath(diffFile.OldName), baseBlob) From a6861881400dfdd76f1c2651b4d182cc3828f96d Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Oct 2025 00:13:22 +0800 Subject: [PATCH 02/14] debug --- .github/workflows/pull-compliance.yml | 197 ----------------------- .github/workflows/pull-db-tests.yml | 141 ---------------- .github/workflows/pull-docker-dryrun.yml | 35 ---- modules/git/blob_nogogit.go | 4 +- modules/git/repo_base_nogogit.go | 5 +- modules/git/repo_branch_nogogit.go | 4 +- 6 files changed, 6 insertions(+), 380 deletions(-) delete mode 100644 .github/workflows/pull-compliance.yml delete mode 100644 .github/workflows/pull-docker-dryrun.yml diff --git a/.github/workflows/pull-compliance.yml b/.github/workflows/pull-compliance.yml deleted file mode 100644 index f73772e934293..0000000000000 --- a/.github/workflows/pull-compliance.yml +++ /dev/null @@ -1,197 +0,0 @@ -name: compliance - -on: - pull_request: - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - files-changed: - uses: ./.github/workflows/files-changed.yml - - lint-backend: - if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: actions/setup-go@v6 - with: - go-version-file: go.mod - check-latest: true - - run: make deps-backend deps-tools - - run: make lint-backend - env: - TAGS: bindata sqlite sqlite_unlock_notify - - lint-templates: - if: needs.files-changed.outputs.templates == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: astral-sh/setup-uv@v6 - - run: uv python install 3.12 - - uses: pnpm/action-setup@v4 - - uses: actions/setup-node@v5 - with: - node-version: 24 - - run: make deps-py - - run: make deps-frontend - - run: make lint-templates - - lint-yaml: - if: needs.files-changed.outputs.yaml == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: astral-sh/setup-uv@v6 - - run: uv python install 3.12 - - run: make deps-py - - run: make lint-yaml - - lint-swagger: - if: needs.files-changed.outputs.swagger == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: pnpm/action-setup@v4 - - uses: actions/setup-node@v5 - with: - node-version: 24 - - run: make deps-frontend - - run: make lint-swagger - - lint-spell: - if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.frontend == 'true' || needs.files-changed.outputs.actions == 'true' || needs.files-changed.outputs.docs == 'true' || needs.files-changed.outputs.templates == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: actions/setup-go@v6 - with: - go-version-file: go.mod - check-latest: true - - run: make lint-spell - - lint-go-windows: - if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: actions/setup-go@v6 - with: - go-version-file: go.mod - check-latest: true - - run: make deps-backend deps-tools - - run: make lint-go-windows lint-go-gitea-vet - env: - TAGS: bindata sqlite sqlite_unlock_notify - GOOS: windows - GOARCH: amd64 - - lint-go-gogit: - if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: actions/setup-go@v6 - with: - go-version-file: go.mod - check-latest: true - - run: make deps-backend deps-tools - - run: make lint-go - env: - TAGS: bindata gogit sqlite sqlite_unlock_notify - - checks-backend: - if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: actions/setup-go@v6 - with: - go-version-file: go.mod - check-latest: true - - run: make deps-backend deps-tools - - run: make --always-make checks-backend # ensure the "go-licenses" make target runs - - frontend: - if: needs.files-changed.outputs.frontend == 'true' || needs.files-changed.outputs.actions == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: pnpm/action-setup@v4 - - uses: actions/setup-node@v5 - with: - node-version: 24 - - run: make deps-frontend - - run: make lint-frontend - - run: make checks-frontend - - run: make test-frontend - - run: make frontend - - backend: - if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: actions/setup-go@v6 - with: - go-version-file: go.mod - check-latest: true - # no frontend build here as backend should be able to build - # even without any frontend files - - run: make deps-backend - - run: go build -o gitea_no_gcc # test if build succeeds without the sqlite tag - - name: build-backend-arm64 - run: make backend # test cross compile - env: - GOOS: linux - GOARCH: arm64 - TAGS: bindata gogit - - name: build-backend-windows - run: go build -o gitea_windows - env: - GOOS: windows - GOARCH: amd64 - TAGS: bindata gogit - - name: build-backend-386 - run: go build -o gitea_linux_386 # test if compatible with 32 bit - env: - GOOS: linux - GOARCH: 386 - - docs: - if: needs.files-changed.outputs.docs == 'true' || needs.files-changed.outputs.actions == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: pnpm/action-setup@v4 - - uses: actions/setup-node@v5 - with: - node-version: 24 - - run: make deps-frontend - - run: make lint-md - - actions: - if: needs.files-changed.outputs.actions == 'true' || needs.files-changed.outputs.actions == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: actions/setup-go@v6 - with: - go-version-file: go.mod - check-latest: true - - run: make lint-actions diff --git a/.github/workflows/pull-db-tests.yml b/.github/workflows/pull-db-tests.yml index 21ec76b48eae4..1819ad3ac6de4 100644 --- a/.github/workflows/pull-db-tests.yml +++ b/.github/workflows/pull-db-tests.yml @@ -49,8 +49,6 @@ jobs: - run: make backend env: TAGS: bindata - - name: run migration tests - run: make test-pgsql-migration - name: run tests run: make test-pgsql timeout-minutes: 50 @@ -61,144 +59,6 @@ jobs: TEST_LDAP: 1 USE_REPO_TEST_DIR: 1 - test-sqlite: - if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: actions/setup-go@v6 - with: - go-version-file: go.mod - check-latest: true - - run: make deps-backend - - run: GOEXPERIMENT='' make backend - env: - TAGS: bindata gogit sqlite sqlite_unlock_notify - - name: run migration tests - run: make test-sqlite-migration - - name: run tests - run: GOEXPERIMENT='' make test-sqlite - timeout-minutes: 50 - env: - TAGS: bindata gogit sqlite sqlite_unlock_notify - RACE_ENABLED: true - TEST_TAGS: gogit sqlite sqlite_unlock_notify - USE_REPO_TEST_DIR: 1 - - test-unit: - if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true' - needs: files-changed - runs-on: ubuntu-latest - services: - elasticsearch: - image: elasticsearch:7.5.0 - env: - discovery.type: single-node - ports: - - "9200:9200" - meilisearch: - image: getmeili/meilisearch:v1 - env: - MEILI_ENV: development # disable auth - ports: - - "7700:7700" - redis: - image: redis - options: >- # wait until redis has started - --health-cmd "redis-cli ping" - --health-interval 5s - --health-timeout 3s - --health-retries 10 - ports: - - 6379:6379 - minio: - image: bitnamilegacy/minio:2021.3.17 - env: - MINIO_ACCESS_KEY: 123456 - MINIO_SECRET_KEY: 12345678 - ports: - - "9000:9000" - devstoreaccount1.azurite.local: # https://github.com/Azure/Azurite/issues/1583 - image: mcr.microsoft.com/azure-storage/azurite:latest - ports: - - 10000:10000 - steps: - - uses: actions/checkout@v5 - - uses: actions/setup-go@v6 - with: - go-version-file: go.mod - check-latest: true - - name: Add hosts to /etc/hosts - run: '[ -e "/.dockerenv" ] || [ -e "/run/.containerenv" ] || echo "127.0.0.1 minio devstoreaccount1.azurite.local mysql elasticsearch meilisearch smtpimap" | sudo tee -a /etc/hosts' - - run: make deps-backend - - run: make backend - env: - TAGS: bindata - - name: unit-tests - run: make unit-test-coverage test-check - env: - TAGS: bindata - RACE_ENABLED: true - GITHUB_READ_TOKEN: ${{ secrets.GITHUB_READ_TOKEN }} - - name: unit-tests-gogit - run: GOEXPERIMENT='' make unit-test-coverage test-check - env: - TAGS: bindata gogit - RACE_ENABLED: true - GITHUB_READ_TOKEN: ${{ secrets.GITHUB_READ_TOKEN }} - - test-mysql: - if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true' - needs: files-changed - runs-on: ubuntu-latest - services: - mysql: - # the bitnami mysql image has more options than the official one, it's easier to customize - image: bitnamilegacy/mysql:8.0 - env: - ALLOW_EMPTY_PASSWORD: true - MYSQL_DATABASE: testgitea - ports: - - "3306:3306" - options: >- - --mount type=tmpfs,destination=/bitnami/mysql/data - elasticsearch: - image: elasticsearch:7.5.0 - env: - discovery.type: single-node - ports: - - "9200:9200" - smtpimap: - image: tabascoterrier/docker-imap-devel:latest - ports: - - "25:25" - - "143:143" - - "587:587" - - "993:993" - steps: - - uses: actions/checkout@v5 - - uses: actions/setup-go@v6 - with: - go-version-file: go.mod - check-latest: true - - name: Add hosts to /etc/hosts - run: '[ -e "/.dockerenv" ] || [ -e "/run/.containerenv" ] || echo "127.0.0.1 mysql elasticsearch smtpimap" | sudo tee -a /etc/hosts' - - run: make deps-backend - - run: make backend - env: - TAGS: bindata - - name: run migration tests - run: make test-mysql-migration - - name: run tests - # run: make integration-test-coverage (at the moment, no coverage is really handled) - run: make test-mysql - env: - TAGS: bindata - RACE_ENABLED: true - USE_REPO_TEST_DIR: 1 - TEST_INDEXER_CODE_ES_URL: "http://elastic:changeme@elasticsearch:9200" - test-mssql: if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true' needs: files-changed @@ -228,7 +88,6 @@ jobs: - run: make backend env: TAGS: bindata - - run: make test-mssql-migration - name: run tests run: make test-mssql timeout-minutes: 50 diff --git a/.github/workflows/pull-docker-dryrun.yml b/.github/workflows/pull-docker-dryrun.yml deleted file mode 100644 index f74277de671bf..0000000000000 --- a/.github/workflows/pull-docker-dryrun.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: docker-dryrun - -on: - pull_request: - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - files-changed: - uses: ./.github/workflows/files-changed.yml - - regular: - if: needs.files-changed.outputs.docker == 'true' || needs.files-changed.outputs.actions == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: docker/setup-buildx-action@v3 - - uses: docker/build-push-action@v5 - with: - push: false - tags: gitea/gitea:linux-amd64 - - rootless: - if: needs.files-changed.outputs.docker == 'true' || needs.files-changed.outputs.actions == 'true' - needs: files-changed - runs-on: ubuntu-latest - steps: - - uses: docker/setup-buildx-action@v3 - - uses: docker/build-push-action@v5 - with: - push: false - file: Dockerfile.rootless - tags: gitea/gitea:linux-amd64 diff --git a/modules/git/blob_nogogit.go b/modules/git/blob_nogogit.go index 07d857cb51de1..d26c169cdbf21 100644 --- a/modules/git/blob_nogogit.go +++ b/modules/git/blob_nogogit.go @@ -24,7 +24,7 @@ type Blob struct { // DataAsync gets a ReadCloser for the contents of a blob without reading it all. // Calling the Close function on the result will discard all unread output. func (b *Blob) DataAsync() (_ io.ReadCloser, retErr error) { - batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx) + batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx, true) if err != nil { return nil, err } @@ -57,7 +57,7 @@ func (b *Blob) Size() int64 { return b.size } - batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx) + batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx, true) if err != nil { log.Debug("error whilst reading size for %s in %s. Error: %v", b.ID.String(), b.repo.Path, err) return 0 diff --git a/modules/git/repo_base_nogogit.go b/modules/git/repo_base_nogogit.go index 2021c3db32bf6..10743e34ecd6f 100644 --- a/modules/git/repo_base_nogogit.go +++ b/modules/git/repo_base_nogogit.go @@ -62,14 +62,13 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) { // In theory, the `t.Context()` should never be affected by testing code and can never be canceled, but it does happen. // The stranger thing is that the failure tests are almost around TestAPIPullUpdateByRebase, // it almost are during MSSQL testing, sometimes PGSQL, never others. -var debugTestAlwaysNewBatch = false // CatFileBatch obtains a CatFileBatch for this repository -func (repo *Repository) CatFileBatch(ctx context.Context) (_ CatFileBatch, closeFunc func(), err error) { +func (repo *Repository) CatFileBatch(ctx context.Context, optAlwaysNewBatch ...bool) (_ CatFileBatch, closeFunc func(), err error) { repo.mu.Lock() defer repo.mu.Unlock() - if debugTestAlwaysNewBatch { + if util.OptionalArg(optAlwaysNewBatch) { b, err := NewBatch(ctx, repo.Path) return b, b.Close, err } diff --git a/modules/git/repo_branch_nogogit.go b/modules/git/repo_branch_nogogit.go index be8dc5bfa74d8..aeb1cae415761 100644 --- a/modules/git/repo_branch_nogogit.go +++ b/modules/git/repo_branch_nogogit.go @@ -23,7 +23,7 @@ func (repo *Repository) IsObjectExist(name string) bool { return false } - batch, cancel, err := repo.CatFileBatch(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) if err != nil { log.Debug("Error writing to CatFileBatchCheck %v", err) return false @@ -44,7 +44,7 @@ func (repo *Repository) IsReferenceExist(name string) bool { return false } - batch, cancel, err := repo.CatFileBatch(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) if err != nil { log.Debug("Error writing to CatFileBatchCheck %v", err) return false From 0aa7967488aa79ec86cee4b3f75bc4905ead89d5 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Oct 2025 00:35:49 +0800 Subject: [PATCH 03/14] debug --- modules/git/blob_nogogit.go | 4 ++-- modules/git/repo_branch_nogogit.go | 4 ++-- modules/git/repo_commit_nogogit.go | 6 +++--- modules/git/repo_tree_nogogit.go | 2 +- modules/git/tree_entry_nogogit.go | 2 +- modules/git/tree_nogogit.go | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/git/blob_nogogit.go b/modules/git/blob_nogogit.go index d26c169cdbf21..79acf8dfa8956 100644 --- a/modules/git/blob_nogogit.go +++ b/modules/git/blob_nogogit.go @@ -24,7 +24,7 @@ type Blob struct { // DataAsync gets a ReadCloser for the contents of a blob without reading it all. // Calling the Close function on the result will discard all unread output. func (b *Blob) DataAsync() (_ io.ReadCloser, retErr error) { - batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx, true) + batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx, true) // not related if err != nil { return nil, err } @@ -57,7 +57,7 @@ func (b *Blob) Size() int64 { return b.size } - batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx, true) + batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx, true) // not related if err != nil { log.Debug("error whilst reading size for %s in %s. Error: %v", b.ID.String(), b.repo.Path, err) return 0 diff --git a/modules/git/repo_branch_nogogit.go b/modules/git/repo_branch_nogogit.go index aeb1cae415761..aea0a6f955807 100644 --- a/modules/git/repo_branch_nogogit.go +++ b/modules/git/repo_branch_nogogit.go @@ -23,7 +23,7 @@ func (repo *Repository) IsObjectExist(name string) bool { return false } - batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) + batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) // not related if err != nil { log.Debug("Error writing to CatFileBatchCheck %v", err) return false @@ -44,7 +44,7 @@ func (repo *Repository) IsReferenceExist(name string) bool { return false } - batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) + batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) // not related if err != nil { log.Debug("Error writing to CatFileBatchCheck %v", err) return false diff --git a/modules/git/repo_commit_nogogit.go b/modules/git/repo_commit_nogogit.go index 9c94bdd0e275e..3d67e371d8c98 100644 --- a/modules/git/repo_commit_nogogit.go +++ b/modules/git/repo_commit_nogogit.go @@ -36,7 +36,7 @@ func (repo *Repository) ResolveReference(name string) (string, error) { // GetRefCommitID returns the last commit ID string of given reference (branch or tag). func (repo *Repository) GetRefCommitID(name string) (string, error) { - batch, cancel, err := repo.CatFileBatch(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) if err != nil { return "", err } @@ -67,7 +67,7 @@ func (repo *Repository) IsCommitExist(name string) bool { } func (repo *Repository) getCommit(id ObjectID) (*Commit, error) { - batch, cancel, err := repo.CatFileBatch(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) if err != nil { return nil, err } @@ -151,7 +151,7 @@ func (repo *Repository) ConvertToGitID(commitID string) (ObjectID, error) { } } - batch, cancel, err := repo.CatFileBatch(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) if err != nil { return nil, err } diff --git a/modules/git/repo_tree_nogogit.go b/modules/git/repo_tree_nogogit.go index 5501429498bef..13c471eca3f1f 100644 --- a/modules/git/repo_tree_nogogit.go +++ b/modules/git/repo_tree_nogogit.go @@ -10,7 +10,7 @@ import ( ) func (repo *Repository) getTree(id ObjectID) (*Tree, error) { - batch, cancel, err := repo.CatFileBatch(repo.Ctx) + batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) if err != nil { return nil, err } diff --git a/modules/git/tree_entry_nogogit.go b/modules/git/tree_entry_nogogit.go index 4399b603add2a..4e0720be8202d 100644 --- a/modules/git/tree_entry_nogogit.go +++ b/modules/git/tree_entry_nogogit.go @@ -36,7 +36,7 @@ func (te *TreeEntry) Size() int64 { return te.size } - batch, cancel, err := te.ptree.repo.CatFileBatch(te.ptree.repo.Ctx) + batch, cancel, err := te.ptree.repo.CatFileBatch(te.ptree.repo.Ctx, true) if err != nil { log.Debug("error whilst reading size for %s in %s. Error: %v", te.ID.String(), te.ptree.repo.Path, err) return 0 diff --git a/modules/git/tree_nogogit.go b/modules/git/tree_nogogit.go index b4e1fcd796637..3cf7decb1d47b 100644 --- a/modules/git/tree_nogogit.go +++ b/modules/git/tree_nogogit.go @@ -35,7 +35,7 @@ func (t *Tree) ListEntries() (Entries, error) { } if t.repo != nil { - batch, cancel, err := t.repo.CatFileBatch(t.repo.Ctx) + batch, cancel, err := t.repo.CatFileBatch(t.repo.Ctx, true) if err != nil { return nil, err } From c725e6d71c8f5019ce3b1c5119cf7ab51553e98a Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Oct 2025 01:34:34 +0800 Subject: [PATCH 04/14] test2 --- modules/git/repo_tree_nogogit.go | 2 +- modules/git/tree_entry_nogogit.go | 2 +- modules/git/tree_nogogit.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/git/repo_tree_nogogit.go b/modules/git/repo_tree_nogogit.go index 13c471eca3f1f..de078479861c0 100644 --- a/modules/git/repo_tree_nogogit.go +++ b/modules/git/repo_tree_nogogit.go @@ -10,7 +10,7 @@ import ( ) func (repo *Repository) getTree(id ObjectID) (*Tree, error) { - batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) + batch, cancel, err := repo.CatFileBatch(repo.Ctx, false) //test if err != nil { return nil, err } diff --git a/modules/git/tree_entry_nogogit.go b/modules/git/tree_entry_nogogit.go index 4e0720be8202d..c4cdb7d1570ca 100644 --- a/modules/git/tree_entry_nogogit.go +++ b/modules/git/tree_entry_nogogit.go @@ -36,7 +36,7 @@ func (te *TreeEntry) Size() int64 { return te.size } - batch, cancel, err := te.ptree.repo.CatFileBatch(te.ptree.repo.Ctx, true) + batch, cancel, err := te.ptree.repo.CatFileBatch(te.ptree.repo.Ctx, false) //test if err != nil { log.Debug("error whilst reading size for %s in %s. Error: %v", te.ID.String(), te.ptree.repo.Path, err) return 0 diff --git a/modules/git/tree_nogogit.go b/modules/git/tree_nogogit.go index 3cf7decb1d47b..6dbeba8bbc2a9 100644 --- a/modules/git/tree_nogogit.go +++ b/modules/git/tree_nogogit.go @@ -35,7 +35,7 @@ func (t *Tree) ListEntries() (Entries, error) { } if t.repo != nil { - batch, cancel, err := t.repo.CatFileBatch(t.repo.Ctx, true) + batch, cancel, err := t.repo.CatFileBatch(t.repo.Ctx, false) //test if err != nil { return nil, err } From 19abd3f3dc77ba4a1727c8f3453c922b10925b10 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Oct 2025 02:15:12 +0800 Subject: [PATCH 05/14] test --- modules/git/blob_nogogit.go | 4 ++-- modules/git/repo_branch_nogogit.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/git/blob_nogogit.go b/modules/git/blob_nogogit.go index 79acf8dfa8956..1cbe96d70bb87 100644 --- a/modules/git/blob_nogogit.go +++ b/modules/git/blob_nogogit.go @@ -24,7 +24,7 @@ type Blob struct { // DataAsync gets a ReadCloser for the contents of a blob without reading it all. // Calling the Close function on the result will discard all unread output. func (b *Blob) DataAsync() (_ io.ReadCloser, retErr error) { - batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx, true) // not related + batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx, false) // not related if err != nil { return nil, err } @@ -57,7 +57,7 @@ func (b *Blob) Size() int64 { return b.size } - batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx, true) // not related + batch, cancel, err := b.repo.CatFileBatch(b.repo.Ctx, false) // not related if err != nil { log.Debug("error whilst reading size for %s in %s. Error: %v", b.ID.String(), b.repo.Path, err) return 0 diff --git a/modules/git/repo_branch_nogogit.go b/modules/git/repo_branch_nogogit.go index aea0a6f955807..c909e4ad024a8 100644 --- a/modules/git/repo_branch_nogogit.go +++ b/modules/git/repo_branch_nogogit.go @@ -23,7 +23,7 @@ func (repo *Repository) IsObjectExist(name string) bool { return false } - batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) // not related + batch, cancel, err := repo.CatFileBatch(repo.Ctx, false) // not related if err != nil { log.Debug("Error writing to CatFileBatchCheck %v", err) return false @@ -44,7 +44,7 @@ func (repo *Repository) IsReferenceExist(name string) bool { return false } - batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) // not related + batch, cancel, err := repo.CatFileBatch(repo.Ctx, false) // not related if err != nil { log.Debug("Error writing to CatFileBatchCheck %v", err) return false From ab56250b9f504af2879c73f8a995c40a6c7ecc68 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Oct 2025 02:36:41 +0800 Subject: [PATCH 06/14] test --- .github/workflows/pull-db-tests.yml | 72 +++++++++++++++++++---------- modules/git/repo_commit_nogogit.go | 4 +- 2 files changed, 50 insertions(+), 26 deletions(-) diff --git a/.github/workflows/pull-db-tests.yml b/.github/workflows/pull-db-tests.yml index 1819ad3ac6de4..a57b94bda602e 100644 --- a/.github/workflows/pull-db-tests.yml +++ b/.github/workflows/pull-db-tests.yml @@ -11,32 +11,59 @@ jobs: files-changed: uses: ./.github/workflows/files-changed.yml - test-pgsql: + test-mssql1: if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true' needs: files-changed runs-on: ubuntu-latest services: - pgsql: - image: postgres:14 + mssql: + image: mcr.microsoft.com/mssql/server:2019-latest env: - POSTGRES_DB: test - POSTGRES_PASSWORD: postgres + ACCEPT_EULA: Y + MSSQL_PID: Standard + SA_PASSWORD: MwantsaSecurePassword1 ports: - - "5432:5432" - ldap: - image: gitea/test-openldap:latest + - "1433:1433" + devstoreaccount1.azurite.local: # https://github.com/Azure/Azurite/issues/1583 + image: mcr.microsoft.com/azure-storage/azurite:latest ports: - - "389:389" - - "636:636" - minio: - # as github actions doesn't support "entrypoint", we need to use a non-official image - # that has a custom entrypoint set to "minio server /data" - image: bitnamilegacy/minio:2023.8.31 + - 10000:10000 + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-go@v6 + with: + go-version-file: go.mod + check-latest: true + - name: Add hosts to /etc/hosts + run: '[ -e "/.dockerenv" ] || [ -e "/run/.containerenv" ] || echo "127.0.0.1 mssql devstoreaccount1.azurite.local" | sudo tee -a /etc/hosts' + - run: make deps-backend + - run: make backend env: - MINIO_ROOT_USER: 123456 - MINIO_ROOT_PASSWORD: 12345678 + TAGS: bindata + - name: run tests + run: make test-mssql + timeout-minutes: 50 + env: + TAGS: bindata + USE_REPO_TEST_DIR: 1 + + test-mssql2: + if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true' + needs: files-changed + runs-on: ubuntu-latest + services: + mssql: + image: mcr.microsoft.com/mssql/server:2019-latest + env: + ACCEPT_EULA: Y + MSSQL_PID: Standard + SA_PASSWORD: MwantsaSecurePassword1 ports: - - "9000:9000" + - "1433:1433" + devstoreaccount1.azurite.local: # https://github.com/Azure/Azurite/issues/1583 + image: mcr.microsoft.com/azure-storage/azurite:latest + ports: + - 10000:10000 steps: - uses: actions/checkout@v5 - uses: actions/setup-go@v6 @@ -44,22 +71,19 @@ jobs: go-version-file: go.mod check-latest: true - name: Add hosts to /etc/hosts - run: '[ -e "/.dockerenv" ] || [ -e "/run/.containerenv" ] || echo "127.0.0.1 pgsql ldap minio" | sudo tee -a /etc/hosts' + run: '[ -e "/.dockerenv" ] || [ -e "/run/.containerenv" ] || echo "127.0.0.1 mssql devstoreaccount1.azurite.local" | sudo tee -a /etc/hosts' - run: make deps-backend - run: make backend env: TAGS: bindata - name: run tests - run: make test-pgsql + run: make test-mssql timeout-minutes: 50 env: - TAGS: bindata gogit - RACE_ENABLED: true - TEST_TAGS: gogit - TEST_LDAP: 1 + TAGS: bindata USE_REPO_TEST_DIR: 1 - test-mssql: + test-mssql3: if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true' needs: files-changed runs-on: ubuntu-latest diff --git a/modules/git/repo_commit_nogogit.go b/modules/git/repo_commit_nogogit.go index 3d67e371d8c98..11e825122b781 100644 --- a/modules/git/repo_commit_nogogit.go +++ b/modules/git/repo_commit_nogogit.go @@ -36,7 +36,7 @@ func (repo *Repository) ResolveReference(name string) (string, error) { // GetRefCommitID returns the last commit ID string of given reference (branch or tag). func (repo *Repository) GetRefCommitID(name string) (string, error) { - batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) + batch, cancel, err := repo.CatFileBatch(repo.Ctx, false) // final test if err != nil { return "", err } @@ -151,7 +151,7 @@ func (repo *Repository) ConvertToGitID(commitID string) (ObjectID, error) { } } - batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) + batch, cancel, err := repo.CatFileBatch(repo.Ctx, false) // final test if err != nil { return nil, err } From 46fb5b1092b40e5053fdedbf7beb0b81ea1e68b9 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Oct 2025 02:55:19 +0800 Subject: [PATCH 07/14] test --- modules/git/repo_commit_nogogit.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/git/repo_commit_nogogit.go b/modules/git/repo_commit_nogogit.go index 11e825122b781..6b9026c1e6678 100644 --- a/modules/git/repo_commit_nogogit.go +++ b/modules/git/repo_commit_nogogit.go @@ -36,7 +36,7 @@ func (repo *Repository) ResolveReference(name string) (string, error) { // GetRefCommitID returns the last commit ID string of given reference (branch or tag). func (repo *Repository) GetRefCommitID(name string) (string, error) { - batch, cancel, err := repo.CatFileBatch(repo.Ctx, false) // final test + batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) if err != nil { return "", err } @@ -67,7 +67,7 @@ func (repo *Repository) IsCommitExist(name string) bool { } func (repo *Repository) getCommit(id ObjectID) (*Commit, error) { - batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) + batch, cancel, err := repo.CatFileBatch(repo.Ctx, false) // final test (not related?) if err != nil { return nil, err } From 533687cdf829d9ea4d55c4811dbcbe78f1e290f3 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Oct 2025 12:17:13 +0800 Subject: [PATCH 08/14] test --- modules/git/repo_base_nogogit.go | 7 ------- modules/git/repo_commit_nogogit.go | 2 +- tests/integration/repo_commits_test.go | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/modules/git/repo_base_nogogit.go b/modules/git/repo_base_nogogit.go index 10743e34ecd6f..b13cfd88f9bb2 100644 --- a/modules/git/repo_base_nogogit.go +++ b/modules/git/repo_base_nogogit.go @@ -9,7 +9,6 @@ package git import ( "context" "path/filepath" - "sync" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/util" @@ -25,7 +24,6 @@ type Repository struct { gpgSettings *GPGSettings - mu sync.Mutex catFileBatchCloser CatFileBatchCloser catFileBatchInUse bool @@ -65,9 +63,6 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) { // CatFileBatch obtains a CatFileBatch for this repository func (repo *Repository) CatFileBatch(ctx context.Context, optAlwaysNewBatch ...bool) (_ CatFileBatch, closeFunc func(), err error) { - repo.mu.Lock() - defer repo.mu.Unlock() - if util.OptionalArg(optAlwaysNewBatch) { b, err := NewBatch(ctx, repo.Path) return b, b.Close, err @@ -83,8 +78,6 @@ func (repo *Repository) CatFileBatch(ctx context.Context, optAlwaysNewBatch ...b if !repo.catFileBatchInUse { repo.catFileBatchInUse = true return CatFileBatch(repo.catFileBatchCloser), func() { - repo.mu.Lock() - defer repo.mu.Unlock() repo.catFileBatchInUse = false }, nil } diff --git a/modules/git/repo_commit_nogogit.go b/modules/git/repo_commit_nogogit.go index 6b9026c1e6678..a4088717dd82e 100644 --- a/modules/git/repo_commit_nogogit.go +++ b/modules/git/repo_commit_nogogit.go @@ -36,7 +36,7 @@ func (repo *Repository) ResolveReference(name string) (string, error) { // GetRefCommitID returns the last commit ID string of given reference (branch or tag). func (repo *Repository) GetRefCommitID(name string) (string, error) { - batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) + batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) // here is the real fatal point? if err != nil { return "", err } diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go index b8f086e2b15ce..43a1b9ff6ab8d 100644 --- a/tests/integration/repo_commits_test.go +++ b/tests/integration/repo_commits_test.go @@ -193,6 +193,7 @@ func TestRepoCommitsStatusParallel(t *testing.T) { wg.Add(1) go func(parentT *testing.T, i int) { parentT.Run(fmt.Sprintf("ParallelCreateStatus_%d", i), func(t *testing.T) { + defer wg.Done() ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository) runBody := doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{ State: commitstatus.CommitStatusPending, @@ -201,7 +202,6 @@ func TestRepoCommitsStatusParallel(t *testing.T) { Context: "testci", }) runBody(t) - wg.Done() }) }(t, i) } From e7e9a045a281a1f168cd4ea3cc86cb0edb07d2c3 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Oct 2025 13:25:47 +0800 Subject: [PATCH 09/14] test --- modules/git/repo_commit.go | 4 ++-- modules/git/repo_commit_nogogit.go | 21 ++++++++++++++++++++- modules/git/repo_commit_test.go | 2 +- modules/git/repo_compare_test.go | 4 ++-- modules/git/repo_tree_nogogit.go | 2 +- modules/indexer/code/gitgrep/gitgrep.go | 2 +- routers/api/v1/repo/pull.go | 2 +- routers/api/v1/repo/pull_review.go | 4 ++-- routers/web/repo/pull.go | 12 ++++++------ routers/web/repo/pull_review.go | 4 ++-- services/actions/notifier_helper.go | 2 +- services/agit/agit.go | 2 +- services/automerge/automerge.go | 2 +- services/automergequeue/automergequeue.go | 2 +- services/convert/pull.go | 6 +++--- services/migrations/gitea_uploader.go | 2 +- services/mirror/mirror_pull.go | 2 +- services/pull/commit_status.go | 2 +- services/pull/patch.go | 4 ++-- services/pull/pull.go | 6 +++--- services/pull/review.go | 4 ++-- services/repository/branch.go | 4 ++-- tests/integration/git_general_test.go | 4 ++-- tests/integration/git_misc_test.go | 2 +- tests/integration/pull_merge_test.go | 6 +++--- 25 files changed, 63 insertions(+), 44 deletions(-) diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index 5f4487ce7e24b..b4b3bd9fa45d2 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -18,12 +18,12 @@ import ( // GetBranchCommitID returns last commit ID string of given branch. func (repo *Repository) GetBranchCommitID(name string) (string, error) { - return repo.GetRefCommitID(BranchPrefix + name) + return repo.GetRefCommitIDOld(BranchPrefix + name) } // GetTagCommitID returns last commit ID string of given tag. func (repo *Repository) GetTagCommitID(name string) (string, error) { - return repo.GetRefCommitID(TagPrefix + name) + return repo.GetRefCommitIDOld(TagPrefix + name) } // GetCommit returns commit object of by ID string. diff --git a/modules/git/repo_commit_nogogit.go b/modules/git/repo_commit_nogogit.go index a4088717dd82e..0c471e09666c1 100644 --- a/modules/git/repo_commit_nogogit.go +++ b/modules/git/repo_commit_nogogit.go @@ -35,7 +35,26 @@ func (repo *Repository) ResolveReference(name string) (string, error) { } // GetRefCommitID returns the last commit ID string of given reference (branch or tag). -func (repo *Repository) GetRefCommitID(name string) (string, error) { +func (repo *Repository) GetRefCommitIDOld(name string) (string, error) { + batch, cancel, err := repo.CatFileBatch(repo.Ctx, false) // here is the real fatal point? + if err != nil { + return "", err + } + defer cancel() + rd, err := batch.QueryInfo(name) + if err != nil { + return "", err + } + shaBs, _, _, err := ReadBatchLine(rd) + if IsErrNotExist(err) { + return "", ErrNotExist{name, ""} + } + + return string(shaBs), nil +} + +// GetRefCommitID returns the last commit ID string of given reference (branch or tag). +func (repo *Repository) GetRefCommitIDNew(name string) (string, error) { batch, cancel, err := repo.CatFileBatch(repo.Ctx, true) // here is the real fatal point? if err != nil { return "", err diff --git a/modules/git/repo_commit_test.go b/modules/git/repo_commit_test.go index 3f7883ab14d6a..efe8eac53dba7 100644 --- a/modules/git/repo_commit_test.go +++ b/modules/git/repo_commit_test.go @@ -124,7 +124,7 @@ func TestGetRefCommitID(t *testing.T) { } for _, testCase := range testCases { - commitID, err := bareRepo1.GetRefCommitID(testCase.Ref) + commitID, err := bareRepo1.GetRefCommitIDNew(testCase.Ref) if assert.NoError(t, err) { assert.Equal(t, testCase.ExpectedCommitID, commitID) } diff --git a/modules/git/repo_compare_test.go b/modules/git/repo_compare_test.go index bf16b7cfceb61..86d259bd84c78 100644 --- a/modules/git/repo_compare_test.go +++ b/modules/git/repo_compare_test.go @@ -96,7 +96,7 @@ func TestReadWritePullHead(t *testing.T) { defer repo.Close() // Try to open non-existing Pull - _, err = repo.GetRefCommitID(PullPrefix + "0/head") + _, err = repo.GetRefCommitIDNew(PullPrefix + "0/head") assert.Error(t, err) // Write a fake sha1 with only 40 zeros @@ -111,7 +111,7 @@ func TestReadWritePullHead(t *testing.T) { } // Read the file created - headContents, err := repo.GetRefCommitID(PullPrefix + "1/head") + headContents, err := repo.GetRefCommitIDNew(PullPrefix + "1/head") if err != nil { assert.NoError(t, err) return diff --git a/modules/git/repo_tree_nogogit.go b/modules/git/repo_tree_nogogit.go index de078479861c0..f8e5da9ee78f2 100644 --- a/modules/git/repo_tree_nogogit.go +++ b/modules/git/repo_tree_nogogit.go @@ -88,7 +88,7 @@ func (repo *Repository) GetTree(idStr string) (*Tree, error) { return nil, err } if len(idStr) != objectFormat.FullLength() { - res, err := repo.GetRefCommitID(idStr) + res, err := repo.GetRefCommitIDOld(idStr) if err != nil { return nil, err } diff --git a/modules/indexer/code/gitgrep/gitgrep.go b/modules/indexer/code/gitgrep/gitgrep.go index 6f6e0b47b9e2e..0bc702d60f361 100644 --- a/modules/indexer/code/gitgrep/gitgrep.go +++ b/modules/indexer/code/gitgrep/gitgrep.go @@ -42,7 +42,7 @@ func PerformSearch(ctx context.Context, page int, repoID int64, gitRepo *git.Rep // TODO: if no branch exists, it reports: exit status 128, fatal: this operation must be run in a work tree. return nil, 0, fmt.Errorf("git.GrepSearch: %w", err) } - commitID, err := gitRepo.GetRefCommitID(ref.String()) + commitID, err := gitRepo.GetRefCommitIDOld(ref.String()) if err != nil { return nil, 0, fmt.Errorf("gitRepo.GetRefCommitID: %w", err) } diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 9305ad8c2d7b2..fd2c366d4a97e 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1567,7 +1567,7 @@ func GetPullRequestFiles(ctx *context.APIContext) { return } - headCommitID, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + headCommitID, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { ctx.APIErrorInternal(err) return diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go index 3c00193fac1d9..65719a7cd3ace 100644 --- a/routers/api/v1/repo/pull_review.go +++ b/routers/api/v1/repo/pull_review.go @@ -336,7 +336,7 @@ func CreatePullReview(ctx *context.APIContext) { } defer closer.Close() - headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + headCommitID, err := gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { ctx.APIErrorInternal(err) return @@ -455,7 +455,7 @@ func SubmitPullReview(ctx *context.APIContext) { return } - headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + headCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { ctx.APIErrorInternal(err) return diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 580339d2cb00b..a3952db4c3800 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -197,7 +197,7 @@ func GetPullDiffStats(ctx *context.Context) { } // do not report 500 server error to end users if error occurs, otherwise a PR missing ref won't be able to view. - headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pull.GetGitHeadRefName()) + headCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) if err != nil { log.Error("Failed to GetRefCommitID: %v, repo: %v", err, ctx.Repo.Repository.FullName()) return @@ -219,7 +219,7 @@ func GetMergedBaseCommitID(ctx *context.Context, issue *issues_model.Issue) stri if pull.MergeBase == "" { var commitSHA, parentCommit string // If there is a head or a patch file, and it is readable, grab info - commitSHA, err := ctx.Repo.GitRepo.GetRefCommitID(pull.GetGitHeadRefName()) + commitSHA, err := ctx.Repo.GitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) if err != nil { // Head File does not exist, try the patch commitSHA, err = ctx.Repo.GitRepo.ReadPatchCommit(pull.Index) @@ -364,7 +364,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_ ctx.Data["BaseTarget"] = pull.BaseBranch ctx.Data["HeadTarget"] = pull.HeadBranch - sha, err := baseGitRepo.GetRefCommitID(pull.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) if err != nil { ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitHeadRefName()), err) return nil @@ -422,7 +422,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_ if headBranchExist { if pull.Flow != issues_model.PullRequestFlowGithub { - headBranchSha, err = baseGitRepo.GetRefCommitID(pull.GetGitHeadRefName()) + headBranchSha, err = baseGitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) } else { headBranchSha, err = headGitRepo.GetBranchCommitID(pull.HeadBranch) } @@ -445,7 +445,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_ ctx.Data["GetCommitMessages"] = "" } - sha, err := baseGitRepo.GetRefCommitID(pull.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) if err != nil { if git.IsErrNotExist(err) { ctx.Data["IsPullRequestBroken"] = true @@ -702,7 +702,7 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) { return } - headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitHeadRefName()) + headCommitID, err := gitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) if err != nil { ctx.ServerError("GetRefCommitID", err) return diff --git a/routers/web/repo/pull_review.go b/routers/web/repo/pull_review.go index 18e14e9b224c4..f156bc4e27cb7 100644 --- a/routers/web/repo/pull_review.go +++ b/routers/web/repo/pull_review.go @@ -49,7 +49,7 @@ func RenderNewCodeCommentForm(ctx *context.Context) { ctx.Data["PageIsPullFiles"] = true ctx.Data["Issue"] = issue ctx.Data["CurrentReview"] = currentReview - pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(issue.PullRequest.GetGitHeadRefName()) + pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(issue.PullRequest.GetGitHeadRefName()) if err != nil { ctx.ServerError("GetRefCommitID", err) return @@ -199,7 +199,7 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment, ori ctx.ServerError("comment.Issue.LoadPullRequest", err) return } - pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(comment.Issue.PullRequest.GetGitHeadRefName()) + pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(comment.Issue.PullRequest.GetGitHeadRefName()) if err != nil { ctx.ServerError("GetRefCommitID", err) return diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index d17955b029081..5db83a4b61883 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -166,7 +166,7 @@ func notify(ctx context.Context, input *notifyInput) error { ref = git.RefNameFromBranch(input.Repo.DefaultBranch) } - commitID, err := gitRepo.GetRefCommitID(ref.String()) + commitID, err := gitRepo.GetRefCommitIDNew(ref.String()) if err != nil { return fmt.Errorf("gitRepo.GetRefCommitID: %w", err) } diff --git a/services/agit/agit.go b/services/agit/agit.go index 15fc2e8fb51f1..d2b138d3c3fce 100644 --- a/services/agit/agit.go +++ b/services/agit/agit.go @@ -213,7 +213,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. return nil, fmt.Errorf("unable to load base repository for PR[%d] Error: %w", pr.ID, err) } - oldCommitID, err := gitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + oldCommitID, err := gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { return nil, fmt.Errorf("unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err) } diff --git a/services/automerge/automerge.go b/services/automerge/automerge.go index f14911f880db8..64996688a4196 100644 --- a/services/automerge/automerge.go +++ b/services/automerge/automerge.go @@ -188,7 +188,7 @@ func handlePullRequestAutoMerge(pullID int64, sha string) { } defer baseGitRepo.Close() - headCommitID, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + headCommitID, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { log.Error("GetRefCommitID: %v", err) return diff --git a/services/automergequeue/automergequeue.go b/services/automergequeue/automergequeue.go index e8cc4512a7e21..3d22ecd570d57 100644 --- a/services/automergequeue/automergequeue.go +++ b/services/automergequeue/automergequeue.go @@ -40,7 +40,7 @@ func StartPRCheckAndAutoMerge(ctx context.Context, pull *issues_model.PullReques return } defer gitRepo.Close() - commitID, err := gitRepo.GetRefCommitID(pull.GetGitHeadRefName()) + commitID, err := gitRepo.GetRefCommitIDNew(pull.GetGitHeadRefName()) if err != nil { log.Error("GetRefCommitID: %v", err) return diff --git a/services/convert/pull.go b/services/convert/pull.go index 8b783d396aee8..dcd6e4faaede4 100644 --- a/services/convert/pull.go +++ b/services/convert/pull.go @@ -170,7 +170,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u } if pr.Flow == issues_model.PullRequestFlowAGit { - apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { log.Error("GetRefCommitID[%s]: %v", pr.GetGitHeadRefName(), err) return nil @@ -210,7 +210,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u ) if !exist { - headCommitID, err := headGitRepo.GetRefCommitID(apiPullRequest.Head.Ref) + headCommitID, err := headGitRepo.GetRefCommitIDNew(apiPullRequest.Head.Ref) if err != nil && !git.IsErrNotExist(err) { log.Error("GetCommit[%s]: %v", pr.HeadBranch, err) return nil @@ -450,7 +450,7 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs if pr.Flow == issues_model.PullRequestFlowAGit { apiPullRequest.Head.Name = "" } - apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { log.Error("GetRefCommitID[%s]: %v", pr.GetGitHeadRefName(), err) } diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index 4d23060661d9a..2417931b5690a 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -879,7 +879,7 @@ func (g *GiteaLocalUploader) CreateReviews(ctx context.Context, reviews ...*base continue } - headCommitID, err := g.gitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + headCommitID, err := g.gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { log.Warn("PR #%d GetRefCommitID[%s] in %s/%s: %v, all review comments will be ignored", pr.Index, pr.GetGitHeadRefName(), g.repoOwner, g.repoName, err) continue diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index da58bbd1b6d8f..6d21fa7a6a165 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -493,7 +493,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { // Create reference if result.oldCommitID == gitShortEmptySha { - commitID, err := gitRepo.GetRefCommitID(result.refName.String()) + commitID, err := gitRepo.GetRefCommitIDNew(result.refName.String()) if err != nil { log.Error("SyncMirrors [repo: %-v]: unable to GetRefCommitID [ref_name: %s]: %v", m.Repo, result.refName, err) continue diff --git a/services/pull/commit_status.go b/services/pull/commit_status.go index 25860fc1a8a2c..fab7644fbe900 100644 --- a/services/pull/commit_status.go +++ b/services/pull/commit_status.go @@ -111,7 +111,7 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullR if pr.Flow == issues_model.PullRequestFlowGithub { sha, err = headGitRepo.GetBranchCommitID(pr.HeadBranch) } else { - sha, err = headGitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + sha, err = headGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) } if err != nil { return "", err diff --git a/services/pull/patch.go b/services/pull/patch.go index d82fe3e2251cd..b0c140b1fe529 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -94,13 +94,13 @@ func testPullRequestTmpRepoBranchMergeable(ctx context.Context, prCtx *prTmpRepo pr.MergeBase, _, err = gitcmd.NewCommand("merge-base", "--", "base", "tracking").WithDir(prCtx.tmpBasePath).RunStdString(ctx) if err != nil { var err2 error - pr.MergeBase, err2 = gitRepo.GetRefCommitID(git.BranchPrefix + "base") + pr.MergeBase, err2 = gitRepo.GetRefCommitIDNew(git.BranchPrefix + "base") if err2 != nil { return fmt.Errorf("GetMergeBase: %v and can't find commit ID for base: %w", err, err2) } } pr.MergeBase = strings.TrimSpace(pr.MergeBase) - if pr.HeadCommitID, err = gitRepo.GetRefCommitID(git.BranchPrefix + "tracking"); err != nil { + if pr.HeadCommitID, err = gitRepo.GetRefCommitIDNew(git.BranchPrefix + "tracking"); err != nil { return fmt.Errorf("GetBranchCommitID: can't find commit ID for head: %w", err) } diff --git a/services/pull/pull.go b/services/pull/pull.go index a8468b5bf3446..02430d9e2b8e0 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -805,7 +805,7 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequ if pr.Flow == issues_model.PullRequestFlowGithub { headCommit, err = gitRepo.GetBranchCommit(pr.HeadBranch) } else { - pr.HeadCommitID, err = gitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + pr.HeadCommitID, err = gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { log.Error("Unable to get head commit: %s Error: %v", pr.GetGitHeadRefName(), err) return "" @@ -982,7 +982,7 @@ func GetIssuesAllCommitStatus(ctx context.Context, issues issues_model.IssueList // getAllCommitStatus get pr's commit statuses. func getAllCommitStatus(ctx context.Context, gitRepo *git.Repository, pr *issues_model.PullRequest) (statuses []*git_model.CommitStatus, lastStatus *git_model.CommitStatus, err error) { - sha, shaErr := gitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + sha, shaErr := gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if shaErr != nil { return nil, nil, shaErr } @@ -1032,7 +1032,7 @@ func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, br return false, err } } else { - pr.HeadCommitID, err = baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + pr.HeadCommitID, err = baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { return false, err } diff --git a/services/pull/review.go b/services/pull/review.go index 3977e351ca731..276b0c8a6f21e 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -259,7 +259,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo // Only fetch diff if comment is review comment if len(patch) == 0 && reviewID != 0 { - headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + headCommitID, err := gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { return nil, fmt.Errorf("GetRefCommitID[%s]: %w", pr.GetGitHeadRefName(), err) } @@ -325,7 +325,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos return nil, nil, ErrSubmitReviewOnClosedPR } - headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + headCommitID, err := gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { return nil, nil, err } diff --git a/services/repository/branch.go b/services/repository/branch.go index 0a2fd30620d22..35d4bde7e24f7 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -232,7 +232,7 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g defer baseGitRepo.Close() repoIDToGitRepo[pr.BaseRepoID] = baseGitRepo } - pullCommit, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + pullCommit, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil && !git.IsErrNotExist(err) { return nil, fmt.Errorf("GetBranchCommitID: %v", err) } @@ -807,7 +807,7 @@ func DeleteBranchAfterMerge(ctx context.Context, doer *user_model.User, prID int defer gitHeadCloser.Close() // Check if branch has no new commits - headCommitID, err := gitBaseRepo.GetRefCommitID(pr.GetGitHeadRefName()) + headCommitID, err := gitBaseRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { log.Error("GetRefCommitID: %v", err) return errFailedToDelete(err) diff --git a/tests/integration/git_general_test.go b/tests/integration/git_general_test.go index a726f0349f5cb..e3067c79f6bd0 100644 --- a/tests/integration/git_general_test.go +++ b/tests/integration/git_general_test.go @@ -844,7 +844,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string Message: "Testing commit 1", }) assert.NoError(t, err) - commit, err = gitRepo.GetRefCommitID("HEAD") + commit, err = gitRepo.GetRefCommitIDNew("HEAD") assert.NoError(t, err) }) @@ -916,7 +916,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string Message: "Testing commit 2", }) assert.NoError(t, err) - commit, err = gitRepo.GetRefCommitID("HEAD") + commit, err = gitRepo.GetRefCommitIDNew("HEAD") assert.NoError(t, err) }) diff --git a/tests/integration/git_misc_test.go b/tests/integration/git_misc_test.go index c830086e3fa11..ffc648f35c371 100644 --- a/tests/integration/git_misc_test.go +++ b/tests/integration/git_misc_test.go @@ -226,7 +226,7 @@ func TestAgitReviewStaleness(t *testing.T) { assert.NoError(t, err) defer baseGitRepo.Close() - updatedCommitID, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + updatedCommitID, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) assert.NoError(t, err) t.Logf("Updated commit ID: %s", updatedCommitID) diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go index 32ab7413829c7..9f69153aeaf6b 100644 --- a/tests/integration/pull_merge_test.go +++ b/tests/integration/pull_merge_test.go @@ -842,7 +842,7 @@ func TestPullAutoMergeAfterCommitStatusSucceed(t *testing.T) { // update commit status to success, then it should be merged automatically baseGitRepo, err := gitrepo.OpenRepository(t.Context(), baseRepo) assert.NoError(t, err) - sha, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) assert.NoError(t, err) masterCommitID, err := baseGitRepo.GetBranchCommitID("master") assert.NoError(t, err) @@ -924,7 +924,7 @@ func TestPullAutoMergeAfterCommitStatusSucceedAndApproval(t *testing.T) { // update commit status to success, then it should be merged automatically baseGitRepo, err := gitrepo.OpenRepository(t.Context(), baseRepo) assert.NoError(t, err) - sha, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) assert.NoError(t, err) masterCommitID, err := baseGitRepo.GetBranchCommitID("master") assert.NoError(t, err) @@ -1055,7 +1055,7 @@ func TestPullAutoMergeAfterCommitStatusSucceedAndApprovalForAgitFlow(t *testing. // update commit status to success, then it should be merged automatically baseGitRepo, err := gitrepo.OpenRepository(t.Context(), baseRepo) assert.NoError(t, err) - sha, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) assert.NoError(t, err) masterCommitID, err := baseGitRepo.GetBranchCommitID("master") assert.NoError(t, err) From b6a426dc7cf1c02f582da42f8a6b2fc323c377e0 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Oct 2025 14:06:16 +0800 Subject: [PATCH 10/14] test --- modules/git/repo_commit_test.go | 2 +- modules/git/repo_compare_test.go | 4 ++-- services/actions/notifier_helper.go | 2 +- services/agit/agit.go | 2 +- services/convert/pull.go | 6 +++--- services/migrations/gitea_uploader.go | 2 +- services/mirror/mirror_pull.go | 2 +- tests/integration/git_general_test.go | 4 ++-- tests/integration/git_misc_test.go | 2 +- tests/integration/pull_merge_test.go | 6 +++--- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/git/repo_commit_test.go b/modules/git/repo_commit_test.go index efe8eac53dba7..a47ae6d3b0d0f 100644 --- a/modules/git/repo_commit_test.go +++ b/modules/git/repo_commit_test.go @@ -124,7 +124,7 @@ func TestGetRefCommitID(t *testing.T) { } for _, testCase := range testCases { - commitID, err := bareRepo1.GetRefCommitIDNew(testCase.Ref) + commitID, err := bareRepo1.GetRefCommitIDOld(testCase.Ref) if assert.NoError(t, err) { assert.Equal(t, testCase.ExpectedCommitID, commitID) } diff --git a/modules/git/repo_compare_test.go b/modules/git/repo_compare_test.go index 86d259bd84c78..4dfc2fd4087b2 100644 --- a/modules/git/repo_compare_test.go +++ b/modules/git/repo_compare_test.go @@ -96,7 +96,7 @@ func TestReadWritePullHead(t *testing.T) { defer repo.Close() // Try to open non-existing Pull - _, err = repo.GetRefCommitIDNew(PullPrefix + "0/head") + _, err = repo.GetRefCommitIDOld(PullPrefix + "0/head") assert.Error(t, err) // Write a fake sha1 with only 40 zeros @@ -111,7 +111,7 @@ func TestReadWritePullHead(t *testing.T) { } // Read the file created - headContents, err := repo.GetRefCommitIDNew(PullPrefix + "1/head") + headContents, err := repo.GetRefCommitIDOld(PullPrefix + "1/head") if err != nil { assert.NoError(t, err) return diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 5db83a4b61883..d4dc475da62a9 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -166,7 +166,7 @@ func notify(ctx context.Context, input *notifyInput) error { ref = git.RefNameFromBranch(input.Repo.DefaultBranch) } - commitID, err := gitRepo.GetRefCommitIDNew(ref.String()) + commitID, err := gitRepo.GetRefCommitIDOld(ref.String()) if err != nil { return fmt.Errorf("gitRepo.GetRefCommitID: %w", err) } diff --git a/services/agit/agit.go b/services/agit/agit.go index d2b138d3c3fce..a96d30724a778 100644 --- a/services/agit/agit.go +++ b/services/agit/agit.go @@ -213,7 +213,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. return nil, fmt.Errorf("unable to load base repository for PR[%d] Error: %w", pr.ID, err) } - oldCommitID, err := gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + oldCommitID, err := gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { return nil, fmt.Errorf("unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err) } diff --git a/services/convert/pull.go b/services/convert/pull.go index dcd6e4faaede4..eb25173b520c7 100644 --- a/services/convert/pull.go +++ b/services/convert/pull.go @@ -170,7 +170,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u } if pr.Flow == issues_model.PullRequestFlowAGit { - apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { log.Error("GetRefCommitID[%s]: %v", pr.GetGitHeadRefName(), err) return nil @@ -210,7 +210,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u ) if !exist { - headCommitID, err := headGitRepo.GetRefCommitIDNew(apiPullRequest.Head.Ref) + headCommitID, err := headGitRepo.GetRefCommitIDOld(apiPullRequest.Head.Ref) if err != nil && !git.IsErrNotExist(err) { log.Error("GetCommit[%s]: %v", pr.HeadBranch, err) return nil @@ -450,7 +450,7 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs if pr.Flow == issues_model.PullRequestFlowAGit { apiPullRequest.Head.Name = "" } - apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { log.Error("GetRefCommitID[%s]: %v", pr.GetGitHeadRefName(), err) } diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index 2417931b5690a..06ea1dbd17567 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -879,7 +879,7 @@ func (g *GiteaLocalUploader) CreateReviews(ctx context.Context, reviews ...*base continue } - headCommitID, err := g.gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + headCommitID, err := g.gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { log.Warn("PR #%d GetRefCommitID[%s] in %s/%s: %v, all review comments will be ignored", pr.Index, pr.GetGitHeadRefName(), g.repoOwner, g.repoName, err) continue diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index 6d21fa7a6a165..734aa347420a9 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -493,7 +493,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { // Create reference if result.oldCommitID == gitShortEmptySha { - commitID, err := gitRepo.GetRefCommitIDNew(result.refName.String()) + commitID, err := gitRepo.GetRefCommitIDOld(result.refName.String()) if err != nil { log.Error("SyncMirrors [repo: %-v]: unable to GetRefCommitID [ref_name: %s]: %v", m.Repo, result.refName, err) continue diff --git a/tests/integration/git_general_test.go b/tests/integration/git_general_test.go index e3067c79f6bd0..5a6d992ec4c35 100644 --- a/tests/integration/git_general_test.go +++ b/tests/integration/git_general_test.go @@ -844,7 +844,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string Message: "Testing commit 1", }) assert.NoError(t, err) - commit, err = gitRepo.GetRefCommitIDNew("HEAD") + commit, err = gitRepo.GetRefCommitIDOld("HEAD") assert.NoError(t, err) }) @@ -916,7 +916,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string Message: "Testing commit 2", }) assert.NoError(t, err) - commit, err = gitRepo.GetRefCommitIDNew("HEAD") + commit, err = gitRepo.GetRefCommitIDOld("HEAD") assert.NoError(t, err) }) diff --git a/tests/integration/git_misc_test.go b/tests/integration/git_misc_test.go index ffc648f35c371..5beffcb7f497c 100644 --- a/tests/integration/git_misc_test.go +++ b/tests/integration/git_misc_test.go @@ -226,7 +226,7 @@ func TestAgitReviewStaleness(t *testing.T) { assert.NoError(t, err) defer baseGitRepo.Close() - updatedCommitID, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + updatedCommitID, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) assert.NoError(t, err) t.Logf("Updated commit ID: %s", updatedCommitID) diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go index 9f69153aeaf6b..feca5994db655 100644 --- a/tests/integration/pull_merge_test.go +++ b/tests/integration/pull_merge_test.go @@ -842,7 +842,7 @@ func TestPullAutoMergeAfterCommitStatusSucceed(t *testing.T) { // update commit status to success, then it should be merged automatically baseGitRepo, err := gitrepo.OpenRepository(t.Context(), baseRepo) assert.NoError(t, err) - sha, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) assert.NoError(t, err) masterCommitID, err := baseGitRepo.GetBranchCommitID("master") assert.NoError(t, err) @@ -924,7 +924,7 @@ func TestPullAutoMergeAfterCommitStatusSucceedAndApproval(t *testing.T) { // update commit status to success, then it should be merged automatically baseGitRepo, err := gitrepo.OpenRepository(t.Context(), baseRepo) assert.NoError(t, err) - sha, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) assert.NoError(t, err) masterCommitID, err := baseGitRepo.GetBranchCommitID("master") assert.NoError(t, err) @@ -1055,7 +1055,7 @@ func TestPullAutoMergeAfterCommitStatusSucceedAndApprovalForAgitFlow(t *testing. // update commit status to success, then it should be merged automatically baseGitRepo, err := gitrepo.OpenRepository(t.Context(), baseRepo) assert.NoError(t, err) - sha, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) assert.NoError(t, err) masterCommitID, err := baseGitRepo.GetBranchCommitID("master") assert.NoError(t, err) From 2bd187344962d8c03431c392178905a6ad40ac93 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Oct 2025 14:50:17 +0800 Subject: [PATCH 11/14] test --- .github/workflows/pull-db-tests.yml | 6 +++--- Makefile | 2 +- modules/git/repo_commit.go | 4 ++-- modules/git/repo_commit_test.go | 2 +- modules/git/repo_compare_test.go | 4 ++-- modules/git/repo_tree_nogogit.go | 2 +- modules/indexer/code/gitgrep/gitgrep.go | 2 +- routers/api/v1/repo/pull.go | 2 +- routers/api/v1/repo/pull_review.go | 4 ++-- routers/web/repo/pull.go | 12 ++++++------ routers/web/repo/pull_review.go | 4 ++-- services/actions/notifier_helper.go | 2 +- services/agit/agit.go | 2 +- services/automerge/automerge.go | 2 +- services/automergequeue/automergequeue.go | 2 +- services/convert/pull.go | 6 +++--- services/mailer/incoming/incoming_handler.go | 2 +- services/migrations/gitea_uploader.go | 2 +- services/mirror/mirror_pull.go | 2 +- services/pull/commit_status.go | 2 +- services/pull/patch.go | 4 ++-- services/pull/pull.go | 6 +++--- services/pull/review.go | 5 +++-- services/repository/branch.go | 6 +++--- tests/integration/git_general_test.go | 4 ++-- tests/integration/git_misc_test.go | 2 +- tests/integration/pull_merge_test.go | 6 +++--- 27 files changed, 50 insertions(+), 49 deletions(-) diff --git a/.github/workflows/pull-db-tests.yml b/.github/workflows/pull-db-tests.yml index a57b94bda602e..a67134b188488 100644 --- a/.github/workflows/pull-db-tests.yml +++ b/.github/workflows/pull-db-tests.yml @@ -41,7 +41,7 @@ jobs: env: TAGS: bindata - name: run tests - run: make test-mssql + run: TEST_LOGGER=console,test,file make test-mssql timeout-minutes: 50 env: TAGS: bindata @@ -77,7 +77,7 @@ jobs: env: TAGS: bindata - name: run tests - run: make test-mssql + run: TEST_LOGGER=console,test,file make test-mssql timeout-minutes: 50 env: TAGS: bindata @@ -109,7 +109,7 @@ jobs: - name: Add hosts to /etc/hosts run: '[ -e "/.dockerenv" ] || [ -e "/run/.containerenv" ] || echo "127.0.0.1 mssql devstoreaccount1.azurite.local" | sudo tee -a /etc/hosts' - run: make deps-backend - - run: make backend + - run: TEST_LOGGER=console,test,file make backend env: TAGS: bindata - name: run tests diff --git a/Makefile b/Makefile index 7531e56d83406..7c6fa8a6f611b 100644 --- a/Makefile +++ b/Makefile @@ -581,7 +581,7 @@ generate-ini-mssql: .PHONY: test-mssql test-mssql: integrations.mssql.test generate-ini-mssql - GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./integrations.mssql.test + GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./integrations.mssql.test -test.v .PHONY: test-mssql\#% test-mssql\#%: integrations.mssql.test generate-ini-mssql diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index b4b3bd9fa45d2..699c7de52f07c 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -18,12 +18,12 @@ import ( // GetBranchCommitID returns last commit ID string of given branch. func (repo *Repository) GetBranchCommitID(name string) (string, error) { - return repo.GetRefCommitIDOld(BranchPrefix + name) + return repo.GetRefCommitIDNew(BranchPrefix + name) } // GetTagCommitID returns last commit ID string of given tag. func (repo *Repository) GetTagCommitID(name string) (string, error) { - return repo.GetRefCommitIDOld(TagPrefix + name) + return repo.GetRefCommitIDNew(TagPrefix + name) } // GetCommit returns commit object of by ID string. diff --git a/modules/git/repo_commit_test.go b/modules/git/repo_commit_test.go index a47ae6d3b0d0f..efe8eac53dba7 100644 --- a/modules/git/repo_commit_test.go +++ b/modules/git/repo_commit_test.go @@ -124,7 +124,7 @@ func TestGetRefCommitID(t *testing.T) { } for _, testCase := range testCases { - commitID, err := bareRepo1.GetRefCommitIDOld(testCase.Ref) + commitID, err := bareRepo1.GetRefCommitIDNew(testCase.Ref) if assert.NoError(t, err) { assert.Equal(t, testCase.ExpectedCommitID, commitID) } diff --git a/modules/git/repo_compare_test.go b/modules/git/repo_compare_test.go index 4dfc2fd4087b2..86d259bd84c78 100644 --- a/modules/git/repo_compare_test.go +++ b/modules/git/repo_compare_test.go @@ -96,7 +96,7 @@ func TestReadWritePullHead(t *testing.T) { defer repo.Close() // Try to open non-existing Pull - _, err = repo.GetRefCommitIDOld(PullPrefix + "0/head") + _, err = repo.GetRefCommitIDNew(PullPrefix + "0/head") assert.Error(t, err) // Write a fake sha1 with only 40 zeros @@ -111,7 +111,7 @@ func TestReadWritePullHead(t *testing.T) { } // Read the file created - headContents, err := repo.GetRefCommitIDOld(PullPrefix + "1/head") + headContents, err := repo.GetRefCommitIDNew(PullPrefix + "1/head") if err != nil { assert.NoError(t, err) return diff --git a/modules/git/repo_tree_nogogit.go b/modules/git/repo_tree_nogogit.go index f8e5da9ee78f2..7a2bbbd04fc06 100644 --- a/modules/git/repo_tree_nogogit.go +++ b/modules/git/repo_tree_nogogit.go @@ -88,7 +88,7 @@ func (repo *Repository) GetTree(idStr string) (*Tree, error) { return nil, err } if len(idStr) != objectFormat.FullLength() { - res, err := repo.GetRefCommitIDOld(idStr) + res, err := repo.GetRefCommitIDNew(idStr) if err != nil { return nil, err } diff --git a/modules/indexer/code/gitgrep/gitgrep.go b/modules/indexer/code/gitgrep/gitgrep.go index 0bc702d60f361..f3d828f81a664 100644 --- a/modules/indexer/code/gitgrep/gitgrep.go +++ b/modules/indexer/code/gitgrep/gitgrep.go @@ -42,7 +42,7 @@ func PerformSearch(ctx context.Context, page int, repoID int64, gitRepo *git.Rep // TODO: if no branch exists, it reports: exit status 128, fatal: this operation must be run in a work tree. return nil, 0, fmt.Errorf("git.GrepSearch: %w", err) } - commitID, err := gitRepo.GetRefCommitIDOld(ref.String()) + commitID, err := gitRepo.GetRefCommitIDNew(ref.String()) if err != nil { return nil, 0, fmt.Errorf("gitRepo.GetRefCommitID: %w", err) } diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index fd2c366d4a97e..9fde653d2f60a 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1567,7 +1567,7 @@ func GetPullRequestFiles(ctx *context.APIContext) { return } - headCommitID, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) + headCommitID, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { ctx.APIErrorInternal(err) return diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go index 65719a7cd3ace..0f0bcf30e4c70 100644 --- a/routers/api/v1/repo/pull_review.go +++ b/routers/api/v1/repo/pull_review.go @@ -336,7 +336,7 @@ func CreatePullReview(ctx *context.APIContext) { } defer closer.Close() - headCommitID, err := gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) + headCommitID, err := gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { ctx.APIErrorInternal(err) return @@ -455,7 +455,7 @@ func SubmitPullReview(ctx *context.APIContext) { return } - headCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) + headCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { ctx.APIErrorInternal(err) return diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index a3952db4c3800..58e8b3b1f13a2 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -197,7 +197,7 @@ func GetPullDiffStats(ctx *context.Context) { } // do not report 500 server error to end users if error occurs, otherwise a PR missing ref won't be able to view. - headCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) + headCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDNew(pull.GetGitHeadRefName()) if err != nil { log.Error("Failed to GetRefCommitID: %v, repo: %v", err, ctx.Repo.Repository.FullName()) return @@ -219,7 +219,7 @@ func GetMergedBaseCommitID(ctx *context.Context, issue *issues_model.Issue) stri if pull.MergeBase == "" { var commitSHA, parentCommit string // If there is a head or a patch file, and it is readable, grab info - commitSHA, err := ctx.Repo.GitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) + commitSHA, err := ctx.Repo.GitRepo.GetRefCommitIDNew(pull.GetGitHeadRefName()) if err != nil { // Head File does not exist, try the patch commitSHA, err = ctx.Repo.GitRepo.ReadPatchCommit(pull.Index) @@ -364,7 +364,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_ ctx.Data["BaseTarget"] = pull.BaseBranch ctx.Data["HeadTarget"] = pull.HeadBranch - sha, err := baseGitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDNew(pull.GetGitHeadRefName()) if err != nil { ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitHeadRefName()), err) return nil @@ -422,7 +422,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_ if headBranchExist { if pull.Flow != issues_model.PullRequestFlowGithub { - headBranchSha, err = baseGitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) + headBranchSha, err = baseGitRepo.GetRefCommitIDNew(pull.GetGitHeadRefName()) } else { headBranchSha, err = headGitRepo.GetBranchCommitID(pull.HeadBranch) } @@ -445,7 +445,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_ ctx.Data["GetCommitMessages"] = "" } - sha, err := baseGitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDNew(pull.GetGitHeadRefName()) if err != nil { if git.IsErrNotExist(err) { ctx.Data["IsPullRequestBroken"] = true @@ -702,7 +702,7 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) { return } - headCommitID, err := gitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) + headCommitID, err := gitRepo.GetRefCommitIDNew(pull.GetGitHeadRefName()) if err != nil { ctx.ServerError("GetRefCommitID", err) return diff --git a/routers/web/repo/pull_review.go b/routers/web/repo/pull_review.go index f156bc4e27cb7..7ed6ef61b28aa 100644 --- a/routers/web/repo/pull_review.go +++ b/routers/web/repo/pull_review.go @@ -49,7 +49,7 @@ func RenderNewCodeCommentForm(ctx *context.Context) { ctx.Data["PageIsPullFiles"] = true ctx.Data["Issue"] = issue ctx.Data["CurrentReview"] = currentReview - pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(issue.PullRequest.GetGitHeadRefName()) + pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDNew(issue.PullRequest.GetGitHeadRefName()) if err != nil { ctx.ServerError("GetRefCommitID", err) return @@ -199,7 +199,7 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment, ori ctx.ServerError("comment.Issue.LoadPullRequest", err) return } - pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(comment.Issue.PullRequest.GetGitHeadRefName()) + pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDNew(comment.Issue.PullRequest.GetGitHeadRefName()) if err != nil { ctx.ServerError("GetRefCommitID", err) return diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index d4dc475da62a9..5db83a4b61883 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -166,7 +166,7 @@ func notify(ctx context.Context, input *notifyInput) error { ref = git.RefNameFromBranch(input.Repo.DefaultBranch) } - commitID, err := gitRepo.GetRefCommitIDOld(ref.String()) + commitID, err := gitRepo.GetRefCommitIDNew(ref.String()) if err != nil { return fmt.Errorf("gitRepo.GetRefCommitID: %w", err) } diff --git a/services/agit/agit.go b/services/agit/agit.go index a96d30724a778..d2b138d3c3fce 100644 --- a/services/agit/agit.go +++ b/services/agit/agit.go @@ -213,7 +213,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. return nil, fmt.Errorf("unable to load base repository for PR[%d] Error: %w", pr.ID, err) } - oldCommitID, err := gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) + oldCommitID, err := gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { return nil, fmt.Errorf("unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err) } diff --git a/services/automerge/automerge.go b/services/automerge/automerge.go index 64996688a4196..2a01aaf7b2e11 100644 --- a/services/automerge/automerge.go +++ b/services/automerge/automerge.go @@ -188,7 +188,7 @@ func handlePullRequestAutoMerge(pullID int64, sha string) { } defer baseGitRepo.Close() - headCommitID, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + headCommitID, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { log.Error("GetRefCommitID: %v", err) return diff --git a/services/automergequeue/automergequeue.go b/services/automergequeue/automergequeue.go index 3d22ecd570d57..3d0ec5d711434 100644 --- a/services/automergequeue/automergequeue.go +++ b/services/automergequeue/automergequeue.go @@ -40,7 +40,7 @@ func StartPRCheckAndAutoMerge(ctx context.Context, pull *issues_model.PullReques return } defer gitRepo.Close() - commitID, err := gitRepo.GetRefCommitIDNew(pull.GetGitHeadRefName()) + commitID, err := gitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) if err != nil { log.Error("GetRefCommitID: %v", err) return diff --git a/services/convert/pull.go b/services/convert/pull.go index eb25173b520c7..dcd6e4faaede4 100644 --- a/services/convert/pull.go +++ b/services/convert/pull.go @@ -170,7 +170,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u } if pr.Flow == issues_model.PullRequestFlowAGit { - apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) + apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { log.Error("GetRefCommitID[%s]: %v", pr.GetGitHeadRefName(), err) return nil @@ -210,7 +210,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u ) if !exist { - headCommitID, err := headGitRepo.GetRefCommitIDOld(apiPullRequest.Head.Ref) + headCommitID, err := headGitRepo.GetRefCommitIDNew(apiPullRequest.Head.Ref) if err != nil && !git.IsErrNotExist(err) { log.Error("GetCommit[%s]: %v", pr.HeadBranch, err) return nil @@ -450,7 +450,7 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs if pr.Flow == issues_model.PullRequestFlowAGit { apiPullRequest.Head.Name = "" } - apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) + apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { log.Error("GetRefCommitID[%s]: %v", pr.GetGitHeadRefName(), err) } diff --git a/services/mailer/incoming/incoming_handler.go b/services/mailer/incoming/incoming_handler.go index 440b3a6b59fca..00582065d8ac0 100644 --- a/services/mailer/incoming/incoming_handler.go +++ b/services/mailer/incoming/incoming_handler.go @@ -127,7 +127,7 @@ func (h *ReplyHandler) Handle(ctx context.Context, content *MailContent, doer *u _, err := pull_service.CreateCodeComment( ctx, doer, - nil, + nil, // FIXME: INCOMING-MAIL-GIT-REPO: it doesn't seem right to use nil for git repo issue, comment.Line, content.Content, diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index 06ea1dbd17567..2417931b5690a 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -879,7 +879,7 @@ func (g *GiteaLocalUploader) CreateReviews(ctx context.Context, reviews ...*base continue } - headCommitID, err := g.gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) + headCommitID, err := g.gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) if err != nil { log.Warn("PR #%d GetRefCommitID[%s] in %s/%s: %v, all review comments will be ignored", pr.Index, pr.GetGitHeadRefName(), g.repoOwner, g.repoName, err) continue diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index 734aa347420a9..6d21fa7a6a165 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -493,7 +493,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { // Create reference if result.oldCommitID == gitShortEmptySha { - commitID, err := gitRepo.GetRefCommitIDOld(result.refName.String()) + commitID, err := gitRepo.GetRefCommitIDNew(result.refName.String()) if err != nil { log.Error("SyncMirrors [repo: %-v]: unable to GetRefCommitID [ref_name: %s]: %v", m.Repo, result.refName, err) continue diff --git a/services/pull/commit_status.go b/services/pull/commit_status.go index fab7644fbe900..350b480c9a884 100644 --- a/services/pull/commit_status.go +++ b/services/pull/commit_status.go @@ -111,7 +111,7 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullR if pr.Flow == issues_model.PullRequestFlowGithub { sha, err = headGitRepo.GetBranchCommitID(pr.HeadBranch) } else { - sha, err = headGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + sha, err = headGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) } if err != nil { return "", err diff --git a/services/pull/patch.go b/services/pull/patch.go index b0c140b1fe529..8507299df7fd9 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -94,13 +94,13 @@ func testPullRequestTmpRepoBranchMergeable(ctx context.Context, prCtx *prTmpRepo pr.MergeBase, _, err = gitcmd.NewCommand("merge-base", "--", "base", "tracking").WithDir(prCtx.tmpBasePath).RunStdString(ctx) if err != nil { var err2 error - pr.MergeBase, err2 = gitRepo.GetRefCommitIDNew(git.BranchPrefix + "base") + pr.MergeBase, err2 = gitRepo.GetRefCommitIDOld(git.BranchPrefix + "base") if err2 != nil { return fmt.Errorf("GetMergeBase: %v and can't find commit ID for base: %w", err, err2) } } pr.MergeBase = strings.TrimSpace(pr.MergeBase) - if pr.HeadCommitID, err = gitRepo.GetRefCommitIDNew(git.BranchPrefix + "tracking"); err != nil { + if pr.HeadCommitID, err = gitRepo.GetRefCommitIDOld(git.BranchPrefix + "tracking"); err != nil { return fmt.Errorf("GetBranchCommitID: can't find commit ID for head: %w", err) } diff --git a/services/pull/pull.go b/services/pull/pull.go index 02430d9e2b8e0..661ade113ce65 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -805,7 +805,7 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequ if pr.Flow == issues_model.PullRequestFlowGithub { headCommit, err = gitRepo.GetBranchCommit(pr.HeadBranch) } else { - pr.HeadCommitID, err = gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + pr.HeadCommitID, err = gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { log.Error("Unable to get head commit: %s Error: %v", pr.GetGitHeadRefName(), err) return "" @@ -982,7 +982,7 @@ func GetIssuesAllCommitStatus(ctx context.Context, issues issues_model.IssueList // getAllCommitStatus get pr's commit statuses. func getAllCommitStatus(ctx context.Context, gitRepo *git.Repository, pr *issues_model.PullRequest) (statuses []*git_model.CommitStatus, lastStatus *git_model.CommitStatus, err error) { - sha, shaErr := gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + sha, shaErr := gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if shaErr != nil { return nil, nil, shaErr } @@ -1032,7 +1032,7 @@ func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, br return false, err } } else { - pr.HeadCommitID, err = baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + pr.HeadCommitID, err = baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { return false, err } diff --git a/services/pull/review.go b/services/pull/review.go index 276b0c8a6f21e..8083b2d0a4624 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -259,7 +259,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo // Only fetch diff if comment is review comment if len(patch) == 0 && reviewID != 0 { - headCommitID, err := gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + headCommitID, err := gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { return nil, fmt.Errorf("GetRefCommitID[%s]: %w", pr.GetGitHeadRefName(), err) } @@ -325,7 +325,8 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos return nil, nil, ErrSubmitReviewOnClosedPR } - headCommitID, err := gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + // FIXME: INCOMING-MAIL-GIT-REPO: the gitRepo can be nil when it is from incoming mail + headCommitID, err := gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { return nil, nil, err } diff --git a/services/repository/branch.go b/services/repository/branch.go index 35d4bde7e24f7..092a7e0b71442 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -230,9 +230,9 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g return nil, fmt.Errorf("OpenRepository: %v", err) } defer baseGitRepo.Close() - repoIDToGitRepo[pr.BaseRepoID] = baseGitRepo + repoIDToGitRepo[pr.BaseRepoID] = baseGitRepo // FIXME: it's not right to update the caller's map and inserted a closed git repo into it } - pullCommit, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + pullCommit, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil && !git.IsErrNotExist(err) { return nil, fmt.Errorf("GetBranchCommitID: %v", err) } @@ -807,7 +807,7 @@ func DeleteBranchAfterMerge(ctx context.Context, doer *user_model.User, prID int defer gitHeadCloser.Close() // Check if branch has no new commits - headCommitID, err := gitBaseRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + headCommitID, err := gitBaseRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { log.Error("GetRefCommitID: %v", err) return errFailedToDelete(err) diff --git a/tests/integration/git_general_test.go b/tests/integration/git_general_test.go index 5a6d992ec4c35..e3067c79f6bd0 100644 --- a/tests/integration/git_general_test.go +++ b/tests/integration/git_general_test.go @@ -844,7 +844,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string Message: "Testing commit 1", }) assert.NoError(t, err) - commit, err = gitRepo.GetRefCommitIDOld("HEAD") + commit, err = gitRepo.GetRefCommitIDNew("HEAD") assert.NoError(t, err) }) @@ -916,7 +916,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string Message: "Testing commit 2", }) assert.NoError(t, err) - commit, err = gitRepo.GetRefCommitIDOld("HEAD") + commit, err = gitRepo.GetRefCommitIDNew("HEAD") assert.NoError(t, err) }) diff --git a/tests/integration/git_misc_test.go b/tests/integration/git_misc_test.go index 5beffcb7f497c..ffc648f35c371 100644 --- a/tests/integration/git_misc_test.go +++ b/tests/integration/git_misc_test.go @@ -226,7 +226,7 @@ func TestAgitReviewStaleness(t *testing.T) { assert.NoError(t, err) defer baseGitRepo.Close() - updatedCommitID, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) + updatedCommitID, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) assert.NoError(t, err) t.Logf("Updated commit ID: %s", updatedCommitID) diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go index feca5994db655..9f69153aeaf6b 100644 --- a/tests/integration/pull_merge_test.go +++ b/tests/integration/pull_merge_test.go @@ -842,7 +842,7 @@ func TestPullAutoMergeAfterCommitStatusSucceed(t *testing.T) { // update commit status to success, then it should be merged automatically baseGitRepo, err := gitrepo.OpenRepository(t.Context(), baseRepo) assert.NoError(t, err) - sha, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) assert.NoError(t, err) masterCommitID, err := baseGitRepo.GetBranchCommitID("master") assert.NoError(t, err) @@ -924,7 +924,7 @@ func TestPullAutoMergeAfterCommitStatusSucceedAndApproval(t *testing.T) { // update commit status to success, then it should be merged automatically baseGitRepo, err := gitrepo.OpenRepository(t.Context(), baseRepo) assert.NoError(t, err) - sha, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) assert.NoError(t, err) masterCommitID, err := baseGitRepo.GetBranchCommitID("master") assert.NoError(t, err) @@ -1055,7 +1055,7 @@ func TestPullAutoMergeAfterCommitStatusSucceedAndApprovalForAgitFlow(t *testing. // update commit status to success, then it should be merged automatically baseGitRepo, err := gitrepo.OpenRepository(t.Context(), baseRepo) assert.NoError(t, err) - sha, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) assert.NoError(t, err) masterCommitID, err := baseGitRepo.GetBranchCommitID("master") assert.NoError(t, err) From 6394d981844a44812949b2635dc3c72b23f59926 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Oct 2025 17:41:54 +0800 Subject: [PATCH 12/14] test --- modules/git/repo_commit_test.go | 2 +- modules/git/repo_compare_test.go | 4 ++-- tests/integration/git_general_test.go | 4 ++-- tests/integration/git_misc_test.go | 2 +- tests/integration/pull_merge_test.go | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/git/repo_commit_test.go b/modules/git/repo_commit_test.go index efe8eac53dba7..a47ae6d3b0d0f 100644 --- a/modules/git/repo_commit_test.go +++ b/modules/git/repo_commit_test.go @@ -124,7 +124,7 @@ func TestGetRefCommitID(t *testing.T) { } for _, testCase := range testCases { - commitID, err := bareRepo1.GetRefCommitIDNew(testCase.Ref) + commitID, err := bareRepo1.GetRefCommitIDOld(testCase.Ref) if assert.NoError(t, err) { assert.Equal(t, testCase.ExpectedCommitID, commitID) } diff --git a/modules/git/repo_compare_test.go b/modules/git/repo_compare_test.go index 86d259bd84c78..4dfc2fd4087b2 100644 --- a/modules/git/repo_compare_test.go +++ b/modules/git/repo_compare_test.go @@ -96,7 +96,7 @@ func TestReadWritePullHead(t *testing.T) { defer repo.Close() // Try to open non-existing Pull - _, err = repo.GetRefCommitIDNew(PullPrefix + "0/head") + _, err = repo.GetRefCommitIDOld(PullPrefix + "0/head") assert.Error(t, err) // Write a fake sha1 with only 40 zeros @@ -111,7 +111,7 @@ func TestReadWritePullHead(t *testing.T) { } // Read the file created - headContents, err := repo.GetRefCommitIDNew(PullPrefix + "1/head") + headContents, err := repo.GetRefCommitIDOld(PullPrefix + "1/head") if err != nil { assert.NoError(t, err) return diff --git a/tests/integration/git_general_test.go b/tests/integration/git_general_test.go index e3067c79f6bd0..5a6d992ec4c35 100644 --- a/tests/integration/git_general_test.go +++ b/tests/integration/git_general_test.go @@ -844,7 +844,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string Message: "Testing commit 1", }) assert.NoError(t, err) - commit, err = gitRepo.GetRefCommitIDNew("HEAD") + commit, err = gitRepo.GetRefCommitIDOld("HEAD") assert.NoError(t, err) }) @@ -916,7 +916,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string Message: "Testing commit 2", }) assert.NoError(t, err) - commit, err = gitRepo.GetRefCommitIDNew("HEAD") + commit, err = gitRepo.GetRefCommitIDOld("HEAD") assert.NoError(t, err) }) diff --git a/tests/integration/git_misc_test.go b/tests/integration/git_misc_test.go index ffc648f35c371..5beffcb7f497c 100644 --- a/tests/integration/git_misc_test.go +++ b/tests/integration/git_misc_test.go @@ -226,7 +226,7 @@ func TestAgitReviewStaleness(t *testing.T) { assert.NoError(t, err) defer baseGitRepo.Close() - updatedCommitID, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + updatedCommitID, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) assert.NoError(t, err) t.Logf("Updated commit ID: %s", updatedCommitID) diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go index 9f69153aeaf6b..feca5994db655 100644 --- a/tests/integration/pull_merge_test.go +++ b/tests/integration/pull_merge_test.go @@ -842,7 +842,7 @@ func TestPullAutoMergeAfterCommitStatusSucceed(t *testing.T) { // update commit status to success, then it should be merged automatically baseGitRepo, err := gitrepo.OpenRepository(t.Context(), baseRepo) assert.NoError(t, err) - sha, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) assert.NoError(t, err) masterCommitID, err := baseGitRepo.GetBranchCommitID("master") assert.NoError(t, err) @@ -924,7 +924,7 @@ func TestPullAutoMergeAfterCommitStatusSucceedAndApproval(t *testing.T) { // update commit status to success, then it should be merged automatically baseGitRepo, err := gitrepo.OpenRepository(t.Context(), baseRepo) assert.NoError(t, err) - sha, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) assert.NoError(t, err) masterCommitID, err := baseGitRepo.GetBranchCommitID("master") assert.NoError(t, err) @@ -1055,7 +1055,7 @@ func TestPullAutoMergeAfterCommitStatusSucceedAndApprovalForAgitFlow(t *testing. // update commit status to success, then it should be merged automatically baseGitRepo, err := gitrepo.OpenRepository(t.Context(), baseRepo) assert.NoError(t, err) - sha, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) assert.NoError(t, err) masterCommitID, err := baseGitRepo.GetBranchCommitID("master") assert.NoError(t, err) From 672eb104b9e4bd9657949c718a5adb78af3755bf Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Oct 2025 18:29:53 +0800 Subject: [PATCH 13/14] test temp --- services/agit/agit.go | 2 +- services/convert/pull.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/agit/agit.go b/services/agit/agit.go index d2b138d3c3fce..a96d30724a778 100644 --- a/services/agit/agit.go +++ b/services/agit/agit.go @@ -213,7 +213,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. return nil, fmt.Errorf("unable to load base repository for PR[%d] Error: %w", pr.ID, err) } - oldCommitID, err := gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + oldCommitID, err := gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { return nil, fmt.Errorf("unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err) } diff --git a/services/convert/pull.go b/services/convert/pull.go index dcd6e4faaede4..eb25173b520c7 100644 --- a/services/convert/pull.go +++ b/services/convert/pull.go @@ -170,7 +170,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u } if pr.Flow == issues_model.PullRequestFlowAGit { - apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { log.Error("GetRefCommitID[%s]: %v", pr.GetGitHeadRefName(), err) return nil @@ -210,7 +210,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u ) if !exist { - headCommitID, err := headGitRepo.GetRefCommitIDNew(apiPullRequest.Head.Ref) + headCommitID, err := headGitRepo.GetRefCommitIDOld(apiPullRequest.Head.Ref) if err != nil && !git.IsErrNotExist(err) { log.Error("GetCommit[%s]: %v", pr.HeadBranch, err) return nil @@ -450,7 +450,7 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs if pr.Flow == issues_model.PullRequestFlowAGit { apiPullRequest.Head.Name = "" } - apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + apiPullRequest.Head.Sha, err = gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { log.Error("GetRefCommitID[%s]: %v", pr.GetGitHeadRefName(), err) } From b82d7480be6e4c48196cf6431836cadf30f40958 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 30 Oct 2025 19:08:22 +0800 Subject: [PATCH 14/14] test temp --- routers/api/v1/repo/pull.go | 2 +- routers/api/v1/repo/pull_review.go | 4 ++-- routers/web/repo/pull.go | 12 ++++++------ routers/web/repo/pull_review.go | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 9fde653d2f60a..fd2c366d4a97e 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1567,7 +1567,7 @@ func GetPullRequestFiles(ctx *context.APIContext) { return } - headCommitID, err := baseGitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + headCommitID, err := baseGitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { ctx.APIErrorInternal(err) return diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go index 0f0bcf30e4c70..65719a7cd3ace 100644 --- a/routers/api/v1/repo/pull_review.go +++ b/routers/api/v1/repo/pull_review.go @@ -336,7 +336,7 @@ func CreatePullReview(ctx *context.APIContext) { } defer closer.Close() - headCommitID, err := gitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + headCommitID, err := gitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { ctx.APIErrorInternal(err) return @@ -455,7 +455,7 @@ func SubmitPullReview(ctx *context.APIContext) { return } - headCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDNew(pr.GetGitHeadRefName()) + headCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(pr.GetGitHeadRefName()) if err != nil { ctx.APIErrorInternal(err) return diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 58e8b3b1f13a2..a3952db4c3800 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -197,7 +197,7 @@ func GetPullDiffStats(ctx *context.Context) { } // do not report 500 server error to end users if error occurs, otherwise a PR missing ref won't be able to view. - headCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDNew(pull.GetGitHeadRefName()) + headCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) if err != nil { log.Error("Failed to GetRefCommitID: %v, repo: %v", err, ctx.Repo.Repository.FullName()) return @@ -219,7 +219,7 @@ func GetMergedBaseCommitID(ctx *context.Context, issue *issues_model.Issue) stri if pull.MergeBase == "" { var commitSHA, parentCommit string // If there is a head or a patch file, and it is readable, grab info - commitSHA, err := ctx.Repo.GitRepo.GetRefCommitIDNew(pull.GetGitHeadRefName()) + commitSHA, err := ctx.Repo.GitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) if err != nil { // Head File does not exist, try the patch commitSHA, err = ctx.Repo.GitRepo.ReadPatchCommit(pull.Index) @@ -364,7 +364,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_ ctx.Data["BaseTarget"] = pull.BaseBranch ctx.Data["HeadTarget"] = pull.HeadBranch - sha, err := baseGitRepo.GetRefCommitIDNew(pull.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) if err != nil { ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitHeadRefName()), err) return nil @@ -422,7 +422,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_ if headBranchExist { if pull.Flow != issues_model.PullRequestFlowGithub { - headBranchSha, err = baseGitRepo.GetRefCommitIDNew(pull.GetGitHeadRefName()) + headBranchSha, err = baseGitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) } else { headBranchSha, err = headGitRepo.GetBranchCommitID(pull.HeadBranch) } @@ -445,7 +445,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_ ctx.Data["GetCommitMessages"] = "" } - sha, err := baseGitRepo.GetRefCommitIDNew(pull.GetGitHeadRefName()) + sha, err := baseGitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) if err != nil { if git.IsErrNotExist(err) { ctx.Data["IsPullRequestBroken"] = true @@ -702,7 +702,7 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) { return } - headCommitID, err := gitRepo.GetRefCommitIDNew(pull.GetGitHeadRefName()) + headCommitID, err := gitRepo.GetRefCommitIDOld(pull.GetGitHeadRefName()) if err != nil { ctx.ServerError("GetRefCommitID", err) return diff --git a/routers/web/repo/pull_review.go b/routers/web/repo/pull_review.go index 7ed6ef61b28aa..f156bc4e27cb7 100644 --- a/routers/web/repo/pull_review.go +++ b/routers/web/repo/pull_review.go @@ -49,7 +49,7 @@ func RenderNewCodeCommentForm(ctx *context.Context) { ctx.Data["PageIsPullFiles"] = true ctx.Data["Issue"] = issue ctx.Data["CurrentReview"] = currentReview - pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDNew(issue.PullRequest.GetGitHeadRefName()) + pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(issue.PullRequest.GetGitHeadRefName()) if err != nil { ctx.ServerError("GetRefCommitID", err) return @@ -199,7 +199,7 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment, ori ctx.ServerError("comment.Issue.LoadPullRequest", err) return } - pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDNew(comment.Issue.PullRequest.GetGitHeadRefName()) + pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitIDOld(comment.Issue.PullRequest.GetGitHeadRefName()) if err != nil { ctx.ServerError("GetRefCommitID", err) return