@@ -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.
@@ -161,6 +162,8 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
161
162
baseRepo := ctx .Repo .Repository
162
163
ci := & CompareInfo {}
163
164
165
+ fileOnly := ctx .FormBool ("file-only" )
166
+
164
167
// Get compared branches information
165
168
// A full compare url is of the form:
166
169
//
@@ -411,15 +414,19 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
411
414
if rootRepo != nil &&
412
415
rootRepo .ID != ci .HeadRepo .ID &&
413
416
rootRepo .ID != baseRepo .ID {
414
- perm , branches , tags , err := getBranchesAndTagsForRepo (ctx .User , rootRepo )
415
- if err != nil {
416
- ctx .ServerError ("GetBranchesForRepo" , err )
417
- return nil
418
- }
419
- if perm {
417
+ canRead := rootRepo .CheckUnitUser (ctx .User , models .UnitTypeCode )
418
+ if canRead {
420
419
ctx .Data ["RootRepo" ] = rootRepo
421
- ctx .Data ["RootRepoBranches" ] = branches
422
- ctx .Data ["RootRepoTags" ] = tags
420
+ if ! fileOnly {
421
+ branches , tags , err := getBranchesAndTagsForRepo (ctx .User , rootRepo )
422
+ if err != nil {
423
+ ctx .ServerError ("GetBranchesForRepo" , err )
424
+ return nil
425
+ }
426
+
427
+ ctx .Data ["RootRepoBranches" ] = branches
428
+ ctx .Data ["RootRepoTags" ] = tags
429
+ }
423
430
}
424
431
}
425
432
@@ -432,15 +439,18 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
432
439
ownForkRepo .ID != ci .HeadRepo .ID &&
433
440
ownForkRepo .ID != baseRepo .ID &&
434
441
(rootRepo == nil || ownForkRepo .ID != rootRepo .ID ) {
435
- perm , branches , tags , err := getBranchesAndTagsForRepo (ctx .User , ownForkRepo )
436
- if err != nil {
437
- ctx .ServerError ("GetBranchesForRepo" , err )
438
- return nil
439
- }
440
- if perm {
442
+ canRead := ownForkRepo .CheckUnitUser (ctx .User , models .UnitTypeCode )
443
+ if canRead {
441
444
ctx .Data ["OwnForkRepo" ] = ownForkRepo
442
- ctx .Data ["OwnForkRepoBranches" ] = branches
443
- ctx .Data ["OwnForkRepoTags" ] = tags
445
+ if ! fileOnly {
446
+ branches , tags , err := getBranchesAndTagsForRepo (ctx .User , ownForkRepo )
447
+ if err != nil {
448
+ ctx .ServerError ("GetBranchesForRepo" , err )
449
+ return nil
450
+ }
451
+ ctx .Data ["OwnForkRepoBranches" ] = branches
452
+ ctx .Data ["OwnForkRepoTags" ] = tags
453
+ }
444
454
}
445
455
}
446
456
@@ -492,7 +502,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
492
502
headBranchRef = git .TagPrefix + ci .HeadBranch
493
503
}
494
504
495
- ci .CompareInfo , err = ci .HeadGitRepo .GetCompareInfo (baseRepo .RepoPath (), baseBranchRef , headBranchRef , ci .DirectComparison )
505
+ ci .CompareInfo , err = ci .HeadGitRepo .GetCompareInfo (baseRepo .RepoPath (), baseBranchRef , headBranchRef , ci .DirectComparison , fileOnly )
496
506
if err != nil {
497
507
ctx .ServerError ("GetCompareInfo" , err )
498
508
return nil
@@ -545,7 +555,7 @@ func PrepareCompareDiff(
545
555
}
546
556
547
557
diff , err := gitdiff .GetDiffRangeWithWhitespaceBehavior (ci .HeadGitRepo ,
548
- beforeCommitID , headCommitID , setting .Git .MaxGitDiffLines ,
558
+ beforeCommitID , headCommitID , ctx . FormString ( "skip-to" ), setting .Git .MaxGitDiffLines ,
549
559
setting .Git .MaxGitDiffLineCharacters , setting .Git .MaxGitDiffFiles , whitespaceBehavior , ci .DirectComparison )
550
560
if err != nil {
551
561
ctx .ServerError ("GetDiffRangeWithWhitespaceBehavior" , err )
@@ -606,29 +616,22 @@ func PrepareCompareDiff(
606
616
return false
607
617
}
608
618
609
- func getBranchesAndTagsForRepo (user * models.User , repo * models.Repository ) (bool , []string , []string , error ) {
610
- perm , err := models .GetUserRepoPermission (repo , user )
611
- if err != nil {
612
- return false , nil , nil , err
613
- }
614
- if ! perm .CanRead (models .UnitTypeCode ) {
615
- return false , nil , nil , nil
616
- }
619
+ func getBranchesAndTagsForRepo (user * models.User , repo * models.Repository ) (branches , tags []string , err error ) {
617
620
gitRepo , err := git .OpenRepository (repo .RepoPath ())
618
621
if err != nil {
619
- return false , nil , nil , err
622
+ return nil , nil , err
620
623
}
621
624
defer gitRepo .Close ()
622
625
623
- branches , _ , err : = gitRepo .GetBranches (0 , 0 )
626
+ branches , _ , err = gitRepo .GetBranches (0 , 0 )
624
627
if err != nil {
625
- return false , nil , nil , err
628
+ return nil , nil , err
626
629
}
627
- tags , err : = gitRepo .GetTags (0 , 0 )
630
+ tags , err = gitRepo .GetTags (0 , 0 )
628
631
if err != nil {
629
- return false , nil , nil , err
632
+ return nil , nil , err
630
633
}
631
- return true , branches , tags , nil
634
+ return branches , tags , nil
632
635
}
633
636
634
637
// CompareDiff show different from one commit to another commit
@@ -665,6 +668,12 @@ func CompareDiff(ctx *context.Context) {
665
668
}
666
669
ctx .Data ["Tags" ] = baseTags
667
670
671
+ fileOnly := ctx .FormBool ("file-only" )
672
+ if fileOnly {
673
+ ctx .HTML (http .StatusOK , tplDiffBox )
674
+ return
675
+ }
676
+
668
677
headBranches , _ , err := ci .HeadGitRepo .GetBranches (0 , 0 )
669
678
if err != nil {
670
679
ctx .ServerError ("GetBranches" , err )
0 commit comments