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

Method init

atomic-repository/src/repository/mod.rs:238–300  ·  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

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

Callers 1

init_loggingFunction · 0.80

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