]> source.dussan.org Git - gitea.git/commitdiff
Fix NPE on try to get tag reference via API (#18245)
author6543 <6543@obermui.de>
Wed, 12 Jan 2022 20:37:46 +0000 (21:37 +0100)
committerGitHub <noreply@github.com>
Wed, 12 Jan 2022 20:37:46 +0000 (20:37 +0000)
* fix npe

* rm gitRepo from Tag

modules/git/repo_commit_nogogit.go
modules/git/repo_tag.go
modules/git/repo_tag_test.go
modules/git/repo_tree_nogogit.go
modules/git/tag.go
modules/git/tag_test.go
modules/repository/repo.go
routers/api/v1/repo/tag.go
services/repository/push.go

index 4c1670742c7227aa73e62dea92aa8aa781e4f22c..cc02e551baa59ab70d6da5b1820edb4b2255251c 100644 (file)
@@ -103,9 +103,8 @@ func (repo *Repository) getCommitFromBatchReader(rd *bufio.Reader, id SHA1) (*Co
                if err != nil {
                        return nil, err
                }
-               tag.repo = repo
 
-               commit, err := tag.Commit()
+               commit, err := tag.Commit(repo)
                if err != nil {
                        return nil, err
                }
index 4262e0804f14a91207595e1ecb0d55601f5cc937..6b5dbeef482399a76917cf9657e3b959ba31940d 100644 (file)
@@ -72,7 +72,6 @@ func (repo *Repository) getTag(tagID SHA1, name string) (*Tag, error) {
                        Type:    tp,
                        Tagger:  commit.Committer,
                        Message: commit.Message(),
-                       repo:    repo,
                }
 
                repo.tagCache.Set(tagID.String(), tag)
@@ -92,7 +91,6 @@ func (repo *Repository) getTag(tagID SHA1, name string) (*Tag, error) {
 
        tag.Name = name
        tag.ID = tagID
-       tag.repo = repo
        tag.Type = tp
 
        repo.tagCache.Set(tagID.String(), tag)
index 33d34743f805bb5bbcea90ba213b3aed219ada97..f4d6726ea1a6072c6fe7f16977818c0efb1273d5 100644 (file)
@@ -55,7 +55,6 @@ func TestRepository_GetTag(t *testing.T) {
        if lTag == nil {
                assert.FailNow(t, "nil lTag: %s", lTagName)
        }
-       lTag.repo = nil
        assert.EqualValues(t, lTagName, lTag.Name)
        assert.EqualValues(t, lTagCommitID, lTag.ID.String())
        assert.EqualValues(t, lTagCommitID, lTag.Object.String())
index 56a4a732e034c84d931f26d769ae4b16f3808812..00009c997dfec8e93bdc063f0de3e4d7569c96c7 100644 (file)
@@ -34,7 +34,7 @@ func (repo *Repository) getTree(id SHA1) (*Tree, error) {
                if err != nil {
                        return nil, err
                }
-               commit, err := tag.Commit()
+               commit, err := tag.Commit(repo)
                if err != nil {
                        return nil, err
                }
index 23f09e25b6c8a91e3d617a4885d5c7a4f77d0568..71dd866a18bbf2c680130eaa9e696f3d0a4a46c7 100644 (file)
@@ -17,7 +17,6 @@ const endpgp = "\n-----END PGP SIGNATURE-----"
 type Tag struct {
        Name      string
        ID        SHA1
-       repo      *Repository
        Object    SHA1 // The id of this commit object
        Type      string
        Tagger    *Signature
@@ -26,8 +25,8 @@ type Tag struct {
 }
 
 // Commit return the commit of the tag reference
-func (tag *Tag) Commit() (*Commit, error) {
-       return tag.repo.getCommit(tag.Object)
+func (tag *Tag) Commit(gitRepo *Repository) (*Commit, error) {
+       return gitRepo.getCommit(tag.Object)
 }
 
 // Parse commit information from the (uncompressed) raw
index 3aa49df4b25579327e9ec0dbd99d43a3e410a845..e5f1660b8ef3c57d07826056ac1fb4c2e6e95ab4 100644 (file)
@@ -24,7 +24,6 @@ tagger Lucas Michot <lucas@semalead.com> 1484491741 +0100
 `), tag: Tag{
                        Name:      "",
                        ID:        SHA1{},
-                       repo:      nil,
                        Object:    SHA1{0x3b, 0x11, 0x4a, 0xb8, 0x0, 0xc6, 0x43, 0x2a, 0xd4, 0x23, 0x87, 0xcc, 0xf6, 0xbc, 0x8d, 0x43, 0x88, 0xa2, 0x88, 0x5a},
                        Type:      "commit",
                        Tagger:    &Signature{Name: "Lucas Michot", Email: "lucas@semalead.com", When: time.Unix(1484491741, 0)},
@@ -42,7 +41,6 @@ o
 ono`), tag: Tag{
                        Name:      "",
                        ID:        SHA1{},
-                       repo:      nil,
                        Object:    SHA1{0x7c, 0xdf, 0x42, 0xc0, 0xb1, 0xcc, 0x76, 0x3a, 0xb7, 0xe4, 0xc3, 0x3c, 0x47, 0xa2, 0x4e, 0x27, 0xc6, 0x6b, 0xfc, 0xcc},
                        Type:      "commit",
                        Tagger:    &Signature{Name: "Lucas Michot", Email: "lucas@semalead.com", When: time.Unix(1484553735, 0)},
index d04cd28a59f0d23ef1a18c264af3096fba5bd63f..eb3f58e937ec261eaf355d55a863f7c5230e28fe 100644 (file)
@@ -296,7 +296,7 @@ func PushUpdateAddTag(repo *repo_model.Repository, gitRepo *git.Repository, tagN
        if err != nil {
                return fmt.Errorf("GetTag: %v", err)
        }
-       commit, err := tag.Commit()
+       commit, err := tag.Commit(gitRepo)
        if err != nil {
                return fmt.Errorf("Commit: %v", err)
        }
index 8d42e63a489f07e490b2727a3c035d9593d409a6..13a625bafb6e00bc7a8b37fd74753739bbf40c77 100644 (file)
@@ -103,7 +103,7 @@ func GetAnnotatedTag(ctx *context.APIContext) {
        if tag, err := ctx.Repo.GitRepo.GetAnnotatedTag(sha); err != nil {
                ctx.Error(http.StatusBadRequest, "GetAnnotatedTag", err)
        } else {
-               commit, err := tag.Commit()
+               commit, err := tag.Commit(ctx.Repo.GitRepo)
                if err != nil {
                        ctx.Error(http.StatusBadRequest, "GetAnnotatedTag", err)
                }
index fe3f32f8396321f63be067d318f3846079ecf8c3..11854ccb3978c78cb206499aae9ed8f0bd4efa31 100644 (file)
@@ -294,7 +294,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
                if err != nil {
                        return fmt.Errorf("GetTag: %v", err)
                }
-               commit, err := tag.Commit()
+               commit, err := tag.Commit(gitRepo)
                if err != nil {
                        return fmt.Errorf("Commit: %v", err)
                }