caio.co/de/caca

Migrate to gix 0.72, YOLO style

Id
4d45fcddaf5f51892fcae5e1aa0bec6ad9fdb2f0
Author
Caio
Commit time
2025-08-04T08:48:04+02:00

Modified urso/Cargo.toml

@@ -1,10 +1,10
[package]
name = "urso"
version = "0.1.0"
edition = "2021"

[dependencies]
-gix = { version = "0.64", default-features = false, features = ["revision", "blob-diff", "mailmap", "parallel"] }
+gix = { version = "0.72.1", default-features = false, features = ["revision", "blob-diff", "mailmap", "parallel"] }
tracing = { workspace = true }
mime_guess = { version = "2.0.4", default-features = false }
infer = { version = "0.16.0", default-features = false }

Modified urso/src/lib.rs

@@ -37,12 +37,10
clippy::map_err_ignore,
clippy::map_flatten,
clippy::map_unwrap_or,
- clippy::match_on_vec_items,
clippy::match_same_arms,
clippy::match_wildcard_for_single_variants,
clippy::match_wild_err_arm,
clippy::mem_forget,
- clippy::mismatched_target_os,
clippy::missing_enforced_import_renames,
clippy::mutex_integer,
clippy::mut_mut,
@@ -72,19 +70,20
clippy::zero_sized_map_values,
future_incompatible,
nonstandard_style,
- rust_2018_idioms
+ rust_2018_idioms,
+ unexpected_cfgs
)]

use error::wrap_err;
use gix::{
- bstr::BStr, object::tree, objs::tree::EntryKind, odb::HeaderExt, prelude::FindExt,
- traverse::commit::simple::Sorting, Object, Repository, Tree,
+ bstr::BStr, object::tree, objs::tree::EntryKind, odb::HeaderExt, prelude::FindExt, Object,
+ Repository, Tree,
};

// re-export
pub use gix::{
actor::SignatureRef,
- date::time::Sign as TimeSign,
+ date::parse as parse_date,
date::Time,
mailmap::Snapshot as Mailmap,
objs::{tree::EntryMode, CommitRef, TagRef},
@@ -238,7 +237,7
return Err(Error::NotFound);
}

- let Some(entry) = find_path(&path, &tree, buf)? else {
+ let Some(entry) = find_path(&path, &tree)? else {
return Err(Error::NotFound);
};

@@ -302,9 +301,7
return list_tree(tree, visitor);
}

- let mut buf = Vec::new();
-
- if let Some(entry) = find_path(&dir, &tree, &mut buf)? {
+ if let Some(entry) = find_path(&dir, &tree)? {
if !entry.mode().is_tree() {
Err(Error::NotADir(dir.as_ref().into()))
} else {
@@ -338,13 +335,12
return Ok(());
}

- let mut buf = Vec::new();
let base = dir.as_ref();
for rev in self
.find_commit(commit_id)?
.ancestors()
.first_parent_only()
- .sorting(Sorting::ByCommitTimeNewestFirst)
+ .sorting(gix::revision::walk::Sorting::BreadthFirst)
.all()
.map_err(|e| wrap_err(format!("walking ancestry of commit {}", commit_id), e))?
.flatten()
@@ -365,8 +361,8
let t = &wanted[idx];
let target = base.join(&t.name);

- let cur = find_path(&target, &commit_tree, &mut buf)?.map(|entry| entry.id());
- let prev = find_path(&target, &parent_tree, &mut buf)?.map(|entry| entry.id());
+ let cur = find_path(&target, &commit_tree)?.map(|entry| entry.id());
+ let prev = find_path(&target, &parent_tree)?.map(|entry| entry.id());

if cur != prev {
let target = wanted.swap_remove(idx);
@@ -399,7 +395,7

let tree = self.get_commit_tree(head)?;

- if let Some(entry) = find_path(&path, &tree, buf)? {
+ if let Some(entry) = find_path(&path, &tree)? {
if entry.mode().is_blob() {
buf.clear();
self.read_blob(entry.object_id(), buf)?;
@@ -415,9 +411,8
pub fn annotate(&self, commit: ObjectId, path: PathBuf) -> Result<()> {
// Must be able to find the given path as a blob
// using commit as the head
- let mut buf = Vec::new();
let tree = self.get_commit_tree(commit)?;
- if let Some(e) = find_path(&path, &tree, &mut buf)? {
+ if let Some(e) = find_path(&path, &tree)? {
if !e.mode().is_blob() {
return Err(Error::NotAFile(path));
}
@@ -508,8 +503,7
F: FnMut(Commit<'_>, &Path, Option<ObjectId>, Option<ObjectId>) -> bool,
{
let tree = self.get_commit_tree(head)?;
- let mut buf = Vec::new();
- if find_entry(path.as_ref(), &tree, &mut buf)?.is_none() {
+ if find_entry(path.as_ref(), &tree)?.is_none() {
return Err(Error::NotFound);
}

@@ -709,7 +703,6
enqueue!(head);

let mut parent_ids = Vec::new();
- let mut buf = Vec::new();

while let Some(info) = queue.remove() {
let ByCommitTime {
@@ -719,7 +712,7
let commit = self.find_commit(commit_id)?;

let commit_tree = self.get_commit_tree(commit_id)?;
- let entry = find_entry(&path, &commit_tree, &mut buf)?;
+ let entry = find_entry(&path, &commit_tree)?;
let current = entry.as_ref().map(|e| e.0);

if options.stop_when_path_disappears && current.is_none() {
@@ -753,8 +746,8
for (idx, &parent_id) in parent_ids.iter().enumerate() {
let parent_tree = self.get_commit_tree(parent_id)?;

- let previous = find_path(&path, &parent_tree, &mut buf)?
- .map(|entry| entry.object_id());
+ let previous =
+ find_path(&path, &parent_tree)?.map(|entry| entry.object_id());

if previous == current {
first_treesame_idx = Some(idx);
@@ -787,7 +780,7

let parent_tree = self.get_commit_tree(parent_id)?;

- let mut previous = find_entry(&path, &parent_tree, &mut buf)?.map(|entry| entry.0);
+ let mut previous = find_entry(&path, &parent_tree)?.map(|entry| entry.0);

let mut has_renamed = false;
if options.rename_similarity_threshold.is_some()
@@ -1069,12 +1062,8
.map_err(|e| wrap_err(format!("reading tree for commit {}", commit.id), e).into())
}

-fn find_path<'a, P: AsRef<Path>>(
- path: P,
- tree: &Tree<'a>,
- buf: &mut Vec<u8>,
-) -> Result<Option<tree::Entry<'a>>> {
- match tree.lookup_entry_by_path(&path, buf) {
+fn find_path<'a, P: AsRef<Path>>(path: P, tree: &Tree<'a>) -> Result<Option<tree::Entry<'a>>> {
+ match tree.lookup_entry_by_path(&path) {
Ok(found) => Ok(found),
Err(gix::object::find::existing::Error::NotFound { oid }) => {
Err(Error::ObjectNotFound(oid))
@@ -1087,15 +1076,11
}
}

-fn find_entry<P: AsRef<Path>>(
- path: P,
- tree: &Tree<'_>,
- buf: &mut Vec<u8>,
-) -> Result<Option<(ObjectId, EntryKind)>> {
+fn find_entry<P: AsRef<Path>>(path: P, tree: &Tree<'_>) -> Result<Option<(ObjectId, EntryKind)>> {
if path.as_ref().as_os_str().is_empty() {
Ok(Some((tree.id, EntryKind::Tree)))
} else {
- Ok(find_path(path, tree, buf)?.map(|e| (e.object_id(), e.mode().kind())))
+ Ok(find_path(path, tree)?.map(|e| (e.object_id(), e.mode().kind())))
}
}

Modified caca/src/repo/id.rs

@@ -44,9 +44,7
{
// FIXME will break on sha256
let mut hex = [0u8; 40];
- let max_len = self.id.hex_to_buf(hex.as_mut());
- let hex = std::str::from_utf8(&hex[..hex.len().min(max_len)]).expect("ascii only in hex");
- serializer.serialize_str(hex)
+ serializer.serialize_str(self.id.hex_to_buf(hex.as_mut()))
}
}

Modified caca/src/repo/mod.rs

@@ -1219,7 +1219,7
}

fn convert(t: urso::Time) -> DateTime {
- let offset = if t.sign == urso::TimeSign::Plus {
+ let offset = if t.offset >= 0 {
chrono::FixedOffset::east_opt(t.offset.abs())
} else {
chrono::FixedOffset::west_opt(t.offset.abs())
@@ -1719,7 +1719,7
}
}

- let time = convert(sig.time);
+ let time = convert(urso::parse_date(sig.time, None).expect("FIXME"));
Signature {
name,
email,

Modified urso/src/diff/mod.rs

@@ -1,10 +1,11
use std::{borrow::Cow, ops::Range};

use gix::{
bstr::{BStr, ByteSlice},
diff::Rewrites,
object::tree::diff::for_each::Error as ForEachError,
- object::tree::diff::{change::Event as GixEvent, Action},
+ object::tree::diff::Action,
+ object::tree::diff::Change as GixChange,
objs::tree::EntryMode,
Commit, ObjectId, Tree,
};
@@ -51,57 +52,60
e,
)
})?
- .track_path()
- // FIXME using gix's rename detection here, but using mine on log
- .track_rewrites(Some(Rewrites {
- copies: None,
- percentage: repo.min_similarity(),
- limit: 0,
- }))
+ .options(|opts| {
+ // FIXME using gix's rename detection here, but using mine on log
+ opts.track_path().track_rewrites(Some(Rewrites {
+ copies: None,
+ percentage: repo.min_similarity(),
+ limit: 0,
+ track_empty: false,
+ }));
+ })
.for_each_to_obtain_tree(&tree, |change| -> Result<Action, E> {
- match change.event {
- GixEvent::Addition { entry_mode, id } => {
- if let Some(event) =
- handle_change(&repo, change.location, entry_mode, true, id)?
- {
+ match change {
+ GixChange::Addition {
+ entry_mode,
+ id,
+ location,
+ relation,
+ } => {
+ if let Some(event) = handle_change(&repo, location, entry_mode, true, id)? {
visitor(Event::Addition(event));
}
}
- GixEvent::Deletion { entry_mode, id } => {
- if let Some(event) =
- handle_change(&repo, change.location, entry_mode, false, id)?
- {
+ GixChange::Deletion {
+ entry_mode,
+ id,
+ location,
+ relation,
+ } => {
+ if let Some(event) = handle_change(&repo, location, entry_mode, false, id)? {
visitor(Event::Deletion(event));
}
}
- GixEvent::Modification {
+ GixChange::Modification {
previous_entry_mode,
previous_id,
entry_mode,
id,
+ location,
} => {
// if both sides aren't blobs, handle as if it
// were a Deletion followed by an Addition
// FIXME can yield a Modification when entry modes are equal eh
if !(entry_mode.is_blob() || previous_entry_mode.is_blob()) {
- if let Some(event) = handle_change(
- repo,
- change.location,
- previous_entry_mode,
- false,
- previous_id,
- )? {
+ if let Some(event) =
+ handle_change(repo, location, previous_entry_mode, false, previous_id)?
+ {
visitor(Event::Deletion(event));
}
- if let Some(event) =
- handle_change(&repo, change.location, entry_mode, true, id)?
- {
+ if let Some(event) = handle_change(&repo, location, entry_mode, true, id)? {
visitor(Event::Addition(event));
}
} else {
handle_modification(
&repo,
- change.location,
+ location,
previous_entry_mode,
previous_id,
entry_mode,
@@ -115,7 +119,7
})?;
}
}
- GixEvent::Rewrite {
+ GixChange::Rewrite {
source_location,
source_entry_mode,
source_id,
@@ -123,10 +127,13
entry_mode,
id,
copy: _,
+ source_relation,
+ location,
+ relation,
} => {
handle_modification(
&repo,
- change.location,
+ location,
source_entry_mode,
source_id,
entry_mode,

Modified urso/src/rename/mod.rs

@@ -1,6 +1,6
use gix::{
bstr::{BStr, ByteSlice},
- object::tree::diff::{change::Event, Action},
+ object::tree::diff::{Action, Change},
ObjectId, Tree,
};

@@ -170,11 +170,18
e,
)
})?
- .track_path()
- .track_rewrites(None)
+ .options(|opts| {
+ opts.track_path().track_rewrites(None);
+ })
.for_each_to_obtain_tree(current, |change| -> std::result::Result<_, WrappedError> {
- if let Event::Deletion { entry_mode, id } = change.event {
- if entry_mode.is_blob() && !cb(change.location, id.detach()) {
+ if let Change::Deletion {
+ entry_mode,
+ id,
+ location,
+ relation,
+ } = change
+ {
+ if entry_mode.is_blob() && !cb(location, id.detach()) {
return Ok(Action::Cancel);
}
};
@@ -184,10 +191,7
match outcome {
// If comparing the trees yields no error or gets cancelled
// manually, everything went fine
- Ok(_)
- | Err(gix::object::tree::diff::for_each::Error::Diff(
- gix::diff::tree::changes::Error::Cancelled,
- )) => Ok(()),
+ Ok(_) | Err(gix::object::tree::diff::for_each::Error::ForEach(_)) => Ok(()),
Err(e) => Err(wrap_err(
format!(
"walking diff between trees {} and {}",