This is an automated email from the ASF dual-hosted git repository.

zhangliang2022 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 7a7d711cb fix: commit_files of initial commits were not collected 
(#4022)
7a7d711cb is described below

commit 7a7d711cbea2744b54d0dcb8d57ec1eff65b40f7
Author: Klesh Wong <[email protected]>
AuthorDate: Fri Dec 23 18:04:18 2022 +0800

    fix: commit_files of initial commits were not collected (#4022)
---
 plugins/gitextractor/impl/impl.go   |  3 +++
 plugins/gitextractor/parser/repo.go | 21 +++++++++++----------
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/plugins/gitextractor/impl/impl.go 
b/plugins/gitextractor/impl/impl.go
index 45f829185..15f9769c0 100644
--- a/plugins/gitextractor/impl/impl.go
+++ b/plugins/gitextractor/impl/impl.go
@@ -18,6 +18,7 @@ limitations under the License.
 package impl
 
 import (
+       "fmt"
        "strings"
 
        "github.com/apache/incubator-devlake/errors"
@@ -94,6 +95,8 @@ func NewGitRepo(logger core.Logger, storage models.Store, op 
tasks.GitExtractorO
                repo, err = p.CloneOverSSH(op.RepoId, url, op.PrivateKey, 
op.Passphrase)
        } else if strings.HasPrefix(op.Url, "/") {
                repo, err = p.LocalRepo(op.Url, op.RepoId)
+       } else {
+               return nil, errors.BadInput.New(fmt.Sprintf("unsupported url 
[%s]", op.Url))
        }
        return repo, err
 }
diff --git a/plugins/gitextractor/parser/repo.go 
b/plugins/gitextractor/parser/repo.go
index d5169e974..0c1700416 100644
--- a/plugins/gitextractor/parser/repo.go
+++ b/plugins/gitextractor/parser/repo.go
@@ -270,17 +270,16 @@ func (r *GitRepo) CollectCommits(subtaskCtx 
core.SubTaskContext) errors.Error {
                if err != nil {
                        return err
                }
+               var parent *git.Commit
                if commit.ParentCount() > 0 {
-                       parent := commit.Parent(0)
-                       if parent != nil {
-                               var stats *git.DiffStats
-                               if stats, err = 
r.getDiffComparedToParent(c.Sha, commit, parent, opts, componentMap); err != 
nil {
-                                       return err
-                               }
-                               c.Additions += stats.Insertions()
-                               c.Deletions += stats.Deletions()
-                       }
+                       parent = commit.Parent(0)
                }
+               var stats *git.DiffStats
+               if stats, err = r.getDiffComparedToParent(c.Sha, commit, 
parent, opts, componentMap); err != nil {
+                       return err
+               }
+               c.Additions += stats.Insertions()
+               c.Deletions += stats.Deletions()
                err = r.store.Commits(c)
                if err != nil {
                        return err
@@ -317,7 +316,9 @@ func (r *GitRepo) storeParentCommits(commitSha string, 
commit *git.Commit) error
 func (r *GitRepo) getDiffComparedToParent(commitSha string, commit 
*git.Commit, parent *git.Commit, opts *git.DiffOptions, componentMap 
map[string]*regexp.Regexp) (*git.DiffStats, errors.Error) {
        var err error
        var parentTree, tree *git.Tree
-       parentTree, err = parent.Tree()
+       if parent != nil {
+               parentTree, err = parent.Tree()
+       }
        if err != nil {
                return nil, errors.Convert(err)
        }

Reply via email to