Skip to content

Commit ff00b86

Browse files
authored
Fix NPE on try to get tag reference via API (#18245)
* fix npe * rm gitRepo from Tag
1 parent 67d7388 commit ff00b86

File tree

9 files changed

+7
-14
lines changed

9 files changed

+7
-14
lines changed

modules/git/repo_commit_nogogit.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ func (repo *Repository) getCommitFromBatchReader(rd *bufio.Reader, id SHA1) (*Co
103103
if err != nil {
104104
return nil, err
105105
}
106-
tag.repo = repo
107106

108-
commit, err := tag.Commit()
107+
commit, err := tag.Commit(repo)
109108
if err != nil {
110109
return nil, err
111110
}

modules/git/repo_tag.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ func (repo *Repository) getTag(tagID SHA1, name string) (*Tag, error) {
7272
Type: tp,
7373
Tagger: commit.Committer,
7474
Message: commit.Message(),
75-
repo: repo,
7675
}
7776

7877
repo.tagCache.Set(tagID.String(), tag)
@@ -92,7 +91,6 @@ func (repo *Repository) getTag(tagID SHA1, name string) (*Tag, error) {
9291

9392
tag.Name = name
9493
tag.ID = tagID
95-
tag.repo = repo
9694
tag.Type = tp
9795

9896
repo.tagCache.Set(tagID.String(), tag)

modules/git/repo_tag_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ func TestRepository_GetTag(t *testing.T) {
5555
if lTag == nil {
5656
assert.FailNow(t, "nil lTag: %s", lTagName)
5757
}
58-
lTag.repo = nil
5958
assert.EqualValues(t, lTagName, lTag.Name)
6059
assert.EqualValues(t, lTagCommitID, lTag.ID.String())
6160
assert.EqualValues(t, lTagCommitID, lTag.Object.String())

modules/git/repo_tree_nogogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (repo *Repository) getTree(id SHA1) (*Tree, error) {
3434
if err != nil {
3535
return nil, err
3636
}
37-
commit, err := tag.Commit()
37+
commit, err := tag.Commit(repo)
3838
if err != nil {
3939
return nil, err
4040
}

modules/git/tag.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const endpgp = "\n-----END PGP SIGNATURE-----"
1717
type Tag struct {
1818
Name string
1919
ID SHA1
20-
repo *Repository
2120
Object SHA1 // The id of this commit object
2221
Type string
2322
Tagger *Signature
@@ -26,8 +25,8 @@ type Tag struct {
2625
}
2726

2827
// Commit return the commit of the tag reference
29-
func (tag *Tag) Commit() (*Commit, error) {
30-
return tag.repo.getCommit(tag.Object)
28+
func (tag *Tag) Commit(gitRepo *Repository) (*Commit, error) {
29+
return gitRepo.getCommit(tag.Object)
3130
}
3231

3332
// Parse commit information from the (uncompressed) raw

modules/git/tag_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ tagger Lucas Michot <[email protected]> 1484491741 +0100
2424
`), tag: Tag{
2525
Name: "",
2626
ID: SHA1{},
27-
repo: nil,
2827
Object: SHA1{0x3b, 0x11, 0x4a, 0xb8, 0x0, 0xc6, 0x43, 0x2a, 0xd4, 0x23, 0x87, 0xcc, 0xf6, 0xbc, 0x8d, 0x43, 0x88, 0xa2, 0x88, 0x5a},
2928
Type: "commit",
3029
Tagger: &Signature{Name: "Lucas Michot", Email: "[email protected]", When: time.Unix(1484491741, 0)},
@@ -42,7 +41,6 @@ o
4241
ono`), tag: Tag{
4342
Name: "",
4443
ID: SHA1{},
45-
repo: nil,
4644
Object: SHA1{0x7c, 0xdf, 0x42, 0xc0, 0xb1, 0xcc, 0x76, 0x3a, 0xb7, 0xe4, 0xc3, 0x3c, 0x47, 0xa2, 0x4e, 0x27, 0xc6, 0x6b, 0xfc, 0xcc},
4745
Type: "commit",
4846
Tagger: &Signature{Name: "Lucas Michot", Email: "[email protected]", When: time.Unix(1484553735, 0)},

modules/repository/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func PushUpdateAddTag(repo *repo_model.Repository, gitRepo *git.Repository, tagN
296296
if err != nil {
297297
return fmt.Errorf("GetTag: %v", err)
298298
}
299-
commit, err := tag.Commit()
299+
commit, err := tag.Commit(gitRepo)
300300
if err != nil {
301301
return fmt.Errorf("Commit: %v", err)
302302
}

routers/api/v1/repo/tag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func GetAnnotatedTag(ctx *context.APIContext) {
103103
if tag, err := ctx.Repo.GitRepo.GetAnnotatedTag(sha); err != nil {
104104
ctx.Error(http.StatusBadRequest, "GetAnnotatedTag", err)
105105
} else {
106-
commit, err := tag.Commit()
106+
commit, err := tag.Commit(ctx.Repo.GitRepo)
107107
if err != nil {
108108
ctx.Error(http.StatusBadRequest, "GetAnnotatedTag", err)
109109
}

services/repository/push.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
294294
if err != nil {
295295
return fmt.Errorf("GetTag: %v", err)
296296
}
297-
commit, err := tag.Commit()
297+
commit, err := tag.Commit(gitRepo)
298298
if err != nil {
299299
return fmt.Errorf("Commit: %v", err)
300300
}

0 commit comments

Comments
 (0)