8000 preparations to remove context from repo struct by TheFox0x7 · Pull Request #33893 · go-gitea/gitea · GitHub
[go: up one dir, main page]

Skip to content

preparations to remove context from repo struct #33893

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

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7dee037
add context to GetMergeBase
TheFox0x7 Mar 14, 2025
3631512
add context to GetDiffBinary
TheFox0x7 Mar 14, 2025
162899b
add context to GetPatch
TheFox0x7 Mar 14, 2025
0099c82
use function provided context in GetCompareInfo
TheFox0x7 Mar 14, 2025
34153fd
add context to GetCommitByPath 8000
TheFox0x7 Mar 14, 2025
dfaff77
add context to CommitBetweenLimit
TheFox0x7 Mar 14, 2025
44a6fde
add context to commitsBefore
TheFox0x7 Mar 14, 2025
7fbf350
add context to commitsByRange
TheFox0x7 Mar 14, 2025
3ad5ee2
add contect to GetDiff and SearchCommits
TheFox0x7 Mar 14, 2025
30767c3
add context to FileCommitsCount and FilesCountBetween
TheFox0x7 Mar 14, 2025
1611740
add context to IsCommitInBranch and CommitsBetweenIDs
TheFox0x7 Mar 14, 2025
ea27930
add context to GetTreePathLatestCommit
TheFox0x7 Mar 14, 2025
d2c85c4
add context to CommitsByFileAndRange and FileChangedBetweenCommits
TheFox0x7 Mar 14, 2025
4f1709b
add context to LsTree
TheFox0x7 Mar 14, 2025
3a0af2c
add context to GetRepoRawDiffForFile
TheFox0x7 Mar 14, 2025
8fd4716
add context to GetDiffNumChangedFiles
TheFox0x7 Mar 14, 2025
a4e5604
add context to GetCodeActivityStats
TheFox0x7 Mar 14, 2025
e8f1fb3
add context to LineBlame
TheFox0x7 Mar 14, 2025
00bb0b7
add context to GetDefaultPublicKey
TheFox0x7 Mar 14, 2025
bd41dd4
add context to branch commands
TheFox0x7 Mar 14, 2025
a933423
add context to remaining branch commands
TheFox0x7 Mar 14, 2025
6087fa4
add context to ReadTreeToIndex
TheFox0x7 Mar 14, 2025
ad250db
add context to CommitTree
TheFox0x7 Mar 14, 2025
0d52636
add context to tag commands
TheFox0x7 Mar 14, 2025
6437369
add context to CheckAtrribute
TheFox0x7 Mar 14, 2025
4a60296
fix gogit build
TheFox0x7 Mar 15, 2025
3932669
add context to repo_index commands
TheFox0x7 Mar 15, 2025
97e767e
add context to Size
TheFox0x7 Mar 15, 2025
5122043
fix build
TheFox0x7 Mar 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add context to commitsByRange
add context to commitsBetweenNotBase
  • Loading branch information
TheFox0x7 committed Mar 16, 2025
commit 7fbf350d57e3d56e8dff9ccd359f844117d2258d
4 changes: 2 additions & 2 deletions modules/git/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ func (c *Commit) CommitsCount() (int64, error) {
}

// CommitsByRange returns the specific page commits before current revision, every page's number default by CommitsRangeSize
func (c *Commit) CommitsByRange(page, pageSize int, not string) ([]*Commit, error) {
return c.repo.commitsByRange(c.ID, page, pageSize, not)
func (c *Commit) CommitsByRange(ctx context.Context, page, pageSize int, not string) ([]*Commit, error) {
return c.repo.commitsByRange(ctx, c.ID, page, pageSize, not)
}

// CommitsBefore returns all the commits before current revision
Expand Down
12 changes: 6 additions & 6 deletions modules/git/repo_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (repo *Repository) GetCommitByPath(ctx context.Context, relpath string) (*C
return commits[0], nil
}

func (repo *Repository) commitsByRange(id ObjectID, page, pageSize int, not string) ([]*Commit, error) {
func (repo *Repository) commitsByRange(ctx context.Context, id ObjectID, page, pageSize int, not string) ([]*Commit, error) {
cmd := NewCommand("log").
AddOptionFormat("--skip=%d", (page-1)*pageSize).
AddOptionFormat("--max-count=%d", pageSize).
Expand All @@ -101,7 +101,7 @@ func (repo *Repository) commitsByRange(id ObjectID, page, pageSize int, not stri
cmd.AddOptionValues("--not", not)
}

stdout, _, err := cmd.RunStdBytes(repo.Ctx, &RunOpts{Dir: repo.Path})
stdout, _, err := cmd.RunStdBytes(ctx, &RunOpts{Dir: repo.Path})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -340,17 +340,17 @@ func (repo *Repository) CommitsBetweenLimit(ctx context.Context, last, before *C

// CommitsBetweenNotBase returns a list that contains commits between [before, last), excluding commits in baseBranch.
// If before is detached (removed by reset + push) it is not included.
func (repo *Repository) CommitsBetweenNotBase(last, before *Commit, baseBranch string) ([]*Commit, error) {
func (repo *Repository) CommitsBetweenNotBase(ctx context.Context, last, before *Commit, baseBranch string) ([]*Commit, error) {
var stdout []byte
var err error
if before == nil {
stdout, _, err = NewCommand("rev-list").AddDynamicArguments(last.ID.String()).AddOptionValues("--not", baseBranch).RunStdBytes(repo.Ctx, &RunOpts{Dir: repo.Path})
stdout, _, err = NewCommand("rev-list").AddDynamicArguments(last.ID.String()).AddOptionValues("--not", baseBranch).RunStdBytes(ctx, &RunOpts{Dir: repo.Path})
} else {
stdout, _, err = NewCommand("rev-list").AddDynamicArguments(before.ID.String()+".."+last.ID.String()).AddOptionValues("--not", baseBranch).RunStdBytes(repo.Ctx, &RunOpts{Dir: repo.Path})
stdout, _, err = NewCommand("rev-list").AddDynamicArguments(before.ID.String()+".."+last.ID.String()).AddOptionValues("--not", baseBranch).RunStdBytes(ctx, &RunOpts{Dir: repo.Path})
if err != nil && strings.Contains(err.Error(), "no merge base") {
// future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
// previously it would return the results of git rev-list before last so let's try that...
stdout, _, err = NewCommand("rev-list").AddDynamicArguments(before.ID.String(), last.ID.String()).AddOptionValues("--not", baseBranch).RunStdBytes(repo.Ctx, &RunOpts{Dir: repo.Path})
stdout, _, err = NewCommand("rev-list").AddDynamicArguments(before.ID.String(), last.ID.String()).AddOptionValues("--not", baseBranch).RunStdBytes(ctx, &RunOpts{Dir: repo.Path})
}
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/repo/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func GetAllCommits(ctx *context.APIContext) {
}

// Query commits
commits, err = baseCommit.CommitsByRange(listOptions.Page, listOptions.PageSize, not)
commits, err = baseCommit.CommitsByRange(ctx, listOptions.Page, listOptions.PageSize, not)
if err != nil {
ctx.APIErrorInternal(err)
return
Expand Down
2 changes: 1 addition & 1 deletion routers/web/feed/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

// ShowBranchFeed shows tags and/or releases on the repo as RSS / Atom feed
func ShowBranchFeed(ctx *context.Context, repo *repo.Repository, formatType string) {
commits, err := ctx.Repo.Commit.CommitsByRange(0, 10, "")
commits, err := ctx.Repo.Commit.CommitsByRange(ctx, 0, 10, "")
if err != nil {
ctx.ServerError("ShowBranchFeed", err)
return
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func Commits(ctx *context.Context) {
}

// Both `git log branchName` and `git log commitId` work.
commits, err := ctx.Repo.Commit.CommitsByRange(page, pageSize, "")
commits, err := ctx.Repo.Commit.CommitsByRange(ctx, page, pageSize, "")
if err != nil {
ctx.ServerError("CommitsByRange", err)
return
Expand Down
2 changes: 1 addition & 1 deletion services/pull/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func getCommitIDsFromRepo(ctx context.Context, repo *repo_model.Repository, oldC
}

// Find commits between new and old commit excluding base branch commits
commits, err := gitRepo.CommitsBetweenNotBase(newCommit, oldCommit, baseBranch)
commits, err := gitRepo.CommitsBetweenNotBase(ctx, newCommit, oldCommit, baseBranch)
if err != nil {
return nil, false, err
}
Expand Down
0