@@ -171,6 +171,12 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
171
171
return nil
172
172
}
173
173
174
+ // Outer scope variables to be used in diff calculation
175
+ var (
176
+ startCommitID string
177
+ endCommitID string
178
+ )
179
+
174
180
if git .IsErrBranchNotExist (err ) {
175
181
headCommitID , err := headGitRepo .GetRefCommitID (apiPullRequest .Head .Ref )
176
182
if err != nil && ! git .IsErrNotExist (err ) {
@@ -179,6 +185,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
179
185
}
180
186
if err == nil {
181
187
apiPullRequest .Head .Sha = headCommitID
188
+ endCommitID = headCommitID
182
189
}
183
190
} else {
184
191
commit , err := headBranch .GetCommit ()
@@ -189,24 +196,20 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
189
196
if err == nil {
190
197
apiPullRequest .Head .Ref = pr .HeadBranch
191
198
apiPullRequest .Head .Sha = commit .ID .String ()
199
+ endCommitID = commit .ID .String ()
192
200
}
193
201
}
194
202
195
- startCommitID := pr .MergeBase
196
- endCommitID , err := headGitRepo .GetRefCommitID (apiPullRequest .Head .Ref )
197
- if err != nil {
198
- log .Error ("GetRefCommitID[%s]: %v" , apiPullRequest .Head .Ref , err )
199
- }
200
-
201
- maxLines := setting .Git .MaxGitDiffLines
203
+ // Calcuate diff
204
+ startCommitID = pr .MergeBase
202
205
203
206
// FIXME: If there are too many files in the repo, may cause some unpredictable issues.
204
207
diff , err := gitdiff .GetDiff (ctx , gitRepo ,
205
208
& gitdiff.DiffOptions {
206
209
BeforeCommitID : startCommitID ,
207
210
AfterCommitID : endCommitID ,
208
211
SkipTo : "" , // ctx.FormString("skip-to"),
209
- MaxLines : maxLines ,
212
+ MaxLines : setting . Git . MaxGitDiffLines ,
210
213
MaxLineCharacters : setting .Git .MaxGitDiffLineCharacters ,
211
214
MaxFiles : - 1 , // GetDiff() will return all files
212
215
WhitespaceBehavior : gitdiff .GetWhitespaceFlag ("show-all" ),
0 commit comments