Skip to content

Commit

Permalink
wrap git blame function with recover (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
omryMen committed Apr 25, 2024
1 parent dca94c8 commit 1089971
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/common/gitservice/git_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ func (g *GitService) GetRepoName() string {
return g.repoName
}

func wrapGitBlame(selectedCommit *object.Commit, relativeFilePath string) (*git.BlameResult, error) {
// currently there's a bug inside go-git so in order to mitigate it we wrap it with recover
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered in f", r)
}
}()
blame, err := git.Blame(selectedCommit, relativeFilePath)
if err != nil {
return nil, fmt.Errorf("failed to get blame for latest commit of file %s because of error %s", relativeFilePath, err)
}
return blame, err
}

func (g *GitService) GetFileBlame(filePath string) (*git.BlameResult, error) {
blame, ok := g.BlameByFile.Load(filePath)
if ok {
Expand All @@ -164,13 +178,13 @@ func (g *GitService) GetFileBlame(filePath string) (*git.BlameResult, error) {
if err != nil {
return nil, fmt.Errorf("failed to get previous commit: %s", err)
}
blame, err = git.Blame(selectedCommit, relativeFilePath)
blame, err = wrapGitBlame(selectedCommit, relativeFilePath)
if err != nil {
return nil, fmt.Errorf("failed to get blame for latest commit of file %s because of error %s", filePath, err)
return nil, err
}
previousBlame, err := git.Blame(previousCommit, relativeFilePath)
previousBlame, err := wrapGitBlame(previousCommit, relativeFilePath)
if err != nil {
return nil, fmt.Errorf("failed to get blame for latest commit of file %s because of error %s", filePath, err)
return nil, err
}
g.BlameByFile.Store(filePath, blame)
g.PreviousBlameByFile.Store(filePath, previousBlame)
Expand Down

0 comments on commit 1089971

Please sign in to comment.