Skip to content

Refactor git cat-file batch and with check implementation to make it easier to maintain and reduce goroutines #33934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
Improvements
  • Loading branch information
lunny committed Mar 19, 2025
commit aaec98d34e95604201382d2c608421c47602bfe7
1 change: 0 additions & 1 deletion modules/git/batch_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func ReadBatchLine(rd *bufio.Reader) (sha []byte, typ string, size int64, err er
typ = typ[:idx]

size, err = strconv.ParseInt(sizeStr, 10, 64)

return sha, typ, size, err
}

Expand Down
10 changes: 5 additions & 5 deletions modules/git/commit_info_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func GetLastCommitForPaths(ctx context.Context, commit *Commit, treePath string,
}
defer cancel()

rd := batch.Reader()
batchReader := batch.Reader()

commitsMap := map[string]*Commit{}
commitsMap[commit.ID.String()] = commit
Expand All @@ -150,21 +150,21 @@ func GetLastCommitForPaths(ctx context.Context, commit *Commit, treePath string,
if err := batch.Input(commitID); err != nil {
return nil, err
}
_, typ, size, err := ReadBatchLine(rd)
_, typ, size, err := ReadBatchLine(batchReader)
if err != nil {
return nil, err
}
if typ != "commit" {
if err := DiscardFull(rd, size+1); err != nil {
if err := DiscardFull(batchReader, size+1); err != nil {
return nil, err
}
return nil, fmt.Errorf("unexpected type: %s for commit id: %s", typ, commitID)
}
c, err = CommitFromReader(commit.repo, MustIDFromString(commitID), io.LimitReader(rd, size))
c, err = CommitFromReader(commit.repo, MustIDFromString(commitID), io.LimitReader(batchReader, size))
if err != nil {
return nil, err
}
if _, err := rd.Discard(1); err != nil {
if _, err := batchReader.Discard(1); err != nil {
return nil, err
}
commitCommits[path] = c
Expand Down
1 change: 0 additions & 1 deletion modules/git/pipeline/lfs_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
if err := batch.Input(string(trees[len(trees)-1])); err != nil {
return nil, err
}

curPath = paths[len(paths)-1]
trees = trees[:len(trees)-1]
paths = paths[:len(paths)-1]
Expand Down
Loading