Audit of f8e6783
This commit is contained in:
@@ -206,8 +206,7 @@ func (r *Registry) List() []Client {
|
|||||||
|
|
||||||
func (r *Registry) Call(ctx context.Context, name string, req api.ClientRequest) (api.ClientReply, error) {
|
func (r *Registry) Call(ctx context.Context, name string, req api.ClientRequest) (api.ClientReply, error) {
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
matches := []*conn{}
|
matches := []entry{}
|
||||||
matched := []string{}
|
|
||||||
connected := []string{}
|
connected := []string{}
|
||||||
for _, e := range r.clients {
|
for _, e := range r.clients {
|
||||||
if e.conn == nil {
|
if e.conn == nil {
|
||||||
@@ -215,8 +214,7 @@ func (r *Registry) Call(ctx context.Context, name string, req api.ClientRequest)
|
|||||||
}
|
}
|
||||||
connected = append(connected, fmt.Sprintf("%s (%s)", e.Host, e.ID))
|
connected = append(connected, fmt.Sprintf("%s (%s)", e.Host, e.ID))
|
||||||
if e.ID == name || e.Host == name {
|
if e.ID == name || e.Host == name {
|
||||||
matches = append(matches, e.conn)
|
matches = append(matches, *e)
|
||||||
matched = append(matched, e.ID)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r.mu.Unlock()
|
r.mu.Unlock()
|
||||||
@@ -225,10 +223,14 @@ func (r *Registry) Call(ctx context.Context, name string, req api.ClientRequest)
|
|||||||
return api.ClientReply{}, fmt.Errorf("no client named %q is connected; connected: %s", name, strings.Join(connected, ", "))
|
return api.ClientReply{}, fmt.Errorf("no client named %q is connected; connected: %s", name, strings.Join(connected, ", "))
|
||||||
}
|
}
|
||||||
if len(matches) > 1 {
|
if len(matches) > 1 {
|
||||||
|
matched := make([]string, len(matches))
|
||||||
|
for i, e := range matches {
|
||||||
|
matched[i] = e.ID
|
||||||
|
}
|
||||||
slices.Sort(matched)
|
slices.Sort(matched)
|
||||||
return api.ClientReply{}, fmt.Errorf("%d clients on %s are connected; name one by its id: %s", len(matches), name, strings.Join(matched, ", "))
|
return api.ClientReply{}, fmt.Errorf("%d clients on %s are connected; name one by its id: %s", len(matches), name, strings.Join(matched, ", "))
|
||||||
}
|
}
|
||||||
c := matches[0]
|
c := matches[0].conn
|
||||||
|
|
||||||
req.Id = ids.New(ids.ClientRequest)
|
req.Id = ids.New(ids.ClientRequest)
|
||||||
ch := make(chan api.ClientReply, 1)
|
ch := make(chan api.ClientReply, 1)
|
||||||
|
|||||||
+8
-13
@@ -237,13 +237,10 @@ func SquashCommit(repo, worktree, target, message string, env []string, sign fun
|
|||||||
}
|
}
|
||||||
|
|
||||||
func signCommit(repo, commit string, sign func(payload []byte) ([]byte, error)) (string, error) {
|
func signCommit(repo, commit string, sign func(payload []byte) ([]byte, error)) (string, error) {
|
||||||
payload, stderr, code, err := runCodeInput(context.Background(), repo, nil, nil, "cat-file", "commit", commit)
|
payload, err := runRaw(repo, nil, "", "cat-file", "commit", commit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if code != 0 {
|
|
||||||
return "", fmt.Errorf("git cat-file commit %s: exit status %d: %s", commit, code, stderr)
|
|
||||||
}
|
|
||||||
sig, err := sign([]byte(payload))
|
sig, err := sign([]byte(payload))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("signing the commit: %w", err)
|
return "", fmt.Errorf("signing the commit: %w", err)
|
||||||
@@ -402,17 +399,15 @@ func run(dir string, args ...string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runEnv(dir string, env []string, args ...string) (string, error) {
|
func runEnv(dir string, env []string, args ...string) (string, error) {
|
||||||
out, stderr, code, err := runCode(dir, env, args...)
|
return runInput(dir, env, "", args...)
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if code != 0 {
|
|
||||||
return "", fmt.Errorf("git %s: exit status %d: %s", strings.Join(args, " "), code, stderr)
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func runInput(dir string, env []string, input string, args ...string) (string, error) {
|
func runInput(dir string, env []string, input string, args ...string) (string, error) {
|
||||||
|
out, err := runRaw(dir, env, input, args...)
|
||||||
|
return strings.TrimSpace(out), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func runRaw(dir string, env []string, input string, args ...string) (string, error) {
|
||||||
out, stderr, code, err := runCodeInput(context.Background(), dir, env, strings.NewReader(input), args...)
|
out, stderr, code, err := runCodeInput(context.Background(), dir, env, strings.NewReader(input), args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -420,7 +415,7 @@ func runInput(dir string, env []string, input string, args ...string) (string, e
|
|||||||
if code != 0 {
|
if code != 0 {
|
||||||
return "", fmt.Errorf("git %s: exit status %d: %s", strings.Join(args, " "), code, stderr)
|
return "", fmt.Errorf("git %s: exit status %d: %s", strings.Join(args, " "), code, stderr)
|
||||||
}
|
}
|
||||||
return strings.TrimSpace(out), nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCode(dir string, env []string, args ...string) (string, string, int, error) {
|
func runCode(dir string, env []string, args ...string) (string, string, int, error) {
|
||||||
|
|||||||
+1
-13
@@ -2,7 +2,6 @@ package git
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@@ -147,7 +146,7 @@ func RewriteNotes(repo string, rewrite func(string) string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func catBlobs(repo string, shas []string) (map[string]string, error) {
|
func catBlobs(repo string, shas []string) (map[string]string, error) {
|
||||||
out, err := runRaw(repo, strings.Join(shas, "\n")+"\n", "cat-file", "--batch")
|
out, err := runRaw(repo, nil, strings.Join(shas, "\n")+"\n", "cat-file", "--batch")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -182,14 +181,3 @@ func splitLines(out string) []string {
|
|||||||
}
|
}
|
||||||
return strings.Split(out, "\n")
|
return strings.Split(out, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func runRaw(dir, input string, args ...string) (string, error) {
|
|
||||||
out, stderr, code, err := runCodeInput(context.Background(), dir, nil, strings.NewReader(input), args...)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if code != 0 {
|
|
||||||
return "", fmt.Errorf("git %s: exit status %d: %s", strings.Join(args, " "), code, stderr)
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user