Skip to content

Conversation

@aymanbagabas
Copy link
Member

@aymanbagabas aymanbagabas commented Jul 7, 2025

This adds a new gogit daemon command that starts a Git TCP server. It uses a local pure Go implementation for handling Git protocol server requests using the standard library net package under server/git.

// Handler is the interface that handles TCP requests for the Git protocol.
type Handler interface {
	// ServeTCP handles a TCP connection for the Git protocol.
	ServeTCP(ctx context.Context, c io.ReadWriteCloser, req *packp.GitProtoRequest)
}

// HandlerFunc is a function that implements the Handler interface.
type HandlerFunc func(ctx context.Context, c io.ReadWriteCloser, req *packp.GitProtoRequest)

// ServeTCP implements the Handler interface.
func (f HandlerFunc) ServeTCP(ctx context.Context, c io.ReadWriteCloser, req *packp.GitProtoRequest)

// Server is a TCP server that handles Git protocol requests.
type Server struct {
	// Addr is the address to listen on. If empty, it defaults to ":9418".
	Addr string

	// Handler is the handler for Git protocol requests. It uses
	// [DefaultHandler] when nil.
	Handler Handler

	// ErrorLog is the logger used to log errors. When nil, it won't log
	// errors.
	ErrorLog *log.Logger

	// BaseContext optionally specifies a function to create a base context for
	// the server listeners. If nil, [context.Background] will be used.
	// The provided listener is the specific listener that is about to start
	// accepting connections.
	BaseContext func(net.Listener) context.Context

	// ConnContext optionally specifies a function to create a context for each
	// connection. If nil, the context will be derived from the server's base
	// context.
	ConnContext func(context.Context, net.Conn) context.Context
}

func (s *Server) Close() error
func (s *Server) ListenAndServe() error
func (s *Server) Serve(ln net.Listener) error
func (s *Server) Shutdown(ctx context.Context) error

This adds a new `gogit daemon` command that starts a Git TCP server. It
uses a local pure Go implementation for handling Git protocol
server requests using the standard library net package under server/git.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a pure Go Git daemon server implementation under server/git and a new gogit daemon CLI command.

  • Adds Server type with lifecycle methods (ListenAndServe, Shutdown, etc.) for Git TCP protocol handling.
  • Introduces LoggingMiddleware to wrap protocol handlers with request logging.
  • Extends the CLI with a daemon subcommand to launch the Git daemon and improves root command error handling.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
server/git/server.go Core TCP server implementation for Git protocol.
server/git/logging.go Middleware to log incoming Git requests.
cmd/gogit/main.go Enhanced root command error reporting for remote errors.
cmd/gogit/daemon.go New daemon command to start the Git daemon.
Comments suppressed due to low confidence (2)

server/git/server.go:54

  • The doc for Handler refers to [DefaultHandler] but the actual fallback is DefaultBackend. Update the reference to [DefaultBackend] to match implementation.
	// [DefaultHandler] when nil.

server/git/server.go:85

  • [nitpick] There are no tests validating shutdown behavior (idle connection polling, listener closure, context cancellation). Consider adding unit tests for Shutdown to ensure graceful teardown works as expected.
func (s *Server) Shutdown(ctx context.Context) error {

)

func init() {
daemonCmd.Flags().BoolVarP(&daemonExportAll, "export-all", "", false, "Export all repositories")
Copy link

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The --export-all flag is registered but never used. Consider wiring it into the gitbackend.NewBackend loader logic or removing the flag.

Copilot uses AI. Check for mistakes.
aymanbagabas and others added 3 commits July 6, 2025 22:29
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aymanbagabas thanks for working on this. Overall LGTM, apart from the stat/lstat below.

Co-authored-by: Paulo Gomes <paulo.gomes.uk@gmail.com>
@pjbgf pjbgf merged commit f42e19a into go-git:main Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants