Skip to content

Commit

Permalink
Merge b78983e into fd4b000
Browse files Browse the repository at this point in the history
  • Loading branch information
hauleth committed Jan 14, 2016
2 parents fd4b000 + b78983e commit 5cdd6b8
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/oid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Oid {

/// Test if this OID is all zeros.
pub fn is_zero(&self) -> bool {
unsafe { raw::git_oid_iszero(&self.raw) == 1 }
self.raw.id == [0; 20]
}
}

Expand All @@ -71,13 +71,11 @@ impl fmt::Debug for Oid {
impl fmt::Display for Oid {
/// Hex-encode this Oid into a formatter.
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut dst = [0u8; raw::GIT_OID_HEXSZ + 1];
unsafe {
raw::git_oid_tostr(dst.as_mut_ptr() as *mut libc::c_char,
dst.len() as libc::size_t, &self.raw);
for byte in &self.raw.id {
try!(write!(f, "{:x}", *byte))
}
let s = &dst[..dst.iter().position(|&a| a == 0).unwrap()];
str::from_utf8(s).unwrap().fmt(f)

Ok(())
}
}

Expand All @@ -95,7 +93,7 @@ impl str::FromStr for Oid {

impl PartialEq for Oid {
fn eq(&self, other: &Oid) -> bool {
unsafe { raw::git_oid_equal(&self.raw, &other.raw) != 0 }
self.raw.id == other.raw.id
}
}
impl Eq for Oid {}
Expand All @@ -108,11 +106,7 @@ impl PartialOrd for Oid {

impl Ord for Oid {
fn cmp(&self, other: &Oid) -> Ordering {
match unsafe { raw::git_oid_cmp(&self.raw, &other.raw) } {
0 => Ordering::Equal,
n if n < 0 => Ordering::Less,
_ => Ordering::Greater,
}
Ord::cmp(&self.raw.id, &other.raw.id)
}
}

Expand Down

0 comments on commit 5cdd6b8

Please sign in to comment.