@@ -362,30 +362,23 @@ func ViewPullCommits(ctx *context.Context) {
362
362
pull := issue .PullRequest
363
363
364
364
var commits * list.List
365
+ var prInfo * git.PullRequestInfo
365
366
if pull .HasMerged {
366
- prInfo := PrepareMergedViewPullInfo (ctx , issue )
367
- if ctx .Written () {
368
- return
369
- } else if prInfo == nil {
370
- ctx .NotFound ("ViewPullCommits" , nil )
371
- return
372
- }
373
- ctx .Data ["Username" ] = ctx .Repo .Owner .Name
374
- ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
375
- commits = prInfo .Commits
367
+ prInfo = PrepareMergedViewPullInfo (ctx , issue )
376
368
} else {
377
- prInfo := PrepareViewPullInfo (ctx , issue )
378
- if ctx .Written () {
379
- return
380
- } else if prInfo == nil {
381
- ctx .NotFound ("ViewPullCommits" , nil )
382
- return
383
- }
384
- ctx .Data ["Username" ] = pull .HeadUserName
385
- ctx .Data ["Reponame" ] = pull .HeadRepo .Name
386
- commits = prInfo .Commits
369
+ prInfo = PrepareViewPullInfo (ctx , issue )
387
370
}
388
371
372
+ if ctx .Written () {
373
+ return
374
+ } else if prInfo == nil {
375
+ ctx .NotFound ("ViewPullCommits" , nil )
376
+ return
377
+ }
378
+
379
+ ctx .Data ["Username" ] = ctx .Repo .Owner .Name
380
+ ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
381
+ commits = prInfo .Commits
389
382
commits = models .ValidateCommitsWithEmails (commits )
390
383
commits = models .ParseCommitsWithSignature (commits )
391
384
commits = models .ParseCommitsWithStatus (commits , ctx .Repo .Repository )
@@ -420,62 +413,35 @@ func ViewPullFiles(ctx *context.Context) {
420
413
)
421
414
422
415
var headTarget string
416
+ var prInfo * git.PullRequestInfo
423
417
if pull .HasMerged {
424
- prInfo := PrepareMergedViewPullInfo (ctx , issue )
425
- if ctx .Written () {
426
- return
427
- } else if prInfo == nil {
428
- ctx .NotFound ("ViewPullFiles" , nil )
429
- return
430
- }
431
-
432
- diffRepoPath = ctx .Repo .GitRepo .Path
433
- gitRepo = ctx .Repo .GitRepo
434
-
435
- headCommitID , err := gitRepo .GetRefCommitID (pull .GetGitRefName ())
436
- if err != nil {
437
- ctx .ServerError ("GetRefCommitID" , err )
438
- return
439
- }
440
-
441
- startCommitID = prInfo .MergeBase
442
- endCommitID = headCommitID
443
-
444
- headTarget = path .Join (ctx .Repo .Owner .Name , ctx .Repo .Repository .Name )
445
- ctx .Data ["Username" ] = ctx .Repo .Owner .Name
446
- ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
418
+ prInfo = PrepareMergedViewPullInfo (ctx , issue )
447
419
} else {
448
- prInfo := PrepareViewPullInfo (ctx , issue )
449
- if ctx .Written () {
450
- return
451
- } else if prInfo == nil {
452
- ctx .NotFound ("ViewPullFiles" , nil )
453
- return
454
- }
420
+ prInfo = PrepareViewPullInfo (ctx , issue )
421
+ }
455
422
456
- headRepoPath := models .RepoPath (pull .HeadUserName , pull .HeadRepo .Name )
423
+ if ctx .Written () {
424
+ return
425
+ } else if prInfo == nil {
426
+ ctx .NotFound ("ViewPullFiles" , nil )
427
+ return
428
+ }
457
429
458
- headGitRepo , err := git .OpenRepository (headRepoPath )
459
- if err != nil {
460
- ctx .ServerError ("OpenRepository" , err )
461
- return
462
- }
430
+ diffRepoPath = ctx .Repo .GitRepo .Path
431
+ gitRepo = ctx .Repo .GitRepo
463
432
464
- headCommitID , err := headGitRepo . GetBranchCommitID (pull .HeadBranch )
465
- if err != nil {
466
- ctx .ServerError ("GetBranchCommitID " , err )
467
- return
468
- }
433
+ headCommitID , err := gitRepo . GetRefCommitID (pull .GetGitRefName () )
434
+ if err != nil {
435
+ ctx .ServerError ("GetRefCommitID " , err )
436
+ return
437
+ }
469
438
470
- diffRepoPath = headRepoPath
471
- startCommitID = prInfo .MergeBase
472
- endCommitID = headCommitID
473
- gitRepo = headGitRepo
439
+ startCommitID = prInfo .MergeBase
440
+ endCommitID = headCommitID
474
441
475
- headTarget = path .Join (pull .HeadUserName , pull .HeadRepo .Name )
476
- ctx .Data ["Username" ] = pull .HeadUserName
477
- ctx .Data ["Reponame" ] = pull .HeadRepo .Name
478
- }
442
+ headTarget = path .Join (ctx .Repo .Owner .Name , ctx .Repo .Repository .Name )
443
+ ctx .Data ["Username" ] = ctx .Repo .Owner .Name
444
+ ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
479
445
480
446
diff , err := models .GetDiffRangeWithWhitespaceBehavior (diffRepoPath ,
481
447
startCommitID , endCommitID , setting .Git .MaxGitDiffLines ,
0 commit comments