aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-19 11:20:24 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-19 11:20:24 +0800
commit54926a719de46b3c359f2f7ce3c29ff4fe55397b (patch)
treeb81028ae83c949807313a54296bf6d0b59bea8a0
parentRemove underscores from Go code, pt 2 (diff)
downloadforge-54926a719de46b3c359f2f7ce3c29ff4fe55397b.tar.gz
forge-54926a719de46b3c359f2f7ce3c29ff4fe55397b.tar.zst
forge-54926a719de46b3c359f2f7ce3c29ff4fe55397b.zip
Remove underscores from Go code, pt 3
-rw-r--r--fedauth.go6
-rw-r--r--git_format_patch.go2
-rw-r--r--git_hooks_handle.go188
-rw-r--r--git_init.go20
-rw-r--r--git_misc.go86
-rw-r--r--git_ref.go4
-rw-r--r--http_handle_group_index.go2
-rw-r--r--http_handle_repo_commit.go2
-rw-r--r--http_handle_repo_contrib_one.go6
-rw-r--r--http_handle_repo_index.go6
-rw-r--r--http_handle_repo_log.go4
-rw-r--r--http_handle_repo_raw.go4
-rw-r--r--http_handle_repo_tree.go4
-rw-r--r--http_server.go2
-rw-r--r--ssh_handle_receive_pack.go28
-rw-r--r--ssh_utils.go2
16 files changed, 183 insertions, 183 deletions
diff --git a/fedauth.go b/fedauth.go
index 6687fe3..2084eff 100644
--- a/fedauth.go
+++ b/fedauth.go
@@ -15,7 +15,7 @@ import (
"github.com/jackc/pgx/v5"
)
-func fedauth(ctx context.Context, user_id int, service, remote_username, pubkey string) (bool, error) {
+func fedauth(ctx context.Context, userID int, service, remote_username, pubkey string) (bool, error) {
var err error
var resp *http.Response
matched := false
@@ -74,10 +74,10 @@ func fedauth(ctx context.Context, user_id int, service, remote_username, pubkey
defer func() {
_ = tx.Rollback(ctx)
}()
- if _, err = tx.Exec(ctx, `UPDATE users SET type = 'federated' WHERE id = $1 AND type = 'pubkey_only'`, user_id); err != nil {
+ if _, err = tx.Exec(ctx, `UPDATE users SET type = 'federated' WHERE id = $1 AND type = 'pubkey_only'`, userID); err != nil {
return false, err
}
- if _, err = tx.Exec(ctx, `INSERT INTO federated_identities (user_id, service, remote_username) VALUES ($1, $2, $3)`, user_id, service, remote_username); err != nil {
+ if _, err = tx.Exec(ctx, `INSERT INTO federated_identities (user_id, service, remote_username) VALUES ($1, $2, $3)`, userID, service, remote_username); err != nil {
return false, err
}
if err = tx.Commit(ctx); err != nil {
diff --git a/git_format_patch.go b/git_format_patch.go
index 3533eca..56474d2 100644
--- a/git_format_patch.go
+++ b/git_format_patch.go
@@ -21,7 +21,7 @@ func fmtCommitPatch(commit *object.Commit) (final string, err error) {
var date string
var commitTitle, commitDetails string
- if _, patch, err = get_patch_from_commit(commit); err != nil {
+ if _, patch, err = fmtCommitAsPatch(commit); err != nil {
return "", err
}
diff --git a/git_hooks_handle.go b/git_hooks_handle.go
index e02619f..b931387 100644
--- a/git_hooks_handle.go
+++ b/git_hooks_handle.go
@@ -36,10 +36,10 @@ func hooksHandler(conn net.Conn) {
var ucred *syscall.Ucred
var err error
var cookie []byte
- var pack_to_hook pack_to_hook_t
- var ssh_stderr io.Writer
+ var packPass packPass
+ var sshStderr io.Writer
var ok bool
- var hook_return_value byte
+ var hookRet byte
defer conn.Close()
ctx, cancel = context.WithCancel(context.Background())
@@ -51,14 +51,14 @@ func hooksHandler(conn net.Conn) {
if _, err = conn.Write([]byte{1}); err != nil {
return
}
- wf_error(conn, "\nUnable to get peer credentials: %v", err)
+ writeRedError(conn, "\nUnable to get peer credentials: %v", err)
return
}
if ucred.Uid != uint32(os.Getuid()) {
if _, err = conn.Write([]byte{1}); err != nil {
return
}
- wf_error(conn, "\nUID mismatch")
+ writeRedError(conn, "\nUID mismatch")
return
}
@@ -67,27 +67,27 @@ func hooksHandler(conn net.Conn) {
if _, err = conn.Write([]byte{1}); err != nil {
return
}
- wf_error(conn, "\nFailed to read cookie: %v", err)
+ writeRedError(conn, "\nFailed to read cookie: %v", err)
return
}
- pack_to_hook, ok = pack_to_hook_by_cookie.Load(string(cookie))
+ packPass, ok = packPasses.Load(string(cookie))
if !ok {
if _, err = conn.Write([]byte{1}); err != nil {
return
}
- wf_error(conn, "\nInvalid handler cookie")
+ writeRedError(conn, "\nInvalid handler cookie")
return
}
- ssh_stderr = pack_to_hook.session.Stderr()
+ sshStderr = packPass.session.Stderr()
- _, _ = ssh_stderr.Write([]byte{'\n'})
+ _, _ = sshStderr.Write([]byte{'\n'})
- hook_return_value = func() byte {
+ hookRet = func() byte {
var argc64 uint64
if err = binary.Read(conn, binary.NativeEndian, &argc64); err != nil {
- wf_error(ssh_stderr, "Failed to read argc: %v", err)
+ writeRedError(sshStderr, "Failed to read argc: %v", err)
return 1
}
var args []string
@@ -97,7 +97,7 @@ func hooksHandler(conn net.Conn) {
b := make([]byte, 1)
n, err := conn.Read(b)
if err != nil || n != 1 {
- wf_error(ssh_stderr, "Failed to read arg: %v", err)
+ writeRedError(sshStderr, "Failed to read arg: %v", err)
return 1
}
if b[0] == 0 {
@@ -108,92 +108,92 @@ func hooksHandler(conn net.Conn) {
args = append(args, arg.String())
}
- git_env := make(map[string]string)
+ gitEnv := make(map[string]string)
for {
- var env_line bytes.Buffer
+ var envLine bytes.Buffer
for {
b := make([]byte, 1)
n, err := conn.Read(b)
if err != nil || n != 1 {
- wf_error(ssh_stderr, "Failed to read environment variable: %v", err)
+ writeRedError(sshStderr, "Failed to read environment variable: %v", err)
return 1
}
if b[0] == 0 {
break
}
- env_line.WriteByte(b[0])
+ envLine.WriteByte(b[0])
}
- if env_line.Len() == 0 {
+ if envLine.Len() == 0 {
break
}
- kv := env_line.String()
+ kv := envLine.String()
parts := strings.SplitN(kv, "=", 2)
if len(parts) < 2 {
- wf_error(ssh_stderr, "Invalid environment variable line: %v", kv)
+ writeRedError(sshStderr, "Invalid environment variable line: %v", kv)
return 1
}
- git_env[parts[0]] = parts[1]
+ gitEnv[parts[0]] = parts[1]
}
var stdin bytes.Buffer
if _, err = io.Copy(&stdin, conn); err != nil {
- wf_error(conn, "Failed to read to the stdin buffer: %v", err)
+ writeRedError(conn, "Failed to read to the stdin buffer: %v", err)
}
switch filepath.Base(args[0]) {
case "pre-receive":
- if pack_to_hook.direct_access {
+ if packPass.directAccess {
return 0
} else {
- all_ok := true
+ allOK := true
for {
- var line, old_oid, rest, new_oid, ref_name string
+ var line, oldOID, rest, newIOID, refName string
var found bool
- var old_hash, new_hash plumbing.Hash
- var old_commit, new_commit *object.Commit
- var git_push_option_count int
+ var oldHash, newHash plumbing.Hash
+ var oldCommit, newCommit *object.Commit
+ var pushOptCount int
- git_push_option_count, err = strconv.Atoi(git_env["GIT_PUSH_OPTION_COUNT"])
+ pushOptCount, err = strconv.Atoi(gitEnv["GIT_PUSH_OPTION_COUNT"])
if err != nil {
- wf_error(ssh_stderr, "Failed to parse GIT_PUSH_OPTION_COUNT: %v", err)
+ writeRedError(sshStderr, "Failed to parse GIT_PUSH_OPTION_COUNT: %v", err)
return 1
}
// TODO: Allow existing users (even if they are already federated or registered) to add a federated user ID... though perhaps this should be in the normal SSH interface instead of the git push interface?
// Also it'd be nice to be able to combine users or whatever
- if pack_to_hook.contrib_requirements == "federated" && pack_to_hook.user_type != "federated" && pack_to_hook.user_type != "registered" {
- if git_push_option_count == 0 {
- wf_error(ssh_stderr, "This repo requires contributors to be either federated or registered users. You must supply your federated user ID as a push option. For example, git push -o fedid=sr.ht:runxiyu")
+ if packPass.contribReq == "federated" && packPass.userType != "federated" && packPass.userType != "registered" {
+ if pushOptCount == 0 {
+ writeRedError(sshStderr, "This repo requires contributors to be either federated or registered users. You must supply your federated user ID as a push option. For example, git push -o fedid=sr.ht:runxiyu")
return 1
}
- for i := 0; i < git_push_option_count; i++ {
- push_option, ok := git_env[fmt.Sprintf("GIT_PUSH_OPTION_%d", i)]
+ for i := 0; i < pushOptCount; i++ {
+ pushOpt, ok := gitEnv[fmt.Sprintf("GIT_PUSH_OPTION_%d", i)]
if !ok {
- wf_error(ssh_stderr, "Failed to get push option %d", i)
+ writeRedError(sshStderr, "Failed to get push option %d", i)
return 1
}
- if strings.HasPrefix(push_option, "fedid=") {
- federated_user_identifier := strings.TrimPrefix(push_option, "fedid=")
- service, username, found := strings.Cut(federated_user_identifier, ":")
+ if strings.HasPrefix(pushOpt, "fedid=") {
+ fedUserID := strings.TrimPrefix(pushOpt, "fedid=")
+ service, username, found := strings.Cut(fedUserID, ":")
if !found {
- wf_error(ssh_stderr, "Invalid federated user identifier %#v does not contain a colon", federated_user_identifier)
+ writeRedError(sshStderr, "Invalid federated user identifier %#v does not contain a colon", fedUserID)
return 1
}
- ok, err := fedauth(ctx, pack_to_hook.user_id, service, username, pack_to_hook.pubkey)
+ ok, err := fedauth(ctx, packPass.userID, service, username, packPass.pubkey)
if err != nil {
- wf_error(ssh_stderr, "Failed to verify federated user identifier %#v: %v", federated_user_identifier, err)
+ writeRedError(sshStderr, "Failed to verify federated user identifier %#v: %v", fedUserID, err)
return 1
}
if !ok {
- wf_error(ssh_stderr, "Failed to verify federated user identifier %#v: you don't seem to be on the list", federated_user_identifier)
+ writeRedError(sshStderr, "Failed to verify federated user identifier %#v: you don't seem to be on the list", fedUserID)
return 1
}
break
}
- if i == git_push_option_count-1 {
- wf_error(ssh_stderr, "This repo requires contributors to be either federated or registered users. You must supply your federated user ID as a push option. For example, git push -o fedid=sr.ht:runxiyu")
+ if i == pushOptCount-1 {
+ writeRedError(sshStderr, "This repo requires contributors to be either federated or registered users. You must supply your federated user ID as a push option. For example, git push -o fedid=sr.ht:runxiyu")
return 1
}
}
@@ -203,69 +203,69 @@ func hooksHandler(conn net.Conn) {
if errors.Is(err, io.EOF) {
break
} else if err != nil {
- wf_error(ssh_stderr, "Failed to read pre-receive line: %v", err)
+ writeRedError(sshStderr, "Failed to read pre-receive line: %v", err)
return 1
}
line = line[:len(line)-1]
- old_oid, rest, found = strings.Cut(line, " ")
+ oldOID, rest, found = strings.Cut(line, " ")
if !found {
- wf_error(ssh_stderr, "Invalid pre-receive line: %v", line)
+ writeRedError(sshStderr, "Invalid pre-receive line: %v", line)
return 1
}
- new_oid, ref_name, found = strings.Cut(rest, " ")
+ newIOID, refName, found = strings.Cut(rest, " ")
if !found {
- wf_error(ssh_stderr, "Invalid pre-receive line: %v", line)
+ writeRedError(sshStderr, "Invalid pre-receive line: %v", line)
return 1
}
- if strings.HasPrefix(ref_name, "refs/heads/contrib/") {
- if all_zero_num_string(old_oid) { // New branch
- fmt.Fprintln(ssh_stderr, ansiec.Blue+"POK"+ansiec.Reset, ref_name)
- var new_mr_id int
+ if strings.HasPrefix(refName, "refs/heads/contrib/") {
+ if allZero(oldOID) { // New branch
+ fmt.Fprintln(sshStderr, ansiec.Blue+"POK"+ansiec.Reset, refName)
+ var newMRID int
err = database.QueryRow(ctx,
"INSERT INTO merge_requests (repo_id, creator, source_ref, status) VALUES ($1, $2, $3, 'open') RETURNING id",
- pack_to_hook.repo_id, pack_to_hook.user_id, strings.TrimPrefix(ref_name, "refs/heads/"),
- ).Scan(&new_mr_id)
+ packPass.repoID, packPass.userID, strings.TrimPrefix(refName, "refs/heads/"),
+ ).Scan(&newMRID)
if err != nil {
- wf_error(ssh_stderr, "Error creating merge request: %v", err)
+ writeRedError(sshStderr, "Error creating merge request: %v", err)
return 1
}
- fmt.Fprintln(ssh_stderr, ansiec.Blue+"Created merge request at", generate_http_remote_url(pack_to_hook.group_path, pack_to_hook.repo_name)+"/contrib/"+strconv.FormatUint(uint64(new_mr_id), 10)+"/"+ansiec.Reset)
+ fmt.Fprintln(sshStderr, ansiec.Blue+"Created merge request at", generate_http_remote_url(packPass.group_path, packPass.repo_name)+"/contrib/"+strconv.FormatUint(uint64(newMRID), 10)+"/"+ansiec.Reset)
} else { // Existing contrib branch
- var existing_merge_request_user_id int
- var is_ancestor bool
+ var existingMRUser int
+ var isAncestor bool
err = database.QueryRow(ctx,
"SELECT COALESCE(creator, 0) FROM merge_requests WHERE source_ref = $1 AND repo_id = $2",
- strings.TrimPrefix(ref_name, "refs/heads/"), pack_to_hook.repo_id,
- ).Scan(&existing_merge_request_user_id)
+ strings.TrimPrefix(refName, "refs/heads/"), packPass.repoID,
+ ).Scan(&existingMRUser)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
- wf_error(ssh_stderr, "No existing merge request for existing contrib branch: %v", err)
+ writeRedError(sshStderr, "No existing merge request for existing contrib branch: %v", err)
} else {
- wf_error(ssh_stderr, "Error querying for existing merge request: %v", err)
+ writeRedError(sshStderr, "Error querying for existing merge request: %v", err)
}
return 1
}
- if existing_merge_request_user_id == 0 {
- all_ok = false
- fmt.Fprintln(ssh_stderr, ansiec.Red+"NAK"+ansiec.Reset, ref_name, "(branch belongs to unowned MR)")
+ if existingMRUser == 0 {
+ allOK = false
+ fmt.Fprintln(sshStderr, ansiec.Red+"NAK"+ansiec.Reset, refName, "(branch belongs to unowned MR)")
continue
}
- if existing_merge_request_user_id != pack_to_hook.user_id {
- all_ok = false
- fmt.Fprintln(ssh_stderr, ansiec.Red+"NAK"+ansiec.Reset, ref_name, "(branch belongs another user's MR)")
+ if existingMRUser != packPass.userID {
+ allOK = false
+ fmt.Fprintln(sshStderr, ansiec.Red+"NAK"+ansiec.Reset, refName, "(branch belongs another user's MR)")
continue
}
- old_hash = plumbing.NewHash(old_oid)
+ oldHash = plumbing.NewHash(oldOID)
- if old_commit, err = pack_to_hook.repo.CommitObject(old_hash); err != nil {
- wf_error(ssh_stderr, "Daemon failed to get old commit: %v", err)
+ if oldCommit, err = packPass.repo.CommitObject(oldHash); err != nil {
+ writeRedError(sshStderr, "Daemon failed to get old commit: %v", err)
return 1
}
@@ -273,50 +273,50 @@ func hooksHandler(conn net.Conn) {
// detectable as they haven't been merged into the main repo's
// objects yet. But it seems to work, and I don't think there's
// any reason for this to only work intermitently.
- new_hash = plumbing.NewHash(new_oid)
- if new_commit, err = pack_to_hook.repo.CommitObject(new_hash); err != nil {
- wf_error(ssh_stderr, "Daemon failed to get new commit: %v", err)
+ newHash = plumbing.NewHash(newIOID)
+ if newCommit, err = packPass.repo.CommitObject(newHash); err != nil {
+ writeRedError(sshStderr, "Daemon failed to get new commit: %v", err)
return 1
}
- if is_ancestor, err = old_commit.IsAncestor(new_commit); err != nil {
- wf_error(ssh_stderr, "Daemon failed to check if old commit is ancestor: %v", err)
+ if isAncestor, err = oldCommit.IsAncestor(newCommit); err != nil {
+ writeRedError(sshStderr, "Daemon failed to check if old commit is ancestor: %v", err)
return 1
}
- if !is_ancestor {
+ if !isAncestor {
// TODO: Create MR snapshot ref instead
- all_ok = false
- fmt.Fprintln(ssh_stderr, ansiec.Red+"NAK"+ansiec.Reset, ref_name, "(force pushes are not supported yet)")
+ allOK = false
+ fmt.Fprintln(sshStderr, ansiec.Red+"NAK"+ansiec.Reset, refName, "(force pushes are not supported yet)")
continue
}
- fmt.Fprintln(ssh_stderr, ansiec.Blue+"POK"+ansiec.Reset, ref_name)
+ fmt.Fprintln(sshStderr, ansiec.Blue+"POK"+ansiec.Reset, refName)
}
} else { // Non-contrib branch
- all_ok = false
- fmt.Fprintln(ssh_stderr, ansiec.Red+"NAK"+ansiec.Reset, ref_name, "(you cannot push to branches outside of contrib/*)")
+ allOK = false
+ fmt.Fprintln(sshStderr, ansiec.Red+"NAK"+ansiec.Reset, refName, "(you cannot push to branches outside of contrib/*)")
}
}
- fmt.Fprintln(ssh_stderr)
- if all_ok {
- fmt.Fprintln(ssh_stderr, "Overall "+ansiec.Green+"ACK"+ansiec.Reset+" (all checks passed)")
+ fmt.Fprintln(sshStderr)
+ if allOK {
+ fmt.Fprintln(sshStderr, "Overall "+ansiec.Green+"ACK"+ansiec.Reset+" (all checks passed)")
return 0
} else {
- fmt.Fprintln(ssh_stderr, "Overall "+ansiec.Red+"NAK"+ansiec.Reset+" (one or more branches failed checks)")
+ fmt.Fprintln(sshStderr, "Overall "+ansiec.Red+"NAK"+ansiec.Reset+" (one or more branches failed checks)")
return 1
}
}
default:
- fmt.Fprintln(ssh_stderr, ansiec.Red+"Invalid hook:", args[0]+ansiec.Reset)
+ fmt.Fprintln(sshStderr, ansiec.Red+"Invalid hook:", args[0]+ansiec.Reset)
return 1
}
}()
- fmt.Fprintln(ssh_stderr)
+ fmt.Fprintln(sshStderr)
- _, _ = conn.Write([]byte{hook_return_value})
+ _, _ = conn.Write([]byte{hookRet})
}
func serveGitHooks(listener net.Listener) error {
@@ -330,10 +330,10 @@ func serveGitHooks(listener net.Listener) error {
}
func getUcred(conn net.Conn) (ucred *syscall.Ucred, err error) {
- var unix_conn *net.UnixConn = conn.(*net.UnixConn)
+ var unixConn *net.UnixConn = conn.(*net.UnixConn)
var fd *os.File
- if fd, err = unix_conn.File(); err != nil {
+ if fd, err = unixConn.File(); err != nil {
return nil, errGetFD
}
defer fd.Close()
@@ -344,7 +344,7 @@ func getUcred(conn net.Conn) (ucred *syscall.Ucred, err error) {
return ucred, nil
}
-func all_zero_num_string(s string) bool {
+func allZero(s string) bool {
for _, r := range s {
if r != '0' {
return false
diff --git a/git_init.go b/git_init.go
index 4313ee8..045ddd2 100644
--- a/git_init.go
+++ b/git_init.go
@@ -5,28 +5,28 @@ package main
import (
"github.com/go-git/go-git/v5"
- git_config "github.com/go-git/go-git/v5/config"
- git_format_config "github.com/go-git/go-git/v5/plumbing/format/config"
+ gitConfig "github.com/go-git/go-git/v5/config"
+ gitFmtConfig "github.com/go-git/go-git/v5/plumbing/format/config"
)
-// git_bare_init_with_default_hooks initializes a bare git repository with the
+// gitInit initializes a bare git repository with the
// forge-deployed hooks directory as the hooksPath.
-func git_bare_init_with_default_hooks(repo_path string) (err error) {
+func gitInit(repoPath string) (err error) {
var repo *git.Repository
- var git_config *git_config.Config
+ var gitConf *gitConfig.Config
- if repo, err = git.PlainInit(repo_path, true); err != nil {
+ if repo, err = git.PlainInit(repoPath, true); err != nil {
return err
}
- if git_config, err = repo.Config(); err != nil {
+ if gitConf, err = repo.Config(); err != nil {
return err
}
- git_config.Raw.SetOption("core", git_format_config.NoSubsection, "hooksPath", config.Hooks.Execs)
- git_config.Raw.SetOption("receive", git_format_config.NoSubsection, "advertisePushOptions", "true")
+ gitConf.Raw.SetOption("core", gitFmtConfig.NoSubsection, "hooksPath", config.Hooks.Execs)
+ gitConf.Raw.SetOption("receive", gitFmtConfig.NoSubsection, "advertisePushOptions", "true")
- if err = repo.SetConfig(git_config); err != nil {
+ if err = repo.SetConfig(gitConf); err != nil {
return err
}
diff --git a/git_misc.go b/git_misc.go
index f2f8dba..3f170d0 100644
--- a/git_misc.go
+++ b/git_misc.go
@@ -16,9 +16,9 @@ import (
"github.com/jackc/pgx/v5/pgtype"
)
-// open_git_repo opens a git repository by group and repo name.
-func open_git_repo(ctx context.Context, group_path []string, repo_name string) (repo *git.Repository, description string, repo_id int, err error) {
- var fs_path string
+// openRepo opens a git repository by group and repo name.
+func openRepo(ctx context.Context, groupPath []string, repoName string) (repo *git.Repository, description string, repoID int, err error) {
+ var fsPath string
err = database.QueryRow(ctx, `
WITH RECURSIVE group_path_cte AS (
@@ -53,100 +53,100 @@ FROM group_path_cte g
JOIN repos r ON r.group_id = g.id
WHERE g.depth = cardinality($1::text[])
AND r.name = $2
- `, pgtype.FlatArray[string](group_path), repo_name).Scan(&fs_path, &description, &repo_id)
+ `, pgtype.FlatArray[string](groupPath), repoName).Scan(&fsPath, &description, &repoID)
if err != nil {
return
}
- repo, err = git.PlainOpen(fs_path)
+ repo, err = git.PlainOpen(fsPath)
return
}
// go-git's tree entries are not friendly for use in HTML templates.
-type display_git_tree_entry_t struct {
+type displayTreeEntry struct {
Name string
Mode string
Size int64
- Is_file bool
- Is_subtree bool
+ IsFile bool
+ IsSubtree bool
}
-func build_display_git_tree(tree *object.Tree) (display_git_tree []display_git_tree_entry_t) {
+func makeDisplayTree(tree *object.Tree) (displayTree []displayTreeEntry) {
for _, entry := range tree.Entries {
- display_git_tree_entry := display_git_tree_entry_t{}
+ displayEntry := displayTreeEntry{}
var err error
- var os_mode os.FileMode
+ var osMode os.FileMode
- if os_mode, err = entry.Mode.ToOSFileMode(); err != nil {
- display_git_tree_entry.Mode = "x---------"
+ if osMode, err = entry.Mode.ToOSFileMode(); err != nil {
+ displayEntry.Mode = "x---------"
} else {
- display_git_tree_entry.Mode = os_mode.String()
+ displayEntry.Mode = osMode.String()
}
- display_git_tree_entry.Is_file = entry.Mode.IsFile()
+ displayEntry.IsFile = entry.Mode.IsFile()
- if display_git_tree_entry.Size, err = tree.Size(entry.Name); err != nil {
- display_git_tree_entry.Size = 0
+ if displayEntry.Size, err = tree.Size(entry.Name); err != nil {
+ displayEntry.Size = 0
}
- display_git_tree_entry.Name = strings.TrimPrefix(entry.Name, "/")
+ displayEntry.Name = strings.TrimPrefix(entry.Name, "/")
- display_git_tree = append(display_git_tree, display_git_tree_entry)
+ displayTree = append(displayTree, displayEntry)
}
- return display_git_tree
+ return displayTree
}
-func get_recent_commits(repo *git.Repository, head_hash plumbing.Hash, number_of_commits int) (recent_commits []*object.Commit, err error) {
- var commit_iter object.CommitIter
- var this_recent_commit *object.Commit
+func getRecentCommits(repo *git.Repository, headHash plumbing.Hash, numCommits int) (recentCommits []*object.Commit, err error) {
+ var commitIter object.CommitIter
+ var thisCommit *object.Commit
- commit_iter, err = repo.Log(&git.LogOptions{From: head_hash})
+ commitIter, err = repo.Log(&git.LogOptions{From: headHash})
if err != nil {
return nil, err
}
- recent_commits = make([]*object.Commit, 0)
- defer commit_iter.Close()
- if number_of_commits < 0 {
+ recentCommits = make([]*object.Commit, 0)
+ defer commitIter.Close()
+ if numCommits < 0 {
for {
- this_recent_commit, err = commit_iter.Next()
+ thisCommit, err = commitIter.Next()
if errors.Is(err, io.EOF) {
- return recent_commits, nil
+ return recentCommits, nil
} else if err != nil {
return nil, err
}
- recent_commits = append(recent_commits, this_recent_commit)
+ recentCommits = append(recentCommits, thisCommit)
}
} else {
- for range number_of_commits {
- this_recent_commit, err = commit_iter.Next()
+ for range numCommits {
+ thisCommit, err = commitIter.Next()
if errors.Is(err, io.EOF) {
- return recent_commits, nil
+ return recentCommits, nil
} else if err != nil {
return nil, err
}
- recent_commits = append(recent_commits, this_recent_commit)
+ recentCommits = append(recentCommits, thisCommit)
}
}
- return recent_commits, err
+ return recentCommits, err
}
-func get_patch_from_commit(commit_object *object.Commit) (parent_commit_hash plumbing.Hash, patch *object.Patch, err error) {
- var parent_commit_object *object.Commit
- var commit_tree *object.Tree
+func fmtCommitAsPatch(commit *object.Commit) (parentCommitHash plumbing.Hash, patch *object.Patch, err error) {
+ var parentCommit *object.Commit
+ var commitTree *object.Tree
- parent_commit_object, err = commit_object.Parent(0)
+ parentCommit, err = commit.Parent(0)
if errors.Is(err, object.ErrParentNotFound) {
- if commit_tree, err = commit_object.Tree(); err != nil {
+ if commitTree, err = commit.Tree(); err != nil {
return
}
- if patch, err = (&object.Tree{}).Patch(commit_tree); err != nil {
+ if patch, err = (&object.Tree{}).Patch(commitTree); err != nil {
return
}
} else if err != nil {
return
} else {
- parent_commit_hash = parent_commit_object.Hash
- if patch, err = parent_commit_object.Patch(commit_object); err != nil {
+ parentCommitHash = parentCommit.Hash
+ if patch, err = parentCommit.Patch(commit); err != nil {
return
}
}
diff --git a/git_ref.go b/git_ref.go
index 65b90bf..ab8e35d 100644
--- a/git_ref.go
+++ b/git_ref.go
@@ -8,9 +8,9 @@ import (
"github.com/go-git/go-git/v5/plumbing"
)
-// get_ref_hash_from_type_and_name returns the hash of a reference given its
+// getRefHash returns the hash of a reference given its
// type and name as supplied in URL queries.
-func get_ref_hash_from_type_and_name(repo *git.Repository, ref_type, ref_name string) (ref_hash plumbing.Hash, err error) {
+func getRefHash(repo *git.Repository, ref_type, ref_name string) (ref_hash plumbing.Hash, err error) {
var ref *plumbing.Reference
switch ref_type {
case "":
diff --git a/http_handle_group_index.go b/http_handle_group_index.go
index 2c27117..3ed3a85 100644
--- a/http_handle_group_index.go
+++ b/http_handle_group_index.go
@@ -121,7 +121,7 @@ func handle_group_index(w http.ResponseWriter, r *http.Request, params map[strin
return
}
- if err = git_bare_init_with_default_hooks(file_path); err != nil {
+ if err = gitInit(file_path); err != nil {
http.Error(w, "Error initializing repo: "+err.Error(), http.StatusInternalServerError)
return
}
diff --git a/http_handle_repo_commit.go b/http_handle_repo_commit.go
index f9b7dc5..07f24fb 100644
--- a/http_handle_repo_commit.go
+++ b/http_handle_repo_commit.go
@@ -66,7 +66,7 @@ func handle_repo_commit(w http.ResponseWriter, r *http.Request, params map[strin
params["commit_object"] = commit_object
params["commit_id"] = commit_id_string
- parent_commit_hash, patch, err = get_patch_from_commit(commit_object)
+ parent_commit_hash, patch, err = fmtCommitAsPatch(commit_object)
if err != nil {
http.Error(w, "Error getting patch from commit: "+err.Error(), http.StatusInternalServerError)
return
diff --git a/http_handle_repo_contrib_one.go b/http_handle_repo_contrib_one.go
index f4db20c..cc17a67 100644
--- a/http_handle_repo_contrib_one.go
+++ b/http_handle_repo_contrib_one.go
@@ -40,7 +40,7 @@ func handle_repo_contrib_one(w http.ResponseWriter, r *http.Request, params map[
repo = params["repo"].(*git.Repository)
- if source_ref_hash, err = get_ref_hash_from_type_and_name(repo, "branch", source_ref); err != nil {
+ if source_ref_hash, err = getRefHash(repo, "branch", source_ref); err != nil {
http.Error(w, "Error getting source ref hash: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -53,9 +53,9 @@ func handle_repo_contrib_one(w http.ResponseWriter, r *http.Request, params map[
var destination_branch_hash plumbing.Hash
if destination_branch == "" {
destination_branch = "HEAD"
- destination_branch_hash, err = get_ref_hash_from_type_and_name(repo, "", "")
+ destination_branch_hash, err = getRefHash(repo, "", "")
} else {
- destination_branch_hash, err = get_ref_hash_from_type_and_name(repo, "branch", destination_branch)
+ destination_branch_hash, err = getRefHash(repo, "branch", destination_branch)
}
if err != nil {
http.Error(w, "Error getting destination branch hash: "+err.Error(), http.StatusInternalServerError)
diff --git a/http_handle_repo_index.go b/http_handle_repo_index.go
index da06500..b38863c 100644
--- a/http_handle_repo_index.go
+++ b/http_handle_repo_index.go
@@ -32,7 +32,7 @@ func handle_repo_index(w http.ResponseWriter, r *http.Request, params map[string
notes = append(notes, "Path contains newlines; HTTP Git access impossible")
}
- ref_hash, err = get_ref_hash_from_type_and_name(repo, params["ref_type"].(string), params["ref_name"].(string))
+ ref_hash, err = getRefHash(repo, params["ref_type"].(string), params["ref_name"].(string))
if err != nil {
goto no_ref
}
@@ -48,7 +48,7 @@ func handle_repo_index(w http.ResponseWriter, r *http.Request, params map[string
}
params["branches"] = branches
- if recent_commits, err = get_recent_commits(repo, ref_hash, 3); err != nil {
+ if recent_commits, err = getRecentCommits(repo, ref_hash, 3); err != nil {
goto no_ref
}
params["commits"] = recent_commits
@@ -61,7 +61,7 @@ func handle_repo_index(w http.ResponseWriter, r *http.Request, params map[string
goto no_ref
}
- params["files"] = build_display_git_tree(tree)
+ params["files"] = makeDisplayTree(tree)
params["readme_filename"], params["readme"] = render_readme_at_tree(tree)
no_ref:
diff --git a/http_handle_repo_log.go b/http_handle_repo_log.go
index 65719e4..c7dde82 100644
--- a/http_handle_repo_log.go
+++ b/http_handle_repo_log.go
@@ -20,12 +20,12 @@ func handle_repo_log(w http.ResponseWriter, r *http.Request, params map[string]a
repo = params["repo"].(*git.Repository)
- if ref_hash, err = get_ref_hash_from_type_and_name(repo, params["ref_type"].(string), params["ref_name"].(string)); err != nil {
+ if ref_hash, err = getRefHash(repo, params["ref_type"].(string), params["ref_name"].(string)); err != nil {
http.Error(w, "Error getting ref hash: "+err.Error(), http.StatusInternalServerError)
return
}
- if commits, err = get_recent_commits(repo, ref_hash, -1); err != nil {
+ if commits, err = getRecentCommits(repo, ref_hash, -1); err != nil {
http.Error(w, "Error getting recent commits: "+err.Error(), http.StatusInternalServerError)
return
}
diff --git a/http_handle_repo_raw.go b/http_handle_repo_raw.go
index a0f7430..cfe03b6 100644
--- a/http_handle_repo_raw.go
+++ b/http_handle_repo_raw.go
@@ -26,7 +26,7 @@ func handle_repo_raw(w http.ResponseWriter, r *http.Request, params map[string]a
repo, path_spec = params["repo"].(*git.Repository), strings.TrimSuffix(raw_path_spec, "/")
params["path_spec"] = path_spec
- if ref_hash, err = get_ref_hash_from_type_and_name(repo, params["ref_type"].(string), params["ref_name"].(string)); err != nil {
+ if ref_hash, err = getRefHash(repo, params["ref_type"].(string), params["ref_name"].(string)); err != nil {
http.Error(w, "Error getting ref hash: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -69,7 +69,7 @@ func handle_repo_raw(w http.ResponseWriter, r *http.Request, params map[string]a
return
}
- params["files"] = build_display_git_tree(target)
+ params["files"] = makeDisplayTree(target)
render_template(w, "repo_raw_dir", params)
}
diff --git a/http_handle_repo_tree.go b/http_handle_repo_tree.go
index ae9efbc..121e76a 100644
--- a/http_handle_repo_tree.go
+++ b/http_handle_repo_tree.go
@@ -31,7 +31,7 @@ func handle_repo_tree(w http.ResponseWriter, r *http.Request, params map[string]
repo, path_spec = params["repo"].(*git.Repository), strings.TrimSuffix(raw_path_spec, "/")
params["path_spec"] = path_spec
- if ref_hash, err = get_ref_hash_from_type_and_name(repo, params["ref_type"].(string), params["ref_name"].(string)); err != nil {
+ if ref_hash, err = getRefHash(repo, params["ref_type"].(string), params["ref_name"].(string)); err != nil {
http.Error(w, "Error getting ref hash: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -98,7 +98,7 @@ func handle_repo_tree(w http.ResponseWriter, r *http.Request, params map[string]
}
params["readme_filename"], params["readme"] = render_readme_at_tree(target)
- params["files"] = build_display_git_tree(target)
+ params["files"] = makeDisplayTree(target)
render_template(w, "repo_tree_dir", params)
}
diff --git a/http_server.go b/http_server.go
index 747f668..d61dc8f 100644
--- a/http_server.go
+++ b/http_server.go
@@ -155,7 +155,7 @@ func (router *httpRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// TODO: subgroups
- if params["repo"], params["repo_description"], params["repo_id"], err = open_git_repo(r.Context(), group_path, module_name); err != nil {
+ if params["repo"], params["repo_description"], params["repo_id"], err = openRepo(r.Context(), group_path, module_name); err != nil {
http.Error(w, "Error opening repo: "+err.Error(), http.StatusInternalServerError)
return
}
diff --git a/ssh_handle_receive_pack.go b/ssh_handle_receive_pack.go
index 3f7c1f1..b930784 100644
--- a/ssh_handle_receive_pack.go
+++ b/ssh_handle_receive_pack.go
@@ -14,21 +14,21 @@ import (
"go.lindenii.runxiyu.org/lindenii-common/cmap"
)
-type pack_to_hook_t struct {
+type packPass struct {
session glider_ssh.Session
repo *git.Repository
pubkey string
- direct_access bool
+ directAccess bool
repo_path string
- user_id int
- user_type string
- repo_id int
+ userID int
+ userType string
+ repoID int
group_path []string
repo_name string
- contrib_requirements string
+ contribReq string
}
-var pack_to_hook_by_cookie = cmap.Map[string, pack_to_hook_t]{}
+var packPasses = cmap.Map[string, packPass]{}
// ssh_handle_receive_pack handles attempts to push to repos.
func ssh_handle_receive_pack(session glider_ssh.Session, pubkey, repo_identifier string) (err error) {
@@ -92,20 +92,20 @@ func ssh_handle_receive_pack(session glider_ssh.Session, pubkey, repo_identifier
fmt.Fprintln(session.Stderr(), "Error while generating cookie:", err)
}
- pack_to_hook_by_cookie.Store(cookie, pack_to_hook_t{
+ packPasses.Store(cookie, packPass{
session: session,
pubkey: pubkey,
- direct_access: direct_access,
+ directAccess: direct_access,
repo_path: repo_path,
- user_id: user_id,
- repo_id: repo_id,
+ userID: user_id,
+ repoID: repo_id,
group_path: group_path,
repo_name: repo_name,
repo: repo,
- contrib_requirements: contrib_requirements,
- user_type: user_type,
+ contribReq: contrib_requirements,
+ userType: user_type,
})
- defer pack_to_hook_by_cookie.Delete(cookie)
+ defer packPasses.Delete(cookie)
// The Delete won't execute until proc.Wait returns unless something
// horribly wrong such as a panic occurs.
diff --git a/ssh_utils.go b/ssh_utils.go
index d9c11da..092cb6e 100644
--- a/ssh_utils.go
+++ b/ssh_utils.go
@@ -66,6 +66,6 @@ func get_repo_path_perms_from_ssh_path_pubkey(ctx context.Context, ssh_path, ssh
}
}
-func wf_error(w io.Writer, format string, args ...any) {
+func writeRedError(w io.Writer, format string, args ...any) {
fmt.Fprintln(w, ansiec.Red+fmt.Sprintf(format, args...)+ansiec.Reset)
}