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

Method init_with_view

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

458 /// - The directory cannot be created
459 /// - The database cannot be initialized
460 pub fn init_with_view<P: AsRef<Path>>(
461 path: P,
462 view_name: &str,
463 ) -> Result<Self, RepositoryError> {
464 let root = path.as_ref().to_path_buf();
465 let dot_dir = root.join(DOT_DIR);
466
467 // Check if repository already exists
468 if dot_dir.exists() {
469 return Err(RepositoryError::AlreadyExists {
470 path: root.display().to_string(),
471 });
472 }
473
474 // Create directory structure
475 std::fs::create_dir_all(&dot_dir)?;
476 std::fs::create_dir_all(dot_dir.join("changes"))?;
477 std::fs::create_dir_all(dot_dir.join(WORKSPACES_DIR))?;
478
479 // Create initial config
480 let config_path = dot_dir.join("config.toml");
481 let initial_config = format!(
482 r#"# Atomic repository configuration
483
484[view]
485default = "{}"
486"#,
487 view_name
488 );
489 std::fs::write(&config_path, initial_config)?;
490
491 // Initialize the repository database (redb creates the file)
492 let pristine =
493 Arc::new(Pristine::open(dot_dir.join(DATABASE_FILE)).map_err(RepositoryError::from)?);
494
495 // Create the default view and its workspace directory
496 {
497 let mut txn = pristine
498 .write_txn()
499 .map_err(|e| RepositoryError::Database(e.to_string()))?;
500 txn.open_or_create_view(view_name)
501 .map_err(|e| RepositoryError::Database(e.to_string()))?;
502 txn.commit()
503 .map_err(|e| RepositoryError::Database(e.to_string()))?;
504 }
505 ensure_workspace_dir(&dot_dir, view_name)?;
506
507 // Persist the working-copy record before publishing compatibility files.
508 let layout = working_copy::discover_layout(&root)?;
509 let (_working_copy_id, current_view) =
510 working_copy::migrate_identity(&pristine, &layout, view_name)?;
511
512 // Align the stored root with `open`: the layout discovery canonicalizes
513 // the working root (e.g. macOS `/var` → `/private/var`), and a
514 // repository initialized through a symlinked path must report the same
515 // root as one opened from disk.
516 let root = layout.working_root.clone();
517 let dot_dir = root.join(DOT_DIR);

Callers

nothing calls this directly

Calls 12

openFunction · 0.85
ensure_workspace_dirFunction · 0.85
discover_layoutFunction · 0.85
migrate_identityFunction · 0.85
as_refMethod · 0.80
displayMethod · 0.80
write_txnMethod · 0.80
open_or_create_viewMethod · 0.80
writeFunction · 0.50
existsMethod · 0.45
commitMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected