-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignature.rs
81 lines (70 loc) · 1.81 KB
/
signature.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use std::libc::c_int;
use std::str::raw::from_c_str;
use ext;
use super::{Signature, Time};
pub fn to_c_sig(sig: &Signature) -> ext::git_signature {
sig.name.with_c_str(|c_name| {
sig.email.with_c_str(|c_email| {
ext::git_signature {
name: c_name,
email: c_email,
when: ext::git_time {
time: sig.when.time,
offset: sig.when.offset as c_int,
}
}
})
})
}
pub unsafe fn from_c_sig(c_sig: *ext::git_signature) -> Signature {
Signature {
name: from_c_str((*c_sig).name),
email: from_c_str((*c_sig).email),
when: Time { time: (*c_sig).when.time, offset: (*c_sig).when.offset as int }
}
}
#[inline]
fn time_cmp(a: &Time, b: &Time) -> i64 {
let a_utc = a.time + (a.offset as i64) * 60;
let b_utc = b.time + (b.offset as i64) * 60;
return a_utc - b_utc;
}
impl Eq for Time {
fn eq(&self, other: &Time) -> bool {
time_cmp(self, other) == 0
}
fn ne(&self, other: &Time) -> bool {
time_cmp(self, other) != 0
}
}
impl Ord for Time {
fn lt(&self, other: &Time) -> bool {
time_cmp(self, other) < 0
}
fn le(&self, other: &Time) -> bool {
time_cmp(self, other) <= 0
}
fn gt(&self, other: &Time) -> bool {
time_cmp(self, other) > 0
}
fn ge(&self, other: &Time) -> bool {
time_cmp(self, other) >= 0
}
}
impl TotalEq for Time {
fn equals(&self, other: &Time) -> bool {
time_cmp(self, other) == 0
}
}
impl TotalOrd for Time {
fn cmp(&self, other: &Time) -> Ordering {
let res = time_cmp(self, other);
if res < 0 {
Less
} else if res == 0 {
Equal
} else {
Greater
}
}
}