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

Method init

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

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