@@ -437,30 +437,23 @@ func ViewPullCommits(ctx *context.Context) {
437437 pull := issue .PullRequest
438438
439439 var commits * list.List
440+ var prInfo * git.CompareInfo
440441 if pull .HasMerged {
441- prInfo := PrepareMergedViewPullInfo (ctx , issue )
442- if ctx .Written () {
443- return
444- } else if prInfo == nil {
445- ctx .NotFound ("ViewPullCommits" , nil )
446- return
447- }
448- ctx .Data ["Username" ] = ctx .Repo .Owner .Name
449- ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
450- commits = prInfo .Commits
442+ prInfo = PrepareMergedViewPullInfo (ctx , issue )
451443 } else {
452- prInfo := PrepareViewPullInfo (ctx , issue )
453- if ctx .Written () {
454- return
455- } else if prInfo == nil {
456- ctx .NotFound ("ViewPullCommits" , nil )
457- return
458- }
459- ctx .Data ["Username" ] = pull .MustHeadUserName ()
460- ctx .Data ["Reponame" ] = pull .HeadRepo .Name
461- commits = prInfo .Commits
444+ prInfo = PrepareViewPullInfo (ctx , issue )
462445 }
463446
447+ if ctx .Written () {
448+ return
449+ } else if prInfo == nil {
450+ ctx .NotFound ("ViewPullCommits" , nil )
451+ return
452+ }
453+
454+ ctx .Data ["Username" ] = ctx .Repo .Owner .Name
455+ ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
456+ commits = prInfo .Commits
464457 commits = models .ValidateCommitsWithEmails (commits )
465458 commits = models .ParseCommitsWithSignature (commits )
466459 commits = models .ParseCommitsWithStatus (commits , ctx .Repo .Repository )
@@ -495,63 +488,35 @@ func ViewPullFiles(ctx *context.Context) {
495488 )
496489
497490 var headTarget string
491+ var prInfo * git.CompareInfo
498492 if pull .HasMerged {
499- prInfo := PrepareMergedViewPullInfo (ctx , issue )
500- if ctx .Written () {
501- return
502- } else if prInfo == nil {
503- ctx .NotFound ("ViewPullFiles" , nil )
504- return
505- }
506-
507- diffRepoPath = ctx .Repo .GitRepo .Path
508- gitRepo = ctx .Repo .GitRepo
509-
510- headCommitID , err := gitRepo .GetRefCommitID (pull .GetGitRefName ())
511- if err != nil {
512- ctx .ServerError ("GetRefCommitID" , err )
513- return
514- }
515-
516- startCommitID = prInfo .MergeBase
517- endCommitID = headCommitID
518-
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
493+ prInfo = PrepareMergedViewPullInfo (ctx , issue )
522494 } else {
523- prInfo := PrepareViewPullInfo (ctx , issue )
524- if ctx .Written () {
525- return
526- } else if prInfo == nil {
527- ctx .NotFound ("ViewPullFiles" , nil )
528- return
529- }
495+ prInfo = PrepareViewPullInfo (ctx , issue )
496+ }
530497
531- headRepoPath := pull .HeadRepo .RepoPath ()
498+ if ctx .Written () {
499+ return
500+ } else if prInfo == nil {
501+ ctx .NotFound ("ViewPullFiles" , nil )
502+ return
503+ }
532504
533- headGitRepo , err := git .OpenRepository (headRepoPath )
534- if err != nil {
535- ctx .ServerError ("OpenRepository" , err )
536- return
537- }
538- defer headGitRepo .Close ()
505+ diffRepoPath = ctx .Repo .GitRepo .Path
506+ gitRepo = ctx .Repo .GitRepo
539507
540- headCommitID , err := headGitRepo . GetBranchCommitID (pull .HeadBranch )
541- if err != nil {
542- ctx .ServerError ("GetBranchCommitID " , err )
543- return
544- }
508+ headCommitID , err := gitRepo . GetRefCommitID (pull .GetGitRefName () )
509+ if err != nil {
510+ ctx .ServerError ("GetRefCommitID " , err )
511+ return
512+ }
545513
546- diffRepoPath = headRepoPath
547- startCommitID = prInfo .MergeBase
548- endCommitID = headCommitID
549- gitRepo = headGitRepo
514+ startCommitID = prInfo .MergeBase
515+ endCommitID = headCommitID
550516
551- headTarget = path .Join (pull .MustHeadUserName (), pull .HeadRepo .Name )
552- ctx .Data ["Username" ] = pull .MustHeadUserName ()
553- ctx .Data ["Reponame" ] = pull .HeadRepo .Name
554- }
517+ headTarget = path .Join (ctx .Repo .Owner .Name , ctx .Repo .Repository .Name )
518+ ctx .Data ["Username" ] = ctx .Repo .Owner .Name
519+ ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
555520 ctx .Data ["AfterCommitID" ] = endCommitID
556521
557522 diff , err := gitdiff .GetDiffRangeWithWhitespaceBehavior (diffRepoPath ,
0 commit comments