aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_status.go
diff options
context:
space:
mode:
authorThinkChaos <ThinkChaos@users.noreply.github.com>2023-03-07 10:10:26 -0500
committerThinkChaos <ThinkChaos@users.noreply.github.com>2023-05-30 12:21:19 -0400
commitcb287f782ad8b5847a721d3f06265a0e9750d41f (patch)
tree119ef4399fb53013bd363e71efe8036682037263 /worktree_status.go
parentd37c8b92eb84a2b66413262c33812236b91422f9 (diff)
downloadgo-git-cb287f782ad8b5847a721d3f06265a0e9750d41f.tar.gz
worktree: minor speedup for doAddDirectory
Diffstat (limited to 'worktree_status.go')
-rw-r--r--worktree_status.go22
1 files changed, 4 insertions, 18 deletions
diff --git a/worktree_status.go b/worktree_status.go
index a26c9e5..389482d 100644
--- a/worktree_status.go
+++ b/worktree_status.go
@@ -281,8 +281,10 @@ func (w *Worktree) doAddDirectory(idx *index.Index, s Status, directory string,
}
}
+ directory = filepath.ToSlash(filepath.Clean(directory))
+
for name := range s {
- if !isPathInDirectory(name, filepath.ToSlash(filepath.Clean(directory))) {
+ if !isPathInDirectory(name, directory) {
continue
}
@@ -301,23 +303,7 @@ func (w *Worktree) doAddDirectory(idx *index.Index, s Status, directory string,
}
func isPathInDirectory(path, directory string) bool {
- ps := strings.Split(path, "/")
- ds := strings.Split(directory, "/")
-
- if len(ds) == 1 && ds[0] == "." {
- return true
- }
-
- if len(ps) < len(ds) {
- return false
- }
-
- for i := 0; i < len(ds); i++ {
- if ps[i] != ds[i] {
- return false
- }
- }
- return true
+ return directory == "." || strings.HasPrefix(path, directory+"/")
}
// AddWithOptions file contents to the index, updates the index using the