aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_status.go
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2023-07-01 23:00:51 +0100
committerGitHub <noreply@github.com>2023-07-01 23:00:51 +0100
commit1574937058a9c2ce9b35b9d44ecb4918f0a2e908 (patch)
tree36f304f712c47a0be1e2899e016ca9b3a8b80766 /worktree_status.go
parent35f7e6770361a2c16c9b6c44acdc38ae04c75bd3 (diff)
parent3f7913e4c889b557e1b5d89faf9bbcce869fb7ce (diff)
downloadgo-git-1574937058a9c2ce9b35b9d44ecb4918f0a2e908.tar.gz
Merge pull request #702 from ThinkChaos/perf/add-directory-minor-speedup
perf: minor speedup for `doAddDirectory`
Diffstat (limited to 'worktree_status.go')
-rw-r--r--worktree_status.go26
1 files changed, 5 insertions, 21 deletions
diff --git a/worktree_status.go b/worktree_status.go
index a26c9e5..61bb6f7 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
}
@@ -292,32 +294,14 @@ func (w *Worktree) doAddDirectory(idx *index.Index, s Status, directory string,
return
}
- if !added && a {
- added = true
- }
+ added = added || a
}
return
}
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