forked from rust-lang/git2-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_update.rs
55 lines (47 loc) · 1.71 KB
/
push_update.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::util::Binding;
use crate::{raw, Oid};
use std::marker;
use std::str;
/// Represents an update which will be performed on the remote during push.
pub struct PushUpdate<'a> {
raw: *const raw::git_push_update,
_marker: marker::PhantomData<&'a raw::git_push_update>,
}
impl<'a> Binding for PushUpdate<'a> {
type Raw = *const raw::git_push_update;
unsafe fn from_raw(raw: *const raw::git_push_update) -> PushUpdate<'a> {
PushUpdate {
raw,
_marker: marker::PhantomData,
}
}
fn raw(&self) -> Self::Raw {
self.raw
}
}
impl PushUpdate<'_> {
/// Returns the source name of the reference as a byte slice.
pub fn src_refname_bytes(&self) -> &[u8] {
unsafe { crate::opt_bytes(self, (*self.raw).src_refname).unwrap() }
}
/// Returns the source name of the reference, or None if it is not valid UTF-8.
pub fn src_refname(&self) -> Option<&str> {
str::from_utf8(self.src_refname_bytes()).ok()
}
/// Returns the name of the reference to update on the server as a byte slice.
pub fn dst_refname_bytes(&self) -> &[u8] {
unsafe { crate::opt_bytes(self, (*self.raw).dst_refname).unwrap() }
}
/// Returns the name of the reference to update on the server, or None if it is not valid UTF-8.
pub fn dst_refname(&self) -> Option<&str> {
str::from_utf8(self.dst_refname_bytes()).ok()
}
/// Returns the current target of the reference.
pub fn src(&self) -> Oid {
unsafe { Binding::from_raw(&(*self.raw).src as *const _) }
}
/// Returns the new target for the reference.
pub fn dst(&self) -> Oid {
unsafe { Binding::from_raw(&(*self.raw).dst as *const _) }
}
}