Clean some legacy files and move some build files (#23699)
* Clean the "tools" directory. The "tools" directory contains only two
files, move them.
* The "external_renderer.go" works like "cat" command to echo Stdin to
Stdout , to help testing.
* The `// gobuild: external_renderer` is incorrect, there should be no
space: `//gobuild: external_renderer`
* The `fmt.Print(os.Args[1])` is not a well-defined behavior, and it's
never used.
* The "watch.sh" is for "make watch", it's somewhat related to "build"
* After this PR, there is no "tools" directory, the project root
directory looks slightly simpler than before.
* Remove the legacy "contrib/autoboot.sh", there is no
"gogs_supervisord.sh"
* Remove the legacy "contrib/mysql.sql", it's never mentioned anywhere.
* Remove the legacy "contrib/pr/checkout.go", it has been broken for
long time, and it introduces unnecessary dependencies of the main code
base.
2023-03-26 04:22:51 +08:00
|
|
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2023-03-24 01:27:03 +08:00
|
|
|
//go:build ignore
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
2023-06-02 17:27:30 +08:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2023-03-24 01:27:03 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if len(os.Args) != 2 {
|
|
|
|
println("usage: backport-locales <to-ref>")
|
|
|
|
println("eg: backport-locales release/v1.19")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
mustNoErr := func(err error) {
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
2023-06-02 17:27:30 +08:00
|
|
|
collectInis := func(ref string) map[string]setting.ConfigProvider {
|
|
|
|
inis := map[string]setting.ConfigProvider{}
|
2023-03-24 01:27:03 +08:00
|
|
|
err := filepath.WalkDir("options/locale", func(path string, d os.DirEntry, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if d.IsDir() || !strings.HasSuffix(d.Name(), ".ini") {
|
|
|
|
return nil
|
|
|
|
}
|
2023-06-02 17:27:30 +08:00
|
|
|
cfg, err := setting.NewConfigProviderForLocale(path)
|
2023-03-24 01:27:03 +08:00
|
|
|
mustNoErr(err)
|
|
|
|
inis[path] = cfg
|
|
|
|
fmt.Printf("collecting: %s @ %s\n", path, ref)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
mustNoErr(err)
|
|
|
|
return inis
|
|
|
|
}
|
|
|
|
|
|
|
|
// collect new locales from current working directory
|
|
|
|
inisNew := collectInis("HEAD")
|
|
|
|
|
|
|
|
// switch to the target ref, and collect the old locales
|
|
|
|
cmd := exec.Command("git", "checkout", os.Args[1])
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
mustNoErr(cmd.Run())
|
|
|
|
inisOld := collectInis(os.Args[1])
|
|
|
|
|
|
|
|
// use old en-US as the base, and copy the new translations to the old locales
|
|
|
|
enUsOld := inisOld["options/locale/locale_en-US.ini"]
|
2023-04-03 11:12:47 +08:00
|
|
|
brokenWarned := map[string]bool{}
|
2023-03-24 01:27:03 +08:00
|
|
|
for path, iniOld := range inisOld {
|
|
|
|
if iniOld == enUsOld {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
iniNew := inisNew[path]
|
|
|
|
if iniNew == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, secEnUS := range enUsOld.Sections() {
|
|
|
|
secOld := iniOld.Section(secEnUS.Name())
|
|
|
|
secNew := iniNew.Section(secEnUS.Name())
|
|
|
|
for _, keyEnUs := range secEnUS.Keys() {
|
|
|
|
if secNew.HasKey(keyEnUs.Name()) {
|
|
|
|
oldStr := secOld.Key(keyEnUs.Name()).String()
|
|
|
|
newStr := secNew.Key(keyEnUs.Name()).String()
|
2023-04-03 11:12:47 +08:00
|
|
|
broken := oldStr != "" && strings.Count(oldStr, "%") != strings.Count(newStr, "%")
|
|
|
|
broken = broken || strings.Contains(oldStr, "\n") || strings.Contains(oldStr, "\n")
|
|
|
|
if broken {
|
|
|
|
brokenWarned[secOld.Name()+"."+keyEnUs.Name()] = true
|
|
|
|
fmt.Println("----")
|
|
|
|
fmt.Printf("WARNING: skip broken locale: %s , [%s] %s\n", path, secEnUS.Name(), keyEnUs.Name())
|
|
|
|
fmt.Printf("\told: %s\n", strings.ReplaceAll(oldStr, "\n", "\\n"))
|
|
|
|
fmt.Printf("\tnew: %s\n", strings.ReplaceAll(newStr, "\n", "\\n"))
|
2023-03-24 01:27:03 +08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
secOld.Key(keyEnUs.Name()).SetValue(newStr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mustNoErr(iniOld.SaveTo(path))
|
|
|
|
}
|
2023-04-03 11:12:47 +08:00
|
|
|
|
|
|
|
fmt.Println("========")
|
|
|
|
|
|
|
|
for path, iniNew := range inisNew {
|
|
|
|
for _, sec := range iniNew.Sections() {
|
|
|
|
for _, key := range sec.Keys() {
|
|
|
|
str := sec.Key(key.Name()).String()
|
|
|
|
broken := strings.Contains(str, "\n")
|
|
|
|
broken = broken || strings.HasPrefix(str, "`") != strings.HasSuffix(str, "`")
|
|
|
|
broken = broken || strings.HasPrefix(str, "\"`")
|
|
|
|
broken = broken || strings.HasPrefix(str, "`\"")
|
|
|
|
broken = broken || strings.Count(str, `"`)%2 == 1
|
|
|
|
broken = broken || strings.Count(str, "`")%2 == 1
|
|
|
|
if broken && !brokenWarned[sec.Name()+"."+key.Name()] {
|
|
|
|
fmt.Printf("WARNING: found broken locale: %s , [%s] %s\n", path, sec.Name(), key.Name())
|
|
|
|
fmt.Printf("\tstr: %s\n", strings.ReplaceAll(str, "\n", "\\n"))
|
|
|
|
fmt.Println("----")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-24 01:27:03 +08:00
|
|
|
}
|