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

Method init

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

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