Skip to content

Commit 0003aaf

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Hide internal package versions (go-gitea#20492) Fix org members bug (go-gitea#20489) Add labels to two buttons that were missing them (go-gitea#20419) fix enabling repo packages when projects are off (go-gitea#20486) Display project in issue list (go-gitea#20434) Make code review ceckboxes clickable (go-gitea#20481) Slightly simplify LastCommitCache (go-gitea#20444)
2 parents 6779933 + a3d55ac commit 0003aaf

40 files changed

+318
-219
lines changed

integrations/api_packages_container_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
container_module "code.gitea.io/gitea/modules/packages/container"
2121
"code.gitea.io/gitea/modules/packages/container/oci"
2222
"code.gitea.io/gitea/modules/setting"
23+
api "code.gitea.io/gitea/modules/structs"
2324

2425
"github.com/stretchr/testify/assert"
2526
)
@@ -487,6 +488,13 @@ func TestPackageContainer(t *testing.T) {
487488
assert.Equal(t, c.ExpectedTags, tagList.Tags)
488489
assert.Equal(t, c.ExpectedLink, resp.Header().Get("Link"))
489490
}
491+
492+
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/packages/%s?type=container&q=%s", user.Name, image))
493+
resp := MakeRequest(t, req, http.StatusOK)
494+
495+
var apiPackages []*api.Package
496+
DecodeJSON(t, resp, &apiPackages)
497+
assert.Len(t, apiPackages, 4) // "latest", "main", "multi", "sha256:..."
490498
})
491499

492500
t.Run("Delete", func(t *testing.T) {

integrations/org_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ func TestPrivateOrg(t *testing.T) {
116116
session.MakeRequest(t, req, http.StatusOK)
117117
}
118118

119+
func TestOrgMembers(t *testing.T) {
120+
defer prepareTestEnv(t)()
121+
122+
// not logged in user
123+
req := NewRequest(t, "GET", "/org/org25/members")
124+
MakeRequest(t, req, http.StatusOK)
125+
126+
// org member
127+
session := loginUser(t, "user24")
128+
req = NewRequest(t, "GET", "/org/org25/members")
129+
session.MakeRequest(t, req, http.StatusOK)
130+
131+
// site admin
132+
session = loginUser(t, "user1")
133+
req = NewRequest(t, "GET", "/org/org25/members")
134+
session.MakeRequest(t, req, http.StatusOK)
135+
}
136+
119137
func TestOrgRestrictedUser(t *testing.T) {
120138
defer prepareTestEnv(t)()
121139

models/issues/issue_list.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010

1111
"code.gitea.io/gitea/models/db"
12+
project_model "code.gitea.io/gitea/models/project"
1213
repo_model "code.gitea.io/gitea/models/repo"
1314
user_model "code.gitea.io/gitea/models/user"
1415
"code.gitea.io/gitea/modules/container"
@@ -222,6 +223,46 @@ func (issues IssueList) loadMilestones(ctx context.Context) error {
222223
return nil
223224
}
224225

226+
func (issues IssueList) getProjectIDs() []int64 {
227+
ids := make(map[int64]struct{}, len(issues))
228+
for _, issue := range issues {
229+
projectID := issue.ProjectID()
230+
if _, ok := ids[projectID]; !ok {
231+
ids[projectID] = struct{}{}
232+
}
233+
}
234+
return container.KeysInt64(ids)
235+
}
236+
237+
func (issues IssueList) loadProjects(ctx context.Context) error {
238+
projectIDs := issues.getProjectIDs()
239+
if len(projectIDs) == 0 {
240+
return nil
241+
}
242+
243+
projectMaps := make(map[int64]*project_model.Project, len(projectIDs))
244+
left := len(projectIDs)
245+
for left > 0 {
246+
limit := db.DefaultMaxInSize
247+
if left < limit {
248+
limit = left
249+
}
250+
err := db.GetEngine(ctx).
251+
In("id", projectIDs[:limit]).
252+
Find(&projectMaps)
253+
if err != nil {
254+
return err
255+
}
256+
left -= limit
257+
projectIDs = projectIDs[limit:]
258+
}
259+
260+
for _, issue := range issues {
261+
issue.Project = projectMaps[issue.ProjectID()]
262+
}
263+
return nil
264+
}
265+
225266
func (issues IssueList) loadAssignees(ctx context.Context) error {
226267
if len(issues) == 0 {
227268
return nil
@@ -495,6 +536,10 @@ func (issues IssueList) loadAttributes(ctx context.Context) error {
495536
return fmt.Errorf("issue.loadAttributes: loadMilestones: %v", err)
496537
}
497538

539+
if err := issues.loadProjects(ctx); err != nil {
540+
return fmt.Errorf("issue.loadAttributes: loadProjects: %v", err)
541+
}
542+
498543
if err := issues.loadAssignees(ctx); err != nil {
499544
return fmt.Errorf("issue.loadAttributes: loadAssignees: %v", err)
500545
}

models/packages/package_version.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ func getVersionByNameAndVersion(ctx context.Context, ownerID int64, packageType
122122
// GetVersionsByPackageType gets all versions of a specific type
123123
func GetVersionsByPackageType(ctx context.Context, ownerID int64, packageType Type) ([]*PackageVersion, error) {
124124
pvs, _, err := SearchVersions(ctx, &PackageSearchOptions{
125-
OwnerID: ownerID,
126-
Type: packageType,
125+
OwnerID: ownerID,
126+
Type: packageType,
127+
IsInternal: util.OptionalBoolFalse,
127128
})
128129
return pvs, err
129130
}
@@ -137,6 +138,7 @@ func GetVersionsByPackageName(ctx context.Context, ownerID int64, packageType Ty
137138
ExactMatch: true,
138139
Value: name,
139140
},
141+
IsInternal: util.OptionalBoolFalse,
140142
})
141143
return pvs, err
142144
}

modules/context/repo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,8 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
10011001
return
10021002
}
10031003
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
1004+
ctx.Repo.GitRepo.LastCommitCache = git.NewLastCommitCache(ctx.Repo.CommitsCount, ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, cache.GetCache())
1005+
10041006
return cancel
10051007
}
10061008
}

modules/git/commit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ func (c *Commit) ParentCount() int {
8080

8181
// GetCommitByPath return the commit of relative path object.
8282
func (c *Commit) GetCommitByPath(relpath string) (*Commit, error) {
83+
if c.repo.LastCommitCache != nil {
84+
return c.repo.LastCommitCache.GetCommitByPath(c.ID.String(), relpath)
85+
}
8386
return c.repo.getCommitByPathWithID(c.ID, relpath)
8487
}
8588

modules/git/commit_info_gogit.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
// GetCommitsInfo gets information of all commits that are corresponding to these entries
20-
func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath string, cache *LastCommitCache) ([]CommitInfo, *Commit, error) {
20+
func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath string) ([]CommitInfo, *Commit, error) {
2121
entryPaths := make([]string, len(tes)+1)
2222
// Get the commit for the treePath itself
2323
entryPaths[0] = ""
@@ -35,15 +35,15 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
3535
return nil, nil, err
3636
}
3737

38-
var revs map[string]*object.Commit
39-
if cache != nil {
38+
var revs map[string]*Commit
39+
if commit.repo.LastCommitCache != nil {
4040
var unHitPaths []string
41-
revs, unHitPaths, err = getLastCommitForPathsByCache(commit.ID.String(), treePath, entryPaths, cache)
41+
revs, unHitPaths, err = getLastCommitForPathsByCache(commit.ID.String(), treePath, entryPaths, commit.repo.LastCommitCache)
4242
if err != nil {
4343
return nil, nil, err
4444
}
4545
if len(unHitPaths) > 0 {
46-
revs2, err := GetLastCommitForPaths(ctx, cache, c, treePath, unHitPaths)
46+
revs2, err := GetLastCommitForPaths(ctx, commit.repo.LastCommitCache, c, treePath, unHitPaths)
4747
if err != nil {
4848
return nil, nil, err
4949
}
@@ -68,8 +68,7 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
6868
}
6969

7070
// Check if we have found a commit for this entry in time
71-
if rev, ok := revs[entry.Name()]; ok {
72-
entryCommit := convertCommit(rev)
71+
if entryCommit, ok := revs[entry.Name()]; ok {
7372
commitsInfo[i].Commit = entryCommit
7473
}
7574

@@ -96,10 +95,10 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
9695
// get it for free during the tree traversal and it's used for listing
9796
// pages to display information about newest commit for a given path.
9897
var treeCommit *Commit
98+
var ok bool
9999
if treePath == "" {
100100
treeCommit = commit
101-
} else if rev, ok := revs[""]; ok {
102-
treeCommit = convertCommit(rev)
101+
} else if treeCommit, ok = revs[""]; ok {
103102
treeCommit.repo = commit.repo
104103
}
105104
return commitsInfo, treeCommit, nil
@@ -155,16 +154,16 @@ func getFileHashes(c cgobject.CommitNode, treePath string, paths []string) (map[
155154
return hashes, nil
156155
}
157156

158-
func getLastCommitForPathsByCache(commitID, treePath string, paths []string, cache *LastCommitCache) (map[string]*object.Commit, []string, error) {
157+
func getLastCommitForPathsByCache(commitID, treePath string, paths []string, cache *LastCommitCache) (map[string]*Commit, []string, error) {
159158
var unHitEntryPaths []string
160-
results := make(map[string]*object.Commit)
159+
results := make(map[string]*Commit)
161160
for _, p := range paths {
162161
lastCommit, err := cache.Get(commitID, path.Join(treePath, p))
163162
if err != nil {
164163
return nil, nil, err
165164
}
166165
if lastCommit != nil {
167-
results[p] = lastCommit.(*object.Commit)
166+
results[p] = lastCommit
168167
continue
169168
}
170169

@@ -175,7 +174,7 @@ func getLastCommitForPathsByCache(commitID, treePath string, paths []string, cac
175174
}
176175

177176
// GetLastCommitForPaths returns last commit information
178-
func GetLastCommitForPaths(ctx context.Context, cache *LastCommitCache, c cgobject.CommitNode, treePath string, paths []string) (map[string]*object.Commit, error) {
177+
func GetLastCommitForPaths(ctx context.Context, cache *LastCommitCache, c cgobject.CommitNode, treePath string, paths []string) (map[string]*Commit, error) {
179178
refSha := c.ID().String()
180179

181180
// We do a tree traversal with nodes sorted by commit time
@@ -293,13 +292,13 @@ heaploop:
293292
}
294293

295294
// Post-processing
296-
result := make(map[string]*object.Commit)
295+
result := make(map[string]*Commit)
297296
for path, commitNode := range resultNodes {
298-
var err error
299-
result[path], err = commitNode.Commit()
297+
commit, err := commitNode.Commit()
300298
if err != nil {
301299
return nil, err
302300
}
301+
result[path] = convertCommit(commit)
303302
}
304303

305304
return result, nil

modules/git/commit_info_nogogit.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
// GetCommitsInfo gets information of all commits that are corresponding to these entries
20-
func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath string, cache *LastCommitCache) ([]CommitInfo, *Commit, error) {
20+
func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath string) ([]CommitInfo, *Commit, error) {
2121
entryPaths := make([]string, len(tes)+1)
2222
// Get the commit for the treePath itself
2323
entryPaths[0] = ""
@@ -28,15 +28,15 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
2828
var err error
2929

3030
var revs map[string]*Commit
31-
if cache != nil {
31+
if commit.repo.LastCommitCache != nil {
3232
var unHitPaths []string
33-
revs, unHitPaths, err = getLastCommitForPathsByCache(ctx, commit.ID.String(), treePath, entryPaths, cache)
33+
revs, unHitPaths, err = getLastCommitForPathsByCache(ctx, commit.ID.String(), treePath, entryPaths, commit.repo.LastCommitCache)
3434
if err != nil {
3535
return nil, nil, err
3636
}
3737
if len(unHitPaths) > 0 {
3838
sort.Strings(unHitPaths)
39-
commits, err := GetLastCommitForPaths(ctx, cache, commit, treePath, unHitPaths)
39+
commits, err := GetLastCommitForPaths(ctx, commit, treePath, unHitPaths)
4040
if err != nil {
4141
return nil, nil, err
4242
}
@@ -47,7 +47,7 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
4747
}
4848
} else {
4949
sort.Strings(entryPaths)
50-
revs, err = GetLastCommitForPaths(ctx, nil, commit, treePath, entryPaths)
50+
revs, err = GetLastCommitForPaths(ctx, commit, treePath, entryPaths)
5151
}
5252
if err != nil {
5353
return nil, nil, err
@@ -99,18 +99,15 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
9999
}
100100

101101
func getLastCommitForPathsByCache(ctx context.Context, commitID, treePath string, paths []string, cache *LastCommitCache) (map[string]*Commit, []string, error) {
102-
wr, rd, cancel := cache.repo.CatFileBatch(ctx)
103-
defer cancel()
104-
105102
var unHitEntryPaths []string
106103
results := make(map[string]*Commit)
107104
for _, p := range paths {
108-
lastCommit, err := cache.Get(commitID, path.Join(treePath, p), wr, rd)
105+
lastCommit, err := cache.Get(commitID, path.Join(treePath, p))
109106
if err != nil {
110107
return nil, nil, err
111108
}
112109
if lastCommit != nil {
113-
results[p] = lastCommit.(*Commit)
110+
results[p] = lastCommit
114111
continue
115112
}
116113

@@ -121,9 +118,9 @@ func getLastCommitForPathsByCache(ctx context.Context, commitID, treePath string
121118
}
122119

123120
// GetLastCommitForPaths returns last commit information
124-
func GetLastCommitForPaths(ctx context.Context, cache *LastCommitCache, commit *Commit, treePath string, paths []string) (map[string]*Commit, error) {
121+
func GetLastCommitForPaths(ctx context.Context, commit *Commit, treePath string, paths []string) (map[string]*Commit, error) {
125122
// We read backwards from the commit to obtain all of the commits
126-
revs, err := WalkGitLog(ctx, cache, commit.repo, commit, treePath, paths...)
123+
revs, err := WalkGitLog(ctx, commit.repo, commit, treePath, paths...)
127124
if err != nil {
128125
return nil, err
129126
}

modules/git/commit_info_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func testGetCommitsInfo(t *testing.T, repo1 *Repository) {
9191
}
9292

9393
// FIXME: Context.TODO() - if graceful has started we should use its Shutdown context otherwise use install signals in TestMain.
94-
commitsInfo, treeCommit, err := entries.GetCommitsInfo(context.TODO(), commit, testCase.Path, nil)
94+
commitsInfo, treeCommit, err := entries.GetCommitsInfo(context.TODO(), commit, testCase.Path)
9595
assert.NoError(t, err, "Unable to get commit information for entries of subtree: %s in commit: %s from testcase due to error: %v", testCase.Path, testCase.CommitID, err)
9696
if err != nil {
9797
t.FailNow()
@@ -170,7 +170,7 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
170170
b.ResetTimer()
171171
b.Run(benchmark.name, func(b *testing.B) {
172172
for i := 0; i < b.N; i++ {
173-
_, _, err := entries.GetCommitsInfo(context.Background(), commit, "", nil)
173+
_, _, err := entries.GetCommitsInfo(context.Background(), commit, "")
174174
if err != nil {
175175
b.Fatal(err)
176176
}

0 commit comments

Comments
 (0)