I think this will make the implementation more user friendly, while seeding out cycles that lead to nothing usable.
Unified · Split
| @@ -19,12 +19,12 @@ pub fn resolve(objects_directory: impl Into<PathBuf>) -> Result<Vec<compound::Db · 18 unmodified lines | ||
| 19 | 19 | let mut out = Vec::new(); |
| 20 | 20 | let mut seen = Vec::new(); |
| 21 | 21 | while let Some((depth, dir)) = dirs.pop() { |
| 22 | − if seen.contains(&dir) { | |
| 23 | − return Err(Error::Cycle(seen)); | |
| 24 | − } | |
| 25 | − seen.push(dir.clone()); | |
| 26 | 22 | match fs::read(dir.join("info").join("alternates")) { |
| 27 | 23 | Ok(content) => { |
| 24 | + if seen.contains(&dir) { | |
| 25 | + continue; | |
| 26 | + } | |
| 27 | + seen.push(dir.clone()); | |
| 28 | 28 | dirs.push(( |
| 29 | 29 | depth + 1, |
| 30 | 30 | content |
| @@ -44,5 +44,9 @@ pub fn resolve(objects_directory: impl Into<PathBuf>) -> Result<Vec<compound::Db · 13 unmodified lines | ||
| 44 | 44 | Err(err) => return Err(err.into()), |
| 45 | 45 | }; |
| 46 | 46 | } |
| 47 | + | |
| 48 | + if out.is_empty() && !seen.is_empty() { | |
| 49 | + return Err(Error::Cycle(seen)); | |
| 50 | + } | |
| 47 | 51 | Ok(out) |
| 48 | 52 | } |