mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Add whitespace handling to PR-comparsion (#4683)
* Add whitespace handling to PR-comparsion In a PR we have to keep an eye on a lot of different things. But sometimes the bare code is the key-thing we want to care about and just don't want to care about fixed indention on some places. Especially if we follow the pathfinder rule we face a lot of these situations because these changes don't break the code in many languages but improve the readability a lot. So this change introduce a fine graned button to adjust the way how the reviewer want to see whitespace-changes within the code. The possibilities reflect the possibilities from git itself except of the `--ignore-blank-lines` flag because that one is also handled by `-b` and is really rare. Signed-off-by: Felix Nehrke <felix@nehrke.info>
This commit is contained in:
@@ -50,3 +50,14 @@ func SetDiffViewStyle(ctx *context.Context) {
|
||||
ctx.ServerError("ErrUpdateDiffViewStyle", err)
|
||||
}
|
||||
}
|
||||
|
||||
// SetWhitespaceBehavior set whitespace behavior as render variable
|
||||
func SetWhitespaceBehavior(ctx *context.Context) {
|
||||
whitespaceBehavior := ctx.Query("whitespace")
|
||||
switch whitespaceBehavior {
|
||||
case "ignore-all", "ignore-eol", "ignore-change":
|
||||
ctx.Data["WhitespaceBehavior"] = whitespaceBehavior
|
||||
default:
|
||||
ctx.Data["WhitespaceBehavior"] = ""
|
||||
}
|
||||
}
|
||||
|
@@ -390,6 +390,12 @@ func ViewPullFiles(ctx *context.Context) {
|
||||
}
|
||||
pull := issue.PullRequest
|
||||
|
||||
whitespaceFlags := map[string]string{
|
||||
"ignore-all": "-w",
|
||||
"ignore-change": "-b",
|
||||
"ignore-eol": "--ignore-space-at-eol",
|
||||
"": ""}
|
||||
|
||||
var (
|
||||
diffRepoPath string
|
||||
startCommitID string
|
||||
@@ -455,11 +461,12 @@ func ViewPullFiles(ctx *context.Context) {
|
||||
ctx.Data["Reponame"] = pull.HeadRepo.Name
|
||||
}
|
||||
|
||||
diff, err := models.GetDiffRange(diffRepoPath,
|
||||
diff, err := models.GetDiffRangeWithWhitespaceBehavior(diffRepoPath,
|
||||
startCommitID, endCommitID, setting.Git.MaxGitDiffLines,
|
||||
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles)
|
||||
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles,
|
||||
whitespaceFlags[ctx.Data["WhitespaceBehavior"].(string)])
|
||||
if err != nil {
|
||||
ctx.ServerError("GetDiffRange", err)
|
||||
ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -674,7 +674,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||
m.Post("/merge", reqRepoWriter, bindIgnErr(auth.MergePullRequestForm{}), repo.MergePullRequest)
|
||||
m.Post("/cleanup", context.RepoRef(), repo.CleanUpPullRequest)
|
||||
m.Group("/files", func() {
|
||||
m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ViewPullFiles)
|
||||
m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.ViewPullFiles)
|
||||
m.Group("/reviews", func() {
|
||||
m.Post("/comments", bindIgnErr(auth.CodeCommentForm{}), repo.CreateCodeComment)
|
||||
m.Post("/submit", bindIgnErr(auth.SubmitReviewForm{}), repo.SubmitReview)
|
||||
|
Reference in New Issue
Block a user