Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* giteaofficial/main:
  Remove follow from commits by file (go-gitea#20765)
  [skip ci] Updated translations via Crowdin
  Fix `make watch` for generated files (go-gitea#20794)
  Add missing translation for queue flush workers (go-gitea#20791)
  Update zh-cn translation for Installation from source (go-gitea#20772)
  Improve comment header for Mobile (go-gitea#20781)
  Add myself to MAINTAINERS (go-gitea#20786)
  [skip ci] Updated licenses and gitignores
  Preserve unix socket file (go-gitea#20499)
  Switch Unicode Escaping to a VSCode-like system (go-gitea#19990)
  Fix git.Init for doctor sub-command (go-gitea#20782)
  Remove the translation key website by PR go-gitea#20777 (go-gitea#20779)
  Move the official website link at the footer of gitea (go-gitea#20777)
  Remove useless JS operation for relative time tooltips (go-gitea#20756)
  Remove debug output when coverage fails (go-gitea#20733)
  Slightly reduce exclamation icon size (go-gitea#20753)
  • Loading branch information
zjjhot committed Aug 15, 2022
2 parents 27f7758 + 58a4407 commit dc2ddab
Show file tree
Hide file tree
Showing 53 changed files with 2,507 additions and 443 deletions.
2 changes: 1 addition & 1 deletion .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ bin = "gitea"
include_ext = ["go", "tmpl"]
exclude_dir = ["modules/git/tests", "services/gitdiff/testdata", "modules/avatar/testdata"]
include_dir = ["cmd", "models", "modules", "options", "routers", "services", "templates"]
exclude_regex = ["_test.go$"]
exclude_regex = ["_test.go$", "_gen.go$"]
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ Leon Hofmeister <dev.lh@web.de> (@delvh)
Gusted <williamzijl7@hotmail.com) (@Gusted)
silentcode <silentcode@senga.org> (@silentcodeg)
Wim <wim@42.be> (@42wim)
xinyu <xinyu@nerv.org.cn> (@penlinux)
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ test\#%:
coverage:
grep '^\(mode: .*\)\|\(.*:[0-9]\+\.[0-9]\+,[0-9]\+\.[0-9]\+ [0-9]\+ [0-9]\+\)$$' coverage.out > coverage-bodged.out
grep '^\(mode: .*\)\|\(.*:[0-9]\+\.[0-9]\+,[0-9]\+\.[0-9]\+ [0-9]\+ [0-9]\+\)$$' integration.coverage.out > integration.coverage-bodged.out
$(GO) run build/gocovmerge.go integration.coverage-bodged.out coverage-bodged.out > coverage.all || (echo "gocovmerge failed"; echo "integration.coverage.out"; cat integration.coverage.out; echo "coverage.out"; cat coverage.out; exit 1)
$(GO) run build/gocovmerge.go integration.coverage-bodged.out coverage-bodged.out > coverage.all

.PHONY: unit-test-coverage
unit-test-coverage:
Expand Down
6 changes: 0 additions & 6 deletions cmd/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/migrations"
"code.gitea.io/gitea/modules/doctor"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"

Expand Down Expand Up @@ -128,11 +127,6 @@ func runDoctor(ctx *cli.Context) error {
stdCtx, cancel := installSignals()
defer cancel()

// some doctor sub-commands need to use git command
if err := git.InitFull(stdCtx); err != nil {
return err
}

// Silence the default loggers
log.DelNamedLogger("console")
log.DelNamedLogger(log.DEFAULT)
Expand Down
46 changes: 34 additions & 12 deletions docs/content/doc/installation/from-source.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,35 @@ menu:

# 从源代码安装

首先你需要安装Golang,关于Golang的安装,参见官方文档 [install instructions](https://golang.org/doc/install)
首先你需要安装Golang,关于Golang的安装,参见[官方文档](https://golang.google.cn/doc/install)

其次你需要[安装Node.js](https://nodejs.org/zh-cn/download/),Node.js 和 npm 将用于构建 Gitea 前端。

**目录**

{{< toc >}}

## 下载

你需要获取Gitea的源码,最方便的方式是使用 go 命令。执行以下命令:
你需要获取Gitea的源码,最方便的方式是使用 `git` 命令。执行以下命令:

```
go get -d -u code.gitea.io/gitea
cd $GOPATH/src/code.gitea.io/gitea
git clone https://github.com/go-gitea/gitea
cd gitea
```

然后你可以选择编译和安装的版本,当前你有多个选择。如果你想编译 `master` 版本,你可以直接跳到 [编译](#编译) 部分,这是我们的开发分支,虽然也很稳定但不建议您在正式产品中使用。
然后你可以选择编译和安装的版本,当前你有多个选择。如果你想编译 `main` 版本,你可以直接跳到 [编译](#编译) 部分,这是我们的开发分支,虽然也很稳定但不建议您在正式产品中使用。

如果你想编译最新稳定分支,你可以执行以下命令签出源码:

```
```bash
git branch -a
git checkout v{{< version >}}
```

最后,你也可以直接使用标签版本如 `v{{< version >}}`。你可以执行以下命令列出可用的版本并选择某个版本签出:

```
```bash
git tag -l
git checkout v{{< version >}}
```
Expand All @@ -46,11 +52,11 @@ git checkout v{{< version >}}

要从源代码进行编译,以下依赖程序必须事先安装好:

- `go` {{< min-go-version >}} 或以上版本, 详见 [here](https://golang.org/dl/)
- `node` {{< min-node-version >}} 或以上版本,并且安装 `npm`, 详见 [here](https://nodejs.org/en/download/)
- `make`, 详见 <a href='{{< relref "make.zh-cn.md" >}}'>这里</a>
- `go` {{< min-go-version >}} 或以上版本, 详见[这里](https://golang.google.cn/doc/install)
- `node` {{< min-node-version >}} 或以上版本,并且安装 `npm`, 详见[这里](https://nodejs.org/zh-cn/download/)
- `make`, 详见[这里]({{< relref "make.zh-cn.md" >}})</a>

各种可用的 [make 任务](https://github.com/go-gitea/gitea/blob/master/Makefile)
各种可用的 [make 任务](https://github.com/go-gitea/gitea/blob/main/Makefile)
可以用来使编译过程更方便。

按照您的编译需求,以下 tags 可以使用:
Expand All @@ -76,10 +82,26 @@ TAGS="bindata sqlite sqlite_unlock_notify" make build

在执行了以上步骤之后,你将会获得 `gitea` 的二进制文件,在你复制到部署的机器之前可以先测试一下。在命令行执行完后,你可以 `Ctrl + C` 关掉程序。

```
```bash
./gitea web
```

## 交叉编译

Go 编译器支持交叉编译到不同的目标架构。有关 Go 支持的目标架构列表,请参见 [Optional environment variables](https://go.dev/doc/install/source#environment)

交叉构建适用于 Linux ARM64 的 Gitea:

```bash
GOOS=linux GOARCH=arm64 make build
```

交叉构建适用于 Linux ARM64 的 Gitea,并且带上 Gitea 发行版采用的编译选项:

```bash
CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="bindata sqlite sqlite_unlock_notify" make build
```

## 需要帮助?

如果从本页中没有找到你需要的内容,请访问 [帮助页面]({{< relref "seek-help.zh-cn.md" >}})
2 changes: 1 addition & 1 deletion integrations/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func testViewRepo(t *testing.T) {
}
})

f.commitTime, _ = s.Find("span.time-since").Attr("title")
f.commitTime, _ = s.Find("span.time-since").Attr("data-content")
items = append(items, f)
})

Expand Down
54 changes: 54 additions & 0 deletions modules/charset/ambiguous.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// This file is generated by modules/charset/ambiguous/generate.go DO NOT EDIT
// Copyright 2022 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.

package charset

import (
"sort"
"strings"
"unicode"

"code.gitea.io/gitea/modules/translation"
)

// AmbiguousTablesForLocale provides the table of ambiguous characters for this locale.
func AmbiguousTablesForLocale(locale translation.Locale) []*AmbiguousTable {
key := locale.Language()
var table *AmbiguousTable
var ok bool
for len(key) > 0 {
if table, ok = AmbiguousCharacters[key]; ok {
break
}
idx := strings.LastIndexAny(key, "-_")
if idx < 0 {
key = ""
} else {
key = key[:idx]
}
}
if table == nil {
table = AmbiguousCharacters["_default"]
}

return []*AmbiguousTable{
table,
AmbiguousCharacters["_common"],
}
}

func isAmbiguous(r rune, confusableTo *rune, tables ...*AmbiguousTable) bool {
for _, table := range tables {
if !unicode.Is(table.RangeTable, r) {
continue
}
i := sort.Search(len(table.Confusable), func(i int) bool {
return table.Confusable[i] >= r
})
(*confusableTo) = table.With[i]
return true
}
return false
}
1 change: 1 addition & 0 deletions modules/charset/ambiguous/ambiguous.json

Large diffs are not rendered by default.

178 changes: 178 additions & 0 deletions modules/charset/ambiguous/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
// Copyright 2022 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.

package main

import (
"bytes"
"flag"
"fmt"
"go/format"
"os"
"sort"
"text/template"
"unicode"

"code.gitea.io/gitea/modules/json"

"golang.org/x/text/unicode/rangetable"
)

// ambiguous.json provides a one to one mapping of ambiguous characters to other characters
// See https://github.com/hediet/vscode-unicode-data/blob/main/out/ambiguous.json

type AmbiguousTable struct {
Confusable []rune
With []rune
Locale string
RangeTable *unicode.RangeTable
}

type RunePair struct {
Confusable rune
With rune
}

var verbose bool

func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, `%s: Generate AmbiguousCharacter
Usage: %[1]s [-v] [-o output.go] ambiguous.json
`, os.Args[0])
flag.PrintDefaults()
}

output := ""
flag.BoolVar(&verbose, "v", false, "verbose output")
flag.StringVar(&output, "o", "ambiguous_gen.go", "file to output to")
flag.Parse()
input := flag.Arg(0)
if input == "" {
input = "ambiguous.json"
}

bs, err := os.ReadFile(input)
if err != nil {
fatalf("Unable to read: %s Err: %v", input, err)
}

var unwrapped string
if err := json.Unmarshal(bs, &unwrapped); err != nil {
fatalf("Unable to unwrap content in: %s Err: %v", input, err)
}

fromJSON := map[string][]uint32{}
if err := json.Unmarshal([]byte(unwrapped), &fromJSON); err != nil {
fatalf("Unable to unmarshal content in: %s Err: %v", input, err)
}

tables := make([]*AmbiguousTable, 0, len(fromJSON))
for locale, chars := range fromJSON {
table := &AmbiguousTable{Locale: locale}
table.Confusable = make([]rune, 0, len(chars)/2)
table.With = make([]rune, 0, len(chars)/2)
pairs := make([]RunePair, len(chars)/2)
for i := 0; i < len(chars); i += 2 {
pairs[i/2].Confusable, pairs[i/2].With = rune(chars[i]), rune(chars[i+1])
}
sort.Slice(pairs, func(i, j int) bool {
return pairs[i].Confusable < pairs[j].Confusable
})
for _, pair := range pairs {
table.Confusable = append(table.Confusable, pair.Confusable)
table.With = append(table.With, pair.With)
}
table.RangeTable = rangetable.New(table.Confusable...)
tables = append(tables, table)
}
sort.Slice(tables, func(i, j int) bool {
return tables[i].Locale < tables[j].Locale
})
data := map[string]interface{}{
"Tables": tables,
}

if err := runTemplate(generatorTemplate, output, &data); err != nil {
fatalf("Unable to run template: %v", err)
}
}

func runTemplate(t *template.Template, filename string, data interface{}) error {
buf := bytes.NewBuffer(nil)
if err := t.Execute(buf, data); err != nil {
return fmt.Errorf("unable to execute template: %w", err)
}
bs, err := format.Source(buf.Bytes())
if err != nil {
verbosef("Bad source:\n%s", buf.String())
return fmt.Errorf("unable to format source: %w", err)
}
file, err := os.Create(filename)
if err != nil {
return fmt.Errorf("failed to create file %s because %w", filename, err)
}
defer file.Close()
_, err = file.Write(bs)
if err != nil {
return fmt.Errorf("unable to write generated source: %w", err)
}
return nil
}

var generatorTemplate = template.Must(template.New("ambiguousTemplate").Parse(`// This file is generated by modules/charset/ambiguous/generate.go DO NOT EDIT
// Copyright 2022 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.
package charset
import "unicode"
// This file is generated from https://github.com/hediet/vscode-unicode-data/blob/main/out/ambiguous.json
// AmbiguousTable matches a confusable rune with its partner for the Locale
type AmbiguousTable struct {
Confusable []rune
With []rune
Locale string
RangeTable *unicode.RangeTable
}
// AmbiguousCharacters provides a map by locale name to the confusable characters in that locale
var AmbiguousCharacters = map[string]*AmbiguousTable{
{{range .Tables}}{{printf "%q:" .Locale}} {
Confusable: []rune{ {{range .Confusable}}{{.}},{{end}} },
With: []rune{ {{range .With}}{{.}},{{end}} },
Locale: {{printf "%q" .Locale}},
RangeTable: &unicode.RangeTable{
R16: []unicode.Range16{
{{range .RangeTable.R16 }} {Lo:{{.Lo}}, Hi:{{.Hi}}, Stride: {{.Stride}}},
{{end}} },
R32: []unicode.Range32{
{{range .RangeTable.R32}} {Lo:{{.Lo}}, Hi:{{.Hi}}, Stride: {{.Stride}}},
{{end}} },
LatinOffset: {{.RangeTable.LatinOffset}},
},
},
{{end}}
}
`))

func logf(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, format+"\n", args...)
}

func verbosef(format string, args ...interface{}) {
if verbose {
logf(format, args...)
}
}

func fatalf(format string, args ...interface{}) {
logf("fatal: "+format+"\n", args...)
os.Exit(1)
}
Loading

0 comments on commit dc2ddab

Please sign in to comment.