Skip to content

Commit 57e8393

Browse files
authored
Merge branch 'main' into add-unset-default-project
2 parents ea80754 + 4299c3b commit 57e8393

File tree

167 files changed

+2051
-1890
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+2051
-1890
lines changed

BSDmakefile

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# GNU makefile proxy script for BSD make
2+
#
23
# Written and maintained by Mahmoud Al-Qudsi <[email protected]>
3-
# Copyright NeoSmart Technologies <https://neosmart.net/> 2014-2018
4+
# Copyright NeoSmart Technologies <https://neosmart.net/> 2014-2019
45
# Obtain updates from <https://github.com/neosmart/gmake-proxy>
56
#
67
# Redistribution and use in source and binary forms, with or without
@@ -26,26 +27,32 @@
2627

2728
JARG =
2829
GMAKE = "gmake"
29-
#When gmake is called from another make instance, -w is automatically added
30-
#which causes extraneous messages about directory changes to be emitted.
31-
#--no-print-directory silences these messages.
30+
# When gmake is called from another make instance, -w is automatically added
31+
# which causes extraneous messages about directory changes to be emitted.
32+
# Running with --no-print-directory silences these messages.
3233
GARGS = "--no-print-directory"
3334

3435
.if "$(.MAKE.JOBS)" != ""
35-
JARG = -j$(.MAKE.JOBS)
36+
JARG = -j$(.MAKE.JOBS)
3637
.endif
3738

38-
#by default bmake will cd into ./obj first
39+
# bmake prefers out-of-source builds and tries to cd into ./obj (among others)
40+
# where possible. GNU Make doesn't, so override that value.
3941
.OBJDIR: ./
4042

43+
# The GNU convention is to use the lowercased `prefix` variable/macro to
44+
# specify the installation directory. Humor them.
45+
GPREFIX = ""
46+
.if defined(PREFIX) && ! defined(prefix)
47+
GPREFIX = 'prefix = "$(PREFIX)"'
48+
.endif
49+
50+
.BEGIN: .SILENT
51+
which $(GMAKE) || printf "Error: GNU Make is required!\n\n" 1>&2 && false
52+
4153
.PHONY: FRC
4254
$(.TARGETS): FRC
43-
$(GMAKE) $(GARGS) $(.TARGETS:S,.DONE,,) $(JARG)
55+
$(GMAKE) $(GPREFIX) $(GARGS) $(.TARGETS:S,.DONE,,) $(JARG)
4456

4557
.DONE .DEFAULT: .SILENT
46-
$(GMAKE) $(GARGS) $(.TARGETS:S,.DONE,,) $(JARG)
47-
48-
.ERROR: .SILENT
49-
if ! which $(GMAKE) > /dev/null; then \
50-
echo "GNU Make is required!"; \
51-
fi
58+
$(GMAKE) $(GPREFIX) $(GARGS) $(.TARGETS:S,.DONE,,) $(JARG)

cmd/dump.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ It can be used for backup and capture Gitea server image to send to maintainer`,
112112
Name: "verbose, V",
113113
Usage: "Show process details",
114114
},
115+
cli.BoolFlag{
116+
Name: "quiet, q",
117+
Usage: "Only display warnings and errors",
118+
},
115119
cli.StringFlag{
116120
Name: "tempdir, t",
117121
Value: os.TempDir(),
@@ -192,12 +196,25 @@ func runDump(ctx *cli.Context) error {
192196
if _, err := setting.CfgProvider.Section("log.console").NewKey("STDERR", "true"); err != nil {
193197
fatal("Setting console logger to stderr failed: %v", err)
194198
}
199+
200+
// Set loglevel to Warn if quiet-mode is requested
201+
if ctx.Bool("quiet") {
202+
if _, err := setting.CfgProvider.Section("log.console").NewKey("LEVEL", "Warn"); err != nil {
203+
fatal("Setting console log-level failed: %v", err)
204+
}
205+
}
206+
195207
if !setting.InstallLock {
196208
log.Error("Is '%s' really the right config path?\n", setting.CustomConf)
197209
return fmt.Errorf("gitea is not initialized")
198210
}
199211
setting.LoadSettings() // cannot access session settings otherwise
200212

213+
verbose := ctx.Bool("verbose")
214+
if verbose && ctx.Bool("quiet") {
215+
return fmt.Errorf("--quiet and --verbose cannot both be set")
216+
}
217+
201218
stdCtx, cancel := installSignals()
202219
defer cancel()
203220

@@ -223,7 +240,6 @@ func runDump(ctx *cli.Context) error {
223240
return err
224241
}
225242

226-
verbose := ctx.Bool("verbose")
227243
var iface interface{}
228244
if fileName == "-" {
229245
iface, err = archiver.ByExtension(fmt.Sprintf(".%s", outType))

cmd/embedded.go

Lines changed: 52 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
// Copyright 2020 The Gitea Authors. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

4-
//go:build bindata
5-
64
package cmd
75

86
import (
97
"errors"
108
"fmt"
119
"os"
1210
"path/filepath"
13-
"sort"
1411
"strings"
1512

13+
"code.gitea.io/gitea/modules/assetfs"
1614
"code.gitea.io/gitea/modules/log"
1715
"code.gitea.io/gitea/modules/options"
1816
"code.gitea.io/gitea/modules/public"
@@ -89,24 +87,20 @@ var (
8987
},
9088
}
9189

92-
sections map[string]*section
93-
assets []asset
90+
matchedAssetFiles []assetFile
9491
)
9592

96-
type section struct {
97-
Path string
98-
Names func() []string
99-
IsDir func(string) (bool, error)
100-
Asset func(string) ([]byte, error)
101-
}
102-
103-
type asset struct {
104-
Section *section
105-
Name string
106-
Path string
93+
type assetFile struct {
94+
fs *assetfs.LayeredFS
95+
name string
96+
path string
10797
}
10898

10999
func initEmbeddedExtractor(c *cli.Context) error {
100+
// FIXME: there is a bug, if the user runs `gitea embedded` with a different user or root,
101+
// The setting.Init (loadRunModeFrom) will fail and do log.Fatal
102+
// But the console logger has been deleted, so nothing is printed, the user sees nothing and Gitea just exits.
103+
110104
// Silence the console logger
111105
log.DelNamedLogger("console")
112106
log.DelNamedLogger(log.DEFAULT)
@@ -115,24 +109,14 @@ func initEmbeddedExtractor(c *cli.Context) error {
115109
setting.InitProviderAllowEmpty()
116110
setting.LoadCommonSettings()
117111

118-
pats, err := getPatterns(c.Args())
112+
patterns, err := compileCollectPatterns(c.Args())
119113
if err != nil {
120114
return err
121115
}
122-
sections := make(map[string]*section, 3)
123-
124-
sections["public"] = &section{Path: "public", Names: public.AssetNames, IsDir: public.AssetIsDir, Asset: public.Asset}
125-
sections["options"] = &section{Path: "options", Names: options.AssetNames, IsDir: options.AssetIsDir, Asset: options.Asset}
126-
sections["templates"] = &section{Path: "templates", Names: templates.BuiltinAssetNames, IsDir: templates.BuiltinAssetIsDir, Asset: templates.BuiltinAsset}
127116

128-
for _, sec := range sections {
129-
assets = append(assets, buildAssetList(sec, pats, c)...)
130-
}
131-
132-
// Sort assets
133-
sort.SliceStable(assets, func(i, j int) bool {
134-
return assets[i].Path < assets[j].Path
135-
})
117+
collectAssetFilesByPattern(c, patterns, "options", options.BuiltinAssets())
118+
collectAssetFilesByPattern(c, patterns, "public", public.BuiltinAssets())
119+
collectAssetFilesByPattern(c, patterns, "templates", templates.BuiltinAssets())
136120

137121
return nil
138122
}
@@ -166,8 +150,8 @@ func runListDo(c *cli.Context) error {
166150
return err
167151
}
168152

169-
for _, a := range assets {
170-
fmt.Println(a.Path)
153+
for _, a := range matchedAssetFiles {
154+
fmt.Println(a.path)
171155
}
172156

173157
return nil
@@ -178,19 +162,19 @@ func runViewDo(c *cli.Context) error {
178162
return err
179163
}
180164

181-
if len(assets) == 0 {
182-
return fmt.Errorf("No files matched the given pattern")
183-
} else if len(assets) > 1 {
184-
return fmt.Errorf("Too many files matched the given pattern; try to be more specific")
165+
if len(matchedAssetFiles) == 0 {
166+
return fmt.Errorf("no files matched the given pattern")
167+
} else if len(matchedAssetFiles) > 1 {
168+
return fmt.Errorf("too many files matched the given pattern, try to be more specific")
185169
}
186170

187-
data, err := assets[0].Section.Asset(assets[0].Name)
171+
data, err := matchedAssetFiles[0].fs.ReadFile(matchedAssetFiles[0].name)
188172
if err != nil {
189-
return fmt.Errorf("%s: %w", assets[0].Path, err)
173+
return fmt.Errorf("%s: %w", matchedAssetFiles[0].path, err)
190174
}
191175

192176
if _, err = os.Stdout.Write(data); err != nil {
193-
return fmt.Errorf("%s: %w", assets[0].Path, err)
177+
return fmt.Errorf("%s: %w", matchedAssetFiles[0].path, err)
194178
}
195179

196180
return nil
@@ -202,7 +186,7 @@ func runExtractDo(c *cli.Context) error {
202186
}
203187

204188
if len(c.Args()) == 0 {
205-
return fmt.Errorf("A list of pattern of files to extract is mandatory (e.g. '**' for all)")
189+
return fmt.Errorf("a list of pattern of files to extract is mandatory (e.g. '**' for all)")
206190
}
207191

208192
destdir := "."
@@ -227,31 +211,31 @@ func runExtractDo(c *cli.Context) error {
227211
if err != nil {
228212
return fmt.Errorf("%s: %s", destdir, err)
229213
} else if !fi.IsDir() {
230-
return fmt.Errorf("%s is not a directory.", destdir)
214+
return fmt.Errorf("destination %q is not a directory", destdir)
231215
}
232216

233217
fmt.Printf("Extracting to %s:\n", destdir)
234218

235219
overwrite := c.Bool("overwrite")
236220
rename := c.Bool("rename")
237221

238-
for _, a := range assets {
222+
for _, a := range matchedAssetFiles {
239223
if err := extractAsset(destdir, a, overwrite, rename); err != nil {
240224
// Non-fatal error
241-
fmt.Fprintf(os.Stderr, "%s: %v", a.Path, err)
225+
fmt.Fprintf(os.Stderr, "%s: %v", a.path, err)
242226
}
243227
}
244228

245229
return nil
246230
}
247231

248-
func extractAsset(d string, a asset, overwrite, rename bool) error {
249-
dest := filepath.Join(d, filepath.FromSlash(a.Path))
232+
func extractAsset(d string, a assetFile, overwrite, rename bool) error {
233+
dest := filepath.Join(d, filepath.FromSlash(a.path))
250234
dir := filepath.Dir(dest)
251235

252-
data, err := a.Section.Asset(a.Name)
236+
data, err := a.fs.ReadFile(a.name)
253237
if err != nil {
254-
return fmt.Errorf("%s: %w", a.Path, err)
238+
return fmt.Errorf("%s: %w", a.path, err)
255239
}
256240

257241
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
@@ -272,7 +256,7 @@ func extractAsset(d string, a asset, overwrite, rename bool) error {
272256
return fmt.Errorf("%s already exists, but it's not a regular file", dest)
273257
} else if rename {
274258
if err := util.Rename(dest, dest+".bak"); err != nil {
275-
return fmt.Errorf("Error creating backup for %s: %w", dest, err)
259+
return fmt.Errorf("error creating backup for %s: %w", dest, err)
276260
}
277261
// Attempt to respect file permissions mask (even if user:group will be set anew)
278262
perms = fi.Mode()
@@ -293,40 +277,38 @@ func extractAsset(d string, a asset, overwrite, rename bool) error {
293277
return nil
294278
}
295279

296-
func buildAssetList(sec *section, globs []glob.Glob, c *cli.Context) []asset {
297-
results := make([]asset, 0, 64)
298-
for _, name := range sec.Names() {
299-
if isdir, err := sec.IsDir(name); !isdir && err == nil {
300-
if sec.Path == "public" &&
301-
strings.HasPrefix(name, "vendor/") &&
302-
!c.Bool("include-vendored") {
303-
continue
304-
}
305-
matchName := sec.Path + "/" + name
306-
for _, g := range globs {
307-
if g.Match(matchName) {
308-
results = append(results, asset{
309-
Section: sec,
310-
Name: name,
311-
Path: sec.Path + "/" + name,
312-
})
313-
break
314-
}
280+
func collectAssetFilesByPattern(c *cli.Context, globs []glob.Glob, path string, layer *assetfs.Layer) {
281+
fs := assetfs.Layered(layer)
282+
files, err := fs.ListAllFiles(".", true)
283+
if err != nil {
284+
log.Error("Error listing files in %q: %v", path, err)
285+
return
286+
}
287+
for _, name := range files {
288+
if path == "public" &&
289+
strings.HasPrefix(name, "vendor/") &&
290+
!c.Bool("include-vendored") {
291+
continue
292+
}
293+
matchName := path + "/" + name
294+
for _, g := range globs {
295+
if g.Match(matchName) {
296+
matchedAssetFiles = append(matchedAssetFiles, assetFile{fs: fs, name: name, path: path + "/" + name})
297+
break
315298
}
316299
}
317300
}
318-
return results
319301
}
320302

321-
func getPatterns(args []string) ([]glob.Glob, error) {
303+
func compileCollectPatterns(args []string) ([]glob.Glob, error) {
322304
if len(args) == 0 {
323305
args = []string{"**"}
324306
}
325307
pat := make([]glob.Glob, len(args))
326308
for i := range args {
327309
if g, err := glob.Compile(args[i], '/'); err != nil {
328310
return nil, fmt.Errorf("'%s': Invalid glob pattern: %w", args[i], err)
329-
} else {
311+
} else { //nolint:revive
330312
pat[i] = g
331313
}
332314
}

cmd/embedded_stub.go

Lines changed: 0 additions & 29 deletions
This file was deleted.

custom/conf/app.example.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ RUN_MODE = ; prod
186186
;; default is the system temporary directory.
187187
;SSH_KEY_TEST_PATH =
188188
;;
189-
;; Path to ssh-keygen, default is 'ssh-keygen' which means the shell is responsible for finding out which one to call.
190-
;SSH_KEYGEN_PATH = ssh-keygen
189+
;; Use `ssh-keygen` to parse public SSH keys. The value is passed to the shell. By default, Gitea does the parsing itself.
190+
;SSH_KEYGEN_PATH =
191191
;;
192192
;; Enable SSH Authorized Key Backup when rewriting all keys, default is true
193193
;SSH_AUTHORIZED_KEYS_BACKUP = true

docs/content/doc/administration/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a
345345
- `SSH_SERVER_MACS`: **[email protected], hmac-sha2-256, hmac-sha1**: For the built-in SSH server, choose the MACs to support for SSH connections, for system SSH this setting has no effect
346346
- `SSH_SERVER_HOST_KEYS`: **ssh/gitea.rsa, ssh/gogs.rsa**: For the built-in SSH server, choose the keypairs to offer as the host key. The private key should be at `SSH_SERVER_HOST_KEY` and the public `SSH_SERVER_HOST_KEY.pub`. Relative paths are made absolute relative to the `APP_DATA_PATH`. If no key exists a 4096 bit RSA key will be created for you.
347347
- `SSH_KEY_TEST_PATH`: **/tmp**: Directory to create temporary files in when testing public keys using ssh-keygen, default is the system temporary directory.
348-
- `SSH_KEYGEN_PATH`: **ssh-keygen**: Path to ssh-keygen, default is 'ssh-keygen' which means the shell is responsible for finding out which one to call.
348+
- `SSH_KEYGEN_PATH`: **\<empty\>**: Use `ssh-keygen` to parse public SSH keys. The value is passed to the shell. By default, Gitea does the parsing itself.
349349
- `SSH_EXPOSE_ANONYMOUS`: **false**: Enable exposure of SSH clone URL to anonymous visitors, default is false.
350350
- `SSH_PER_WRITE_TIMEOUT`: **30s**: Timeout for any write to the SSH connections. (Set to
351351
-1 to disable all timeouts.)

0 commit comments

Comments
 (0)