use std::kinds::marker;
use std::str;
use {raw, Remote, Direction} ;
pub struct Refspec<'a> {
raw: *const raw::git_refspec,
marker1: marker::ContravariantLifetime<'a>,
marker2: marker::NoSend,
marker3: marker::NoSync,
marker4: marker::NoCopy,
}
impl<'a> Refspec<'a> {
pub unsafe fn from_raw<'a>(_repo: &'a Remote,
raw: *const raw::git_refspec) -> Refspec<'a> {
Refspec {
raw: raw,
marker1: marker::ContravariantLifetime,
marker2: marker::NoSend,
marker3: marker::NoSync,
marker4: marker::NoCopy,
}
}
pub fn direction(&self) -> Direction {
match unsafe { raw::git_refspec_direction(self.raw) } {
raw::GIT_DIRECTION_FETCH => Direction::Fetch,
raw::GIT_DIRECTION_PUSH => Direction::Push,
}
}
pub fn dst(&self) -> Option<&str> {
str::from_utf8(self.dst_bytes())
}
pub fn dst_bytes(&self) -> &[u8] {
unsafe { ::opt_bytes(self, raw::git_refspec_dst(self.raw)).unwrap() }
}
pub fn dst_matches(&self, refname: &str) -> bool {
let refname = refname.to_c_str();
unsafe { raw::git_refspec_dst_matches(self.raw, refname.as_ptr()) == 1 }
}
pub fn src(&self) -> Option<&str> {
str::from_utf8(self.src_bytes())
}
pub fn src_bytes(&self) -> &[u8] {
unsafe { ::opt_bytes(self, raw::git_refspec_src(self.raw)).unwrap() }
}
pub fn src_matches(&self, refname: &str) -> bool {
let refname = refname.to_c_str();
unsafe { raw::git_refspec_src_matches(self.raw, refname.as_ptr()) == 1 }
}
pub fn is_force(&self) -> bool {
unsafe { raw::git_refspec_force(self.raw) == 1 }
}
pub fn str(&self) -> Option<&str> {
str::from_utf8(self.bytes())
}
pub fn bytes(&self) -> &[u8] {
unsafe { ::opt_bytes(self, raw::git_refspec_string(self.raw)).unwrap() }
}
}