Simplify codebase per audit of 8b89f14
This commit is contained in:
+11
-11
@@ -53,7 +53,7 @@ func Inspect(ctx context.Context, path string) (RepoInfo, error) {
|
||||
return RepoInfo{}, err
|
||||
}
|
||||
|
||||
remote, _, code, err := runCode(ctx, root, nil, "remote", "get-url", Remote)
|
||||
remote, _, code, err := runCode(ctx, root, "remote", "get-url", Remote)
|
||||
if err != nil {
|
||||
return RepoInfo{}, err
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func Inspect(ctx context.Context, path string) (RepoInfo, error) {
|
||||
}
|
||||
|
||||
func HasRemote(ctx context.Context, repo string) (bool, error) {
|
||||
_, _, code, err := runCode(ctx, repo, nil, "remote", "get-url", Remote)
|
||||
_, _, code, err := runCode(ctx, repo, "remote", "get-url", Remote)
|
||||
return err == nil && code == 0, err
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ func AddWorktree(ctx context.Context, repo, path, branch, base string) (string,
|
||||
}
|
||||
|
||||
func EnsureBranchCommit(ctx context.Context, repo, branch string, env []string) error {
|
||||
_, _, code, err := runCode(ctx, repo, nil, "rev-parse", "--verify", "--quiet", "refs/heads/"+branch+"^{commit}")
|
||||
_, _, code, err := runCode(ctx, repo, "rev-parse", "--verify", "--quiet", "refs/heads/"+branch+"^{commit}")
|
||||
if err != nil || code == 0 {
|
||||
return err
|
||||
}
|
||||
@@ -152,7 +152,7 @@ func RemoveWorktree(ctx context.Context, repo, path, branch string) error {
|
||||
}
|
||||
}
|
||||
|
||||
_, _, code, err := runCode(ctx, repo, nil, "rev-parse", "--verify", "--quiet", "refs/heads/"+branch)
|
||||
_, _, code, err := runCode(ctx, repo, "rev-parse", "--verify", "--quiet", "refs/heads/"+branch)
|
||||
if err != nil || code != 0 {
|
||||
return err
|
||||
}
|
||||
@@ -206,7 +206,7 @@ func SquashCommit(ctx context.Context, repo, worktree, target, message string, e
|
||||
return "", err
|
||||
}
|
||||
|
||||
out, stderr, code, err := runCode(ctx, repo, nil, "merge-tree", "--write-tree", "--name-only", "--merge-base="+base, head, tree)
|
||||
out, stderr, code, err := runCode(ctx, repo, "merge-tree", "--write-tree", "--name-only", "--merge-base="+base, head, tree)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -237,7 +237,7 @@ func SquashCommit(ctx context.Context, repo, worktree, target, message string, e
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
signing, stderr, code, err := runCode(ctx, repo, nil, "config", "--type=bool", "--get", "commit.gpgsign")
|
||||
signing, stderr, code, err := runCode(ctx, repo, "config", "--type=bool", "--get", "commit.gpgsign")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -340,7 +340,7 @@ func BranchHead(ctx context.Context, repo, branch string) (string, error) {
|
||||
}
|
||||
|
||||
func IsAncestor(ctx context.Context, dir, ancestor, descendant string) (bool, error) {
|
||||
_, stderr, code, err := runCode(ctx, dir, nil, "merge-base", "--is-ancestor", ancestor, descendant)
|
||||
_, stderr, code, err := runCode(ctx, dir, "merge-base", "--is-ancestor", ancestor, descendant)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -354,7 +354,7 @@ func IsAncestor(ctx context.Context, dir, ancestor, descendant string) (bool, er
|
||||
}
|
||||
|
||||
func MergeInProgress(ctx context.Context, dir string) (bool, error) {
|
||||
_, _, code, err := runCode(ctx, dir, nil, "rev-parse", "--quiet", "--verify", "MERGE_HEAD")
|
||||
_, _, code, err := runCode(ctx, dir, "rev-parse", "--quiet", "--verify", "MERGE_HEAD")
|
||||
return err == nil && code == 0, err
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ func AbortMerge(ctx context.Context, dir string) error {
|
||||
}
|
||||
|
||||
func ReadFile(ctx context.Context, repo, rev, path string) (string, bool, error) {
|
||||
_, _, code, err := runCode(ctx, repo, nil, "cat-file", "-e", rev+":"+path)
|
||||
_, _, code, err := runCode(ctx, repo, "cat-file", "-e", rev+":"+path)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
@@ -434,8 +434,8 @@ func runRaw(ctx context.Context, dir string, env []string, input string, args ..
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func runCode(ctx context.Context, dir string, env []string, args ...string) (string, string, int, error) {
|
||||
out, stderr, code, err := runCodeInput(context.WithoutCancel(ctx), dir, env, nil, args...)
|
||||
func runCode(ctx context.Context, dir string, args ...string) (string, string, int, error) {
|
||||
out, stderr, code, err := runCodeInput(context.WithoutCancel(ctx), dir, nil, nil, args...)
|
||||
return strings.TrimSpace(out), stderr, code, err
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ func ConfigureNotesFetch(ctx context.Context, repo string) error {
|
||||
return err
|
||||
}
|
||||
key := "remote." + Remote + ".fetch"
|
||||
out, stderr, code, err := runCode(ctx, repo, nil, "config", "--get-all", key)
|
||||
out, stderr, code, err := runCode(ctx, repo, "config", "--get-all", key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -39,7 +39,7 @@ func NoteCommit(ctx context.Context, repo, commit, note string, env []string) (s
|
||||
return "", err
|
||||
}
|
||||
|
||||
parent, stderr, code, err := runCode(ctx, repo, nil, "rev-parse", "--verify", "--quiet", NotesRef)
|
||||
parent, stderr, code, err := runCode(ctx, repo, "rev-parse", "--verify", "--quiet", NotesRef)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func NoteCommit(ctx context.Context, repo, commit, note string, env []string) (s
|
||||
}
|
||||
|
||||
func AdvanceNotes(ctx context.Context, repo, notes string) error {
|
||||
current, stderr, code, err := runCode(ctx, repo, nil, "rev-parse", "--verify", "--quiet", NotesRef)
|
||||
current, stderr, code, err := runCode(ctx, repo, "rev-parse", "--verify", "--quiet", NotesRef)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func RepairWorktrees(ctx context.Context, repo string, paths []string) error {
|
||||
}
|
||||
|
||||
func RewriteNotes(ctx context.Context, repo string, rewrite func(string) string) error {
|
||||
parent, stderr, code, err := runCode(ctx, repo, nil, "rev-parse", "--verify", "--quiet", NotesRef)
|
||||
parent, stderr, code, err := runCode(ctx, repo, "rev-parse", "--verify", "--quiet", NotesRef)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user