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

Method init

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

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