@@ -152,12 +152,12 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
152
152
ctx .ServerError ("OpenRepository" , err )
153
153
return nil , nil , nil , nil , "" , ""
154
154
}
155
+ defer headGitRepo .Close ()
155
156
}
156
157
157
158
// user should have permission to read baseRepo's codes and pulls, NOT headRepo's
158
159
permBase , err := models .GetUserRepoPermission (baseRepo , ctx .User )
159
160
if err != nil {
160
- headGitRepo .Close ()
161
161
ctx .ServerError ("GetUserRepoPermission" , err )
162
162
return nil , nil , nil , nil , "" , ""
163
163
}
@@ -168,42 +168,40 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
168
168
baseRepo ,
169
169
permBase )
170
170
}
171
- headGitRepo .Close ()
172
171
ctx .NotFound ("ParseCompareInfo" , nil )
173
172
return nil , nil , nil , nil , "" , ""
174
173
}
175
174
176
- // user should have permission to read headrepo's codes
177
- permHead , err := models .GetUserRepoPermission (headRepo , ctx .User )
178
- if err != nil {
179
- headGitRepo .Close ()
180
- ctx .ServerError ("GetUserRepoPermission" , err )
181
- return nil , nil , nil , nil , "" , ""
182
- }
183
- if ! permHead .CanRead (models .UnitTypeCode ) {
184
- if log .IsTrace () {
185
- log .Trace ("Permission Denied: User: %-v cannot read code in Repo: %-v\n User in headRepo has Permissions: %-+v" ,
186
- ctx .User ,
187
- headRepo ,
188
- permHead )
175
+ if ! isSameRepo {
176
+ // user should have permission to read headrepo's codes
177
+ permHead , err := models .GetUserRepoPermission (headRepo , ctx .User )
178
+ if err != nil {
179
+ ctx .ServerError ("GetUserRepoPermission" , err )
180
+ return nil , nil , nil , nil , "" , ""
181
+ }
182
+ if ! permHead .CanRead (models .UnitTypeCode ) {
183
+ if log .IsTrace () {
184
+ log .Trace ("Permission Denied: User: %-v cannot read code in Repo: %-v\n User in headRepo has Permissions: %-+v" ,
185
+ ctx .User ,
186
+ headRepo ,
187
+ permHead )
188
+ }
189
+ ctx .NotFound ("ParseCompareInfo" , nil )
190
+ return nil , nil , nil , nil , "" , ""
189
191
}
190
- headGitRepo .Close ()
191
- ctx .NotFound ("ParseCompareInfo" , nil )
192
- return nil , nil , nil , nil , "" , ""
193
192
}
194
193
195
194
// Check if head branch is valid.
196
- headIsCommit := ctx . Repo . GitRepo .IsCommitExist (headBranch )
195
+ headIsCommit := headGitRepo .IsCommitExist (headBranch )
197
196
headIsBranch := headGitRepo .IsBranchExist (headBranch )
198
197
headIsTag := headGitRepo .IsTagExist (headBranch )
199
198
if ! headIsCommit && ! headIsBranch && ! headIsTag {
200
199
// Check if headBranch is short sha commit hash
201
- if headCommit , _ := ctx . Repo . GitRepo .GetCommit (headBranch ); headCommit != nil {
200
+ if headCommit , _ := headGitRepo .GetCommit (headBranch ); headCommit != nil {
202
201
headBranch = headCommit .ID .String ()
203
202
ctx .Data ["HeadBranch" ] = headBranch
204
203
headIsCommit = true
205
204
} else {
206
- headGitRepo .Close ()
207
205
ctx .NotFound ("IsRefExist" , nil )
208
206
return nil , nil , nil , nil , "" , ""
209
207
}
@@ -224,14 +222,12 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
224
222
baseRepo ,
225
223
permBase )
226
224
}
227
- headGitRepo .Close ()
228
225
ctx .NotFound ("ParseCompareInfo" , nil )
229
226
return nil , nil , nil , nil , "" , ""
230
227
}
231
228
232
- compareInfo , err := headGitRepo .GetCompareInfo (models .RepoPath (baseRepo . Owner . Name , baseRepo . Name ), baseBranch , headBranch )
229
+ compareInfo , err := headGitRepo .GetCompareInfo (baseRepo .RepoPath (), baseBranch , headBranch )
233
230
if err != nil {
234
- headGitRepo .Close ()
235
231
ctx .ServerError ("GetCompareInfo" , err )
236
232
return nil , nil , nil , nil , "" , ""
237
233
}
0 commit comments