gc: tolerate historical views naming objects pruned under an earlier, shorter op-retention 21b2aec279ff
--- crates/oxy-core/src/repo/gc.rs
- changes.extend(self.store.get_state(&st)?.heads);
- let policy = crate::policy::Policy::decode(&self.store.get_typed(&p, ObjectType::Policy)?)?;
- // Beyond the shallow boundary there is nothing to keep.
+ // A historical view may name objects pruned under an earlier, shorter
+ // retention; there is nothing to keep for those.
+ match self.store.get_state(&st) {
+ Ok(s) => changes.extend(s.heads),
+ Err(StoreError::NotFound(_)) => continue,
+ Err(e) => return Err(e.into()),
+ }
+ let bytes = match self.store.get_typed(&p, ObjectType::Policy) {
+ Ok(b) => b,
+ Err(StoreError::NotFound(_)) => continue,
+ Err(e) => return Err(e.into()),
+ };
+ let policy = crate::policy::Policy::decode(&bytes)?;
+ // Beyond the shallow boundary, or pruned under an earlier
+ // retention, there is nothing to keep.
--- crates/oxy-core/src/repo/tests.rs
- let repo = Repo::open(root).unwrap().with_home(root.join("home"));
+ let mut repo = Repo::open(root).unwrap().with_home(root.join("home"));
+ // Restoring the default retention makes the old views roots again; the
+ // working copies they name were pruned, which gc tolerates.
+ repo.config.set("core.op-retention", "90").unwrap();
+ repo.save_config().unwrap();
+ let repo = Repo::open(root).unwrap().with_home(root.join("home"));
+ let r = repo.gc(false).unwrap();
+ assert_eq!(r.pruned.objects, 0);
+ assert_eq!(repo.log().unwrap().len(), 4);