MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / find_up

Function find_up

crates/opencode-session/src/instruction.rs:88–106  ·  view source on GitHub ↗

Walk from `start` up to `stop` (inclusive), collecting every existing occurrence of `target` (a relative path like "AGENTS.md").

(target: &str, start: &Path, stop: &Path)

Source from the content-addressed store, hash-verified

86/// Walk from `start` up to `stop` (inclusive), collecting every existing
87/// occurrence of `target` (a relative path like "AGENTS.md").
88fn find_up(target: &str, start: &Path, stop: &Path) -> Vec<PathBuf> {
89 let mut current = normalize(start);
90 let stop = normalize(stop);
91 let mut result = Vec::new();
92 loop {
93 let candidate = current.join(target);
94 if candidate.exists() {
95 result.push(candidate);
96 }
97 if current == stop {
98 break;
99 }
100 match current.parent() {
101 Some(p) if p != current => current = p.to_path_buf(),
102 _ => break,
103 }
104 }
105 result
106}
107/// Detect the worktree root by walking up from `start` looking for `.git`.
108/// Returns the directory containing `.git`, or the filesystem root.
109fn detect_worktree_root(start: &Path) -> PathBuf {

Callers 4

resolve_config_pathMethod · 0.70

Calls 3

normalizeFunction · 0.85
newFunction · 0.85
existsMethod · 0.80

Tested by 2