summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-05-12 06:11:42 +0100
committerGitHub <noreply@github.com>2021-05-12 01:11:42 -0400
commit2a565478d17f4a1b59a77b0e2251dd7b7de862c4 (patch)
treee300874a9199a9579767e0477d55a53c21d56d45
parent3d7d750a999b72d422000154a0b1f2801614521e (diff)
downloadgitea-2a565478d17f4a1b59a77b0e2251dd7b7de862c4.tar.gz
gitea-2a565478d17f4a1b59a77b0e2251dd7b7de862c4.zip
Tagger can be empty, as can Commit and Author - tolerate this (#15835)
Unfortunately some old repositories can have tags with empty Tagger, Commit or Author. Go-Git variants will always have empty values for these whereas the native git variant leaves them at nil. The simplest solution is just to always have these set to empty Signatures. v156 migration also makes the incorrect assumption that these cannot be empty. Therefore add some handling to this and add logging and adjust broken logging elsewhere in this migration. Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
-rw-r--r--models/migrations/v156.go32
-rw-r--r--modules/git/commit_reader.go4
-rw-r--r--modules/git/tag.go1
3 files changed, 29 insertions, 8 deletions
diff --git a/models/migrations/v156.go b/models/migrations/v156.go
index 1e7cf28277..7158d7bb6b 100644
--- a/models/migrations/v156.go
+++ b/models/migrations/v156.go
@@ -88,7 +88,7 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
repo = new(Repository)
has, err := sess.ID(release.RepoID).Get(repo)
if err != nil {
- log.Error("Error whilst loading repository[%d] for release[%d] with tag name %s", release.RepoID, release.ID, release.TagName)
+ log.Error("Error whilst loading repository[%d] for release[%d] with tag name %s. Error: %v", release.RepoID, release.ID, release.TagName, err)
return err
} else if !has {
log.Warn("Release[%d] is orphaned and refers to non-existing repository %d", release.ID, release.RepoID)
@@ -105,13 +105,13 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
}
if _, err := sess.ID(release.RepoID).Get(repo); err != nil {
- log.Error("Error whilst loading repository[%d] for release[%d] with tag name %s", release.RepoID, release.ID, release.TagName)
+ log.Error("Error whilst loading repository[%d] for release[%d] with tag name %s. Error: %v", release.RepoID, release.ID, release.TagName, err)
return err
}
}
gitRepo, err = git.OpenRepository(repoPath(repo.OwnerName, repo.Name))
if err != nil {
- log.Error("Error whilst opening git repo for %-v", repo)
+ log.Error("Error whilst opening git repo for [%d]%s/%s. Error: %v", repo.ID, repo.OwnerName, repo.Name, err)
return err
}
}
@@ -119,18 +119,36 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
commit, err := gitRepo.GetTagCommit(release.TagName)
if err != nil {
if git.IsErrNotExist(err) {
- log.Warn("Unable to find commit %s for Tag: %s in %-v. Cannot update publisher ID.", err.(git.ErrNotExist).ID, release.TagName, repo)
+ log.Warn("Unable to find commit %s for Tag: %s in [%d]%s/%s. Cannot update publisher ID.", err.(git.ErrNotExist).ID, release.TagName, repo.ID, repo.OwnerName, repo.Name)
continue
}
- log.Error("Error whilst getting commit for Tag: %s in %-v.", release.TagName, repo)
+ log.Error("Error whilst getting commit for Tag: %s in [%d]%s/%s. Error: %v", release.TagName, repo.ID, repo.OwnerName, repo.Name, err)
return fmt.Errorf("GetTagCommit: %v", err)
}
+ if commit.Author.Email == "" {
+ log.Warn("Tag: %s in Repo[%d]%s/%s does not have a tagger.", release.TagName, repo.ID, repo.OwnerName, repo.Name)
+ commit, err = gitRepo.GetCommit(commit.ID.String())
+ if err != nil {
+ if git.IsErrNotExist(err) {
+ log.Warn("Unable to find commit %s for Tag: %s in [%d]%s/%s. Cannot update publisher ID.", err.(git.ErrNotExist).ID, release.TagName, repo.ID, repo.OwnerName, repo.Name)
+ continue
+ }
+ log.Error("Error whilst getting commit for Tag: %s in [%d]%s/%s. Error: %v", release.TagName, repo.ID, repo.OwnerName, repo.Name, err)
+ return fmt.Errorf("GetCommit: %v", err)
+ }
+ }
+
+ if commit.Author.Email == "" {
+ log.Warn("Tag: %s in Repo[%d]%s/%s does not have a Tagger and its underlying commit does not have an Author either!", release.TagName, repo.ID, repo.OwnerName, repo.Name)
+ continue
+ }
+
if user == nil || !strings.EqualFold(user.Email, commit.Author.Email) {
user = new(User)
_, err = sess.Where("email=?", commit.Author.Email).Get(user)
if err != nil {
- log.Error("Error whilst getting commit author by email: %s for Tag: %s in %-v.", commit.Author.Email, release.TagName, repo)
+ log.Error("Error whilst getting commit author by email: %s for Tag: %s in [%d]%s/%s. Error: %v", commit.Author.Email, release.TagName, repo.ID, repo.OwnerName, repo.Name, err)
return err
}
@@ -143,7 +161,7 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
release.PublisherID = user.ID
if _, err := sess.ID(release.ID).Cols("publisher_id").Update(release); err != nil {
- log.Error("Error whilst updating publisher[%d] for release[%d] with tag name %s", release.PublisherID, release.ID, release.TagName)
+ log.Error("Error whilst updating publisher[%d] for release[%d] with tag name %s. Error: %v", release.PublisherID, release.ID, release.TagName, err)
return err
}
}
diff --git a/modules/git/commit_reader.go b/modules/git/commit_reader.go
index a4d15b6bad..3c1f6f5ffd 100644
--- a/modules/git/commit_reader.go
+++ b/modules/git/commit_reader.go
@@ -17,7 +17,9 @@ import (
// If used as part of a cat-file --batch stream you need to limit the reader to the correct size
func CommitFromReader(gitRepo *Repository, sha SHA1, reader io.Reader) (*Commit, error) {
commit := &Commit{
- ID: sha,
+ ID: sha,
+ Author: &Signature{},
+ Committer: &Signature{},
}
payloadSB := new(strings.Builder)
diff --git a/modules/git/tag.go b/modules/git/tag.go
index 0323cc42ed..23f09e25b6 100644
--- a/modules/git/tag.go
+++ b/modules/git/tag.go
@@ -35,6 +35,7 @@ func (tag *Tag) Commit() (*Commit, error) {
// \n\n separate headers from message
func parseTagData(data []byte) (*Tag, error) {
tag := new(Tag)
+ tag.Tagger = &Signature{}
// we now have the contents of the commit object. Let's investigate...
nextline := 0
l: