Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
* upstream/main:
  [skip ci] Updated translations via Crowdin
  Bump vm2 from 3.9.15 to 3.9.16 (go-gitea#24089)
  Fix difficult translation for other languages (go-gitea#24070)
  Fix mismatch between hook events and github event types (go-gitea#24048)
  Improve LFS error logs (go-gitea#24072)
  Update the value of the `diffEnd` when click `Show More` btn in the DiffFileTree (go-gitea#24069)
  Add tooltips to `Hide comment type` settings where necessary (go-gitea#21306)
  Use a general approach to access custom/static/builtin assets (go-gitea#24022)
  Make Release Download URLs predictable (go-gitea#23891)
  Expand selected file when clicking file tree (go-gitea#24041)
  Localize milestone related time strings (go-gitea#24051)
  update BSDmakefile to latest version from upstream (go-gitea#24063)
  • Loading branch information
zjjhot committed Apr 13, 2023
2 parents f448ed4 + 4299c3b commit a3da958
Show file tree
Hide file tree
Showing 80 changed files with 1,233 additions and 1,124 deletions.
33 changes: 20 additions & 13 deletions BSDmakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# GNU makefile proxy script for BSD make
#
# Written and maintained by Mahmoud Al-Qudsi <[email protected]>
# Copyright NeoSmart Technologies <https://neosmart.net/> 2014-2018
# Copyright NeoSmart Technologies <https://neosmart.net/> 2014-2019
# Obtain updates from <https://github.com/neosmart/gmake-proxy>
#
# Redistribution and use in source and binary forms, with or without
Expand All @@ -26,26 +27,32 @@

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

.if "$(.MAKE.JOBS)" != ""
JARG = -j$(.MAKE.JOBS)
JARG = -j$(.MAKE.JOBS)
.endif

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

# The GNU convention is to use the lowercased `prefix` variable/macro to
# specify the installation directory. Humor them.
GPREFIX = ""
.if defined(PREFIX) && ! defined(prefix)
GPREFIX = 'prefix = "$(PREFIX)"'
.endif

.BEGIN: .SILENT
which $(GMAKE) || printf "Error: GNU Make is required!\n\n" 1>&2 && false

.PHONY: FRC
$(.TARGETS): FRC
$(GMAKE) $(GARGS) $(.TARGETS:S,.DONE,,) $(JARG)
$(GMAKE) $(GPREFIX) $(GARGS) $(.TARGETS:S,.DONE,,) $(JARG)

.DONE .DEFAULT: .SILENT
$(GMAKE) $(GARGS) $(.TARGETS:S,.DONE,,) $(JARG)

.ERROR: .SILENT
if ! which $(GMAKE) > /dev/null; then \
echo "GNU Make is required!"; \
fi
$(GMAKE) $(GPREFIX) $(GARGS) $(.TARGETS:S,.DONE,,) $(JARG)
122 changes: 52 additions & 70 deletions cmd/embedded.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//go:build bindata

package cmd

import (
"errors"
"fmt"
"os"
"path/filepath"
"sort"
"strings"

"code.gitea.io/gitea/modules/assetfs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/options"
"code.gitea.io/gitea/modules/public"
Expand Down Expand Up @@ -89,24 +87,20 @@ var (
},
}

sections map[string]*section
assets []asset
matchedAssetFiles []assetFile
)

type section struct {
Path string
Names func() []string
IsDir func(string) (bool, error)
Asset func(string) ([]byte, error)
}

type asset struct {
Section *section
Name string
Path string
type assetFile struct {
fs *assetfs.LayeredFS
name string
path string
}

func initEmbeddedExtractor(c *cli.Context) error {
// FIXME: there is a bug, if the user runs `gitea embedded` with a different user or root,
// The setting.Init (loadRunModeFrom) will fail and do log.Fatal
// But the console logger has been deleted, so nothing is printed, the user sees nothing and Gitea just exits.

// Silence the console logger
log.DelNamedLogger("console")
log.DelNamedLogger(log.DEFAULT)
Expand All @@ -115,24 +109,14 @@ func initEmbeddedExtractor(c *cli.Context) error {
setting.InitProviderAllowEmpty()
setting.LoadCommonSettings()

pats, err := getPatterns(c.Args())
patterns, err := compileCollectPatterns(c.Args())
if err != nil {
return err
}
sections := make(map[string]*section, 3)

sections["public"] = &section{Path: "public", Names: public.AssetNames, IsDir: public.AssetIsDir, Asset: public.Asset}
sections["options"] = &section{Path: "options", Names: options.AssetNames, IsDir: options.AssetIsDir, Asset: options.Asset}
sections["templates"] = &section{Path: "templates", Names: templates.BuiltinAssetNames, IsDir: templates.BuiltinAssetIsDir, Asset: templates.BuiltinAsset}

for _, sec := range sections {
assets = append(assets, buildAssetList(sec, pats, c)...)
}

// Sort assets
sort.SliceStable(assets, func(i, j int) bool {
return assets[i].Path < assets[j].Path
})
collectAssetFilesByPattern(c, patterns, "options", options.BuiltinAssets())
collectAssetFilesByPattern(c, patterns, "public", public.BuiltinAssets())
collectAssetFilesByPattern(c, patterns, "templates", templates.BuiltinAssets())

return nil
}
Expand Down Expand Up @@ -166,8 +150,8 @@ func runListDo(c *cli.Context) error {
return err
}

for _, a := range assets {
fmt.Println(a.Path)
for _, a := range matchedAssetFiles {
fmt.Println(a.path)
}

return nil
Expand All @@ -178,19 +162,19 @@ func runViewDo(c *cli.Context) error {
return err
}

if len(assets) == 0 {
return fmt.Errorf("No files matched the given pattern")
} else if len(assets) > 1 {
return fmt.Errorf("Too many files matched the given pattern; try to be more specific")
if len(matchedAssetFiles) == 0 {
return fmt.Errorf("no files matched the given pattern")
} else if len(matchedAssetFiles) > 1 {
return fmt.Errorf("too many files matched the given pattern, try to be more specific")
}

data, err := assets[0].Section.Asset(assets[0].Name)
data, err := matchedAssetFiles[0].fs.ReadFile(matchedAssetFiles[0].name)
if err != nil {
return fmt.Errorf("%s: %w", assets[0].Path, err)
return fmt.Errorf("%s: %w", matchedAssetFiles[0].path, err)
}

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

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

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

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

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

overwrite := c.Bool("overwrite")
rename := c.Bool("rename")

for _, a := range assets {
for _, a := range matchedAssetFiles {
if err := extractAsset(destdir, a, overwrite, rename); err != nil {
// Non-fatal error
fmt.Fprintf(os.Stderr, "%s: %v", a.Path, err)
fmt.Fprintf(os.Stderr, "%s: %v", a.path, err)
}
}

return nil
}

func extractAsset(d string, a asset, overwrite, rename bool) error {
dest := filepath.Join(d, filepath.FromSlash(a.Path))
func extractAsset(d string, a assetFile, overwrite, rename bool) error {
dest := filepath.Join(d, filepath.FromSlash(a.path))
dir := filepath.Dir(dest)

data, err := a.Section.Asset(a.Name)
data, err := a.fs.ReadFile(a.name)
if err != nil {
return fmt.Errorf("%s: %w", a.Path, err)
return fmt.Errorf("%s: %w", a.path, err)
}

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

func buildAssetList(sec *section, globs []glob.Glob, c *cli.Context) []asset {
results := make([]asset, 0, 64)
for _, name := range sec.Names() {
if isdir, err := sec.IsDir(name); !isdir && err == nil {
if sec.Path == "public" &&
strings.HasPrefix(name, "vendor/") &&
!c.Bool("include-vendored") {
continue
}
matchName := sec.Path + "/" + name
for _, g := range globs {
if g.Match(matchName) {
results = append(results, asset{
Section: sec,
Name: name,
Path: sec.Path + "/" + name,
})
break
}
func collectAssetFilesByPattern(c *cli.Context, globs []glob.Glob, path string, layer *assetfs.Layer) {
fs := assetfs.Layered(layer)
files, err := fs.ListAllFiles(".", true)
if err != nil {
log.Error("Error listing files in %q: %v", path, err)
return
}
for _, name := range files {
if path == "public" &&
strings.HasPrefix(name, "vendor/") &&
!c.Bool("include-vendored") {
continue
}
matchName := path + "/" + name
for _, g := range globs {
if g.Match(matchName) {
matchedAssetFiles = append(matchedAssetFiles, assetFile{fs: fs, name: name, path: path + "/" + name})
break
}
}
}
return results
}

func getPatterns(args []string) ([]glob.Glob, error) {
func compileCollectPatterns(args []string) ([]glob.Glob, error) {
if len(args) == 0 {
args = []string{"**"}
}
pat := make([]glob.Glob, len(args))
for i := range args {
if g, err := glob.Compile(args[i], '/'); err != nil {
return nil, fmt.Errorf("'%s': Invalid glob pattern: %w", args[i], err)
} else {
} else { //nolint:revive
pat[i] = g
}
}
Expand Down
29 changes: 0 additions & 29 deletions cmd/embedded_stub.go

This file was deleted.

5 changes: 0 additions & 5 deletions models/issues/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"fmt"
"strings"
"time"

"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
Expand Down Expand Up @@ -65,7 +64,6 @@ type Milestone struct {
DeadlineString string `xorm:"-"`

TotalTrackedTime int64 `xorm:"-"`
TimeSinceUpdate int64 `xorm:"-"`
}

func init() {
Expand All @@ -84,9 +82,6 @@ func (m *Milestone) BeforeUpdate() {
// AfterLoad is invoked from XORM after setting the value of a field of
// this object.
func (m *Milestone) AfterLoad() {
if !m.UpdatedUnix.IsZero() {
m.TimeSinceUpdate = time.Now().Unix() - m.UpdatedUnix.AsTime().Unix()
}
m.NumOpenIssues = m.NumIssues - m.NumClosedIssues
if m.DeadlineUnix.Year() == 9999 {
return
Expand Down
27 changes: 16 additions & 11 deletions models/repo/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ import (

// Attachment represent a attachment of issue/comment/release.
type Attachment struct {
ID int64 `xorm:"pk autoincr"`
UUID string `xorm:"uuid UNIQUE"`
RepoID int64 `xorm:"INDEX"` // this should not be zero
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added
CommentID int64
Name string
DownloadCount int64 `xorm:"DEFAULT 0"`
Size int64 `xorm:"DEFAULT 0"`
CreatedUnix timeutil.TimeStamp `xorm:"created"`
ID int64 `xorm:"pk autoincr"`
UUID string `xorm:"uuid UNIQUE"`
RepoID int64 `xorm:"INDEX"` // this should not be zero
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added
CommentID int64
Name string
DownloadCount int64 `xorm:"DEFAULT 0"`
Size int64 `xorm:"DEFAULT 0"`
CreatedUnix timeutil.TimeStamp `xorm:"created"`
CustomDownloadURL string `xorm:"-"`
}

func init() {
Expand Down Expand Up @@ -57,6 +58,10 @@ func (a *Attachment) RelativePath() string {

// DownloadURL returns the download url of the attached file
func (a *Attachment) DownloadURL() string {
if a.CustomDownloadURL != "" {
return a.CustomDownloadURL
}

return setting.AppURL + "attachments/" + url.PathEscape(a.UUID)
}

Expand Down
Loading

0 comments on commit a3da958

Please sign in to comment.