保存仓库状态
(&self, state_dir: &Path)
| 222 | |
| 223 | /// 保存仓库状态 |
| 224 | pub fn save_state(&self, state_dir: &Path) -> Result<(), String> { |
| 225 | std::fs::create_dir_all(state_dir) |
| 226 | .map_err(|e| format!("Failed to create state directory: {}", e))?; |
| 227 | |
| 228 | // 保存实体图 |
| 229 | let entity_graph_path = state_dir.join("entity_graph.json"); |
| 230 | let entity_graph = self.entity_graph.read(); |
| 231 | let entity_graph_json = entity_graph.to_json() |
| 232 | .map_err(|e| format!("Failed to serialize entity graph: {}", e))?; |
| 233 | std::fs::write(&entity_graph_path, entity_graph_json) |
| 234 | .map_err(|e| format!("Failed to write entity graph: {}", e))?; |
| 235 | |
| 236 | // 保存调用图 |
| 237 | let call_graph_path = state_dir.join("call_graph.json"); |
| 238 | let call_graph = self.call_graph.read(); |
| 239 | let call_graph_json = call_graph.to_json() |
| 240 | .map_err(|e| format!("Failed to serialize call graph: {}", e))?; |
| 241 | std::fs::write(&call_graph_path, call_graph_json) |
| 242 | .map_err(|e| format!("Failed to write call graph: {}", e))?; |
| 243 | |
| 244 | // 保存增量更新状态 |
| 245 | let incremental_state_path = state_dir.join("incremental_state.json"); |
| 246 | self.incremental_manager.save_state(&incremental_state_path)?; |
| 247 | |
| 248 | info!("Repository state saved to: {}", state_dir.display()); |
| 249 | Ok(()) |
| 250 | } |
| 251 | |
| 252 | /// 加载仓库状态 |
| 253 | pub fn load_state(&mut self, state_dir: &Path) -> Result<(), String> { |