@@ -438,30 +438,23 @@ func ViewPullCommits(ctx *context.Context) {
438
438
pull := issue .PullRequest
439
439
440
440
var commits * list.List
441
+ var prInfo * git.CompareInfo
441
442
if pull .HasMerged {
442
- prInfo := PrepareMergedViewPullInfo (ctx , issue )
443
- if ctx .Written () {
444
- return
445
- } else if prInfo == nil {
446
- ctx .NotFound ("ViewPullCommits" , nil )
447
- return
448
- }
449
- ctx .Data ["Username" ] = ctx .Repo .Owner .Name
450
- ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
451
- commits = prInfo .Commits
443
+ prInfo = PrepareMergedViewPullInfo (ctx , issue )
452
444
} else {
453
- prInfo := PrepareViewPullInfo (ctx , issue )
454
- if ctx .Written () {
455
- return
456
- } else if prInfo == nil {
457
- ctx .NotFound ("ViewPullCommits" , nil )
458
- return
459
- }
460
- ctx .Data ["Username" ] = pull .MustHeadUserName ()
461
- ctx .Data ["Reponame" ] = pull .HeadRepo .Name
462
- commits = prInfo .Commits
445
+ prInfo = PrepareViewPullInfo (ctx , issue )
463
446
}
464
447
448
+ if ctx .Written () {
449
+ return
450
+ } else if prInfo == nil {
451
+ ctx .NotFound ("ViewPullCommits" , nil )
452
+ return
453
+ }
454
+
455
+ ctx .Data ["Username" ] = ctx .Repo .Owner .Name
456
+ ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
457
+ commits = prInfo .Commits
465
458
commits = models .ValidateCommitsWithEmails (commits )
466
459
commits = models .ParseCommitsWithSignature (commits )
467
460
commits = models .ParseCommitsWithStatus (commits , ctx .Repo .Repository )
@@ -497,63 +490,35 @@ func ViewPullFiles(ctx *context.Context) {
497
490
)
498
491
499
492
var headTarget string
493
+ var prInfo * git.CompareInfo
500
494
if pull .HasMerged {
501
- prInfo := PrepareMergedViewPullInfo (ctx , issue )
502
- if ctx .Written () {
503
- return
504
- } else if prInfo == nil {
505
- ctx .NotFound ("ViewPullFiles" , nil )
506
- return
507
- }
508
-
509
- diffRepoPath = ctx .Repo .GitRepo .Path
510
- gitRepo = ctx .Repo .GitRepo
511
-
512
- headCommitID , err := gitRepo .GetRefCommitID (pull .GetGitRefName ())
513
- if err != nil {
514
- ctx .ServerError ("GetRefCommitID" , err )
515
- return
516
- }
517
-
518
- startCommitID = prInfo .MergeBase
519
- endCommitID = headCommitID
520
-
521
- headTarget = path .Join (ctx .Repo .Owner .Name , ctx .Repo .Repository .Name )
522
- ctx .Data ["Username" ] = ctx .Repo .Owner .Name
523
- ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
495
+ prInfo = PrepareMergedViewPullInfo (ctx , issue )
524
496
} else {
525
- prInfo := PrepareViewPullInfo (ctx , issue )
526
- if ctx .Written () {
527
- return
528
- } else if prInfo == nil {
529
- ctx .NotFound ("ViewPullFiles" , nil )
530
- return
531
- }
497
+ prInfo = PrepareViewPullInfo (ctx , issue )
498
+ }
532
499
533
- headRepoPath := pull .HeadRepo .RepoPath ()
500
+ if ctx .Written () {
501
+ return
502
+ } else if prInfo == nil {
503
+ ctx .NotFound ("ViewPullFiles" , nil )
504
+ return
505
+ }
534
506
535
- headGitRepo , err := git .OpenRepository (headRepoPath )
536
- if err != nil {
537
- ctx .ServerError ("OpenRepository" , err )
538
- return
539
- }
540
- defer headGitRepo .Close ()
507
+ diffRepoPath = ctx .Repo .GitRepo .Path
508
+ gitRepo = ctx .Repo .GitRepo
541
509
542
- headCommitID , err := headGitRepo . GetBranchCommitID (pull .HeadBranch )
543
- if err != nil {
544
- ctx .ServerError ("GetBranchCommitID " , err )
545
- return
546
- }
510
+ headCommitID , err := gitRepo . GetRefCommitID (pull .GetGitRefName () )
511
+ if err != nil {
512
+ ctx .ServerError ("GetRefCommitID " , err )
513
+ return
514
+ }
547
515
548
- diffRepoPath = headRepoPath
549
- startCommitID = prInfo .MergeBase
550
- endCommitID = headCommitID
551
- gitRepo = headGitRepo
516
+ startCommitID = prInfo .MergeBase
517
+ endCommitID = headCommitID
552
518
553
- headTarget = path .Join (pull .MustHeadUserName (), pull .HeadRepo .Name )
554
- ctx .Data ["Username" ] = pull .MustHeadUserName ()
555
- ctx .Data ["Reponame" ] = pull .HeadRepo .Name
556
- }
519
+ headTarget = path .Join (ctx .Repo .Owner .Name , ctx .Repo .Repository .Name )
520
+ ctx .Data ["Username" ] = ctx .Repo .Owner .Name
521
+ ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
557
522
ctx .Data ["AfterCommitID" ] = endCommitID
558
523
559
524
diff , err := gitdiff .GetDiffRangeWithWhitespaceBehavior (diffRepoPath ,
0 commit comments