Commit a3ce9f2b authored by 6543's avatar 6543 Committed by Leo

community/gitea: upgrade to 1.12.4

parent b2c13220
From f63774c304b411dd782d0c919200c8b86ea37ed6 Mon Sep 17 00:00:00 2001
From: 6543 <6543@obermui.de>
Date: Fri, 4 Sep 2020 03:25:48 +0200
Subject: [PATCH] fix go1.15 lint error in modules/public/public.go
---
modules/public/public.go | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/modules/public/public.go b/modules/public/public.go
index 8d027855c..790f418a2 100644
--- a/modules/public/public.go
+++ b/modules/public/public.go
@@ -6,6 +6,7 @@ package public
import (
"encoding/base64"
+ "fmt"
"log"
"net/http"
"path"
@@ -159,7 +160,7 @@ func (opts *Options) handle(ctx *macaron.Context, log *log.Logger, opt *Options)
// Add an Expires header to the static content
if opt.ExpiresAfter > 0 {
ctx.Resp.Header().Set("Expires", time.Now().Add(opt.ExpiresAfter).UTC().Format(http.TimeFormat))
- tag := GenerateETag(string(fi.Size()), fi.Name(), fi.ModTime().UTC().Format(http.TimeFormat))
+ tag := GenerateETag(fmt.Sprint(fi.Size()), fi.Name(), fi.ModTime().UTC().Format(http.TimeFormat))
ctx.Resp.Header().Set("ETag", tag)
if ctx.Req.Header.Get("If-None-Match") == tag {
ctx.Resp.WriteHeader(304)
--
2.28.0
From bd99df60c6c9f67a9eda89e69b3aa9bb82364d5b Mon Sep 17 00:00:00 2001
From: Andrew Thornton <art27@cantab.net>
Date: Wed, 29 Jul 2020 11:38:17 +0100
Subject: [PATCH] Git 2.28 no longer permits diff with ... on unrelated
branches
Backport #12364
Signed-off-by: Andrew Thornton <art27@cantab.net>
---
modules/git/commit.go | 9 +++++----
modules/git/repo_commit.go | 26 ++++++++++++++++++++++++--
modules/git/repo_compare.go | 28 +++++++++++++++++++++++-----
routers/private/hook.go | 2 ++
4 files changed, 54 insertions(+), 11 deletions(-)
diff --git a/modules/git/commit.go b/modules/git/commit.go
index 5e492e27eac..5ba8c2c8afa 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -271,11 +271,12 @@ func AllCommitsCount(repoPath string) (int64, error) {
return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
}
-func commitsCount(repoPath, revision, relpath string) (int64, error) {
+func commitsCount(repoPath string, revision, relpath []string) (int64, error) {
cmd := NewCommand("rev-list", "--count")
- cmd.AddArguments(revision)
+ cmd.AddArguments(revision...)
if len(relpath) > 0 {
- cmd.AddArguments("--", relpath)
+ cmd.AddArguments("--")
+ cmd.AddArguments(relpath...)
}
stdout, err := cmd.RunInDir(repoPath)
@@ -288,7 +289,7 @@ func commitsCount(repoPath, revision, relpath string) (int64, error) {
// CommitsCount returns number of total commits of until given revision.
func CommitsCount(repoPath, revision string) (int64, error) {
- return commitsCount(repoPath, revision, "")
+ return commitsCount(repoPath, []string{revision}, []string{})
}
// CommitsCount returns number of total commits of until current revision.
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index 18c732c6f2d..bab3d8852c0 100644
--- a/modules/git/repo_commit.go
+++ b/modules/git/repo_commit.go
@@ -293,7 +293,7 @@ func (repo *Repository) FileChangedBetweenCommits(filename, id1, id2 string) (bo
// FileCommitsCount return the number of files at a revison
func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) {
- return commitsCount(repo.Path, revision, file)
+ return commitsCount(repo.Path, []string{revision}, []string{file})
}
// CommitsByFileAndRange return the commits according revison file and the page
@@ -319,6 +319,11 @@ func (repo *Repository) CommitsByFileAndRangeNoFollow(revision, file string, pag
// FilesCountBetween return the number of files changed between two commits
func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error) {
stdout, err := NewCommand("diff", "--name-only", startCommitID+"..."+endCommitID).RunInDir(repo.Path)
+ if err != nil && strings.Contains(err.Error(), "no merge base") {
+ // git >= 2.28 now returns an error if startCommitID and endCommitID have become unrelated.
+ // previously it would return the results of git diff --name-only startCommitID endCommitID so let's try that...
+ stdout, err = NewCommand("diff", "--name-only", startCommitID, endCommitID).RunInDir(repo.Path)
+ }
if err != nil {
return 0, err
}
@@ -333,6 +338,11 @@ func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List
stdout, err = NewCommand("rev-list", last.ID.String()).RunInDirBytes(repo.Path)
} else {
stdout, err = NewCommand("rev-list", before.ID.String()+"..."+last.ID.String()).RunInDirBytes(repo.Path)
+ if err != nil && strings.Contains(err.Error(), "no merge base") {
+ // future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
+ // previously it would return the results of git rev-list before last so let's try that...
+ stdout, err = NewCommand("rev-list", before.ID.String(), last.ID.String()).RunInDirBytes(repo.Path)
+ }
}
if err != nil {
return nil, err
@@ -348,6 +358,11 @@ func (repo *Repository) CommitsBetweenLimit(last *Commit, before *Commit, limit,
stdout, err = NewCommand("rev-list", "--max-count", strconv.Itoa(limit), "--skip", strconv.Itoa(skip), last.ID.String()).RunInDirBytes(repo.Path)
} else {
stdout, err = NewCommand("rev-list", "--max-count", strconv.Itoa(limit), "--skip", strconv.Itoa(skip), before.ID.String()+"..."+last.ID.String()).RunInDirBytes(repo.Path)
+ if err != nil && strings.Contains(err.Error(), "no merge base") {
+ // future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
+ // previously it would return the results of git rev-list --max-count n before last so let's try that...
+ stdout, err = NewCommand("rev-list", "--max-count", strconv.Itoa(limit), "--skip", strconv.Itoa(skip), before.ID.String(), last.ID.String()).RunInDirBytes(repo.Path)
+ }
}
if err != nil {
return nil, err
@@ -373,7 +388,14 @@ func (repo *Repository) CommitsBetweenIDs(last, before string) (*list.List, erro
// CommitsCountBetween return numbers of commits between two commits
func (repo *Repository) CommitsCountBetween(start, end string) (int64, error) {
- return commitsCount(repo.Path, start+"..."+end, "")
+ count, err := commitsCount(repo.Path, []string{start + "..." + end}, []string{})
+ if err != nil && strings.Contains(err.Error(), "no merge base") {
+ // future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
+ // previously it would return the results of git rev-list before last so let's try that...
+ return commitsCount(repo.Path, []string{start, end}, []string{})
+ }
+
+ return count, err
}
// commitsBefore the limit is depth, not total number of returned commits.
diff --git a/modules/git/repo_compare.go b/modules/git/repo_compare.go
index 5bc7f9ca5a6..16ea068db23 100644
--- a/modules/git/repo_compare.go
+++ b/modules/git/repo_compare.go
@@ -6,6 +6,7 @@
package git
import (
+ "bytes"
"container/list"
"fmt"
"io"
@@ -66,7 +67,7 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string)
compareInfo := new(CompareInfo)
compareInfo.MergeBase, remoteBranch, err = repo.GetMergeBase(tmpRemote, baseBranch, headBranch)
if err == nil {
- // We have a common base
+ // We have a common base - therefore we know that ... should work
logs, err := NewCommand("log", compareInfo.MergeBase+"..."+headBranch, prettyLogFormat).RunInDirBytes(repo.Path)
if err != nil {
return nil, err
@@ -85,6 +86,11 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string)
// Count number of changed files.
stdout, err := NewCommand("diff", "--name-only", remoteBranch+"..."+headBranch).RunInDir(repo.Path)
+ if err != nil && strings.Contains(err.Error(), "no merge base") {
+ // git >= 2.28 now returns an error if base and head have become unrelated.
+ // previously it would return the results of git diff --name-only base head so let's try that...
+ stdout, err = NewCommand("diff", "--name-only", remoteBranch, headBranch).RunInDir(repo.Path)
+ }
if err != nil {
return nil, err
}
@@ -108,12 +114,24 @@ func (repo *Repository) GetDiff(base, head string, w io.Writer) error {
// GetPatch generates and returns format-patch data between given revisions.
func (repo *Repository) GetPatch(base, head string, w io.Writer) error {
- return NewCommand("format-patch", "--binary", "--stdout", base+"..."+head).
- RunInDirPipeline(repo.Path, w, nil)
+ stderr := new(bytes.Buffer)
+ err := NewCommand("format-patch", "--binary", "--stdout", base+"..."+head).
+ RunInDirPipeline(repo.Path, w, stderr)
+ if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) {
+ return NewCommand("format-patch", "--binary", "--stdout", base, head).
+ RunInDirPipeline(repo.Path, w, nil)
+ }
+ return err
}
// GetDiffFromMergeBase generates and return patch data from merge base to head
func (repo *Repository) GetDiffFromMergeBase(base, head string, w io.Writer) error {
- return NewCommand("diff", "-p", "--binary", base+"..."+head).
- RunInDirPipeline(repo.Path, w, nil)
+ stderr := new(bytes.Buffer)
+ err := NewCommand("diff", "-p", "--binary", base+"..."+head).
+ RunInDirPipeline(repo.Path, w, stderr)
+ if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) {
+ return NewCommand("diff", "-p", "--binary", base, head).
+ RunInDirPipeline(repo.Path, w, nil)
+ }
+ return err
}
diff --git a/routers/private/hook.go b/routers/private/hook.go
index 4b57aff588f..215793c9709 100644
--- a/routers/private/hook.go
+++ b/routers/private/hook.go
@@ -39,6 +39,7 @@ func verifyCommits(oldCommitID, newCommitID string, repo *git.Repository, env []
_ = stdoutWriter.Close()
}()
+ // This is safe as force pushes are already forbidden
err = git.NewCommand("rev-list", oldCommitID+"..."+newCommitID).
RunInDirTimeoutEnvFullPipelineFunc(env, -1, repo.Path,
stdoutWriter, nil, nil,
@@ -70,6 +71,7 @@ func checkFileProtection(oldCommitID, newCommitID string, patterns []glob.Glob,
_ = stdoutWriter.Close()
}()
+ // This use of ... is safe as force-pushes have already been ruled out.
err = git.NewCommand("diff", "--name-only", oldCommitID+"..."+newCommitID).
RunInDirTimeoutEnvFullPipelineFunc(env, -1, repo.Path,
stdoutWriter, nil, nil,
......@@ -2,8 +2,8 @@
# Contributor: 6543 <6543@obermui.de>
# Maintainer: 6543 <6543@obermui.de>
pkgname=gitea
pkgver=1.12.3
pkgrel=1
pkgver=1.12.4
pkgrel=0
pkgdesc="A self-hosted Git service written in Go"
url="https://gitea.io"
arch="all !mips !mips64"
......@@ -19,7 +19,7 @@ subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/go-gitea/gitea/archive/v$pkgver.tar.gz
$pkgname.initd
$pkgname.ini
0001-support-git-2.28-12370.patch
0001-fix-go1.15-lint-error-in-modules-public-public.go.patch
"
builddir="$srcdir/src/code.gitea.io/$pkgname"
......@@ -79,7 +79,7 @@ package() {
"$pkgdir"/etc/init.d/$pkgname
}
sha512sums="c79d1a3146bb3ed05a1f0ce37ecf7ca04320c9b9b16c2929d0dde9fde5eac3c09e860194be31f10cce91d94d58dd33917a814e3e5ce688185c11f29abc323523 gitea-1.12.3.tar.gz
3ae1969fc10fa2fc7323af74ce966d6e52b36f077cdccba1f46aec7213986d5fa0e139819029f09255ab38d79033bf115a0eeb15225574047c02407eeb6a3bb8 0001-support-git-2.28-12370.patch
sha512sums="5580aa5f6eff160f13ade8056a78c5fb866008990544147e116c84bfb4041492b0acd0d12cf5bb7ab72af08805c2cb17de358c1e615b565d7316d0fd4ccae654 gitea-1.12.4.tar.gz
8106650ae0ebffc4cadb32db18ed4af9b71029eee0d5f3be7654cf46596aa6767c80fe32fda82e482d24966b269a9e09c14e31aeb98f39a2fd683dc708991275 0001-fix-go1.15-lint-error-in-modules-public-public.go.patch
2497e6f2a18e3ceb65352cd220eab2c1c0893d0e731600462a60397de2b70d7c1de7db2af2769b25fe708b0822c811bb20dc797b59b9dd93efb376bea1c35796 gitea.initd
431184faffa8996873d92d7b0d16bc4b1a0178d264cd2928d1f49b13ad3e6470d9ede7a18c12112deeeb38f0647ccc0b012e98bcbd96e7b8496a3dc18f5b1fb7 gitea.ini"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment