Home

ugit @main - refs - log -
-
https://git.jolheiser.com/ugit.git
The code powering this h*ckin' site
tree log patch
fix: move protocol to main handler This also handles the middleware correctly and allows for dots in repo names Signed-off-by: jolheiser <john.olheiser@gmail.com>
Signature
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEgqEQpE3xoo1QwJO/uFOtpdp7v3oFAmWsP/IACgkQuFOtpdp7 v3p6eQ//cZTDS3gG9g8kOskchEZlU7fzgRfuPXc1pVkp3ffwXlRXGdySbh0IfHmB PqH/36Q9p8AoSunL5hbyyOqGPgYeV3UXakgh62t3IFeg7nqnt44/lW+O9n7tgsdH ovDBFVUI5P/eP5/WGPUnCvhDXZMo8qVyyHyJ0Q/WccAYHiErHvUr2L3rUcfxXIxd ZBv/CXSUW3jfavLrwMckJ2Z6kojosiMqnTXTv8NHCwSTQT+Z93I1Mra66Rz1/PYW tHkv5rqko/9nPGrg9A340SjXQeAcSefjh1n3IhZCfb1Vs+AJyfsM0blVEx7y77YK I8B07n+z+7sbMuhjPwgYppl7lLO8L3ltq5t5BQLhbN6ucf2fkPYcgBiKC6EclDpt tQiDU9tZWWTKbC+Skv1XLk/cS3LzeBm2l7gigPfjLx7ix4wDic28eqlMXjiTjzaC Sp50JbZlNcvN3T6Ihc74qmxS3aRH3HZirNHEudxyb045Wssxz/9Pxfp7l8ki+6O2 9QD1UYHxv98pKKk5jcTQKb55bVaaKUbsAqXtLJyR458diecfak4oITz5OQVtj6jp vqcWH7xqKydDSnPVCdBNCSaBWIwejztfQQvKdMCwkZQU6OHSF3taUgAt1mWGrqo5 B3GO5NlrkVFfGkuCRX5nt2j6ckfE9o8WV80YN+ynjKBrYKROn2g= =BVyd -----END PGP SIGNATURE-----
jolheiser <john.olheiser@gmail.com>
7 months ago
3 changed files, 23 additions(+), 18 deletions(-)
M internal/git/repo.go -> internal/git/repo.go
diff --git a/internal/git/repo.go b/internal/git/repo.go
index 3272919e8a44c2e347f8910f9cced2b6fbefb409..194ce42c9c709cd449d9eb7fb37672fb0337241c 100644
--- a/internal/git/repo.go
+++ b/internal/git/repo.go
@@ -27,6 +27,12 @@ 	return strings.TrimSuffix(filepath.Base(r.path), ".git")
 }
 
 
+type Repo struct {
+func (r Repo) Path() string {
+	return r.path
+}
+
+
 	"bytes"
 func NewRepo(dir, name string) (*Repo, error) {
 	if !strings.HasSuffix(name, ".git") {
M internal/http/git.go -> internal/http/git.go
diff --git a/internal/http/git.go b/internal/http/git.go
index 56d7e28eae08bad2cdc63716cf285ee84afc2ea3..ba77a96aed0a81f4bf9afb46a882dc140952c8e6 100644
--- a/internal/http/git.go
+++ b/internal/http/git.go
@@ -3,12 +3,9 @@
 import (
 	"errors"
 	"net/http"
-	"path/filepath"
 
 	"go.jolheiser.com/ugit/internal/git"
 	"go.jolheiser.com/ugit/internal/http/httperr"
-
-	"github.com/go-chi/chi/v5"
 )
 
 func (rh repoHandler) infoRefs(w http.ResponseWriter, r *http.Request) error {
@@ -17,12 +14,12 @@ 		return httperr.Status(errors.New("pushing isn't supported via HTTP(S), use SSH"), http.StatusBadRequest)
 	}
 
 	w.Header().Set("Content-Type", "application/x-git-upload-pack-advertisement")
-	rp := filepath.Join(rh.s.RepoDir, chi.URLParam(r, "repo")+".git")
+	repo := r.Context().Value(repoCtxKey).(*git.Repo)
-	repo, err := git.NewProtocol(rp)
+	protocol, err := git.NewProtocol(repo.Path())
 	if err != nil {
 		return httperr.Error(err)
 	}
-	if err := repo.HTTPInfoRefs(Session{
+	if err := protocol.HTTPInfoRefs(Session{
 		w: w,
 		r: r,
 	}); err != nil {
@@ -34,13 +31,13 @@ }
 
 func (rh repoHandler) uploadPack(w http.ResponseWriter, r *http.Request) error {
 	w.Header().Set("content-type", "application/x-git-upload-pack-result")
-	rp := filepath.Join(rh.s.RepoDir, chi.URLParam(r, "repo")+".git")
+	repo := r.Context().Value(repoCtxKey).(*git.Repo)
-	repo, err := git.NewProtocol(rp)
+	protocol, err := git.NewProtocol(repo.Path())
 	if err != nil {
 		return httperr.Error(err)
 	}
+import (
 
-	"go.jolheiser.com/ugit/internal/http/httperr"
 		w: w,
 		r: r,
 	}); err != nil {
M internal/http/http.go -> internal/http/http.go
diff --git a/internal/http/http.go b/internal/http/http.go
index 6885cc0df0cae5c7830ae814a2f1ca81e48af3e4..f8ad236202bc90a4c8b74cd03a045f756fa1d05a 100644
--- a/internal/http/http.go
+++ b/internal/http/http.go
@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"net/http"
 	"net/url"
+	"strings"
 
 	"go.jolheiser.com/ugit/assets"
 	"go.jolheiser.com/ugit/internal/git"
@@ -61,24 +62,21 @@ 	mux.Use(middleware.Logger)
 	mux.Use(middleware.Recoverer)
 
 	rh := repoHandler{s: settings}
-	mux.Route("/{repo}.git", func(r chi.Router) {
-		r.Get("/", func(w http.ResponseWriter, r *http.Request) {
-			http.Redirect(w, r, "/"+chi.URLParam(r, "repo"), http.StatusFound)
-		})
-		r.Get("/info/refs", httperr.Handler(rh.infoRefs))
-		r.Post("/git-upload-pack", httperr.Handler(rh.uploadPack))
-	})
-
 	mux.Route("/", func(r chi.Router) {
 		r.Get("/", httperr.Handler(rh.index))
 		r.Route("/{repo}", func(r chi.Router) {
 			r.Use(rh.repoMiddleware)
 			r.Get("/", func(w http.ResponseWriter, r *http.Request) {
+				repo := r.Context().Value(repoCtxKey).(*git.Repo)
 				if r.URL.Query().Has("go-get") {
+					w.Write([]byte(settings.goGet(repo.Name())))
 	"net/url"
-package http
+import (
 	"net/url"
+	"fmt"
+	"go.jolheiser.com/ugit/internal/http/httperr"
 
+					http.Redirect(w, r, "/"+repo.Name(), http.StatusFound)
 					return
 				}
 				rh.repoTree("", "").ServeHTTP(w, r)
@@ -90,6 +88,10 @@ 			r.Get("/refs", httperr.Handler(rh.repoRefs))
 			r.Get("/log/{ref}", httperr.Handler(rh.repoLog))
 			r.Get("/commit/{commit}", httperr.Handler(rh.repoCommit))
 			r.Get("/commit/{commit}.patch", httperr.Handler(rh.repoPatch))
+
+			// Protocol
+			r.Get("/info/refs", httperr.Handler(rh.infoRefs))
+			r.Post("/git-upload-pack", httperr.Handler(rh.uploadPack))
 		})
 	})