fix: remove panics and unblock flows
Rust / build (macos-latest, stable) (push) Canceled after 0s
Rust / build (ubuntu-latest, stable) (push) Canceled after 0s
Rust / build (windows-latest, stable) (push) Canceled after 0s

This commit is contained in:
2026-11-25 03:20:40 +07:00
parent 0fd8ea12fb
commit 3f64b36ff4
52 changed files with 753 additions and 567 deletions
+16 -3
View File
@@ -29,9 +29,12 @@ impl GitCache {
/// Returns the cache path for a repository address.
pub fn repo_path(&self, addr: &RepoAddr) -> PathBuf {
self.root
.join(addr.public_key().to_hex())
.join(Self::sanitize_path_component(addr.identifier()))
let identifier = addr.identifier();
self.root.join(addr.public_key().to_hex()).join(format!(
"{}-{}",
Self::sanitize_path_component(identifier),
Self::identifier_suffix(identifier),
))
}
/// Opens the cached repository, or `None` when it is not cloned yet.
@@ -103,6 +106,16 @@ impl GitCache {
sanitized
}
/// Distinct identifiers can sanitize alike, and an empty one is the owner directory.
fn identifier_suffix(id: &str) -> String {
let mut hash: u64 = 0xcbf29ce484222325;
for byte in id.as_bytes() {
hash ^= u64::from(*byte);
hash = hash.wrapping_mul(0x100000001b3);
}
format!("{hash:016x}")
}
/// Returns the `owner/identifier` namespace used for fork checkouts.
pub fn fork_namespace(announcement: &Announcement) -> String {
format!(
+10 -1
View File
@@ -271,11 +271,20 @@ impl ConsumeHunk for PatchCollector {
GixLineKind::Remove => '-',
GixLineKind::Add => '+',
};
// Tokens may already carry the line's newline; emit exactly one.
let content = content.strip_suffix(b"\n").unwrap_or(content);
let (content, terminated) = match content.strip_suffix(b"\n") {
Some(rest) => (rest, true),
None => (*content, false),
};
self.text.push(prefix);
self.text.push_str(&String::from_utf8_lossy(content));
self.text.push('\n');
if !terminated {
self.text.push_str("\\ No newline at end of file\n");
}
}
Ok(())
+1 -2
View File
@@ -19,8 +19,7 @@ pub struct FileCommit {
pub description: Option<String>,
pub author: String,
pub time: i64,
/// Human-readable absolute date in the commit's recorded offset, e.g.
/// "Nov 21, 2026 at 4:40 AM GMT+7"; empty when the date cannot be formatted.
/// Date in the commit's offset, e.g. "Nov 21, 2026 at 4:40 AM GMT+7".
pub date_label: String,
/// Full hex parent ids; empty for patch-parsed commits.
pub parents: Vec<String>,
+5 -3
View File
@@ -67,9 +67,10 @@ impl PatchParser {
let mut headers_closed = false;
let mut offset = 0usize;
for line in patch.lines() {
for raw in patch.split_inclusive('\n') {
let line_start = offset;
offset += line.len() + 1;
offset += raw.len();
let line = raw.trim_end_matches(['\r', '\n']);
let is_envelope = line
.strip_prefix("From ")
@@ -78,7 +79,8 @@ impl PatchParser {
if is_envelope {
if let Some((start, id, headers)) = current.take() {
messages.push(Envelope::new(&patch[start..], id, headers));
// A message runs until the next envelope starts.
messages.push(Envelope::new(&patch[start..line_start], id, headers));
}
let id = line
+54 -40
View File
@@ -594,16 +594,16 @@ impl Repo {
}
let platform = attached.diff(&mut cache)?;
platform
.resource_cache
.options
.skip_internal_diff_if_external_is_configured = true;
let outcome = platform.resource_cache.prepare_diff().into_anyhow()?;
match outcome.operation {
Operation::InternalDiff { algorithm } => {
let input = outcome.interned_input();
// Keep line endings so a missing final newline can be marked.
let input = gix::diff::blob::InternedInput::new(
outcome.old.intern_source(),
outcome.new.intern_source(),
);
let diff = gix::diff::blob::diff_with_slider_heuristics(algorithm, &input);
let text = gix::diff::blob::UnifiedDiff::new(
&diff,
@@ -719,10 +719,6 @@ impl Repo {
};
let platform = attached.diff(&mut cache)?;
platform
.resource_cache
.options
.skip_internal_diff_if_external_is_configured = true;
let outcome = platform.resource_cache.prepare_diff().into_anyhow()?;
let (binary, hunks, insertions, deletions) = match outcome.operation {
@@ -1180,14 +1176,15 @@ impl Repo {
let (signature, mut time_buf) = Self::repository_signature();
let signature = signature.to_ref(&mut time_buf);
// HEAD moves only once the worktree holds the new content.
self.force_checkout(&tree)?;
self.move_head(
signature,
gix::refs::Target::Symbolic(branch),
&format!("checkout: moving to {name}"),
)?;
self.force_checkout(&tree)?;
Ok(())
}
@@ -1196,21 +1193,19 @@ impl Repo {
let full = format!("refs/tags/{name}");
let mut reference = self.inner.find_reference(&full)?;
let commit = reference.peel_to_id()?;
let tree = reference.peel_to_tree()?.id;
let (signature, mut time_buf) = Self::repository_signature();
let signature = signature.to_ref(&mut time_buf);
self.force_checkout(&tree)?;
self.move_head(
signature,
gix::refs::Target::Object(commit.detach()),
&format!("checkout: moving to {name}"),
)?;
self.force_checkout(&tree)?;
Ok(())
}
@@ -1224,31 +1219,53 @@ impl Repo {
let mut index = self.inner.index_from_tree(tree)?;
if let Ok(previous) = self.inner.index_or_empty() {
let keep: HashSet<PathBuf> = index
.entries()
.iter()
.map(|entry| {
PathBuf::from(String::from_utf8_lossy(entry.path(&index)).into_owned())
})
.collect();
for entry in previous.entries() {
let rel = entry.path(&previous);
let rel = PathBuf::from(String::from_utf8_lossy(rel).into_owned());
// `overwrite_existing` below is `git checkout --force`; never discard uncommitted work.
if self.inner.is_dirty()? {
bail!("uncommitted changes would be overwritten; commit or stash them first");
}
if keep.contains(&rel) {
continue;
}
let previous = self.inner.index_or_empty()?;
let tracked: HashSet<&gix::bstr::BStr> = previous
.entries()
.iter()
.map(|entry| entry.path(&previous))
.collect();
let path = workdir.join(&rel);
if let Some(path) = index
.entries()
.iter()
.map(|entry| entry.path(&index))
.find(|path| {
!tracked.contains(path) && workdir.join(gix::path::from_bstr(*path)).exists()
})
{
bail!(
"untracked file {} would be overwritten",
String::from_utf8_lossy(path)
);
}
match std::fs::remove_file(&path) {
Ok(()) => {}
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
Err(error) => {
return Err(error)
.with_context(|| format!("failed to remove {}", path.display()));
}
let keep: HashSet<PathBuf> = index
.entries()
.iter()
.map(|entry| PathBuf::from(String::from_utf8_lossy(entry.path(&index)).into_owned()))
.collect();
for entry in previous.entries() {
let rel = entry.path(&previous);
let rel = PathBuf::from(String::from_utf8_lossy(rel).into_owned());
if keep.contains(&rel) {
continue;
}
let path = workdir.join(&rel);
match std::fs::remove_file(&path) {
Ok(()) => {}
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
Err(error) => {
return Err(error)
.with_context(|| format!("failed to remove {}", path.display()));
}
}
}
@@ -1436,10 +1453,7 @@ impl Repo {
)
}
/// Mirrors all branches and tags to the grasp repository at `base_url`.
///
/// Force refspecs keep the server ref map following the local repository,
/// grasp authorizes pushes by ref map equality, not fast-forwards.
/// Mirrors branches and tags to `base_url` with force refspecs; grasp authorizes by ref map.
pub fn push_all(&self, base_url: &str, owner: &str, repo_id: &str) -> Result<()> {
self.push_refspecs(
base_url,
+5
View File
@@ -38,10 +38,15 @@ pub fn find_git_repos(root: &Path) -> Vec<LocalRepo> {
let Some(kind) = entry.file_type() else {
return true;
};
if !kind.is_dir() {
return true;
}
if entry.file_name() == std::ffi::OsStr::new(".git") {
return false;
}
let dir = entry.path();
let Ok(repo) = gix::discover(dir) else {
return true;
-5
View File
@@ -25,11 +25,6 @@ pub struct RepoSyncStatus {
}
impl RepoSyncStatus {
/// True when every branch matches the Nostr state.
pub fn in_sync(&self) -> bool {
self.refs.iter().all(|(_, sync)| *sync == RefSync::InSync)
}
/// Maps branch short name to lowercase commit oid.
pub(crate) fn branches(refs: &[(String, String)]) -> BTreeMap<&str, String> {
refs.iter()