treewide: Avoid `git2::Oid::zero`

In multiple instances, `git2::Oid::zero` is used to obtain an OID that
is equivalent to `radicle_oid::Oid::SHA1_ZERO`. This is needlessly
complex.
This commit is contained in:
Lorenz Leutgeb 2026-04-23 21:27:05 +02:00 committed by Lorenz Leutgeb
parent f65175397f
commit ecca50a5f9
4 changed files with 9 additions and 10 deletions

View File

@ -42,7 +42,7 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
thread::sleep(interval); thread::sleep(interval);
let oid = reference(&repo, &nid, &qualified)?; let oid = reference(&repo, &nid, &qualified)?;
if oid != initial { if oid != initial {
term::info!("{}", oid.unwrap_or(git::raw::Oid::zero().into())); term::info!("{}", oid.unwrap_or(git::Oid::ZERO_SHA1));
break; break;
} }
if now.elapsed()? >= timeout { if now.elapsed()? >= timeout {

View File

@ -42,10 +42,10 @@ impl Refdb {
.fold(Applied::default(), |mut ap, update| match update { .fold(Applied::default(), |mut ap, update| match update {
Update::Direct { name, target, .. } => { Update::Direct { name, target, .. } => {
let name = name.into_qualified().into_owned(); let name = name.into_qualified().into_owned();
let prev = match self.0.insert(name.clone(), target) { let prev = self
Some(prev) => prev, .0
None => radicle::git::raw::Oid::zero().into(), .insert(name.clone(), target)
}; .unwrap_or(radicle::git::Oid::ZERO_SHA1);
ap.updated.push(RefUpdate::Updated { ap.updated.push(RefUpdate::Updated {
name: name.to_ref_string(), name: name.to_ref_string(),
old: prev, old: prev,

View File

@ -690,7 +690,6 @@ mod tests {
use fastrand; use fastrand;
use localtime::LocalTime; use localtime::LocalTime;
use qcheck_macros::quickcheck; use qcheck_macros::quickcheck;
use radicle::git::raw;
use radicle::test::arbitrary; use radicle::test::arbitrary;
use crate::wire::Decode as _; use crate::wire::Decode as _;
@ -701,7 +700,7 @@ mod tests {
fn test_ref_remote_limit() { fn test_ref_remote_limit() {
let mut refs = BoundedVec::<_, REF_REMOTE_LIMIT>::new(); let mut refs = BoundedVec::<_, REF_REMOTE_LIMIT>::new();
let signer = Device::mock(); let signer = Device::mock();
let at = raw::Oid::zero().into(); let at = git::Oid::ZERO_SHA1;
assert_eq!(refs.capacity(), REF_REMOTE_LIMIT); assert_eq!(refs.capacity(), REF_REMOTE_LIMIT);
@ -759,7 +758,7 @@ mod tests {
fn prop_refs_announcement_signing(rid: RepoId) { fn prop_refs_announcement_signing(rid: RepoId) {
let signer = Device::mock_rng(&mut fastrand::Rng::new()); let signer = Device::mock_rng(&mut fastrand::Rng::new());
let timestamp = Timestamp::EPOCH; let timestamp = Timestamp::EPOCH;
let at = raw::Oid::zero().into(); let at = git::Oid::ZERO_SHA1;
let refs = BoundedVec::collect_from( let refs = BoundedVec::collect_from(
&mut [RefsAt { &mut [RefsAt {
remote: *signer.public_key(), remote: *signer.public_key(),

View File

@ -380,7 +380,7 @@ mod parse {
}) })
}) })
}) })
.unwrap_or(Ok(git::raw::Oid::zero().into()))?; .unwrap_or(Ok(git::Oid::ZERO_SHA1))?;
let new = row let new = row
.try_read::<Option<&str>, _>("new")? .try_read::<Option<&str>, _>("new")?
.map(|oid| { .map(|oid| {
@ -391,7 +391,7 @@ mod parse {
}) })
}) })
}) })
.unwrap_or(Ok(git::raw::Oid::zero().into()))?; .unwrap_or(Ok(git::Oid::ZERO_SHA1))?;
let update = RefUpdate::from(RefString::try_from(refstr)?, old, new); let update = RefUpdate::from(RefString::try_from(refstr)?, old, new);
let (namespace, qualified) = git::parse_ref(refstr)?; let (namespace, qualified) = git::parse_ref(refstr)?;
let timestamp = row.try_read::<i64, _>("timestamp")?; let timestamp = row.try_read::<i64, _>("timestamp")?;