This is an automated email from the ASF dual-hosted git repository.
likyh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 14c7be9bd Fix(gitex): return err instead of logging (#4092)
14c7be9bd is described below
commit 14c7be9bd8314eefedc7423b89db3470336356b0
Author: Warren Chen <[email protected]>
AuthorDate: Wed Jan 4 14:49:52 2023 +0800
Fix(gitex): return err instead of logging (#4092)
* fix(gitex): update log
* fix(giex): return err instead of log
---
plugins/gitextractor/parser/repo.go | 36 ++++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/plugins/gitextractor/parser/repo.go
b/plugins/gitextractor/parser/repo.go
index 6e1d9026f..3a58f25a8 100644
--- a/plugins/gitextractor/parser/repo.go
+++ b/plugins/gitextractor/parser/repo.go
@@ -35,6 +35,8 @@ import (
git "github.com/libgit2/git2go/v33"
)
+var TypeNotMatchError = "the requested type does not match the type in the ODB"
+
type GitRepo struct {
store models.Store
logger core.Logger
@@ -116,8 +118,8 @@ func (r *GitRepo) CountCommits(ctx context.Context) (int,
errors.Error) {
default:
}
commit, e := r.repo.LookupCommit(id)
- if e != nil {
- r.logger.Error(e, "")
+ if e != nil && e.Error() != TypeNotMatchError {
+ return errors.Convert(e)
}
if commit != nil {
count++
@@ -139,10 +141,8 @@ func (r *GitRepo) CollectTags(subtaskCtx
core.SubTaskContext) errors.Error {
var tag *git.Tag
var tagCommit string
tag, err1 = r.repo.LookupTag(id)
- if err1 != nil {
- if err1 != nil {
- r.logger.Error(err1, "")
- }
+ if err1 != nil && err1.Error() != TypeNotMatchError {
+ return errors.Convert(err1)
}
if tag != nil {
tagCommit = tag.TargetId().String()
@@ -183,7 +183,7 @@ func (r *GitRepo) CollectBranches(subtaskCtx
core.SubTaskContext) errors.Error {
}
if branch.IsBranch() || branch.IsRemote() {
name, err1 := branch.Name()
- if err1 != nil {
+ if err1 != nil && err1.Error() != TypeNotMatchError {
return err1
}
var sha string
@@ -198,11 +198,11 @@ func (r *GitRepo) CollectBranches(subtaskCtx
core.SubTaskContext) errors.Error {
RefType: BRANCH,
}
ref.IsDefault, err1 = branch.IsHead()
- if err1 != nil {
- r.logger.Error(err1, "")
+ if err1 != nil && err1.Error() != TypeNotMatchError {
+ return err1
}
err1 = r.store.Refs(ref)
- if err1 != nil {
+ if err1 != nil && err1.Error() != TypeNotMatchError {
return err1
}
subtaskCtx.IncProgress(1)
@@ -239,8 +239,8 @@ func (r *GitRepo) CollectCommits(subtaskCtx
core.SubTaskContext) errors.Error {
default:
}
commit, err1 := r.repo.LookupCommit(id)
- if err1 != nil {
- r.logger.Error(err1, "")
+ if err1 != nil && err1.Error() != TypeNotMatchError {
+ return errors.Convert(err1)
}
if commit == nil {
return nil
@@ -416,21 +416,21 @@ func (r *GitRepo) CollectDiffLine(subtaskCtx
core.SubTaskContext) errors.Error {
//get currently head commitsha, dafault is master branch
// check branch, if not master, checkout to branch's head
commitOid, err1 := repo.Head()
- if err1 != nil {
- r.logger.Error(err1, "")
+ if err1 != nil && err1.Error() != TypeNotMatchError {
+ return errors.Convert(err1)
}
//get head commit object and add into commitList
commit, err1 := repo.LookupCommit(commitOid.Target())
- if err1 != nil {
- r.logger.Error(err1, "")
+ if err1 != nil && err1.Error() != TypeNotMatchError {
+ return errors.Convert(err1)
}
commitList = append(commitList, *commit)
// if current head has parents, get parent commitsha
for commit != nil && commit.ParentCount() > 0 {
pid := commit.ParentId(0)
commit, err1 = repo.LookupCommit(pid)
- if err1 != nil {
- r.logger.Error(err1, "")
+ if err1 != nil && err1.Error() != TypeNotMatchError {
+ return errors.Convert(err1)
}
commitList = append(commitList, *commit)
}