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