@@ -31,6 +31,7 @@ import (
3131const (
3232 tplCompare base.TplName = "repo/diff/compare"
3333 tplBlobExcerpt base.TplName = "repo/diff/blob_excerpt"
34+ tplDiffBox base.TplName = "repo/diff/box"
3435)
3536
3637// setCompareContext sets context data.
@@ -149,6 +150,8 @@ func setCsvCompareContext(ctx *context.Context) {
149150func ParseCompareInfo (ctx * context.Context ) (* models.User , * models.Repository , * git.Repository , * git.CompareInfo , string , string ) {
150151 baseRepo := ctx .Repo .Repository
151152
153+ fileOnly := ctx .FormBool ("file-only" )
154+
152155 // Get compared branches information
153156 // A full compare url is of the form:
154157 //
@@ -395,15 +398,26 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
395398 if rootRepo != nil &&
396399 rootRepo .ID != headRepo .ID &&
397400 rootRepo .ID != baseRepo .ID {
398- perm , branches , tags , err := getBranchesAndTagsForRepo (ctx .User , rootRepo )
399- if err != nil {
400- ctx .ServerError ("GetBranchesForRepo" , err )
401- return nil , nil , nil , nil , "" , ""
402- }
403- if perm {
404- ctx .Data ["RootRepo" ] = rootRepo
405- ctx .Data ["RootRepoBranches" ] = branches
406- ctx .Data ["RootRepoTags" ] = tags
401+ if ! fileOnly {
402+ perm , branches , tags , err := getBranchesAndTagsForRepo (ctx .User , rootRepo )
403+ if err != nil {
404+ ctx .ServerError ("GetBranchesForRepo" , err )
405+ return nil , nil , nil , nil , "" , ""
406+ }
407+ if perm {
408+ ctx .Data ["RootRepo" ] = rootRepo
409+ ctx .Data ["RootRepoBranches" ] = branches
410+ ctx .Data ["RootRepoTags" ] = tags
411+ }
412+ } else {
413+ perm , err := models .GetUserRepoPermission (rootRepo , ctx .User )
414+ if err != nil {
415+ ctx .ServerError ("GetUserRepoPermission" , err )
416+ return nil , nil , nil , nil , "" , ""
417+ }
418+ if ! perm .CanRead (models .UnitTypeCode ) {
419+ ctx .Data ["RootRepo" ] = rootRepo
420+ }
407421 }
408422 }
409423
@@ -416,15 +430,26 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
416430 ownForkRepo .ID != headRepo .ID &&
417431 ownForkRepo .ID != baseRepo .ID &&
418432 (rootRepo == nil || ownForkRepo .ID != rootRepo .ID ) {
419- perm , branches , tags , err := getBranchesAndTagsForRepo (ctx .User , ownForkRepo )
420- if err != nil {
421- ctx .ServerError ("GetBranchesForRepo" , err )
422- return nil , nil , nil , nil , "" , ""
423- }
424- if perm {
425- ctx .Data ["OwnForkRepo" ] = ownForkRepo
426- ctx .Data ["OwnForkRepoBranches" ] = branches
427- ctx .Data ["OwnForkRepoTags" ] = tags
433+ if ! fileOnly {
434+ perm , branches , tags , err := getBranchesAndTagsForRepo (ctx .User , ownForkRepo )
435+ if err != nil {
436+ ctx .ServerError ("GetBranchesForRepo" , err )
437+ return nil , nil , nil , nil , "" , ""
438+ }
439+ if perm {
440+ ctx .Data ["OwnForkRepo" ] = ownForkRepo
441+ ctx .Data ["OwnForkRepoBranches" ] = branches
442+ ctx .Data ["OwnForkRepoTags" ] = tags
443+ }
444+ } else {
445+ perm , err := models .GetUserRepoPermission (rootRepo , ctx .User )
446+ if err != nil {
447+ ctx .ServerError ("GetUserRepoPermission" , err )
448+ return nil , nil , nil , nil , "" , ""
449+ }
450+ if ! perm .CanRead (models .UnitTypeCode ) {
451+ ctx .Data ["RootRepo" ] = rootRepo
452+ }
428453 }
429454 }
430455
@@ -476,7 +501,7 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
476501 headBranchRef = git .TagPrefix + headBranch
477502 }
478503
479- compareInfo , err := headGitRepo .GetCompareInfo (baseRepo .RepoPath (), baseBranchRef , headBranchRef )
504+ compareInfo , err := headGitRepo .GetCompareInfo (baseRepo .RepoPath (), baseBranchRef , headBranchRef , fileOnly )
480505 if err != nil {
481506 ctx .ServerError ("GetCompareInfo" , err )
482507 return nil , nil , nil , nil , "" , ""
@@ -527,7 +552,7 @@ func PrepareCompareDiff(
527552 }
528553
529554 diff , err := gitdiff .GetDiffRangeWithWhitespaceBehavior (headGitRepo ,
530- compareInfo .MergeBase , headCommitID , setting .Git .MaxGitDiffLines ,
555+ compareInfo .MergeBase , headCommitID , ctx . FormString ( "skip-to" ), setting .Git .MaxGitDiffLines ,
531556 setting .Git .MaxGitDiffLineCharacters , setting .Git .MaxGitDiffFiles , whitespaceBehavior )
532557 if err != nil {
533558 ctx .ServerError ("GetDiffRangeWithWhitespaceBehavior" , err )
@@ -639,6 +664,12 @@ func CompareDiff(ctx *context.Context) {
639664 }
640665 ctx .Data ["Tags" ] = baseTags
641666
667+ fileOnly := ctx .FormBool ("file-only" )
668+ if fileOnly {
669+ ctx .HTML (http .StatusOK , tplDiffBox )
670+ return
671+ }
672+
642673 headBranches , _ , err := headGitRepo .GetBranches (0 , 0 )
643674 if err != nil {
644675 ctx .ServerError ("GetBranches" , err )
0 commit comments