aboutsummaryrefslogtreecommitdiff
path: root/ssh_handle_receive_pack.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-18 10:23:44 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-18 10:23:44 +0800
commitdd95e2dbfad7f39060dc70f145d0e1478770e454 (patch)
tree863f9c3a941f21a66fe0af1cbe9a09ae444c8a46 /ssh_handle_receive_pack.go
parentREADME.md: Mention that anonymous pushes to contrib/ are possible now (diff)
downloadforge-dd95e2dbfad7f39060dc70f145d0e1478770e454.tar.gz
forge-dd95e2dbfad7f39060dc70f145d0e1478770e454.tar.zst
forge-dd95e2dbfad7f39060dc70f145d0e1478770e454.zip
*.go: Add some comments for docs
Diffstat (limited to 'ssh_handle_receive_pack.go')
-rw-r--r--ssh_handle_receive_pack.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/ssh_handle_receive_pack.go b/ssh_handle_receive_pack.go
index c680011..72ac3de 100644
--- a/ssh_handle_receive_pack.go
+++ b/ssh_handle_receive_pack.go
@@ -1,7 +1,6 @@
package main
import (
- "crypto/rand"
"errors"
"fmt"
"os"
@@ -22,7 +21,12 @@ type pack_to_hook_t struct {
var pack_to_hook_by_cookie = cmap.Map[string, pack_to_hook_t]{}
+// ssh_handle_receive_pack handles attempts to push to repos.
func ssh_handle_receive_pack(session glider_ssh.Session, pubkey string, repo_identifier string) (err error) {
+ // Here "access" means direct maintainer access. access=false doesn't
+ // necessarily mean the push is declined. This decision is delegated to
+ // the pre-receive hook, which is then handled by git_hooks_handle.go
+ // while being aware of the refs to be updated.
repo_path, access, err := get_repo_path_perms_from_ssh_path_pubkey(session.Context(), repo_identifier, pubkey)
if err != nil {
return err
@@ -40,6 +44,8 @@ func ssh_handle_receive_pack(session glider_ssh.Session, pubkey string, repo_ide
repo_path: repo_path,
})
defer pack_to_hook_by_cookie.Delete(cookie)
+ // The Delete won't execute until proc.Wait returns unless something
+ // horribly wrong such as a panic occurs.
proc := exec.CommandContext(session.Context(), "git-receive-pack", repo_path)
proc.Env = append(os.Environ(),
@@ -65,9 +71,3 @@ func ssh_handle_receive_pack(session glider_ssh.Session, pubkey string, repo_ide
return err
}
-
-func random_string(sz int) (string, error) {
- r := make([]byte, sz)
- _, err := rand.Read(r)
- return string(r), err
-}