mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 23:36:20 +00:00
feat(history): export and restore type icons in types.json
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
206b62d4ab
commit
2b079a8d74
4 files changed
+110
-6
No files matched your search
@@ -20,6 +20,30 @@ pub struct RestoreReport {
|
||||
pub safety_snapshot: Option<SnapshotInfo>,
|
||||
}
|
||||
|
||||
/// Brings type definitions back to the snapshot's `types.json` (missing file: none). Types
|
||||
/// defined now but not in the snapshot lose their icon and stay defined (a tombstone would
|
||||
/// also hide a seeded suggestion of that name). Bad entries are skipped.
|
||||
fn restore_types(graph: &Graph, history: &History, files: &crate::repo::Files) -> Result<()> {
|
||||
let wanted: Vec<export::TypeEntry> = match files.get(export::TYPES_FILE) {
|
||||
Some(oid) => serde_json::from_str(&history.read_blob(*oid)?).unwrap_or_default(),
|
||||
None => Vec::new(),
|
||||
};
|
||||
let mut keep: HashSet<String> = HashSet::new();
|
||||
for t in &wanted {
|
||||
if skip_invalid(graph.create_type(&t.name))?.is_some()
|
||||
&& skip_invalid(graph.set_type_icon(&t.name, t.icon.as_deref()))?.is_some()
|
||||
{
|
||||
keep.insert(synapse_core::title_key(&t.name));
|
||||
}
|
||||
}
|
||||
for (key, def) in graph.type_defs()? {
|
||||
if !def.removed && def.icon.is_some() && !keep.contains(&key) {
|
||||
graph.set_type_icon(&def.name, None)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Test hook: fail after this many block writes/deletes.
|
||||
type Fault<'a> = &'a Cell<Option<usize>>;
|
||||
|
||||
@@ -436,6 +460,7 @@ impl History {
|
||||
report.removed += 1;
|
||||
}
|
||||
}
|
||||
restore_types(graph, this, &files)?;
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(report)
|
||||
|
||||
Reference in new issue
Block a user