~sircmpwn/sr.ht-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
14 2

[PATCH git.sr.ht 1/3] Use libgit2/go-git for creating new repos. Also link pre-receive in autocreated repos

Details
Message ID
<b1a9e294353288696e1c62f10ff8dfc9f7789a3c.1597252412.git.nabijaczleweli@nabijaczleweli.xyz>
DKIM signature
pass
Download raw message
Patch: +92 -49
---
git-init(1) creates 11 files in hooks/, libgit2 just a README.sample

info/exclude differs as well, but it's entirely comments in either case

 gitsrht-shell/go.mod  |  1 +
 gitsrht-shell/go.sum  | 54 +++++++++++++++++++++++++++++++++++++++++++
 gitsrht-shell/main.go | 41 ++++++++++++++++----------------
 gitsrht/repos.py      | 45 ++++++++++++++----------------------
 4 files changed, 92 insertions(+), 49 deletions(-)

diff --git a/gitsrht-shell/go.mod b/gitsrht-shell/go.mod
index c9370a8..29a35e5 100644
--- a/gitsrht-shell/go.mod
+++ b/gitsrht-shell/go.mod
@@ -5,6 +5,7 @@ require (
	github.com/lib/pq v1.2.0
	github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec
	golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
	gopkg.in/src-d/go-git.v4 v4.13.1
)

go 1.13
diff --git a/gitsrht-shell/go.sum b/gitsrht-shell/go.sum
index b660f21..285542c 100644
--- a/gitsrht-shell/go.sum
+++ b/gitsrht-shell/go.sum
@@ -1,13 +1,67 @@
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmIpZJGRgNFg2ioYPvFaUxdqpDsg=
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec h1:DGmKwyZwEB8dI7tbLt/I/gQuP559o/0FrAkHKlQM/Ks=
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec/go.mod h1:owBmyHYMLkxyrugmfwE/DLJyW8Ro9mkphwuVErQ0iUw=
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qqCB4teTffacDWr7CI+0=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg=
gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98=
gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g=
gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE=
gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
diff --git a/gitsrht-shell/main.go b/gitsrht-shell/main.go
index b98f1d4..7b20765 100644
--- a/gitsrht-shell/main.go
+++ b/gitsrht-shell/main.go
@@ -17,6 +17,7 @@ import (
	"github.com/google/shlex"
	_ "github.com/lib/pq"
	"github.com/vaughan0/go-ini"
	"gopkg.in/src-d/go-git.v4"
)

const (
@@ -299,33 +300,31 @@ func main() {
				}

				// Note: update gitsrht/repos.py when changing this
				if err = exec.Command("mkdir", "-p", path).Run(); err != nil {
					notFound("mkdir", err)
				}
				if err = exec.Command("git", "init",
					"--bare", path).Run(); err != nil {

				repo, err := git.PlainInit(path, true)
				if err != nil {
					notFound("git init", err)
				}
				if err = exec.Command("git", "-C", path, "config",
					"srht.repo-id", strconv.Itoa(repoId)).Run(); err != nil {

					notFound("git config srht.repo-id", err)
				config, err := repo.Config()
				if err != nil {
					notFound("git config load", err)
				}
				if err = exec.Command("git", "-C", path, "config",
					"receive.denyDeleteCurrent", "ignore").Run(); err != nil {

					notFound("git config receive.denyDeleteCurrent", err)
				// These two are set by default by git(1) and libgit2
				config.Raw.SetOption("core", "", "repositoryformatversion", "0")
				config.Raw.SetOption("core", "", "filemode", "true")
				config.Raw.SetOption("srht", "", "repo-id", strconv.Itoa(repoId))
				config.Raw.SetOption("receive", "", "denyDeleteCurrent", "ignore")
				if err = repo.Storer.SetConfig(config); err != nil {
					notFound("git config save", err)
				}
				if err = exec.Command("ln", "-s", postUpdate,
					gopath.Join(path, "hooks", "update")).Run(); err != nil {

					notFound("ln update", err)
				hookdir := gopath.Join(path, "hooks")
				if err = os.Mkdir(hookdir, os.ModePerm); err != nil {
					notFound("git hook directory", err)
				}
				if err = exec.Command("ln", "-s", postUpdate,
					gopath.Join(path, "hooks", "post-update")).Run(); err != nil {

					notFound("ln post-update", err)
				for _, hook := range []string{"pre-receive", "update", "post-update"} {
					if err = os.Symlink(postUpdate, gopath.Join(hookdir, hook)); err != nil {
						notFound(fmt.Sprintf("linking git hook %v"), err)
					}
				}

				logger.Printf("Autocreated repo %s", path)
diff --git a/gitsrht/repos.py b/gitsrht/repos.py
index f0ad5fa..03fd7f4 100644
--- a/gitsrht/repos.py
+++ b/gitsrht/repos.py
@@ -1,5 +1,6 @@
import hashlib
import os.path
import pygit2
import subprocess
from gitsrht.types import Artifact, Repository, Redirect
from minio import Minio
@@ -85,38 +86,28 @@ class GitRepoApi(SimpleRepoApi):
    def do_init_repo(self, owner, repo):
        # Note: update gitsrht-shell when changing this,
        # do_clone_repo(), or _repo_config_init()
        subprocess.run(["mkdir", "-p", repo.path], check=True,
            stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        subprocess.run(["git", "init", "--bare"], cwd=repo.path, check=True,
            stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        self._repo_config_init(repo)
        git_repo = pygit2.init_repository(repo.path, bare=True,
            flags=pygit2.GIT_REPOSITORY_INIT_BARE |
                  pygit2.GIT_REPOSITORY_INIT_MKPATH)
        self._repo_config_init(repo, git_repo)

    def _repo_config_init(self, repo):
        subprocess.run(["git", "config", "srht.repo-id", str(repo.id)], check=True,
            cwd=repo.path, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    def _repo_config_init(self, repo, git_repo):
        git_repo.config["srht.repo-id"] = repo.id
        # We handle this ourselves in the post-update hook, and git's
        # default behaviour is to print a large notice and reject the push entirely
        subprocess.run(["git", "config", "receive.denyDeleteCurrent", "ignore"],
            check=True, cwd=repo.path,
            stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        subprocess.run(["ln", "-s",
                post_update,
                os.path.join(repo.path, "hooks", "pre-receive")
            ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        subprocess.run(["ln", "-s",
                post_update,
                os.path.join(repo.path, "hooks", "update")
            ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        subprocess.run(["ln", "-s",
                post_update,
                os.path.join(repo.path, "hooks", "post-update")
            ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        git_repo.config["receive.denyDeleteCurrent"] = "ignore"
        os.unlink(os.path.join(repo.path, "info", "exclude"))
        os.unlink(os.path.join(repo.path, "hooks", "README.sample"))
        os.unlink(os.path.join(repo.path, "description"))
        os.symlink(post_update, os.path.join(repo.path, "hooks", "pre-receive"))
        os.symlink(post_update, os.path.join(repo.path, "hooks", "update"))
        os.symlink(post_update, os.path.join(repo.path, "hooks", "post-update"))

    def do_delete_repo(self, repo):
        from gitsrht.webhooks import RepoWebhook
        RepoWebhook.Subscription.query.filter(
                RepoWebhook.Subscription.repo_id == repo.id).delete()
        # TODO: Should we delete these asyncronously?
        # TODO: Should we delete these asynchronously?
        for artifact in (Artifact.query
                .filter(Artifact.user_id == repo.owner_id)
                .filter(Artifact.repo_id == repo.id)):
@@ -124,7 +115,5 @@ class GitRepoApi(SimpleRepoApi):
        super().do_delete_repo(repo)

    def do_clone_repo(self, source, repo):
        subprocess.run(["mkdir", "-p", repo.path], check=True,
            stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        subprocess.run(["git", "clone", "--bare", source, repo.path])
        self._repo_config_init(repo)
        git_repo = pygit2.clone_repository(source, repo.path, bare=True)
        self._repo_config_init(repo, git_repo)
-- 
2.20.1

[PATCH git.sr.ht 2/3] Set receive.advertisePushOptions=true for new repos

Details
Message ID
<d7c556975b240be7bab7a1bb865fd8926980638c.1597252412.git.nabijaczleweli@nabijaczleweli.xyz>
In-Reply-To
<b1a9e294353288696e1c62f10ff8dfc9f7789a3c.1597252412.git.nabijaczleweli@nabijaczleweli.xyz> (view parent)
DKIM signature
pass
Download raw message
Patch: +2 -0
Required to be able to actually use them when pushing
---
Funnily enough, pushing to the official git.sr.ht instance doesn't
reject the push, but it also entirely ignores any options I give it, so

 gitsrht-shell/main.go | 1 +
 gitsrht/repos.py      | 1 +
 2 files changed, 2 insertions(+)

diff --git a/gitsrht-shell/main.go b/gitsrht-shell/main.go
index 7b20765..b0108de 100644
--- a/gitsrht-shell/main.go
+++ b/gitsrht-shell/main.go
@@ -313,6 +313,7 @@ func main() {
				config.Raw.SetOption("core", "", "filemode", "true")
				config.Raw.SetOption("srht", "", "repo-id", strconv.Itoa(repoId))
				config.Raw.SetOption("receive", "", "denyDeleteCurrent", "ignore")
				config.Raw.SetOption("receive", "", "advertisePushOptions", "true")
				if err = repo.Storer.SetConfig(config); err != nil {
					notFound("git config save", err)
				}
diff --git a/gitsrht/repos.py b/gitsrht/repos.py
index 03fd7f4..8691969 100644
--- a/gitsrht/repos.py
+++ b/gitsrht/repos.py
@@ -96,6 +96,7 @@ class GitRepoApi(SimpleRepoApi):
        # We handle this ourselves in the post-update hook, and git's
        # default behaviour is to print a large notice and reject the push entirely
        git_repo.config["receive.denyDeleteCurrent"] = "ignore"
        git_repo.config["receive.advertisePushOptions"] = True
        os.unlink(os.path.join(repo.path, "info", "exclude"))
        os.unlink(os.path.join(repo.path, "hooks", "README.sample"))
        os.unlink(os.path.join(repo.path, "description"))
-- 
2.20.1

[PATCH git.sr.ht 3/3] Add migration for receive.advertisePushOptions=true, previously missing pre-receive hooks, pruning useless files

Details
Message ID
<599536bca35c38ef1e0eab837cbc39f015e757d1.1597252412.git.nabijaczleweli@nabijaczleweli.xyz>
In-Reply-To
<b1a9e294353288696e1c62f10ff8dfc9f7789a3c.1597252412.git.nabijaczleweli@nabijaczleweli.xyz> (view parent)
DKIM signature
pass
Download raw message
Patch: +66 -0
---
We don't use any of these files, and new creation scripts don't make them

 ...a45_clean_up_samples_allow_push_options.py | 66 +++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100755 gitsrht/alembic/versions/dacab1dcba45_clean_up_samples_allow_push_options.py

diff --git a/gitsrht/alembic/versions/dacab1dcba45_clean_up_samples_allow_push_options.py b/gitsrht/alembic/versions/dacab1dcba45_clean_up_samples_allow_push_options.py
new file mode 100755
index 0000000..45cbaa2
--- /dev/null
+++ b/gitsrht/alembic/versions/dacab1dcba45_clean_up_samples_allow_push_options.py
@@ -0,0 +1,66 @@
"""Clean up samples, allow push options

Revision ID: dacab1dcba45
Revises: 9f72f0dea908
Create Date: 2020-08-12 18:45:59.390269

"""

# revision identifiers, used by Alembic.
revision = 'dacab1dcba45'
down_revision = '9f72f0dea908'

import glob
import os.path
from alembic import op
from sqlalchemy.orm import sessionmaker
from pygit2 import Repository as GitRepository
from gitsrht.types import Repository
from srht.config import cfg
try:
    from tqdm import tqdm
except ImportError:
    def tqdm(iterable):
        yield from iterable

Session = sessionmaker()

post_update = cfg("git.sr.ht", "post-update-script")


def upgrade():
    bind = op.get_bind()
    session = Session(bind=bind)
    print("Allowing push options, fixing repositories with missing hooks, pruning samples")
    for repo in tqdm(session.query(Repository).all()):
        git_repo = GitRepository(repo.path)
        git_repo.config["receive.advertisePushOptions"] = True

        try:
            # pre-receive wasn't linked for autocreated repositories
            os.symlink(post_update, os.path.join(repo.path, "hooks", "pre-receive"))
        except FileExistsError:
            pass

        try:
            os.unlink(os.path.join(repo.path, "description"))
        except FileNotFoundError:
            pass
        try:
            os.unlink(os.path.join(repo.path, "info", "exclude"))
        except FileNotFoundError:
            pass

        for samp in glob.glob(os.path.join(repo.path, "hooks", "*.sample")):
            os.unlink(samp)


def downgrade():
    bind = op.get_bind()
    session = Session(bind=bind)
    for repo in tqdm(session.query(Repository).all()):
        git_repo = GitRepository(repo.path)
        try:
            del git_repo.config["receive.advertisePushOptions"]
        except KeyError:
            pass
-- 
2.20.1
Details
Message ID
<C4VWL0NZ4Q18.2S9DE5DS19K7L@homura>
In-Reply-To
<b1a9e294353288696e1c62f10ff8dfc9f7789a3c.1597252412.git.nabijaczleweli@nabijaczleweli.xyz> (view parent)
DKIM signature
pass
Download raw message
Why is this desirable?

For one, it makes the behavior inconsistent with Python.

For another, we've been standardizing on this for Go:

https://github.com/go-git/go-git
Details
Message ID
<20200813142529.fxhi7ahj5zfmzywn@tarta.local.nabijaczleweli.xyz>
In-Reply-To
<C4VWL0NZ4Q18.2S9DE5DS19K7L@homura> (view parent)
DKIM signature
pass
Download raw message
On Thu, Aug 13, 2020 at 09:29:21AM -0400, Drew DeVault wrote:
> Why is this desirable?
For one, it avoids 7 (6 in gitsrht-shell) forks to do something trivial
(and, in the case of gitsrht-shell, somewhere you dubbed Performance
 Important).

It also fixes the missing pre-receive hook in gitsrht-shell,
allthewhile making that part easier to maintain ‒ What's Being Done
isn't lost in dozens of lines of boilerplate and error handling for
the forks
(I've gone through that part of the code however-many times this past
 month, and only noticed the bug only twice, and forgot about it the
 first time, because I was doing something unrelated).

Plus, this is hardly the first time I'm fixing what was Just left out
and didn't match the Python.

Not to mention this avoids the 11+1+1 files of clutter.

> For one, it makes the behavior inconsistent with Python.
nabijaczleweli@tarta:~/uwu$ ./tarsum < hidden-pygit2.tar | sort
4cf2d64e44205fe628ddd534e1151b58  hidden/pygit2/HEAD
7bae3a4535c80fcb31dade4eaf6802e0  hidden/pygit2/config
nabijaczleweli@tarta:~/uwu$ ./tarsum < hidden-go-git.tar | sort
4cf2d64e44205fe628ddd534e1151b58  hidden/go-git/HEAD
7bae3a4535c80fcb31dade4eaf6802e0  hidden/go-git/config
nabijaczleweli@tarta:~/uwu/hidden$ tree
.
├── go-git
│   ├── config
│   ├── HEAD
│   ├── hooks
│   │   ├── post-update -> /usr/bin/gitsrht-update-hook
│   │   ├── pre-receive -> /usr/bin/gitsrht-update-hook
│   │   └── update -> /usr/bin/gitsrht-update-hook
│   ├── objects
│   │   ├── info
│   │   └── pack
│   └── refs
│       ├── heads
│       └── tags
└── pygit2
    ├── config
    ├── HEAD
    ├── hooks
    │   ├── post-update -> /usr/bin/gitsrht-update-hook
    │   ├── pre-receive -> /usr/bin/gitsrht-update-hook
    │   └── update -> /usr/bin/gitsrht-update-hook
    ├── info
    ├── objects
    │   ├── info
    │   └── pack
    └── refs
        ├── heads
        └── tags

17 directories, 10 files

I guess the libgit2 method has a single info directory which is created
by some operations later on anyway, you caught me.

But sure, try out the two attached excerpts, maybe you'll find
something I missed.

> For another, we've been standardizing on this for Go:
Not sure what you mean by this, I just copied the import decl from
gitsrht-update-hook/post-update.go; is that passé?

наб
Details
Message ID
<C4VXSDZWS7G3.3T48KEGSNQ87O@homura>
In-Reply-To
<20200813142529.fxhi7ahj5zfmzywn@tarta.local.nabijaczleweli.xyz> (view parent)
DKIM signature
pass
Download raw message
On Thu Aug 13, 2020 at 10:25 AM EDT, наб wrote:
> On Thu, Aug 13, 2020 at 09:29:21AM -0400, Drew DeVault wrote:
> > Why is this desirable?
> For one, it avoids 7 (6 in gitsrht-shell) forks to do something trivial
> (and, in the case of gitsrht-shell, somewhere you dubbed Performance
> Important).

Right, but automatic repo creation is an edge case where performance
matters a lot less.

> > For another, we've been standardizing on this for Go:
> Not sure what you mean by this, I just copied the import decl from
> gitsrht-update-hook/post-update.go; is that passé?

If post-update.go is using libgit2 go, it should probably be updated to
use go-git.
Details
Message ID
<20200813144847.2fkidcijpsms7qjs@tarta.local.nabijaczleweli.xyz>
In-Reply-To
<C4VXSDZWS7G3.3T48KEGSNQ87O@homura> (view parent)
DKIM signature
pass
Download raw message
On Thu, Aug 13, 2020 at 10:25:59AM -0400, Drew DeVault wrote:
> Right, but automatic repo creation is an edge case where performance
> matters a lot less.
Exactly, and maintainability and avoiding it getting to the terminally
broken point it was at beforehand does matter.

> If post-update.go is using libgit2 go, it should probably be updated to
> use go-git.
No idea where you got that from, since they both very prominently use
go-git, but I'll reroll with an update.
Details
Message ID
<C4VYAAH87TUK.22HTSRC99T4CR@homura>
In-Reply-To
<20200813144847.2fkidcijpsms7qjs@tarta.local.nabijaczleweli.xyz> (view parent)
DKIM signature
pass
Download raw message
On Thu Aug 13, 2020 at 10:48 AM EDT, наб wrote:
> Exactly, and maintainability and avoiding it getting to the terminally
> broken point it was at beforehand does matter.

Okay, I accept the utility of this change. However...

> No idea where you got that from, since they both very prominently use
> go-git, but I'll reroll with an update.

But your *patch* uses a different git implementation, based on libgit2.
There should not be two implementations here.
Details
Message ID
<20200813145749.zlu7qc7gukxhq5q4@tarta.local.nabijaczleweli.xyz>
In-Reply-To
<C4VYAAH87TUK.22HTSRC99T4CR@homura> (view parent)
DKIM signature
pass
Download raw message
On Thu, Aug 13, 2020 at 10:49:22AM -0400, Drew DeVault wrote:
> But your *patch* uses a different git implementation, based on libgit2.
> There should not be two implementations here.
Unless I'm missing the point entirely (which is possible), both
  https://git.sr.ht/~sircmpwn/git.sr.ht/tree/0.56.2/gitsrht-update-hook/post-update.go#L15
and
  https://lists.sr.ht/~sircmpwn/sr.ht-dev/%3Cb1a9e294353288696e1c62f10ff8dfc9f7789a3c.1597252412.git.nabijaczleweli%40nabijaczleweli.xyz%3E#%3Cb1a9e294353288696e1c62f10ff8dfc9f7789a3c.1597252412.git.nabijaczleweli@nabijaczleweli.xyz%3E-104
say
  "gopkg.in/src-d/go-git.v4"
and opening that URL reads
  A highly extensible git implementation in pure Go.
and libgit2 isn't written in Go (yet).
Details
Message ID
<C4VYHAI8I9KW.3UXBMZXGVWDTF@homura>
In-Reply-To
<20200813145749.zlu7qc7gukxhq5q4@tarta.local.nabijaczleweli.xyz> (view parent)
DKIM signature
pass
Download raw message
Oh, I had thought that "libgit2/go-git" was a partial Go package path in
the subject line. I didn't realize that you meant pygit2 here. This
patch is probably good, then, I'll give it a closer look later.

[PATCH git.sr.ht v2 1/4] Update to go-git v5 in gitsrht-update-hook

Details
Message ID
<74ed6e1cee81e5577cffeae3c01f0667a62ddebb.1597331858.git.nabijaczleweli@nabijaczleweli.xyz>
In-Reply-To
<20200813144847.2fkidcijpsms7qjs@tarta.local.nabijaczleweli.xyz> (view parent)
DKIM signature
pass
Download raw message
Patch: +54 -40
---
 gitsrht-update-hook/go.mod         | 14 +++----
 gitsrht-update-hook/go.sum         | 64 ++++++++++++++++++------------
 gitsrht-update-hook/post-update.go |  8 ++--
 gitsrht-update-hook/submitter.go   |  4 +-
 gitsrht-update-hook/types.go       |  4 +-
 5 files changed, 54 insertions(+), 40 deletions(-)

diff --git a/gitsrht-update-hook/go.mod b/gitsrht-update-hook/go.mod
index cc86814..cad4ba1 100644
--- a/gitsrht-update-hook/go.mod
+++ b/gitsrht-update-hook/go.mod
@@ -4,13 +4,13 @@ go 1.13

require (
	github.com/fernet/fernet-go v0.0.0-20191111064656-eff2850e6001
	github.com/go-redis/redis v6.15.6+incompatible
	github.com/go-git/go-git/v5 v5.1.0
	github.com/go-redis/redis v6.15.9+incompatible
	github.com/google/uuid v1.1.1
	github.com/lib/pq v1.2.0
	github.com/mattn/go-runewidth v0.0.6
	github.com/pkg/errors v0.8.1
	github.com/lib/pq v1.8.0
	github.com/mattn/go-runewidth v0.0.9
	github.com/pkg/errors v0.9.1
	github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec
	golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
	gopkg.in/src-d/go-git.v4 v4.13.1
	gopkg.in/yaml.v2 v2.2.7
	golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de
	gopkg.in/yaml.v2 v2.3.0
)
diff --git a/gitsrht-update-hook/go.sum b/gitsrht-update-hook/go.sum
index 71e9d69..eae0f8c 100644
--- a/gitsrht-update-hook/go.sum
+++ b/gitsrht-update-hook/go.sum
@@ -1,7 +1,7 @@
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
@@ -10,11 +10,24 @@ github.com/fernet/fernet-go v0.0.0-20191111064656-eff2850e6001 h1:/UMxx5lGDg30ai
github.com/fernet/fernet-go v0.0.0-20191111064656-eff2850e6001/go.mod h1:2H9hjfbpSMHwY503FclkV/lZTBh2YlOmLLSda12uL8c=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
github.com/go-git/go-billy/v5 v5.0.0 h1:7NQHvd9FVid8VL4qVUMm8XifBK+2xCoZ2lSk0agRrHM=
github.com/go-git/go-billy/v5 v5.0.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
github.com/go-git/go-git v1.0.0 h1:YcN9iDGDoXuIw0vHls6rINwV416HYa0EB2X+RBsyYp4=
github.com/go-git/go-git v4.7.0+incompatible h1:+W9rgGY4DOKKdX2x6HxSR7HNeTxqiKrOvKnuittYVdA=
github.com/go-git/go-git-fixtures/v4 v4.0.1/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw=
github.com/go-git/go-git/v5 v5.1.0 h1:HxJn9g/E7eYvKW3Fm7Jt4ee8LXfPOm/H1cdDu8vEssk=
github.com/go-git/go-git/v5 v5.1.0/go.mod h1:ZKfuPUoY1ZqIG4QG9BDBh3G4gLM5zvPuSJAozQrZuyM=
github.com/go-redis/redis v6.15.6+incompatible h1:H9evprGPLI8+ci7fxQx6WNZHJSb7be8FqJQRhdQZ5Sg=
github.com/go-redis/redis v6.15.6+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
@@ -22,56 +35,57 @@ github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.8.0 h1:9xohqzkUwzR4Ga4ivdTcawVS89YSDVxXMa3xJX3cGzg=
github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-runewidth v0.0.6 h1:V2iyH+aX9C5fsYCpK60U8BYIvmhqxuOL3JZcqc1NB7k=
github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec h1:DGmKwyZwEB8dI7tbLt/I/gQuP559o/0FrAkHKlQM/Ks=
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec/go.mod h1:owBmyHYMLkxyrugmfwE/DLJyW8Ro9mkphwuVErQ0iUw=
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig=
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qqCB4teTffacDWr7CI+0=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg=
gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98=
gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g=
gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE=
gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/gitsrht-update-hook/post-update.go b/gitsrht-update-hook/post-update.go
index 8b9c4e9..4d22f46 100644
--- a/gitsrht-update-hook/post-update.go
+++ b/gitsrht-update-hook/post-update.go
@@ -12,10 +12,10 @@ import (

	goredis "github.com/go-redis/redis"
	_ "github.com/lib/pq"
	"gopkg.in/src-d/go-git.v4"
	"gopkg.in/src-d/go-git.v4/plumbing"
	"gopkg.in/src-d/go-git.v4/plumbing/object"
	"gopkg.in/src-d/go-git.v4/plumbing/storer"
	"github.com/go-git/go-git/v5"
	"github.com/go-git/go-git/v5/plumbing"
	"github.com/go-git/go-git/v5/plumbing/object"
	"github.com/go-git/go-git/v5/plumbing/storer"
)

func printAutocreateInfo(context PushContext) {
diff --git a/gitsrht-update-hook/submitter.go b/gitsrht-update-hook/submitter.go
index 097aa75..712661c 100644
--- a/gitsrht-update-hook/submitter.go
+++ b/gitsrht-update-hook/submitter.go
@@ -15,8 +15,8 @@ import (

	"github.com/fernet/fernet-go"
	"github.com/pkg/errors"
	"gopkg.in/src-d/go-git.v4"
	"gopkg.in/src-d/go-git.v4/plumbing/object"
	"github.com/go-git/go-git/v5"
	"github.com/go-git/go-git/v5/plumbing/object"
)

var (
diff --git a/gitsrht-update-hook/types.go b/gitsrht-update-hook/types.go
index efe1429..5f0033c 100644
--- a/gitsrht-update-hook/types.go
+++ b/gitsrht-update-hook/types.go
@@ -4,8 +4,8 @@ import (
	"encoding/base64"
	"io/ioutil"

	"gopkg.in/src-d/go-git.v4/plumbing"
	"gopkg.in/src-d/go-git.v4/plumbing/object"
	"github.com/go-git/go-git/v5/plumbing"
	"github.com/go-git/go-git/v5/plumbing/object"
)

type RepoContext struct {
-- 
2.20.1

[PATCH git.sr.ht v2 2/4] Use pygit2/go-git for creating new repos. Also link pre-receive in autocreated repos

Details
Message ID
<401cbad007cf59f82c5cf5ea16bd15b6a07d7d62.1597331858.git.nabijaczleweli@nabijaczleweli.xyz>
In-Reply-To
<20200813144847.2fkidcijpsms7qjs@tarta.local.nabijaczleweli.xyz> (view parent)
DKIM signature
pass
Download raw message
Patch: +103 -58
---
 gitsrht-shell/go.mod  |  6 ++--
 gitsrht-shell/go.sum  | 69 +++++++++++++++++++++++++++++++++++++++----
 gitsrht-shell/main.go | 41 +++++++++++++------------
 gitsrht/repos.py      | 45 +++++++++++-----------------
 4 files changed, 103 insertions(+), 58 deletions(-)

diff --git a/gitsrht-shell/go.mod b/gitsrht-shell/go.mod
index c9370a8..6140a10 100644
--- a/gitsrht-shell/go.mod
+++ b/gitsrht-shell/go.mod
@@ -1,10 +1,10 @@
module git.sr.ht/~sircmpwn/git.sr.ht/gitsrht-shell

require (
	github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf
	github.com/lib/pq v1.2.0
	github.com/go-git/go-git/v5 v5.1.0
	github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
	github.com/lib/pq v1.8.0
	github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec
	golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
)

go 1.13
diff --git a/gitsrht-shell/go.sum b/gitsrht-shell/go.sum
index b660f21..fe32c9e 100644
--- a/gitsrht-shell/go.sum
+++ b/gitsrht-shell/go.sum
@@ -1,13 +1,70 @@
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmIpZJGRgNFg2ioYPvFaUxdqpDsg=
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE=
github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
github.com/go-git/go-billy/v5 v5.0.0 h1:7NQHvd9FVid8VL4qVUMm8XifBK+2xCoZ2lSk0agRrHM=
github.com/go-git/go-billy/v5 v5.0.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
github.com/go-git/go-git v1.0.0 h1:YcN9iDGDoXuIw0vHls6rINwV416HYa0EB2X+RBsyYp4=
github.com/go-git/go-git v4.7.0+incompatible h1:+W9rgGY4DOKKdX2x6HxSR7HNeTxqiKrOvKnuittYVdA=
github.com/go-git/go-git-fixtures/v4 v4.0.1/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw=
github.com/go-git/go-git/v5 v5.1.0 h1:HxJn9g/E7eYvKW3Fm7Jt4ee8LXfPOm/H1cdDu8vEssk=
github.com/go-git/go-git/v5 v5.1.0/go.mod h1:ZKfuPUoY1ZqIG4QG9BDBh3G4gLM5zvPuSJAozQrZuyM=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.8.0 h1:9xohqzkUwzR4Ga4ivdTcawVS89YSDVxXMa3xJX3cGzg=
github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec h1:DGmKwyZwEB8dI7tbLt/I/gQuP559o/0FrAkHKlQM/Ks=
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec/go.mod h1:owBmyHYMLkxyrugmfwE/DLJyW8Ro9mkphwuVErQ0iUw=
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/gitsrht-shell/main.go b/gitsrht-shell/main.go
index b98f1d4..810a5d3 100644
--- a/gitsrht-shell/main.go
+++ b/gitsrht-shell/main.go
@@ -17,6 +17,7 @@ import (
	"github.com/google/shlex"
	_ "github.com/lib/pq"
	"github.com/vaughan0/go-ini"
	"github.com/go-git/go-git/v5"
)

const (
@@ -299,33 +300,31 @@ func main() {
				}

				// Note: update gitsrht/repos.py when changing this
				if err = exec.Command("mkdir", "-p", path).Run(); err != nil {
					notFound("mkdir", err)
				}
				if err = exec.Command("git", "init",
					"--bare", path).Run(); err != nil {

				repo, err := git.PlainInit(path, true)
				if err != nil {
					notFound("git init", err)
				}
				if err = exec.Command("git", "-C", path, "config",
					"srht.repo-id", strconv.Itoa(repoId)).Run(); err != nil {

					notFound("git config srht.repo-id", err)
				config, err := repo.Config()
				if err != nil {
					notFound("git config load", err)
				}
				if err = exec.Command("git", "-C", path, "config",
					"receive.denyDeleteCurrent", "ignore").Run(); err != nil {

					notFound("git config receive.denyDeleteCurrent", err)
				// These two are set by default by git(1) and libgit2
				config.Raw.SetOption("core", "", "repositoryformatversion", "0")
				config.Raw.SetOption("core", "", "filemode", "true")
				config.Raw.SetOption("srht", "", "repo-id", strconv.Itoa(repoId))
				config.Raw.SetOption("receive", "", "denyDeleteCurrent", "ignore")
				if err = repo.Storer.SetConfig(config); err != nil {
					notFound("git config save", err)
				}
				if err = exec.Command("ln", "-s", postUpdate,
					gopath.Join(path, "hooks", "update")).Run(); err != nil {

					notFound("ln update", err)
				hookdir := gopath.Join(path, "hooks")
				if err = os.Mkdir(hookdir, os.ModePerm); err != nil {
					notFound("git hook directory", err)
				}
				if err = exec.Command("ln", "-s", postUpdate,
					gopath.Join(path, "hooks", "post-update")).Run(); err != nil {

					notFound("ln post-update", err)
				for _, hook := range []string{"pre-receive", "update", "post-update"} {
					if err = os.Symlink(postUpdate, gopath.Join(hookdir, hook)); err != nil {
						notFound(fmt.Sprintf("linking git hook %v"), err)
					}
				}

				logger.Printf("Autocreated repo %s", path)
diff --git a/gitsrht/repos.py b/gitsrht/repos.py
index f0ad5fa..03fd7f4 100644
--- a/gitsrht/repos.py
+++ b/gitsrht/repos.py
@@ -1,5 +1,6 @@
import hashlib
import os.path
import pygit2
import subprocess
from gitsrht.types import Artifact, Repository, Redirect
from minio import Minio
@@ -85,38 +86,28 @@ class GitRepoApi(SimpleRepoApi):
    def do_init_repo(self, owner, repo):
        # Note: update gitsrht-shell when changing this,
        # do_clone_repo(), or _repo_config_init()
        subprocess.run(["mkdir", "-p", repo.path], check=True,
            stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        subprocess.run(["git", "init", "--bare"], cwd=repo.path, check=True,
            stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        self._repo_config_init(repo)
        git_repo = pygit2.init_repository(repo.path, bare=True,
            flags=pygit2.GIT_REPOSITORY_INIT_BARE |
                  pygit2.GIT_REPOSITORY_INIT_MKPATH)
        self._repo_config_init(repo, git_repo)

    def _repo_config_init(self, repo):
        subprocess.run(["git", "config", "srht.repo-id", str(repo.id)], check=True,
            cwd=repo.path, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    def _repo_config_init(self, repo, git_repo):
        git_repo.config["srht.repo-id"] = repo.id
        # We handle this ourselves in the post-update hook, and git's
        # default behaviour is to print a large notice and reject the push entirely
        subprocess.run(["git", "config", "receive.denyDeleteCurrent", "ignore"],
            check=True, cwd=repo.path,
            stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        subprocess.run(["ln", "-s",
                post_update,
                os.path.join(repo.path, "hooks", "pre-receive")
            ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        subprocess.run(["ln", "-s",
                post_update,
                os.path.join(repo.path, "hooks", "update")
            ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        subprocess.run(["ln", "-s",
                post_update,
                os.path.join(repo.path, "hooks", "post-update")
            ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        git_repo.config["receive.denyDeleteCurrent"] = "ignore"
        os.unlink(os.path.join(repo.path, "info", "exclude"))
        os.unlink(os.path.join(repo.path, "hooks", "README.sample"))
        os.unlink(os.path.join(repo.path, "description"))
        os.symlink(post_update, os.path.join(repo.path, "hooks", "pre-receive"))
        os.symlink(post_update, os.path.join(repo.path, "hooks", "update"))
        os.symlink(post_update, os.path.join(repo.path, "hooks", "post-update"))

    def do_delete_repo(self, repo):
        from gitsrht.webhooks import RepoWebhook
        RepoWebhook.Subscription.query.filter(
                RepoWebhook.Subscription.repo_id == repo.id).delete()
        # TODO: Should we delete these asyncronously?
        # TODO: Should we delete these asynchronously?
        for artifact in (Artifact.query
                .filter(Artifact.user_id == repo.owner_id)
                .filter(Artifact.repo_id == repo.id)):
@@ -124,7 +115,5 @@ class GitRepoApi(SimpleRepoApi):
        super().do_delete_repo(repo)

    def do_clone_repo(self, source, repo):
        subprocess.run(["mkdir", "-p", repo.path], check=True,
            stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        subprocess.run(["git", "clone", "--bare", source, repo.path])
        self._repo_config_init(repo)
        git_repo = pygit2.clone_repository(source, repo.path, bare=True)
        self._repo_config_init(repo, git_repo)
-- 
2.20.1

[PATCH git.sr.ht v2 3/4] Set receive.advertisePushOptions=true for new repos

Details
Message ID
<df7d91fce18ac328abe8bfe9a36a01f1401abb6a.1597331858.git.nabijaczleweli@nabijaczleweli.xyz>
In-Reply-To
<20200813144847.2fkidcijpsms7qjs@tarta.local.nabijaczleweli.xyz> (view parent)
DKIM signature
pass
Download raw message
Patch: +2 -0
Required to be able to actually use them when pushing
---
 gitsrht-shell/main.go | 1 +
 gitsrht/repos.py      | 1 +
 2 files changed, 2 insertions(+)

diff --git a/gitsrht-shell/main.go b/gitsrht-shell/main.go
index 810a5d3..b203419 100644
--- a/gitsrht-shell/main.go
+++ b/gitsrht-shell/main.go
@@ -313,6 +313,7 @@ func main() {
				config.Raw.SetOption("core", "", "filemode", "true")
				config.Raw.SetOption("srht", "", "repo-id", strconv.Itoa(repoId))
				config.Raw.SetOption("receive", "", "denyDeleteCurrent", "ignore")
				config.Raw.SetOption("receive", "", "advertisePushOptions", "true")
				if err = repo.Storer.SetConfig(config); err != nil {
					notFound("git config save", err)
				}
diff --git a/gitsrht/repos.py b/gitsrht/repos.py
index 03fd7f4..8691969 100644
--- a/gitsrht/repos.py
+++ b/gitsrht/repos.py
@@ -96,6 +96,7 @@ class GitRepoApi(SimpleRepoApi):
        # We handle this ourselves in the post-update hook, and git's
        # default behaviour is to print a large notice and reject the push entirely
        git_repo.config["receive.denyDeleteCurrent"] = "ignore"
        git_repo.config["receive.advertisePushOptions"] = True
        os.unlink(os.path.join(repo.path, "info", "exclude"))
        os.unlink(os.path.join(repo.path, "hooks", "README.sample"))
        os.unlink(os.path.join(repo.path, "description"))
-- 
2.20.1

[PATCH git.sr.ht v2 4/4] Add migration for receive.advertisePushOptions=true, previously missing pre-receive hooks, pruning useless files

Details
Message ID
<eea9c9de4df501ccc6b52a7e799ab200d1acb88d.1597331858.git.nabijaczleweli@nabijaczleweli.xyz>
In-Reply-To
<20200813144847.2fkidcijpsms7qjs@tarta.local.nabijaczleweli.xyz> (view parent)
DKIM signature
pass
Download raw message
Patch: +66 -0
---
 ...a45_clean_up_samples_allow_push_options.py | 66 +++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100755 gitsrht/alembic/versions/dacab1dcba45_clean_up_samples_allow_push_options.py

diff --git a/gitsrht/alembic/versions/dacab1dcba45_clean_up_samples_allow_push_options.py b/gitsrht/alembic/versions/dacab1dcba45_clean_up_samples_allow_push_options.py
new file mode 100755
index 0000000..45cbaa2
--- /dev/null
+++ b/gitsrht/alembic/versions/dacab1dcba45_clean_up_samples_allow_push_options.py
@@ -0,0 +1,66 @@
"""Clean up samples, allow push options

Revision ID: dacab1dcba45
Revises: 9f72f0dea908
Create Date: 2020-08-12 18:45:59.390269

"""

# revision identifiers, used by Alembic.
revision = 'dacab1dcba45'
down_revision = '9f72f0dea908'

import glob
import os.path
from alembic import op
from sqlalchemy.orm import sessionmaker
from pygit2 import Repository as GitRepository
from gitsrht.types import Repository
from srht.config import cfg
try:
    from tqdm import tqdm
except ImportError:
    def tqdm(iterable):
        yield from iterable

Session = sessionmaker()

post_update = cfg("git.sr.ht", "post-update-script")


def upgrade():
    bind = op.get_bind()
    session = Session(bind=bind)
    print("Allowing push options, fixing repositories with missing hooks, pruning samples")
    for repo in tqdm(session.query(Repository).all()):
        git_repo = GitRepository(repo.path)
        git_repo.config["receive.advertisePushOptions"] = True

        try:
            # pre-receive wasn't linked for autocreated repositories
            os.symlink(post_update, os.path.join(repo.path, "hooks", "pre-receive"))
        except FileExistsError:
            pass

        try:
            os.unlink(os.path.join(repo.path, "description"))
        except FileNotFoundError:
            pass
        try:
            os.unlink(os.path.join(repo.path, "info", "exclude"))
        except FileNotFoundError:
            pass

        for samp in glob.glob(os.path.join(repo.path, "hooks", "*.sample")):
            os.unlink(samp)


def downgrade():
    bind = op.get_bind()
    session = Session(bind=bind)
    for repo in tqdm(session.query(Repository).all()):
        git_repo = GitRepository(repo.path)
        try:
            del git_repo.config["receive.advertisePushOptions"]
        except KeyError:
            pass
-- 
2.20.1

Re: [PATCH git.sr.ht v2 1/4] Update to go-git v5 in gitsrht-update-hook

Details
Message ID
<C4WT5SDKK1EC.151JIL5XALXMO@homura>
In-Reply-To
<74ed6e1cee81e5577cffeae3c01f0667a62ddebb.1597331858.git.nabijaczleweli@nabijaczleweli.xyz> (view parent)
DKIM signature
pass
Download raw message
Thanks!

To git@git.sr.ht:~sircmpwn/git.sr.ht
   80d9dbc..2e9afc6  master -> master
Review patch Export thread (mbox)