@@ -31,6 +31,7 @@ import (
31
31
const (
32
32
tplCompare base.TplName = "repo/diff/compare"
33
33
tplBlobExcerpt base.TplName = "repo/diff/blob_excerpt"
34
+ tplDiffBox base.TplName = "repo/diff/box"
34
35
)
35
36
36
37
// setCompareContext sets context data.
@@ -149,6 +150,8 @@ func setCsvCompareContext(ctx *context.Context) {
149
150
func ParseCompareInfo (ctx * context.Context ) (* models.User , * models.Repository , * git.Repository , * git.CompareInfo , string , string ) {
150
151
baseRepo := ctx .Repo .Repository
151
152
153
+ fileOnly := ctx .FormBool ("file-only" )
154
+
152
155
// Get compared branches information
153
156
// A full compare url is of the form:
154
157
//
@@ -395,15 +398,26 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
395
398
if rootRepo != nil &&
396
399
rootRepo .ID != headRepo .ID &&
397
400
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
+ }
407
421
}
408
422
}
409
423
@@ -416,15 +430,26 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
416
430
ownForkRepo .ID != headRepo .ID &&
417
431
ownForkRepo .ID != baseRepo .ID &&
418
432
(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
+ }
428
453
}
429
454
}
430
455
@@ -476,7 +501,7 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
476
501
headBranchRef = git .TagPrefix + headBranch
477
502
}
478
503
479
- compareInfo , err := headGitRepo .GetCompareInfo (baseRepo .RepoPath (), baseBranchRef , headBranchRef )
504
+ compareInfo , err := headGitRepo .GetCompareInfo (baseRepo .RepoPath (), baseBranchRef , headBranchRef , fileOnly )
480
505
if err != nil {
481
506
ctx .ServerError ("GetCompareInfo" , err )
482
507
return nil , nil , nil , nil , "" , ""
@@ -527,7 +552,7 @@ func PrepareCompareDiff(
527
552
}
528
553
529
554
diff , err := gitdiff .GetDiffRangeWithWhitespaceBehavior (headGitRepo ,
530
- compareInfo .MergeBase , headCommitID , setting .Git .MaxGitDiffLines ,
555
+ compareInfo .MergeBase , headCommitID , ctx . FormString ( "skip-to" ), setting .Git .MaxGitDiffLines ,
531
556
setting .Git .MaxGitDiffLineCharacters , setting .Git .MaxGitDiffFiles , whitespaceBehavior )
532
557
if err != nil {
533
558
ctx .ServerError ("GetDiffRangeWithWhitespaceBehavior" , err )
@@ -639,6 +664,12 @@ func CompareDiff(ctx *context.Context) {
639
664
}
640
665
ctx .Data ["Tags" ] = baseTags
641
666
667
+ fileOnly := ctx .FormBool ("file-only" )
668
+ if fileOnly {
669
+ ctx .HTML (http .StatusOK , tplDiffBox )
670
+ return
671
+ }
672
+
642
673
headBranches , _ , err := headGitRepo .GetBranches (0 , 0 )
643
674
if err != nil {
644
675
ctx .ServerError ("GetBranches" , err )
0 commit comments