Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use crate::package::build::cas::build::{compare, last_release};
use crate::package::build::cas::object_store::ObjectStore;
use crate::package::build::cas::objects::{Blob, Commit, EntryMode, Tree};
use crate::package::build::cas::object_store::ensure_compatible_store;
use crate::package::build::cas::refs::{main_ref, read_ref, ref_exists};
use crate::package::build::cas::refs::{REF_HEAD_MAIN_FILENAME, read_ref, ref_exists};
use crate::package::build::cas::storage::{from_cbor, to_cbor, Hash};
use crate::package::config::ir::context::ProjectContext;
use crate::package::config::ir::diff::ConfigChange;
Expand Down Expand Up @@ -746,11 +746,11 @@ impl Loaded {
pub fn facts(project_path: &Path, version: Option<&str>) -> Result<PackageFacts> {
// Read-only, and refuses a store in another format without touching it.
ensure_compatible_store(project_path)?;
if !ref_exists(project_path, main_ref()) {
if !ref_exists(project_path, REF_HEAD_MAIN_FILENAME) {
bail!("nothing built yet: run `comline build` first");
}
let store = ObjectStore::new(project_path);
let mut hash = read_ref(project_path, main_ref())?;
let mut hash = read_ref(project_path, REF_HEAD_MAIN_FILENAME)?;
loop {
let commit = Commit::from_bytes(&store.read(&hash)?)?;
if version.map_or(true, |v| v == commit.version) {
Expand Down Expand Up @@ -786,7 +786,7 @@ pub fn facts_of_working_tree(project_path: &Path, context: &ProjectContext) -> R
ensure_compatible_store(project_path)?;
let store = ObjectStore::scratch(project_path);
let tree = working_tree(project_path, context, &store)?;
if !ref_exists(project_path, main_ref()) {
if !ref_exists(project_path, REF_HEAD_MAIN_FILENAME) {
let version = first_version().to_string();
let history = history(&store, None, &tree, &release_of(&version))?;
return Ok(assemble(&Loaded::of(&store, &tree)?, &history, &version));
Expand Down
10 changes: 5 additions & 5 deletions core/src/package/build/cas/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::path::Path;
use super::object_store::ObjectStore;
use super::objects::{Commit, EntryMode, Tree};
use super::reconcile::{self, read_heads, Heads};
use super::refs::{main_ref, ref_exists, update_ref};
use super::refs::{REF_HEAD_MAIN_FILENAME, ref_exists, update_ref};
use super::storage::Hash;
use super::version::{dev_version, next_release, VersionBump};
use crate::compat::release_of;
Expand Down Expand Up @@ -411,7 +411,7 @@ pub fn process_initial_freezing(
let commit_hash = store.write(&commit_bytes)?;

// Update main ref to point to this commit
update_ref(project_path, main_ref(), &commit_hash)?;
update_ref(project_path, REF_HEAD_MAIN_FILENAME, &commit_hash)?;

tracing::info!("CAS: Initial commit {} created", commit_hash);

Expand All @@ -436,7 +436,7 @@ pub fn process_changes(project_path: &Path, latest_project: &ProjectContext) ->
store.init()?;

// Read previous commit
if !ref_exists(project_path, main_ref()) {
if !ref_exists(project_path, REF_HEAD_MAIN_FILENAME) {
// No previous commit, treat as initial
return process_initial_freezing(project_path, latest_project);
}
Expand Down Expand Up @@ -474,7 +474,7 @@ pub fn process_changes(project_path: &Path, latest_project: &ProjectContext) ->
// Reconciling onto a head whose tree is already the merged one:
// nothing to build, but the ref is repaired to that head.
if reconciling.is_some() {
update_ref(project_path, main_ref(), &parent_hash)?;
update_ref(project_path, REF_HEAD_MAIN_FILENAME, &parent_hash)?;
}
let (release, _) = last_release(&store, parent_hash)?;
return Ok(BuildInfo {
Expand Down Expand Up @@ -518,7 +518,7 @@ pub fn process_changes(project_path: &Path, latest_project: &ProjectContext) ->
let commit_hash = store.write(&commit_bytes)?;

// Update main ref
update_ref(project_path, main_ref(), &commit_hash)?;
update_ref(project_path, REF_HEAD_MAIN_FILENAME, &commit_hash)?;

tracing::info!("CAS: New commit {} created ({})", commit_hash, new_version);

Expand Down
2 changes: 1 addition & 1 deletion core/src/package/build/cas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod schema;
pub use storage::{Hash, compress, decompress};
pub use object_store::ObjectStore;
#[cfg(feature = "compiler")]
pub use refs::{update_ref, read_ref, ref_exists, main_ref};
pub use refs::{update_ref, read_ref, ref_exists, REF_HEAD_MAIN_FILENAME};
pub use version::VersionBump;

// Standard Uses
Expand Down
16 changes: 8 additions & 8 deletions core/src/package/build/cas/reconcile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use std::path::Path;
// Crate Uses
use super::object_store::ObjectStore;
use super::objects::Commit;
use super::refs::main_ref;
use super::refs::REF_HEAD_MAIN_FILENAME;
use super::storage::Hash;

// External Uses
Expand Down Expand Up @@ -87,7 +87,7 @@ pub fn parse_heads(text: &str) -> Result<Heads> {
Section::Base => {}
Section::Outside => bail!(
"`.comline/{}` has conflict markers and other content: {line:?}",
main_ref()
REF_HEAD_MAIN_FILENAME
),
}
}
Expand All @@ -98,7 +98,7 @@ pub fn parse_heads(text: &str) -> Result<Heads> {
_ => Err(eyre!(
"`.comline/{}` is conflicted, but {which} side doesn't hold exactly one commit \
hash",
main_ref()
REF_HEAD_MAIN_FILENAME
)),
}
};
Expand All @@ -108,9 +108,9 @@ pub fn parse_heads(text: &str) -> Result<Heads> {

/// Read `refs/heads/main`: one head, or two after a Git merge.
pub fn read_heads(project_path: &Path) -> Result<Heads> {
let path = project_path.join(".comline").join(main_ref());
let path = project_path.join(".comline").join(REF_HEAD_MAIN_FILENAME);
if !path.exists() {
bail!("Ref {} does not exist", main_ref());
bail!("Ref {} does not exist", REF_HEAD_MAIN_FILENAME);
}
parse_heads(&fs::read_to_string(&path)?)
}
Expand All @@ -132,12 +132,12 @@ pub fn mark_diverged(project_path: &Path, other: &Hash) -> Result<()> {
.map_err(|e| eyre!("{other} isn't a commit: {e}"))?;
let current = match read_heads(project_path)? {
Heads::One(hash) => hash,
Heads::Two(..) => bail!("`.comline/{}` already holds two heads", main_ref()),
Heads::Two(..) => bail!("`.comline/{}` already holds two heads", REF_HEAD_MAIN_FILENAME),
};
if current == *other {
return Ok(());
}
let path = project_path.join(".comline").join(main_ref());
let path = project_path.join(".comline").join(REF_HEAD_MAIN_FILENAME);
fs::write(
path,
format!("<<<<<<< current\n{current}\n=======\n{other}\n>>>>>>> reconcile\n"),
Expand Down Expand Up @@ -252,7 +252,7 @@ pub fn plan(store: &ObjectStore, a: Hash, b: Hash) -> Result<Plan> {
in `.comline/objects` but leaves the line.",
ra.version, short(&released_a[0].0), rb.version, short(&released_b[0].0),
a, ra.version, b, rb.version,
ref_ = main_ref(),
ref_ = REF_HEAD_MAIN_FILENAME,
);
}
(Some(_), None) => a,
Expand Down
6 changes: 2 additions & 4 deletions core/src/package/build/cas/refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,5 @@ pub fn ref_exists(project_path: &Path, ref_name: &str) -> bool {
project_path.join(".comline").join(ref_name).exists()
}

/// Get the main branch ref path
pub fn main_ref() -> &'static str {
"refs/heads/main"
}
/// Main branch reference path
pub const REF_HEAD_MAIN_FILENAME: &str = "refs/heads/main";
12 changes: 6 additions & 6 deletions core/src/package/build/cas/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::path::Path;
use super::build::{compare, last_release, Comparison};
use super::object_store::{ensure_compatible_store, ObjectStore};
use super::objects::{Commit, Release, Tree};
use super::refs::{main_ref, read_ref, ref_exists, update_ref};
use super::refs::{REF_HEAD_MAIN_FILENAME, read_ref, ref_exists, update_ref};
use super::version::{next_release, VersionBump};
use crate::schema::ir::frozen::cas::commit::create_version_commit;

Expand Down Expand Up @@ -47,11 +47,11 @@ pub struct ReleaseInfo {
/// The latest release in the package's history, if any.
pub fn latest_release(project_path: &Path) -> Result<Option<Commit>> {
ensure_compatible_store(project_path)?;
if !ref_exists(project_path, main_ref()) {
if !ref_exists(project_path, REF_HEAD_MAIN_FILENAME) {
return Ok(None);
}
let store = ObjectStore::new(project_path);
let (release, _) = last_release(&store, read_ref(project_path, main_ref())?)?;
let (release, _) = last_release(&store, read_ref(project_path, REF_HEAD_MAIN_FILENAME)?)?;
Ok(release.map(|(_, commit)| commit))
}

Expand All @@ -64,12 +64,12 @@ pub fn release(project_path: &Path, request: &ReleaseRequest) -> Result<ReleaseI
bail!("a release to 1.0.0 can't also raise the bump: 1.0.0 is the version it makes");
}
ensure_compatible_store(project_path)?;
if !ref_exists(project_path, main_ref()) {
if !ref_exists(project_path, REF_HEAD_MAIN_FILENAME) {
bail!("nothing built yet: run `comline build` first");
}

let store = ObjectStore::new(project_path);
let head_hash = read_ref(project_path, main_ref())?;
let head_hash = read_ref(project_path, REF_HEAD_MAIN_FILENAME)?;
let head = Commit::from_bytes(&store.read(&head_hash)?)?;
let (previous, _) = last_release(&store, head_hash)?;
let previous_version = previous
Expand Down Expand Up @@ -154,7 +154,7 @@ pub fn release(project_path: &Path, request: &ReleaseRequest) -> Result<ReleaseI
let mut commit = create_version_commit(tree, head_hash, &version.to_string(), &message);
commit.release = Some(record.clone());
let commit_hash = store.write(&commit.to_bytes()?)?;
update_ref(project_path, main_ref(), &commit_hash)?;
update_ref(project_path, REF_HEAD_MAIN_FILENAME, &commit_hash)?;

Ok(ReleaseInfo {
previous_release: previous.map(|(_, commit)| commit.version),
Expand Down
6 changes: 3 additions & 3 deletions core/src/package/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::rc::Rc;

// Crate Uses
#[cfg(feature = "compiler")]
use crate::package::config::idl::constants::CONGREGATION_EXTENSION;
use crate::package::config::idl::PACKAGE_CONFIG_FILENAME;
#[cfg(feature = "compiler")]
use crate::package::config::ir::interpreter::ProjectInterpreter;
#[cfg(feature = "compiler")]
Expand Down Expand Up @@ -105,7 +105,7 @@ fn compile_package_inner(package_path: &Path) -> Result<ProjectContext> {

#[cfg(feature = "compiler")]
fn require_config_path(package_path: &Path) -> Result<std::path::PathBuf> {
let config_path = package_path.join(format!("config.{}", CONGREGATION_EXTENSION));
let config_path = package_path.join(PACKAGE_CONFIG_FILENAME);
let config_name = config_path.file_name().unwrap().to_str().unwrap();

if !config_path.exists() {
Expand Down Expand Up @@ -236,7 +236,7 @@ pub fn build_with(
check(&latest_project)?;

// Use CAS for immutable version storage
let build_info = if cas::refs::ref_exists(package_path, cas::refs::main_ref()) {
let build_info = if cas::refs::ref_exists(package_path, cas::refs::REF_HEAD_MAIN_FILENAME) {
cas::build::process_changes(&package_path, &latest_project)?
} else {
cas::build::process_initial_freezing(&package_path, &latest_project)?
Expand Down
9 changes: 0 additions & 9 deletions core/src/package/config/idl/constants.rs

This file was deleted.

4 changes: 3 additions & 1 deletion core/src/package/config/idl/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Relative Modules
#[cfg(feature = "compiler")]
pub mod grammar;
pub mod constants;
// pub mod parser;
// pub mod ast;

pub const PACKAGE_EXTENSION: &str = "idp";
pub const PACKAGE_CONFIG_FILENAME: &str = concat!("config.", "idp");
8 changes: 2 additions & 6 deletions core/src/package/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ pub mod dependency; // NEW: Dependency configuration
use std::path::Path;

// Crate Uses
use crate::package::config::idl::constants::CONGREGATION_EXTENSION;
use crate::package::config::idl::PACKAGE_CONFIG_FILENAME;

// External Uses


/// Determines if given path is a package directory by checking minimally
/// required files in it
pub fn is_package_path(package_path: &Path) -> bool {
let config_path = package_path.join(
format!("config.{}", CONGREGATION_EXTENSION)
);

config_path.exists()
package_path.join(PACKAGE_CONFIG_FILENAME).exists()
}

6 changes: 3 additions & 3 deletions core/src/package/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,15 @@ pub(crate) fn resolve_dependency_schemas(
/// own CAS history says — this reads the ground truth.
fn resolved_version(package_path: &Path) -> String {
use crate::package::build::cas::objects::Commit;
use crate::package::build::cas::{main_ref, read_ref, ref_exists, ObjectStore};
use crate::package::build::cas::{REF_HEAD_MAIN_FILENAME, read_ref, ref_exists, ObjectStore};

if !ref_exists(package_path, main_ref()) {
if !ref_exists(package_path, REF_HEAD_MAIN_FILENAME) {
return "0.0.0-unbuilt".to_string();
}

(|| -> Result<String> {
let store = ObjectStore::new(package_path);
let commit_hash = read_ref(package_path, main_ref())?;
let commit_hash = read_ref(package_path, REF_HEAD_MAIN_FILENAME)?;
let commit = Commit::from_bytes(&store.read(&commit_hash)?)?;
Ok(commit.version)
})()
Expand Down
Loading
Loading