parent
					
						
							
								8dd5ab2a14
							
						
					
				
			
			
				commit
				
					
						d3468ed79f
					
				
			
		
					 1 changed files with 20 additions and 24 deletions
				
			
		| 
						 | 
					@ -157,12 +157,12 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
 | 
				
			||||||
			ctx.ServerError("OpenRepository", err)
 | 
								ctx.ServerError("OpenRepository", err)
 | 
				
			||||||
			return nil, nil, nil, nil, "", ""
 | 
								return nil, nil, nil, nil, "", ""
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							defer headGitRepo.Close()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// user should have permission to read baseRepo's codes and pulls, NOT headRepo's
 | 
						// user should have permission to read baseRepo's codes and pulls, NOT headRepo's
 | 
				
			||||||
	permBase, err := models.GetUserRepoPermission(baseRepo, ctx.User)
 | 
						permBase, err := models.GetUserRepoPermission(baseRepo, ctx.User)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		headGitRepo.Close()
 | 
					 | 
				
			||||||
		ctx.ServerError("GetUserRepoPermission", err)
 | 
							ctx.ServerError("GetUserRepoPermission", err)
 | 
				
			||||||
		return nil, nil, nil, nil, "", ""
 | 
							return nil, nil, nil, nil, "", ""
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -173,15 +173,14 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
 | 
				
			||||||
				baseRepo,
 | 
									baseRepo,
 | 
				
			||||||
				permBase)
 | 
									permBase)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		headGitRepo.Close()
 | 
					 | 
				
			||||||
		ctx.NotFound("ParseCompareInfo", nil)
 | 
							ctx.NotFound("ParseCompareInfo", nil)
 | 
				
			||||||
		return nil, nil, nil, nil, "", ""
 | 
							return nil, nil, nil, nil, "", ""
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !isSameRepo {
 | 
				
			||||||
		// user should have permission to read headrepo's codes
 | 
							// user should have permission to read headrepo's codes
 | 
				
			||||||
		permHead, err := models.GetUserRepoPermission(headRepo, ctx.User)
 | 
							permHead, err := models.GetUserRepoPermission(headRepo, ctx.User)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
		headGitRepo.Close()
 | 
					 | 
				
			||||||
			ctx.ServerError("GetUserRepoPermission", err)
 | 
								ctx.ServerError("GetUserRepoPermission", err)
 | 
				
			||||||
			return nil, nil, nil, nil, "", ""
 | 
								return nil, nil, nil, nil, "", ""
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -192,23 +191,22 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
 | 
				
			||||||
					headRepo,
 | 
										headRepo,
 | 
				
			||||||
					permHead)
 | 
										permHead)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		headGitRepo.Close()
 | 
					 | 
				
			||||||
			ctx.NotFound("ParseCompareInfo", nil)
 | 
								ctx.NotFound("ParseCompareInfo", nil)
 | 
				
			||||||
			return nil, nil, nil, nil, "", ""
 | 
								return nil, nil, nil, nil, "", ""
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check if head branch is valid.
 | 
						// Check if head branch is valid.
 | 
				
			||||||
	headIsCommit := ctx.Repo.GitRepo.IsCommitExist(headBranch)
 | 
						headIsCommit := headGitRepo.IsCommitExist(headBranch)
 | 
				
			||||||
	headIsBranch := headGitRepo.IsBranchExist(headBranch)
 | 
						headIsBranch := headGitRepo.IsBranchExist(headBranch)
 | 
				
			||||||
	headIsTag := headGitRepo.IsTagExist(headBranch)
 | 
						headIsTag := headGitRepo.IsTagExist(headBranch)
 | 
				
			||||||
	if !headIsCommit && !headIsBranch && !headIsTag {
 | 
						if !headIsCommit && !headIsBranch && !headIsTag {
 | 
				
			||||||
		// Check if headBranch is short sha commit hash
 | 
							// Check if headBranch is short sha commit hash
 | 
				
			||||||
		if headCommit, _ := ctx.Repo.GitRepo.GetCommit(headBranch); headCommit != nil {
 | 
							if headCommit, _ := headGitRepo.GetCommit(headBranch); headCommit != nil {
 | 
				
			||||||
			headBranch = headCommit.ID.String()
 | 
								headBranch = headCommit.ID.String()
 | 
				
			||||||
			ctx.Data["HeadBranch"] = headBranch
 | 
								ctx.Data["HeadBranch"] = headBranch
 | 
				
			||||||
			headIsCommit = true
 | 
								headIsCommit = true
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			headGitRepo.Close()
 | 
					 | 
				
			||||||
			ctx.NotFound("IsRefExist", nil)
 | 
								ctx.NotFound("IsRefExist", nil)
 | 
				
			||||||
			return nil, nil, nil, nil, "", ""
 | 
								return nil, nil, nil, nil, "", ""
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -229,14 +227,12 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
 | 
				
			||||||
				baseRepo,
 | 
									baseRepo,
 | 
				
			||||||
				permBase)
 | 
									permBase)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		headGitRepo.Close()
 | 
					 | 
				
			||||||
		ctx.NotFound("ParseCompareInfo", nil)
 | 
							ctx.NotFound("ParseCompareInfo", nil)
 | 
				
			||||||
		return nil, nil, nil, nil, "", ""
 | 
							return nil, nil, nil, nil, "", ""
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	compareInfo, err := headGitRepo.GetCompareInfo(models.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseBranch, headBranch)
 | 
						compareInfo, err := headGitRepo.GetCompareInfo(baseRepo.RepoPath(), baseBranch, headBranch)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		headGitRepo.Close()
 | 
					 | 
				
			||||||
		ctx.ServerError("GetCompareInfo", err)
 | 
							ctx.ServerError("GetCompareInfo", err)
 | 
				
			||||||
		return nil, nil, nil, nil, "", ""
 | 
							return nil, nil, nil, nil, "", ""
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue