mirror of
https://github.com/imjasonh/infinite-git
synced 2026-07-08 09:05:06 +00:00
Major rewrite to eliminate git CLI dependency: - Created object package for Git object format handling (blob, tree, commit) - Implemented packfile generation from scratch - Rewrote repo initialization to create Git repos without CLI - Implemented git-upload-pack protocol in pure Go - Updated all server handlers to use new implementation - Added Git packet tracing to test.sh for debugging - Fixed tests to work with new implementation The server now works entirely with Go code, no git commands needed. Clone operations work correctly, but pull operations still have protocol negotiation issues that need further debugging. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"sync"
|
|
|
|
"github.com/chainguard-dev/clog"
|
|
"github.com/imjasonh/infinite-git/internal/generator"
|
|
"github.com/imjasonh/infinite-git/internal/repo"
|
|
)
|
|
|
|
// Server handles Git HTTP protocol requests.
|
|
type Server struct {
|
|
repo *repo.Repository
|
|
generator *generator.Generator
|
|
mu sync.Mutex
|
|
}
|
|
|
|
// New creates a new Git HTTP server.
|
|
func New(r *repo.Repository) *Server {
|
|
return &Server{
|
|
repo: r,
|
|
generator: generator.New(r),
|
|
}
|
|
}
|
|
|
|
// Handler returns the HTTP handler for the server.
|
|
func (s *Server) Handler() http.Handler {
|
|
mux := http.NewServeMux()
|
|
|
|
// Git smart HTTP endpoints
|
|
mux.HandleFunc("/info/refs", s.handleInfoRefs)
|
|
mux.HandleFunc("/git-upload-pack", s.handleUploadPack)
|
|
mux.HandleFunc("/git-receive-pack", s.handleReceivePack)
|
|
|
|
// Static file serving for dumb protocol (objects, refs)
|
|
mux.HandleFunc("/", s.handleStatic)
|
|
|
|
return s.logMiddleware(mux)
|
|
}
|
|
|
|
// logMiddleware logs HTTP requests.
|
|
func (s *Server) logMiddleware(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
log := clog.FromContext(r.Context())
|
|
log.Info("request",
|
|
"method", r.Method,
|
|
"path", r.URL.Path,
|
|
"query", r.URL.RawQuery,
|
|
"remote", r.RemoteAddr,
|
|
)
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
|
|
// handleReceivePack rejects push operations.
|
|
func (s *Server) handleReceivePack(w http.ResponseWriter, r *http.Request) {
|
|
log := clog.FromContext(r.Context())
|
|
log.Info("rejecting push attempt", "path", r.URL.Path)
|
|
http.Error(w, "Push access denied", http.StatusForbidden)
|
|
}
|
|
|
|
// handleStatic serves static Git files (for dumb protocol).
|
|
func (s *Server) handleStatic(w http.ResponseWriter, r *http.Request) {
|
|
// For now, we'll focus on smart protocol only
|
|
http.NotFound(w, r)
|
|
}
|