Skip to content

Commit f0c74fb

Browse files
Fix diff calculation when using sqlite.
1 parent 99487dd commit f0c74fb

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

services/convert/pull.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
171171
return nil
172172
}
173173

174+
// Outer scope variables to be used in diff calculation
175+
var (
176+
startCommitID string
177+
endCommitID string
178+
)
179+
174180
if git.IsErrBranchNotExist(err) {
175181
headCommitID, err := headGitRepo.GetRefCommitID(apiPullRequest.Head.Ref)
176182
if err != nil && !git.IsErrNotExist(err) {
@@ -179,6 +185,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
179185
}
180186
if err == nil {
181187
apiPullRequest.Head.Sha = headCommitID
188+
endCommitID = headCommitID
182189
}
183190
} else {
184191
commit, err := headBranch.GetCommit()
@@ -189,24 +196,20 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
189196
if err == nil {
190197
apiPullRequest.Head.Ref = pr.HeadBranch
191198
apiPullRequest.Head.Sha = commit.ID.String()
199+
endCommitID = commit.ID.String()
192200
}
193201
}
194202

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
202205

203206
// FIXME: If there are too many files in the repo, may cause some unpredictable issues.
204207
diff, err := gitdiff.GetDiff(ctx, gitRepo,
205208
&gitdiff.DiffOptions{
206209
BeforeCommitID: startCommitID,
207210
AfterCommitID: endCommitID,
208211
SkipTo: "", // ctx.FormString("skip-to"),
209-
MaxLines: maxLines,
212+
MaxLines: setting.Git.MaxGitDiffLines,
210213
MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters,
211214
MaxFiles: -1, // GetDiff() will return all files
212215
WhitespaceBehavior: gitdiff.GetWhitespaceFlag("show-all"),

0 commit comments

Comments
 (0)