mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.8 KiB
73 lines
1.8 KiB
5 years ago
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
8 years ago
|
package repo
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
8 years ago
|
"code.gitea.io/gitea/models"
|
||
|
"code.gitea.io/gitea/modules/context"
|
||
6 years ago
|
"code.gitea.io/gitea/modules/git"
|
||
8 years ago
|
)
|
||
|
|
||
8 years ago
|
// SetEditorconfigIfExists set editor config as render variable
|
||
8 years ago
|
func SetEditorconfigIfExists(ctx *context.Context) {
|
||
5 years ago
|
if ctx.Repo.Repository.IsEmpty {
|
||
|
ctx.Data["Editorconfig"] = nil
|
||
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
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 {
|
||
7 years ago
|
ctx.ServerError("ErrCreatingReporitoryNotice", err)
|
||
8 years ago
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
ctx.Data["Editorconfig"] = ec
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
// SetDiffViewStyle set diff style as render variable
|
||
8 years ago
|
func SetDiffViewStyle(ctx *context.Context) {
|
||
8 years ago
|
queryStyle := ctx.Query("style")
|
||
|
|
||
8 years ago
|
if !ctx.IsSigned {
|
||
8 years ago
|
ctx.Data["IsSplitStyle"] = queryStyle == "split"
|
||
8 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
var (
|
||
8 years ago
|
userStyle = ctx.User.DiffViewStyle
|
||
|
style string
|
||
8 years ago
|
)
|
||
|
|
||
|
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 {
|
||
7 years ago
|
ctx.ServerError("ErrUpdateDiffViewStyle", err)
|
||
8 years ago
|
}
|
||
|
}
|
||
6 years ago
|
|
||
|
// 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"] = ""
|
||
|
}
|
||
|
}
|