MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / init

Method init

atomic-repository/src/repository/mod.rs:228–289  ·  view source on GitHub ↗

Initialize a new repository at the given path. This creates the `.atomic` directory structure and initializes the database with an empty graph. # Arguments `path` - The directory to initialize as a repository # Errors Returns an error if: - A repository already exists at the path - The directory cannot be created - The database cannot be initialized

(path: P)

Source from the content-addressed store, hash-verified

226 /// - The directory cannot be created
227 /// - The database cannot be initialized
228 pub fn init<P: AsRef<Path>>(path: P) -> Result<Self, RepositoryError> {
229 let root = path.as_ref().to_path_buf();
230 let dot_dir = root.join(DOT_DIR);
231
232 // Check if repository already exists
233 if dot_dir.exists() {
234 return Err(RepositoryError::AlreadyExists {
235 path: root.display().to_string(),
236 });
237 }
238
239 // Create directory structure
240 std::fs::create_dir_all(&dot_dir)?;
241 std::fs::create_dir_all(dot_dir.join("changes"))?;
242 std::fs::create_dir_all(dot_dir.join(WORKSPACES_DIR))?;
243
244 // Create initial config
245 let config_path = dot_dir.join("config.toml");
246 let initial_config = format!(
247 r#"# Atomic repository configuration
248
249[view]
250default = "{}"
251"#,
252 DEFAULT_VIEW
253 );
254 std::fs::write(&config_path, initial_config)?;
255
256 // Create working copy ID file
257 let wc_id_path = dot_dir.join("working_copy_id");
258 std::fs::write(&wc_id_path, "")?;
259
260 // Initialize the pristine database (redb creates the file)
261 let pristine = Arc::new(
262 Pristine::open(dot_dir.join("pristine.redb"))
263 .map_err(|e| RepositoryError::Database(e.to_string()))?,
264 );
265
266 // Create the default view and its workspace directory
267 {
268 let mut txn = pristine
269 .write_txn()
270 .map_err(|e| RepositoryError::Database(e.to_string()))?;
271 txn.open_or_create_view(DEFAULT_VIEW)
272 .map_err(|e| RepositoryError::Database(e.to_string()))?;
273 txn.commit()
274 .map_err(|e| RepositoryError::Database(e.to_string()))?;
275 }
276 ensure_workspace_dir(&dot_dir, DEFAULT_VIEW)?;
277
278 // Initialize the change store
279 let change_store = ChangeStore::new(dot_dir.join("changes"), DEFAULT_CACHE_CAPACITY)
280 .map_err(|e| RepositoryError::Database(e.to_string()))?;
281
282 Ok(Self {
283 root,
284 dot_dir,
285 current_view: DEFAULT_VIEW.to_string(),

Callers

nothing calls this directly

Calls 8

writeFunction · 0.85
ensure_workspace_dirFunction · 0.85
as_refMethod · 0.80
displayMethod · 0.80
write_txnMethod · 0.80
open_or_create_viewMethod · 0.80
commitMethod · 0.80
existsMethod · 0.45

Tested by

no test coverage detected