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

Method init_with_view

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

Initialize a new repository whose default view has the given name. Behaves like [`Repository::init`], but the initial shared root view — and the config's `[view] default` — is `view_name` instead of [`DEFAULT_VIEW`]. This is used by `atomic git import` so the imported repository's default view matches the Git default branch rather than leaving an unused `dev` view behind. # Arguments `path` - T

(
        path: P,
        view_name: &str,
    )

Source from the content-addressed store, hash-verified

263 /// - The directory cannot be created
264 /// - The database cannot be initialized
265 pub fn init_with_view<P: AsRef<Path>>(
266 path: P,
267 view_name: &str,
268 ) -> Result<Self, RepositoryError> {
269 let root = path.as_ref().to_path_buf();
270 let dot_dir = root.join(DOT_DIR);
271
272 // Check if repository already exists
273 if dot_dir.exists() {
274 return Err(RepositoryError::AlreadyExists {
275 path: root.display().to_string(),
276 });
277 }
278
279 // Create directory structure
280 std::fs::create_dir_all(&dot_dir)?;
281 std::fs::create_dir_all(dot_dir.join("changes"))?;
282 std::fs::create_dir_all(dot_dir.join(WORKSPACES_DIR))?;
283
284 // Create initial config
285 let config_path = dot_dir.join("config.toml");
286 let initial_config = format!(
287 r#"# Atomic repository configuration
288
289[view]
290default = "{}"
291"#,
292 view_name
293 );
294 std::fs::write(&config_path, initial_config)?;
295
296 // Create working copy ID file
297 let wc_id_path = dot_dir.join("working_copy_id");
298 std::fs::write(&wc_id_path, "")?;
299
300 // Initialize the pristine database (redb creates the file)
301 let pristine = Arc::new(
302 Pristine::open(dot_dir.join("pristine.redb"))
303 .map_err(|e| RepositoryError::Database(e.to_string()))?,
304 );
305
306 // Create the default view and its workspace directory
307 {
308 let mut txn = pristine
309 .write_txn()
310 .map_err(|e| RepositoryError::Database(e.to_string()))?;
311 txn.open_or_create_view(view_name)
312 .map_err(|e| RepositoryError::Database(e.to_string()))?;
313 txn.commit()
314 .map_err(|e| RepositoryError::Database(e.to_string()))?;
315 }
316 ensure_workspace_dir(&dot_dir, view_name)?;
317
318 // Initialize the change store
319 let change_store = ChangeStore::new(dot_dir.join("changes"), DEFAULT_CACHE_CAPACITY)
320 .map_err(|e| RepositoryError::Database(e.to_string()))?;
321
322 let repository = Self {

Callers

nothing calls this directly

Calls 9

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
write_current_viewMethod · 0.80
existsMethod · 0.45

Tested by

no test coverage detected