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 | let mut out = Vec::new(); | 19 | let mut out = Vec::new(); |
| 20 | let mut seen = Vec::new(); | 20 | let mut seen = Vec::new(); |
| 21 | while let Some((depth, dir)) = dirs.pop() { | 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 | match fs::read(dir.join("info").join("alternates")) { | 22 | match fs::read(dir.join("info").join("alternates")) { |
| 27 | Ok(content) => { | 23 | Ok(content) => { |
| 24 | if seen.contains(&dir) { | ||
| 25 | continue; | ||
| 26 | } | ||
| 27 | seen.push(dir.clone()); | ||
| 28 | dirs.push(( | 28 | dirs.push(( |
| 29 | depth + 1, | 29 | depth + 1, |
| 30 | content | 30 | content |
| @@ -44,5 +44,9 @@ pub fn resolve(objects_directory: impl Into<PathBuf>) -> Result<Vec<compound::Db · 13 unmodified lines | |||
| 44 | Err(err) => return Err(err.into()), | 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 | Ok(out) | 51 | Ok(out) |
| 48 | } | 52 | } |