mirror of
https://github.com/sbrow/envr.git
synced 2026-08-26 09:53:32 -04:00
refactor(findr): Now accepts an allocator parameter.
This commit is contained in:
@@ -18,11 +18,9 @@
|
||||
|
||||
9. Update `read_wire_string` to use a slice.
|
||||
|
||||
10. Pass allocator to findr?
|
||||
10. Consider getting rid of color global.
|
||||
|
||||
11. Consider getting rid of color global.
|
||||
|
||||
12. `write_flags_table` should never return false.
|
||||
11. `write_flags_table` should never return false.
|
||||
|
||||
## Double-check AI output
|
||||
|
||||
|
||||
+4
-3
@@ -201,8 +201,7 @@ find_git_roots :: proc(
|
||||
ok: bool,
|
||||
) {
|
||||
paths := search_paths(cfg, allocator)
|
||||
// TODO: Pass allocator to findr
|
||||
findr.find_repos(paths[:], &roots, os.get_processor_core_count())
|
||||
findr.find_repos(paths[:], &roots, os.get_processor_core_count(), allocator)
|
||||
ok = true
|
||||
return
|
||||
}
|
||||
@@ -214,6 +213,7 @@ search_paths :: proc(cfg: Config, allocator := context.allocator) -> [dynamic]st
|
||||
}
|
||||
|
||||
paths := new_clone(cfg.scan_config.include, allocator)
|
||||
defer free(paths, allocator)
|
||||
|
||||
for &include in paths {
|
||||
expanded, _ := strings.replace(include, "~", home, 1, allocator)
|
||||
@@ -227,7 +227,8 @@ search_paths :: proc(cfg: Config, allocator := context.allocator) -> [dynamic]st
|
||||
}
|
||||
}
|
||||
}
|
||||
return paths^
|
||||
result := paths^
|
||||
return result
|
||||
}
|
||||
|
||||
envr_dir :: proc(config_path: string) -> string {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import "core:mem"
|
||||
import "core:os"
|
||||
import "core:path/filepath"
|
||||
import "core:strings"
|
||||
@@ -194,3 +195,14 @@ test_search_paths_expands_tilde :: proc(t: ^testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_search_paths_no_leak :: proc(t: ^testing.T) {
|
||||
cfg := Config {
|
||||
scan_config = ScanConfig{include = make([dynamic]string, 0, 1)},
|
||||
}
|
||||
defer delete(cfg.scan_config.include)
|
||||
append(&cfg.scan_config.include, "/tmp")
|
||||
|
||||
_ = search_paths(cfg, context.allocator)
|
||||
}
|
||||
|
||||
|
||||
@@ -491,7 +491,7 @@ db_persist :: proc(db: ^Db, f: ^EnvFile, old_path: string) -> bool {
|
||||
}
|
||||
|
||||
try_move_dir :: proc(db: ^Db, f: ^EnvFile, allocator: mem.Allocator) -> (bool, SyncError) {
|
||||
roots, ok := find_git_roots(db.cfg)
|
||||
roots, ok := find_git_roots(db.cfg, context.allocator)
|
||||
if !ok {
|
||||
return false, .GitRootFailed
|
||||
}
|
||||
|
||||
+9
-1
@@ -16,7 +16,14 @@ RepoPool :: struct {
|
||||
threads: []^thread.Thread,
|
||||
}
|
||||
|
||||
find_repos :: proc(roots: []string, results: ^[dynamic]string, thread_count: int) {
|
||||
find_repos :: proc(
|
||||
roots: []string,
|
||||
results: ^[dynamic]string,
|
||||
thread_count: int,
|
||||
allocator := context.allocator,
|
||||
) {
|
||||
// TODO: This may be a code smell
|
||||
context.allocator = allocator
|
||||
if len(roots) == 0 do return
|
||||
|
||||
pool := new(RepoPool)
|
||||
@@ -126,3 +133,4 @@ process_repo_dir :: proc(pool: ^RepoPool, dir_path: string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-1
@@ -78,7 +78,15 @@ collect_worker :: proc(t: ^thread.Thread) {
|
||||
}
|
||||
}
|
||||
|
||||
walk :: proc(roots: []string, results: ^[dynamic]string, opts: WalkOptions, thread_count: int) {
|
||||
walk :: proc(
|
||||
roots: []string,
|
||||
results: ^[dynamic]string,
|
||||
opts: WalkOptions,
|
||||
thread_count: int,
|
||||
allocator := context.allocator,
|
||||
) {
|
||||
// TODO: This may be a code smell
|
||||
context.allocator = allocator
|
||||
if len(roots) == 0 do return
|
||||
|
||||
ch, _ := chan.create(chan.Chan([]u8), max(2 * thread_count, 2), context.allocator)
|
||||
|
||||
Reference in New Issue
Block a user