Fix NPE on try to get tag reference via API (#18245)
* fix npe * rm gitRepo from Tag
This commit is contained in:
parent
67d73882f4
commit
ff00b8688b
|
@ -103,9 +103,8 @@ func (repo *Repository) getCommitFromBatchReader(rd *bufio.Reader, id SHA1) (*Co
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
tag.repo = repo
|
|
||||||
|
|
||||||
commit, err := tag.Commit()
|
commit, err := tag.Commit(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,6 @@ func (repo *Repository) getTag(tagID SHA1, name string) (*Tag, error) {
|
||||||
Type: tp,
|
Type: tp,
|
||||||
Tagger: commit.Committer,
|
Tagger: commit.Committer,
|
||||||
Message: commit.Message(),
|
Message: commit.Message(),
|
||||||
repo: repo,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.tagCache.Set(tagID.String(), tag)
|
repo.tagCache.Set(tagID.String(), tag)
|
||||||
|
@ -92,7 +91,6 @@ func (repo *Repository) getTag(tagID SHA1, name string) (*Tag, error) {
|
||||||
|
|
||||||
tag.Name = name
|
tag.Name = name
|
||||||
tag.ID = tagID
|
tag.ID = tagID
|
||||||
tag.repo = repo
|
|
||||||
tag.Type = tp
|
tag.Type = tp
|
||||||
|
|
||||||
repo.tagCache.Set(tagID.String(), tag)
|
repo.tagCache.Set(tagID.String(), tag)
|
||||||
|
|
|
@ -55,7 +55,6 @@ func TestRepository_GetTag(t *testing.T) {
|
||||||
if lTag == nil {
|
if lTag == nil {
|
||||||
assert.FailNow(t, "nil lTag: %s", lTagName)
|
assert.FailNow(t, "nil lTag: %s", lTagName)
|
||||||
}
|
}
|
||||||
lTag.repo = nil
|
|
||||||
assert.EqualValues(t, lTagName, lTag.Name)
|
assert.EqualValues(t, lTagName, lTag.Name)
|
||||||
assert.EqualValues(t, lTagCommitID, lTag.ID.String())
|
assert.EqualValues(t, lTagCommitID, lTag.ID.String())
|
||||||
assert.EqualValues(t, lTagCommitID, lTag.Object.String())
|
assert.EqualValues(t, lTagCommitID, lTag.Object.String())
|
||||||
|
|
|
@ -34,7 +34,7 @@ func (repo *Repository) getTree(id SHA1) (*Tree, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
commit, err := tag.Commit()
|
commit, err := tag.Commit(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ const endpgp = "\n-----END PGP SIGNATURE-----"
|
||||||
type Tag struct {
|
type Tag struct {
|
||||||
Name string
|
Name string
|
||||||
ID SHA1
|
ID SHA1
|
||||||
repo *Repository
|
|
||||||
Object SHA1 // The id of this commit object
|
Object SHA1 // The id of this commit object
|
||||||
Type string
|
Type string
|
||||||
Tagger *Signature
|
Tagger *Signature
|
||||||
|
@ -26,8 +25,8 @@ type Tag struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit return the commit of the tag reference
|
// Commit return the commit of the tag reference
|
||||||
func (tag *Tag) Commit() (*Commit, error) {
|
func (tag *Tag) Commit(gitRepo *Repository) (*Commit, error) {
|
||||||
return tag.repo.getCommit(tag.Object)
|
return gitRepo.getCommit(tag.Object)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse commit information from the (uncompressed) raw
|
// Parse commit information from the (uncompressed) raw
|
||||||
|
|
|
@ -24,7 +24,6 @@ tagger Lucas Michot <lucas@semalead.com> 1484491741 +0100
|
||||||
`), tag: Tag{
|
`), tag: Tag{
|
||||||
Name: "",
|
Name: "",
|
||||||
ID: SHA1{},
|
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},
|
Object: SHA1{0x3b, 0x11, 0x4a, 0xb8, 0x0, 0xc6, 0x43, 0x2a, 0xd4, 0x23, 0x87, 0xcc, 0xf6, 0xbc, 0x8d, 0x43, 0x88, 0xa2, 0x88, 0x5a},
|
||||||
Type: "commit",
|
Type: "commit",
|
||||||
Tagger: &Signature{Name: "Lucas Michot", Email: "lucas@semalead.com", When: time.Unix(1484491741, 0)},
|
Tagger: &Signature{Name: "Lucas Michot", Email: "lucas@semalead.com", When: time.Unix(1484491741, 0)},
|
||||||
|
@ -42,7 +41,6 @@ o
|
||||||
ono`), tag: Tag{
|
ono`), tag: Tag{
|
||||||
Name: "",
|
Name: "",
|
||||||
ID: SHA1{},
|
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},
|
Object: SHA1{0x7c, 0xdf, 0x42, 0xc0, 0xb1, 0xcc, 0x76, 0x3a, 0xb7, 0xe4, 0xc3, 0x3c, 0x47, 0xa2, 0x4e, 0x27, 0xc6, 0x6b, 0xfc, 0xcc},
|
||||||
Type: "commit",
|
Type: "commit",
|
||||||
Tagger: &Signature{Name: "Lucas Michot", Email: "lucas@semalead.com", When: time.Unix(1484553735, 0)},
|
Tagger: &Signature{Name: "Lucas Michot", Email: "lucas@semalead.com", When: time.Unix(1484553735, 0)},
|
||||||
|
|
|
@ -296,7 +296,7 @@ func PushUpdateAddTag(repo *repo_model.Repository, gitRepo *git.Repository, tagN
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("GetTag: %v", err)
|
return fmt.Errorf("GetTag: %v", err)
|
||||||
}
|
}
|
||||||
commit, err := tag.Commit()
|
commit, err := tag.Commit(gitRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Commit: %v", err)
|
return fmt.Errorf("Commit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ func GetAnnotatedTag(ctx *context.APIContext) {
|
||||||
if tag, err := ctx.Repo.GitRepo.GetAnnotatedTag(sha); err != nil {
|
if tag, err := ctx.Repo.GitRepo.GetAnnotatedTag(sha); err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "GetAnnotatedTag", err)
|
ctx.Error(http.StatusBadRequest, "GetAnnotatedTag", err)
|
||||||
} else {
|
} else {
|
||||||
commit, err := tag.Commit()
|
commit, err := tag.Commit(ctx.Repo.GitRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "GetAnnotatedTag", err)
|
ctx.Error(http.StatusBadRequest, "GetAnnotatedTag", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -294,7 +294,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("GetTag: %v", err)
|
return fmt.Errorf("GetTag: %v", err)
|
||||||
}
|
}
|
||||||
commit, err := tag.Commit()
|
commit, err := tag.Commit(gitRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Commit: %v", err)
|
return fmt.Errorf("Commit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue