mirror of
https://github.com/alibaba/open-code-review.git
synced 2026-11-15 03:57:46 +08:00
* fix(preview): collapse provider-directory rows and keep changeset order Size the path column per section, render provider_directory entries as one summary line in text output, and keep preview entries in Git order. * docs(faq): document collapsed provider-directory preview rows Terminal preview summarizes provider-directory files; JSON still lists every entry. Sync the wording and sample across all five locales. * docs(preview): tighten comment and FAQ wording Use --format json in a test comment, separate the totals and ordering reasons in preview.go, and stop saying preview lists every candidate file.
51 lines
1.8 KiB
Go
51 lines
1.8 KiB
Go
// SPDX-License-Identifier: Apache-2.0
|
|
// Copyright 2026 alibaba/open-code-review Contributors
|
|
|
|
package diff
|
|
|
|
import "strings"
|
|
|
|
// ExcludedDirs is the list of directory prefixes that scanners and diff
|
|
// providers should always skip. Exposed so internal/scan and other consumers
|
|
// can reuse the same blocklist.
|
|
func ExcludedDirs() []string {
|
|
out := make([]string, len(providerDirIgnoreDirs))
|
|
copy(out, providerDirIgnoreDirs)
|
|
return out
|
|
}
|
|
|
|
// ProviderDirPrefix returns the blocklist prefix that excludes relPath,
|
|
// including the trailing slash (for example "vendor/"), or "" if none match.
|
|
func ProviderDirPrefix(relPath string) string {
|
|
for _, prefix := range providerDirIgnoreDirs {
|
|
dirPart := strings.TrimSuffix(prefix, "/")
|
|
if relPath == dirPart || strings.HasPrefix(relPath, prefix) {
|
|
return prefix
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// LoadGitignorePatterns reads and parses .gitignore patterns from the given
|
|
// repository root. Returns nil if the file is missing or unreadable.
|
|
func LoadGitignorePatterns(repoDir string) []string {
|
|
stub := &Provider{repoDir: repoDir}
|
|
return stub.loadGitignorePatterns()
|
|
}
|
|
|
|
// IsPathExcluded returns true when relPath matches any of the supplied
|
|
// gitignore-style patterns or any default excluded directory prefix
|
|
// (see ExcludedDirs).
|
|
func IsPathExcluded(repoDir, relPath string, patterns []string) bool {
|
|
stub := &Provider{repoDir: repoDir}
|
|
return stub.isPathExcluded(relPath, patterns)
|
|
}
|
|
|
|
// MatchGitignorePattern reports whether relPath matches a single
|
|
// gitignore-style pattern, using the simplified semantics that diff.Provider
|
|
// already implements (basename match, prefix match, directory-only suffix).
|
|
// Useful when callers want to test a single pattern in isolation.
|
|
func MatchGitignorePattern(relPath, pat string) bool {
|
|
return matchGitignorePattern(relPath, pat)
|
|
}
|