diff options
author | Jimmy Praet <jimmy.praet@telenet.be> | 2020-12-16 10:54:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-16 11:54:58 +0200 |
commit | e7a77d32cc96692f5dbbd3ed1cfa7ff4a9ba026b (patch) | |
tree | de0ec4792f813f34db8d2352aa61b609016570fc | |
parent | 88b585c2e08d43af705cec178c1c7771f5d66e70 (diff) | |
download | gitea-e7a77d32cc96692f5dbbd3ed1cfa7ff4a9ba026b.tar.gz gitea-e7a77d32cc96692f5dbbd3ed1cfa7ff4a9ba026b.zip |
Fix correct diff view for PR review comments in PR view page (#14002)
Fixes #13683.
The diff snippet that provides context for a code review comment on the pull request timeline page used to be calculated based on the headCommitID. But in 1.13, with PR #13448, this changed to the commitID from the blame for the commented line, which seems to cause these incorrect review comment diff snippets.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
-rw-r--r-- | services/pull/review.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/services/pull/review.go b/services/pull/review.go index f0ee234a42..6781136061 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -167,16 +167,16 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models // Only fetch diff if comment is review comment if len(patch) == 0 && reviewID != 0 { + headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName()) + if err != nil { + return nil, fmt.Errorf("GetRefCommitID[%s]: %v", pr.GetGitRefName(), err) + } if len(commitID) == 0 { - commitID, err = gitRepo.GetRefCommitID(pr.GetGitRefName()) - if err != nil { - return nil, fmt.Errorf("GetRefCommitID[%s]: %v", pr.GetGitRefName(), err) - } + commitID = headCommitID } - patchBuf := new(bytes.Buffer) - if err := git.GetRepoRawDiffForFile(gitRepo, pr.MergeBase, commitID, git.RawDiffNormal, treePath, patchBuf); err != nil { - return nil, fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %v", gitRepo.Path, pr.MergeBase, commitID, treePath, err) + if err := git.GetRepoRawDiffForFile(gitRepo, pr.MergeBase, headCommitID, git.RawDiffNormal, treePath, patchBuf); err != nil { + return nil, fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %v", gitRepo.Path, pr.MergeBase, headCommitID, treePath, err) } patch = git.CutDiffAroundLine(patchBuf, int64((&models.Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines) } |