@ -392,7 +392,7 @@ func (c *Comment) checkInvalidation(e Engine, doer *User, repo *git.Repository,
if err != nil {
if err != nil {
return err
return err
}
}
if c . CommitSHA != commit . ID . String ( ) {
if c . CommitSHA != "" && c . CommitSHA != commit . ID . String ( ) {
c . Invalidated = true
c . Invalidated = true
return UpdateComment ( doer , c , "" )
return UpdateComment ( doer , c , "" )
}
}
@ -824,17 +824,18 @@ func CreateCodeComment(doer *User, repo *Repository, issue *Issue, content, tree
if err != nil {
if err != nil {
return nil , fmt . Errorf ( "OpenRepository: %v" , err )
return nil , fmt . Errorf ( "OpenRepository: %v" , err )
}
}
// FIXME differentiate between previous and proposed line
var gitLine = line
if gitLine < 0 {
gitLine *= - 1
}
// FIXME validate treePath
// FIXME validate treePath
// Get latest commit referencing the commented line
// Get latest commit referencing the commented line
commit , err := gitRepo . LineBlame ( pr . GetGitRefName ( ) , gitRepo . Path , treePath , uint ( gitLine ) )
// No need for get commit for base branch changes
if line > 0 {
commit , err := gitRepo . LineBlame ( pr . GetGitRefName ( ) , gitRepo . Path , treePath , uint ( line ) )
if err != nil {
if err != nil {
return nil , fmt . Errorf ( "LineBlame[%s, %s, %s, %d]: %v" , pr . GetGitRefName ( ) , gitRepo . Path , treePath , gitLine , err )
return nil , fmt . Errorf ( "LineBlame[%s, %s, %s, %d]: %v" , pr . GetGitRefName ( ) , gitRepo . Path , treePath , l ine, err )
}
}
commitID = commit . ID . String ( )
}
// Only fetch diff if comment is review comment
// Only fetch diff if comment is review comment
if reviewID != 0 {
if reviewID != 0 {
headCommitID , err := gitRepo . GetRefCommitID ( pr . GetGitRefName ( ) )
headCommitID , err := gitRepo . GetRefCommitID ( pr . GetGitRefName ( ) )
@ -846,7 +847,6 @@ func CreateCodeComment(doer *User, repo *Repository, issue *Issue, content, tree
return nil , fmt . Errorf ( "GetRawDiffForLine[%s, %s, %s, %s]: %v" , err , gitRepo . Path , pr . MergeBase , headCommitID , treePath )
return nil , fmt . Errorf ( "GetRawDiffForLine[%s, %s, %s, %s]: %v" , err , gitRepo . Path , pr . MergeBase , headCommitID , treePath )
}
}
patch = CutDiffAroundLine ( strings . NewReader ( patchBuf . String ( ) ) , int64 ( ( & Comment { Line : line } ) . UnsignedLine ( ) ) , line < 0 , setting . UI . CodeCommentLines )
patch = CutDiffAroundLine ( strings . NewReader ( patchBuf . String ( ) ) , int64 ( ( & Comment { Line : line } ) . UnsignedLine ( ) ) , line < 0 , setting . UI . CodeCommentLines )
commitID = commit . ID . String ( )
}
}
return CreateComment ( & CreateCommentOptions {
return CreateComment ( & CreateCommentOptions {
Type : CommentTypeCode ,
Type : CommentTypeCode ,