-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor: tidy up server git use git services to implement handling git server commands pass config to git as environment variables * feat(git): enable partial clones * feat(server): use smart http git backend This implements the smart http git protocol which also supports git-receive-pack service.
- Loading branch information
1 parent
b60a7f2
commit e78725f
Showing
18 changed files
with
1,189 additions
and
560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package git | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gogs/git-module" | ||
) | ||
|
||
// UpdateServerInfo updates the server info file for the given repo path. | ||
func UpdateServerInfo(ctx context.Context, path string) error { | ||
if !isGitDir(path) { | ||
return ErrNotAGitRepository | ||
} | ||
|
||
cmd := git.NewCommand("update-server-info").WithContext(ctx).WithTimeout(-1) | ||
_, err := cmd.RunInDir(path) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package daemon | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"net" | ||
"sync" | ||
"time" | ||
) | ||
|
||
// connections is a synchronizes access to to a net.Conn pool. | ||
type connections struct { | ||
m map[net.Conn]struct{} | ||
mu sync.Mutex | ||
} | ||
|
||
func (m *connections) Add(c net.Conn) { | ||
m.mu.Lock() | ||
defer m.mu.Unlock() | ||
m.m[c] = struct{}{} | ||
} | ||
|
||
func (m *connections) Close(c net.Conn) error { | ||
m.mu.Lock() | ||
defer m.mu.Unlock() | ||
err := c.Close() | ||
delete(m.m, c) | ||
return err | ||
} | ||
|
||
func (m *connections) Size() int { | ||
m.mu.Lock() | ||
defer m.mu.Unlock() | ||
return len(m.m) | ||
} | ||
|
||
func (m *connections) CloseAll() error { | ||
m.mu.Lock() | ||
defer m.mu.Unlock() | ||
var err error | ||
for c := range m.m { | ||
err = errors.Join(err, c.Close()) | ||
delete(m.m, c) | ||
} | ||
|
||
return err | ||
} | ||
|
||
// serverConn is a wrapper around a net.Conn that closes the connection when | ||
// the one of the timeouts is reached. | ||
type serverConn struct { | ||
net.Conn | ||
|
||
initTimeout time.Duration | ||
idleTimeout time.Duration | ||
maxDeadline time.Time | ||
closeCanceler context.CancelFunc | ||
} | ||
|
||
var _ net.Conn = (*serverConn)(nil) | ||
|
||
func (c *serverConn) Write(p []byte) (n int, err error) { | ||
c.updateDeadline() | ||
n, err = c.Conn.Write(p) | ||
if _, isNetErr := err.(net.Error); isNetErr && c.closeCanceler != nil { | ||
c.closeCanceler() | ||
} | ||
return | ||
} | ||
|
||
func (c *serverConn) Read(b []byte) (n int, err error) { | ||
c.updateDeadline() | ||
n, err = c.Conn.Read(b) | ||
if _, isNetErr := err.(net.Error); isNetErr && c.closeCanceler != nil { | ||
c.closeCanceler() | ||
} | ||
return | ||
} | ||
|
||
func (c *serverConn) Close() (err error) { | ||
err = c.Conn.Close() | ||
if c.closeCanceler != nil { | ||
c.closeCanceler() | ||
} | ||
return | ||
} | ||
|
||
func (c *serverConn) updateDeadline() { | ||
switch { | ||
case c.initTimeout > 0: | ||
initTimeout := time.Now().Add(c.initTimeout) | ||
c.initTimeout = 0 | ||
if initTimeout.Unix() < c.maxDeadline.Unix() || c.maxDeadline.IsZero() { | ||
c.Conn.SetDeadline(initTimeout) | ||
return | ||
} | ||
case c.idleTimeout > 0: | ||
idleDeadline := time.Now().Add(c.idleTimeout) | ||
if idleDeadline.Unix() < c.maxDeadline.Unix() || c.maxDeadline.IsZero() { | ||
c.Conn.SetDeadline(idleDeadline) | ||
return | ||
} | ||
} | ||
c.Conn.SetDeadline(c.maxDeadline) | ||
} |
Oops, something went wrong.