Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/release/v1.21' into release/dc…
Browse files Browse the repository at this point in the history
…s/v1.21
  • Loading branch information
richmahn committed Dec 7, 2023
2 parents c45c63e + 272ae03 commit 895102b
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 36 deletions.
7 changes: 6 additions & 1 deletion models/migrations/v1_21/v263.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ func AddGitSizeAndLFSSizeToRepositoryTable(x *xorm.Engine) error {
return err
}

_, err = sess.Exec(`UPDATE repository SET git_size = size - lfs_size`)
_, err = sess.Exec(`UPDATE repository SET size = 0 WHERE size IS NULL`)
if err != nil {
return err
}

_, err = sess.Exec(`UPDATE repository SET git_size = size - lfs_size WHERE size > lfs_size`)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion modules/git/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ func (c *Commit) Message() string {
}

// Summary returns first line of commit message.
// The string is forced to be valid UTF8
func (c *Commit) Summary() string {
return strings.Split(strings.TrimSpace(c.CommitMessage), "\n")[0]
return strings.ToValidUTF8(strings.Split(strings.TrimSpace(c.CommitMessage), "\n")[0], "?")
}

// ParentID returns oid of n-th parent (0-based index).
Expand Down
41 changes: 28 additions & 13 deletions modules/git/repo_branch_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package git

import (
"context"
"sort"
"strings"

"github.com/go-git/go-git/v5/plumbing"
Expand Down Expand Up @@ -52,32 +53,46 @@ func (repo *Repository) IsBranchExist(name string) bool {

// GetBranches returns branches from the repository, skipping "skip" initial branches and
// returning at most "limit" branches, or all branches if "limit" is 0.
// Branches are returned with sort of `-commiterdate` as the nogogit
// implementation. This requires full fetch, sort and then the
// skip/limit applies later as gogit returns in undefined order.
func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error) {
var branchNames []string
type BranchData struct {
name string
committerDate int64
}
var branchData []BranchData

branches, err := repo.gogitRepo.Branches()
branchIter, err := repo.gogitRepo.Branches()
if err != nil {
return nil, 0, err
}

i := 0
count := 0
_ = branches.ForEach(func(branch *plumbing.Reference) error {
count++
if i < skip {
i++
return nil
} else if limit != 0 && count > skip+limit {
_ = branchIter.ForEach(func(branch *plumbing.Reference) error {
obj, err := repo.gogitRepo.CommitObject(branch.Hash())
if err != nil {
// skip branch if can't find commit
return nil
}

branchNames = append(branchNames, strings.TrimPrefix(branch.Name().String(), BranchPrefix))
branchData = append(branchData, BranchData{strings.TrimPrefix(branch.Name().String(), BranchPrefix), obj.Committer.When.Unix()})
return nil
})

// TODO: Sort?
sort.Slice(branchData, func(i, j int) bool {
return !(branchData[i].committerDate < branchData[j].committerDate)
})

var branchNames []string
maxPos := len(branchData)
if limit > 0 {
maxPos = min(skip+limit, maxPos)
}
for i := skip; i < maxPos; i++ {
branchNames = append(branchNames, branchData[i].name)
}

return branchNames, count, nil
return branchNames, len(branchData), nil
}

// WalkReferences walks all the references from the repository
Expand Down
2 changes: 1 addition & 1 deletion modules/setting/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func loadAttachmentFrom(rootCfg ConfigProvider) (err error) {
}

Attachment.AllowedTypes = sec.Key("ALLOWED_TYPES").MustString(".csv,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.xls,.xlsx,.zip")
Attachment.MaxSize = sec.Key("MAX_SIZE").MustInt64(4)
Attachment.MaxSize = sec.Key("MAX_SIZE").MustInt64(2048)
Attachment.MaxFiles = sec.Key("MAX_FILES").MustInt(5)
Attachment.Enabled = sec.Key("ENABLED").MustBool(true)

Expand Down
3 changes: 1 addition & 2 deletions modules/setting/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net"
"net/url"
"os"
"path"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -117,7 +116,7 @@ func DBConnStr() (string, error) {
if !EnableSQLite3 {
return "", errors.New("this Gitea binary was not built with SQLite3 support")
}
if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil {
if err := os.MkdirAll(filepath.Dir(Database.Path), os.ModePerm); err != nil {
return "", fmt.Errorf("Failed to create directories: %w", err)
}
journalMode := ""
Expand Down
5 changes: 4 additions & 1 deletion routers/api/packages/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ func CommonRoutes() *web.Route {
r.Get("", rpm.DownloadPackageFile)
r.Delete("", reqPackageAccess(perm.AccessModeWrite), rpm.DeletePackageFile)
})
r.Get("/repodata/{filename}", rpm.GetRepositoryFile)
r.Group("/repodata/{filename}", func() {
r.Head("", rpm.CheckRepositoryFileExistence)
r.Get("", rpm.GetRepositoryFile)
})
}, reqPackageAccess(perm.AccessModeRead))
r.Group("/rubygems", func() {
r.Get("/specs.4.8.gz", rubygems.EnumeratePackages)
Expand Down
24 changes: 24 additions & 0 deletions routers/api/packages/rpm/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ func GetRepositoryKey(ctx *context.Context) {
})
}

func CheckRepositoryFileExistence(ctx *context.Context) {
pv, err := rpm_service.GetOrCreateRepositoryVersion(ctx, ctx.Package.Owner.ID)
if err != nil {
apiError(ctx, http.StatusInternalServerError, err)
return
}

pf, err := packages_model.GetFileForVersionByName(ctx, pv.ID, ctx.Params("filename"), packages_model.EmptyFileKey)
if err != nil {
if errors.Is(err, util.ErrNotExist) {
ctx.Status(http.StatusNotFound)
} else {
apiError(ctx, http.StatusInternalServerError, err)
}
return
}

ctx.SetServeHeaders(&context.ServeHeaderOptions{
Filename: pf.Name,
LastModified: pf.CreatedUnix.AsLocalTime(),
})
ctx.Status(http.StatusOK)
}

// Gets a pre-generated repository metadata file
func GetRepositoryFile(ctx *context.Context) {
pv, err := rpm_service.GetOrCreateRepositoryVersion(ctx, ctx.Package.Owner.ID)
Expand Down
1 change: 1 addition & 0 deletions routers/web/repo/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func List(ctx *context.Context) {
pager.AddParamString("actor", fmt.Sprint(actorID))
pager.AddParamString("status", fmt.Sprint(status))
ctx.Data["Page"] = pager
ctx.Data["HasWorkflowsOrRuns"] = len(workflows) > 0 || len(runs) > 0

ctx.HTML(http.StatusOK, tplListActions)
}
19 changes: 6 additions & 13 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,21 +726,14 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) {
}
for _, entry := range allEntries {
if entry.Name() == "CITATION.cff" || entry.Name() == "CITATION.bib" {
ctx.Data["CitiationExist"] = true
// Read Citation file contents
blob := entry.Blob()
dataRc, err := blob.DataAsync()
if err != nil {
ctx.ServerError("DataAsync", err)
return
}
defer dataRc.Close()
ctx.PageData["citationFileContent"], err = blob.GetBlobContent(setting.UI.MaxDisplayFileSize)
if err != nil {
ctx.ServerError("GetBlobContent", err)
return
if content, err := entry.Blob().GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil {
log.Error("checkCitationFile: GetBlobContent: %v", err)
} else {
ctx.Data["CitiationExist"] = true
ctx.PageData["citationFileContent"] = content
break
}
break
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion services/migrations/gitea_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
line := comment.Line
if line != 0 {
comment.Position = 1
} else {
} else if comment.DiffHunk != "" {
_, _, line, _ = git.ParseDiffHunkString(comment.DiffHunk)
}

Expand Down
2 changes: 1 addition & 1 deletion templates/repo/actions/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="ui container">
{{template "base/alert" .}}

{{if .workflows}}
{{if .HasWorkflowsOrRuns}}
<div class="ui stackable grid">
<div class="four wide column">
<div class="ui fluid vertical menu">
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/commit_page.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
{{else}}
<span title="{{ctx.Locale.Tr "gpg.default_key"}}">{{svg "gitea-lock-cog" 16 "gt-mr-3"}}</span>
<span class="ui text gt-mr-3">{{ctx.Locale.Tr "repo.commits.signed_by"}}:</span>
{{ctx.AvatarUtils.AvatarByEmail .Verification.SigningEmail "" 28}}
{{ctx.AvatarUtils.AvatarByEmail .Verification.SigningEmail "" 28 "gt-mr-3"}}
<strong>{{.Verification.SigningUser.GetDisplayName}}</strong>
{{end}}
{{else}}
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/api_packages_rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,18 @@ gpgkey=%sapi/packages/%s/rpm/repository.key`, user.Name, user.Name, setting.AppN

url := rootURL + "/repodata"

req := NewRequest(t, "GET", url+"/dummy.xml")
req := NewRequest(t, "HEAD", url+"/dummy.xml")
MakeRequest(t, req, http.StatusNotFound)

req = NewRequest(t, "GET", url+"/dummy.xml")
MakeRequest(t, req, http.StatusNotFound)

t.Run("repomd.xml", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()

req = NewRequest(t, "HEAD", url+"/repomd.xml")
MakeRequest(t, req, http.StatusOK)

req = NewRequest(t, "GET", url+"/repomd.xml")
resp := MakeRequest(t, req, http.StatusOK)

Expand Down

0 comments on commit 895102b

Please sign in to comment.