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
315 changes: 95 additions & 220 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ serde_json = "1.0"
# a sequence of Unicode scalar values, a number outside the profile -- are
# refused with a named error rather than collapsed or rounded.
jcs-admit = "0.1"
postcard = { version = "1.0", features = ["alloc"] }
postcard = { version = "1.0", default-features = false, features = ["alloc"] }
toml = "0.8"
semver = "1"

Expand All @@ -76,11 +76,11 @@ fastcdc = "3.1"
# Hashing & Crypto
bs58 = "0.5"
blake3 = "1.5"
ed25519-dalek = { version = "2.1", features = ["serde"] }
ed25519-dalek = { version = "3.0", features = ["serde"] }
rand = "0.8"

# Compression
zstd = "0.13"
zstd = "0.14"

# Database
# SnapshotBackend forwards the locking API introduced after redb 4.2.
Expand All @@ -93,7 +93,7 @@ rusqlite = { version = "0.32", features = ["bundled"] }
# CLI
clap = { version = "4.5", features = ["derive", "env", "wrap_help"] }
clap_complete = { version = "4.5", features = ["unstable-dynamic"] }
indicatif = "0.17"
indicatif = "0.18"
dialoguer = "0.11"
console = "0.15"

Expand Down Expand Up @@ -141,7 +141,7 @@ syntext = { version = "1.1", default-features = false, features = ["memmap2", "r
# vendored-openssl compiles OpenSSL from source, which is required for
# cross-compilation targets (e.g. aarch64-unknown-linux-gnu) where the
# target architecture's OpenSSL system libraries are not available.
git2 = { version = "0.19", features = ["vendored-openssl"] }
git2 = { version = "0.21", features = ["vendored-openssl", "https", "ssh"] }

# Testing
quickcheck = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion atomic-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ zstd = { workspace = true }

# Hashing
blake3 = { workspace = true }
sha2 = "0.10"
sha2 = "0.11"

# Time
chrono = { workspace = true }
Expand Down
59 changes: 52 additions & 7 deletions atomic-agent/src/record/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,36 @@ fn checked_path(root: &Path, path: &str) -> Result<std::path::PathBuf, String> {
Ok(full)
}

/// Lowercase hex of a digest. `digest` 0.11 dropped the `LowerHex` output.
fn hex(bytes: &[u8]) -> String {
use std::fmt::Write as _;

let mut out = String::with_capacity(bytes.len() * 2);
for byte in bytes {
// Writing to a `String` cannot fail.
let _ = write!(out, "{byte:02x}");
}
out
}

/// `digest` 0.11 removed its `std::io` impls and its `std` feature, moving
/// them to the separate `digest-io` crate (RustCrypto/traits#1809), so
/// streaming bytes into a hasher needs a wrapper again. Kept local instead of
/// taking a dependency for one `Write` impl; equivalent to
/// `digest_io::IoWrapper`.
struct DigestWriter<'a, D>(&'a mut D);

impl<D: Digest> std::io::Write for DigestWriter<'_, D> {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.0.update(buf);
Ok(buf.len())
}

fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}

/// Fingerprint a file without following its final symlink. `None` means deleted.
/// Reject directories and paths outside the working tree.
pub fn fingerprint(root: &Path, path: &str) -> Result<Option<String>, String> {
Expand All @@ -56,8 +86,8 @@ pub fn fingerprint(root: &Path, path: &str) -> Result<Option<String>, String> {
if meta.file_type().is_symlink() {
let target = std::fs::read_link(full).map_err(|e| e.to_string())?;
return Ok(Some(format!(
"link:{:x}",
Sha256::digest(target.as_os_str().as_encoded_bytes())
"link:{}",
hex(&Sha256::digest(target.as_os_str().as_encoded_bytes()))
)));
}
if !meta.is_file() {
Expand All @@ -72,11 +102,8 @@ pub fn fingerprint(root: &Path, path: &str) -> Result<Option<String>, String> {
let executable = false;
let mut file = std::fs::File::open(full).map_err(|e| e.to_string())?;
let mut hash = Sha256::new();
std::io::copy(&mut file, &mut hash).map_err(|e| e.to_string())?;
Ok(Some(format!(
"file:{hash:x}:{executable}",
hash = hash.finalize()
)))
std::io::copy(&mut file, &mut DigestWriter(&mut hash)).map_err(|e| e.to_string())?;
Ok(Some(format!("file:{}:{executable}", hex(&hash.finalize()))))
}

/// Return fingerprints for dirty files and explicitly requested prior candidates.
Expand Down Expand Up @@ -194,3 +221,21 @@ pub(super) fn filter(status: RepositoryStatus, files: Option<&FileManifest>) ->
}
result
}

#[cfg(test)]
mod tests {
use super::*;

/// Fingerprints persist in session manifests and are compared across
/// binaries, so the encoding must stay the lowercase SHA-256 hex that the
/// pre-`digest`-0.11 `{:x}` formatting produced.
#[test]
fn fingerprints_are_lowercase_sha256_hex() {
let dir = tempfile::tempdir().unwrap();
std::fs::write(dir.path().join("f.txt"), b"hi\n").unwrap();
assert_eq!(
fingerprint(dir.path(), "f.txt").unwrap().unwrap(),
"file:98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4:false"
);
}
}
2 changes: 1 addition & 1 deletion atomic-cli/src/commands/clone/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl Clone {
})?;
git.head()
.ok()
.and_then(|head| head.shorthand().map(str::to_owned))
.and_then(|head| head.shorthand().ok().map(str::to_owned))
.unwrap_or_else(|| self.view.clone())
};
let outcome = crate::commands::git::bootstrap::clone_git_url(
Expand Down
5 changes: 4 additions & 1 deletion atomic-cli/src/commands/git/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,10 @@ fn resolve_published_binding(git: &GitRepository, id: &str) -> CliResult<GitStat
.map_err(|error| git_map(format!("cannot enumerate binding refs: {error}")))?
{
let reference = reference.map_err(|error| git_map(error.to_string()))?;
let Some(name) = reference.name() else {
// `name()` fails only when the name is not UTF-8. Canonical binding refs
// are ASCII by layout, and everything below needs a `&str`, so a stray
// non-UTF-8 ref in this namespace is skipped, not fatal.
let Ok(name) = reference.name() else {
continue;
};
let Some(target) = reference.target() else {
Expand Down
17 changes: 9 additions & 8 deletions atomic-cli/src/commands/git/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,15 @@ pub(crate) fn install_degraded_bindings(
let reference = reference.map_err(|error| CliError::GitError {
message: format!("cannot read ref: {error}"),
})?;
if let Some(name) = reference.name() {
if let Some(rest) = name.strip_prefix(DEGRADED_HEAD_BINDING_PREFIX) {
let mut parts = rest.split('/');
let shard = parts.next().unwrap_or("");
let id_hex = parts.next().unwrap_or("");
if parts.next().is_none() && shard.len() == 2 && id_hex.len() == 64 {
names.push(name.to_string());
}
let Ok(name) = reference.name() else {
continue;
};
if let Some(rest) = name.strip_prefix(DEGRADED_HEAD_BINDING_PREFIX) {
let mut parts = rest.split('/');
let shard = parts.next().unwrap_or("");
let id_hex = parts.next().unwrap_or("");
if parts.next().is_none() && shard.len() == 2 && id_hex.len() == 64 {
names.push(name.to_string());
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions atomic-cli/src/commands/git/census.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,10 @@ fn wip_census_class(repo: &Repository, root: &Path) -> CensusClass {
.map_err(|e| e.to_string())?
{
let reference = reference.map_err(|e| e.to_string())?;
if let Some(name) = reference.name() {
refs.push(name.to_string());
}
let Ok(name) = reference.name() else {
continue;
};
refs.push(name.to_string());
}
if refs.is_empty() {
return Ok(CensusClass {
Expand Down
2 changes: 1 addition & 1 deletion atomic-cli/src/commands/git/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ fn warn_if_view_mismatch(root: &Path) {
repository
.head()
.ok()
.and_then(|head| head.shorthand().map(str::to_string))
.and_then(|head| head.shorthand().ok().map(str::to_string))
});
if let Some(git_branch) = git_branch {
if !atomic_view.is_empty() && git_branch != atomic_view {
Expand Down
10 changes: 5 additions & 5 deletions atomic-cli/src/commands/git/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn current_git_branch(git_repo: &GitRepository) -> Option<String> {
if !head.is_branch() {
return None;
}
head.shorthand().map(ToOwned::to_owned)
head.shorthand().ok().map(ToOwned::to_owned)
}

/// Binding transport requires the ordinary importer. Presence selects the
Expand Down Expand Up @@ -431,7 +431,7 @@ impl Import {
git_repo
.find_remote("origin")
.ok()
.and_then(|remote| remote.url().map(|s| s.to_string()))
.and_then(|remote| remote.url().ok().map(ToString::to_string))
.and_then(|url| {
// Extract repo name from URL like "https://github.com/holman/spark.git"
// or "git@github.com:holman/spark.git"
Expand Down Expand Up @@ -1533,7 +1533,7 @@ fn import_git_tags_into_view(repo: &mut Repository, git_repo: &GitRepository, vi
let mut imported = 0usize;
let mut refused = 0usize;
for reference in tag_refs.flatten() {
let Some(name) = reference.shorthand().map(str::to_string) else {
let Ok(name) = reference.shorthand().map(str::to_string) else {
continue;
};
match repo.import_git_tag_from_git(view, git_repo, &name) {
Expand Down Expand Up @@ -1610,7 +1610,7 @@ impl MaterializationTarget<'_> {
message: format!("cannot read the tree of branch '{branch}': {error}"),
})?;
tree.walk(git2::TreeWalkMode::PreOrder, |directory, entry| {
if let Some(name) = entry.name() {
if let Ok(name) = entry.name() {
paths.insert(format!("{directory}{name}"));
}
git2::TreeWalkResult::Ok
Expand Down Expand Up @@ -1665,7 +1665,7 @@ fn require_materializable_worktree(
let mut colliding: Vec<String> = statuses
.iter()
.filter(|entry| entry.status().contains(git2::Status::WT_NEW))
.filter_map(|entry| entry.path().map(str::to_string))
.filter_map(|entry| entry.path().ok().map(str::to_string))
.filter(|path| target_paths.contains(path))
.collect();
colliding.sort();
Expand Down
13 changes: 9 additions & 4 deletions atomic-cli/src/commands/git/observation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,10 @@ pub fn observe_head(repository: &GitRepository) -> Result<HeadObservation, Obser
.find_reference("HEAD")
.map_err(|error| ObservationError::new(format!("cannot read Git HEAD: {error}")))?;

if let Some(symref) = head.symbolic_target() {
let symref = symref.to_string();
let symref = head
.symbolic_target()
.map_err(|error| ObservationError::new(format!("cannot read Git HEAD: {error}")))?;
if let Some(symref) = symref.map(str::to_string) {
match head.resolve() {
Ok(resolved) => {
let oid = resolved.target().ok_or_else(|| {
Expand Down Expand Up @@ -1028,7 +1030,7 @@ fn compute_index_tree_oid(
}),
));
};
if entry.oid == Oid::zero() || insert_index_tree_entry(&mut root, entry, mode).is_err() {
if entry.oid == Oid::ZERO_SHA1 || insert_index_tree_entry(&mut root, entry, mode).is_err() {
return Ok((
None,
IndexTreeAvailability::Unavailable(IndexTreeUnavailable::UnsupportedEntry {
Expand Down Expand Up @@ -1357,7 +1359,10 @@ fn observe_refs(repository: &GitRepository) -> Result<Vec<RefObservation>, Obser
})?;
let target = if let Some(oid) = reference.target() {
RefTargetObservation::Direct(oid)
} else if let Some(symbolic) = reference.symbolic_target() {
} else if let Some(symbolic) = reference
.symbolic_target()
.map_err(|error| ObservationError::new(format!("cannot read Git HEAD: {error}")))?
{
RefTargetObservation::Symbolic(symbolic.as_bytes().to_vec())
} else {
RefTargetObservation::Unresolved
Expand Down
16 changes: 7 additions & 9 deletions atomic-cli/src/commands/git/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1807,10 +1807,8 @@ pub(crate) fn detect_git_boundaries(git: &GitRepository) -> CliResult<Vec<GitClo
boundaries.push(GitClosureBoundary::Promisor);
} else if let Ok(mut entries) = config.entries(Some("remote.*.promisor")) {
while let Some(entry) = entries.next() {
let is_promisor = entry
.ok()
.and_then(|entry| entry.value().map(|value| value == "true"))
.unwrap_or(false);
let is_promisor =
entry.is_ok_and(|entry| entry.value().is_ok_and(|value| value == "true"));
if is_promisor {
boundaries.push(GitClosureBoundary::Promisor);
break;
Expand Down Expand Up @@ -4469,7 +4467,7 @@ impl ParallelImporter {
if git
.head()
.ok()
.and_then(|head| head.shorthand().map(str::to_owned))
.and_then(|head| head.shorthand().ok().map(str::to_owned))
.as_deref()
!= Some(branch_name)
{
Expand Down Expand Up @@ -7522,7 +7520,7 @@ impl ParallelImporter {
merge_tree
.walk(git2::TreeWalkMode::PreOrder, |prefix, entry| {
if entry.kind() == Some(git2::ObjectType::Tree) {
if let Some(name) = entry.name() {
if let Ok(name) = entry.name() {
directories.insert(format!("{prefix}{name}"));
}
}
Expand Down Expand Up @@ -8872,7 +8870,7 @@ fn parse_push_trailer(message: &str) -> Option<PushTrailer> {
fn extract_commit_metadata(commit: &git2::Commit) -> CliResult<CommitMetadata> {
let author = commit.author();
let author_name = author.name().unwrap_or("Unknown").to_string();
let author_email = author.email().map(|s| s.to_string());
let author_email = author.email().ok().map(ToString::to_string);
let author_name_raw = author.name_bytes().to_vec();
let author_email_raw = {
let bytes = author.email_bytes();
Expand All @@ -8884,7 +8882,7 @@ fn extract_commit_metadata(commit: &git2::Commit) -> CliResult<CommitMetadata> {
};
let committer = commit.committer();
let committer_name = committer.name().unwrap_or("Unknown").to_string();
let committer_email = committer.email().map(|s| s.to_string());
let committer_email = committer.email().ok().map(ToString::to_string);
let committer_name_raw = committer.name_bytes().to_vec();
let committer_email_raw = {
let bytes = committer.email_bytes();
Expand Down Expand Up @@ -10161,7 +10159,7 @@ mod tests {
"feat: test\n\nAtomic-View: {}\nAtomic-State: {}",
view, state_b32
)),
tree_oid: Oid::zero(),
tree_oid: Oid::ZERO_SHA1,
parent_tree_oid: None,
raw_object: Vec::new(),
}
Expand Down
16 changes: 10 additions & 6 deletions atomic-cli/src/commands/git/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl Command for Push {
let branch_name = git_repo
.head()
.ok()
.and_then(|h| h.shorthand().map(str::to_owned))
.and_then(|h| h.shorthand().ok().map(str::to_owned))
.unwrap_or_else(|| "HEAD".to_string());
let target = target_override.unwrap_or(&branch_name);
let ahead = self.unpushed_commit_count(&git_repo, &branch_name, target_override);
Expand Down Expand Up @@ -545,8 +545,12 @@ impl Push {
let git_sig = git_repo.signature().map_err(|e| CliError::GitError {
message: format!("Failed to get git signature: {}", e),
})?;
let author =
super::shadow::projection_author(repo, repo_root, git_sig.name(), git_sig.email());
let author = super::shadow::projection_author(
repo,
repo_root,
git_sig.name().ok(),
git_sig.email().ok(),
);
msg.push_str(&format!("atomic-author {}\n", author.did));
if let Some(agent) = &author.agent_did {
msg.push_str(&format!("atomic-agent {agent}\n"));
Expand Down Expand Up @@ -668,7 +672,7 @@ impl Push {
git_repo
.head()
.ok()
.and_then(|h| h.shorthand().map(str::to_owned))
.and_then(|h| h.shorthand().ok().map(str::to_owned))
.unwrap_or_else(|| "HEAD".to_string())
}

Expand All @@ -695,7 +699,7 @@ impl Push {
None => git_repo
.branch_upstream_name(&local_ref)
.ok()
.and_then(|buf| buf.as_str().map(str::to_owned))
.and_then(|buf| buf.as_str().ok().map(str::to_owned))
.and_then(|name| git_repo.refname_to_id(&name).ok()),
};

Expand Down Expand Up @@ -841,7 +845,7 @@ impl Push {
git_repo
.head()
.ok()
.and_then(|head| head.shorthand().map(str::to_string))
.and_then(|head| head.shorthand().ok().map(str::to_string))
.unwrap_or_else(|| "master".to_string())
);
let verified = publication.git_head.ok_or_else(|| CliError::GitError {
Expand Down
2 changes: 1 addition & 1 deletion atomic-cli/src/commands/git/real_import_sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn prepare_hyperfine_publication_sample() {
assert_ne!(
git.head()
.ok()
.and_then(|head| head.shorthand().map(str::to_owned))
.and_then(|head| head.shorthand().ok().map(str::to_owned))
.as_deref(),
Some(view.as_str()),
"this ODB-only sample must not claim to import the source's checked-out branch"
Expand Down
Loading
Loading