Skip to content

fix: panic handling for large file #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions pkg/git/RepositoryManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (impl RepositoryManagerImpl) Add(gitProviderId int, location string, url st
}

//git config core.sshCommand
_, errorMsg, err := impl.gitUtil.ConfigureSshCommand(location, sshPrivateKeyPath)
_, errorMsg, err := impl.gitUtil.ConfigureSshCommand(location, sshPrivateKeyPath)
if err != nil {
impl.logger.Errorw("error in configuring ssh command while adding repo", "errorMsg", errorMsg, "err", err)
return err
Expand Down Expand Up @@ -224,7 +224,6 @@ func (impl RepositoryManagerImpl) GetCommitMetadata(checkoutPath, commitHash str
return gitCommit, nil
}


//from -> old commit
//to -> new commit
//
Expand Down Expand Up @@ -274,7 +273,7 @@ func (impl RepositoryManagerImpl) ChangesSinceByRepository(repository *git.Repos
Date: commit.Author.When,
Message: commit.Message,
}
fs, err := commit.Stats()
fs, err := impl.getStats(commit)
if err != nil {
impl.logger.Errorw("error in getting fs", "branch", branch, "err", err)
break
Expand All @@ -288,6 +287,18 @@ func (impl RepositoryManagerImpl) ChangesSinceByRepository(repository *git.Repos
return gitCommits, err
}

func (impl RepositoryManagerImpl) getStats(commit *object.Commit) (object.FileStats, error) {
defer func() {
if err := recover(); err != nil {
// sometimes the Patch generation will fail due to a known bug in
// sergi's go-diff: https://github.com/sergi/go-diff/issues/89.
return
}
}()
fs, err := commit.Stats()
return fs, err
}

func (impl RepositoryManagerImpl) ChangesSince(checkoutPath string, branch string, from string, to string, count int) ([]*GitCommit, error) {
if count == 0 {
count = 15
Expand Down Expand Up @@ -514,4 +525,4 @@ func transform(src *object.Commit, tag *object.Tag) (dst *Commit) {
}
}
return
}
}