chore: exec go fix ./...

This commit is contained in:
yulog 2026-02-15 19:45:03 +09:00
parent 7caa68bcd0
commit cefa808653
4 changed files with 12 additions and 17 deletions

View file

@ -149,8 +149,8 @@ func detectLocalRepoRoot(remotePath, repoPath string) string {
pathParts = pathParts[1:]
for i := 0; i < len(pathParts); i++ {
subPath := "/" + path.Join(pathParts[i:]...)
if subIdx := strings.Index(remotePath, subPath); subIdx >= 0 {
return remotePath[0:subIdx] + subPath
if before, _, ok := strings.Cut(remotePath, subPath); ok {
return before + subPath
}
}
return ""

View file

@ -6,6 +6,7 @@ import (
"net/url"
"os"
"path/filepath"
"slices"
"strings"
"sync"
@ -166,7 +167,7 @@ func (repo *LocalRepository) repoRootCandidates() []string {
hostRoot := filepath.Join(repo.RootPath, repo.PathParts[0])
nonHostParts := repo.PathParts[1:]
candidates := make([]string, len(nonHostParts))
for i := 0; i < len(nonHostParts); i++ {
for i := range nonHostParts {
candidates[i] = filepath.Join(append(
[]string{hostRoot}, nonHostParts[0:len(nonHostParts)-i]...)...)
}
@ -184,13 +185,7 @@ func (repo *LocalRepository) IsUnderPrimaryRoot() bool {
// Matches checks if any subpath of the local repository equals the query.
func (repo *LocalRepository) Matches(pathQuery string) bool {
for _, p := range repo.Subpaths() {
if p == pathQuery {
return true
}
}
return false
return slices.Contains(repo.Subpaths(), pathQuery)
}
// VCS returns VCSBackend of the repository

View file

@ -71,6 +71,6 @@ func Log(prefix, message string) {
}
// Logf outputs log with format
func Logf(prefix, msg string, args ...interface{}) {
func Logf(prefix, msg string, args ...any) {
Log(prefix, fmt.Sprintf(msg, args...))
}

12
vcs.go
View file

@ -193,8 +193,8 @@ func replaceOnce(reg *regexp.Regexp, str, replace string) string {
}
func svnBase(p string) string {
if strings.HasSuffix(p, trunk) {
return strings.TrimSuffix(p, trunk)
if before, ok := strings.CutSuffix(p, trunk); ok {
return before
}
return replaceOnce(svnReg, p, "")
}
@ -394,8 +394,8 @@ var DarcsBackend = &VCSBackend{
if err != nil {
return "", fmt.Errorf("failed to show repo: %w", err)
}
lines := strings.Split(string(output), "\n")
for _, line := range lines {
lines := strings.SplitSeq(string(output), "\n")
for line := range lines {
if strings.HasPrefix(strings.TrimSpace(line), "Default Remote:") {
parts := strings.SplitN(line, ":", 2)
if len(parts) == 2 {
@ -441,8 +441,8 @@ var PijulBackend = &VCSBackend{
if err != nil {
return "", fmt.Errorf("failed to list remotes: %w", err)
}
lines := strings.Split(strings.TrimSpace(string(output)), "\n")
for _, line := range lines {
lines := strings.SplitSeq(strings.TrimSpace(string(output)), "\n")
for line := range lines {
trimmed := strings.TrimSpace(line)
if trimmed != "" {
// First non-empty line is the first remote