mirror of
https://github.com/go-gitea/gitea
synced 2024-11-15 22:54:24 +00:00
ca112f0a04
* 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>
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package repo
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"code.gitea.io/git"
|
|
"code.gitea.io/gitea/models"
|
|
"code.gitea.io/gitea/modules/context"
|
|
)
|
|
|
|
// SetEditorconfigIfExists set editor config as render variable
|
|
func SetEditorconfigIfExists(ctx *context.Context) {
|
|
ec, err := ctx.Repo.GetEditorconfig()
|
|
|
|
if err != nil && !git.IsErrNotExist(err) {
|
|
description := fmt.Sprintf("Error while getting .editorconfig file: %v", err)
|
|
if err := models.CreateRepositoryNotice(description); err != nil {
|
|
ctx.ServerError("ErrCreatingReporitoryNotice", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
ctx.Data["Editorconfig"] = ec
|
|
}
|
|
|
|
// SetDiffViewStyle set diff style as render variable
|
|
func SetDiffViewStyle(ctx *context.Context) {
|
|
queryStyle := ctx.Query("style")
|
|
|
|
if !ctx.IsSigned {
|
|
ctx.Data["IsSplitStyle"] = queryStyle == "split"
|
|
return
|
|
}
|
|
|
|
var (
|
|
userStyle = ctx.User.DiffViewStyle
|
|
style string
|
|
)
|
|
|
|
if queryStyle == "unified" || queryStyle == "split" {
|
|
style = queryStyle
|
|
} else if userStyle == "unified" || userStyle == "split" {
|
|
style = userStyle
|
|
} else {
|
|
style = "unified"
|
|
}
|
|
|
|
ctx.Data["IsSplitStyle"] = style == "split"
|
|
if err := ctx.User.UpdateDiffViewStyle(style); err != nil {
|
|
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"] = ""
|
|
}
|
|
}
|