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

Method init_with_view

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

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

Callers

nothing calls this directly

Calls 12

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
openFunction · 0.50
existsMethod · 0.45
commitMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected