@@ -414,26 +414,19 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
414
414
if rootRepo != nil &&
415
415
rootRepo .ID != ci .HeadRepo .ID &&
416
416
rootRepo .ID != baseRepo .ID {
417
- if ! fileOnly {
418
- perm , branches , tags , err := getBranchesAndTagsForRepo (ctx .User , rootRepo )
419
- if err != nil {
420
- ctx .ServerError ("GetBranchesForRepo" , err )
421
- return nil
422
- }
423
- if perm {
424
- ctx .Data ["RootRepo" ] = rootRepo
417
+ canRead := rootRepo .CheckUnitUser (ctx .User , models .UnitTypeCode )
418
+ if canRead {
419
+ ctx .Data ["RootRepo" ] = rootRepo
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
+
425
427
ctx .Data ["RootRepoBranches" ] = branches
426
428
ctx .Data ["RootRepoTags" ] = tags
427
429
}
428
- } else {
429
- perm , err := models .GetUserRepoPermission (rootRepo , ctx .User )
430
- if err != nil {
431
- ctx .ServerError ("GetUserRepoPermission" , err )
432
- return nil
433
- }
434
- if perm .CanRead (models .UnitTypeCode ) {
435
- ctx .Data ["RootRepo" ] = rootRepo
436
- }
437
430
}
438
431
}
439
432
@@ -446,26 +439,18 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
446
439
ownForkRepo .ID != ci .HeadRepo .ID &&
447
440
ownForkRepo .ID != baseRepo .ID &&
448
441
(rootRepo == nil || ownForkRepo .ID != rootRepo .ID ) {
449
- if ! fileOnly {
450
- perm , branches , tags , err := getBranchesAndTagsForRepo (ctx .User , ownForkRepo )
451
- if err != nil {
452
- ctx .ServerError ("GetBranchesForRepo" , err )
453
- return nil
454
- }
455
- if perm {
456
- ctx .Data ["OwnForkRepo" ] = ownForkRepo
442
+ canRead := ownForkRepo .CheckUnitUser (ctx .User , models .UnitTypeCode )
443
+ if canRead {
444
+ ctx .Data ["OwnForkRepo" ] = ownForkRepo
445
+ if ! fileOnly {
446
+ branches , tags , err := getBranchesAndTagsForRepo (ctx .User , ownForkRepo )
447
+ if err != nil {
448
+ ctx .ServerError ("GetBranchesForRepo" , err )
449
+ return nil
450
+ }
457
451
ctx .Data ["OwnForkRepoBranches" ] = branches
458
452
ctx .Data ["OwnForkRepoTags" ] = tags
459
453
}
460
- } else {
461
- perm , err := models .GetUserRepoPermission (ownForkRepo , ctx .User )
462
- if err != nil {
463
- ctx .ServerError ("GetUserRepoPermission" , err )
464
- return nil
465
- }
466
- if perm .CanRead (models .UnitTypeCode ) {
467
- ctx .Data ["OwnForkRepo" ] = ownForkRepo
468
- }
469
454
}
470
455
}
471
456
@@ -631,29 +616,22 @@ func PrepareCompareDiff(
631
616
return false
632
617
}
633
618
634
- func getBranchesAndTagsForRepo (user * models.User , repo * models.Repository ) (bool , []string , []string , error ) {
635
- perm , err := models .GetUserRepoPermission (repo , user )
636
- if err != nil {
637
- return false , nil , nil , err
638
- }
639
- if ! perm .CanRead (models .UnitTypeCode ) {
640
- return false , nil , nil , nil
641
- }
619
+ func getBranchesAndTagsForRepo (user * models.User , repo * models.Repository ) (branches , tags []string , err error ) {
642
620
gitRepo , err := git .OpenRepository (repo .RepoPath ())
643
621
if err != nil {
644
- return false , nil , nil , err
622
+ return nil , nil , err
645
623
}
646
624
defer gitRepo .Close ()
647
625
648
- branches , _ , err : = gitRepo .GetBranches (0 , 0 )
626
+ branches , _ , err = gitRepo .GetBranches (0 , 0 )
649
627
if err != nil {
650
- return false , nil , nil , err
628
+ return nil , nil , err
651
629
}
652
- tags , err : = gitRepo .GetTags (0 , 0 )
630
+ tags , err = gitRepo .GetTags (0 , 0 )
653
631
if err != nil {
654
- return false , nil , nil , err
632
+ return nil , nil , err
655
633
}
656
- return true , branches , tags , nil
634
+ return branches , tags , nil
657
635
}
658
636
659
637
// CompareDiff show different from one commit to another commit
0 commit comments