1
- use bstr:: { BString , ByteSlice } ;
1
+ use crate :: Snapshot ;
2
+ use bstr:: { BStr , BString , ByteSlice } ;
2
3
use std:: cmp:: Ordering ;
3
4
use std:: ops:: Deref ;
4
5
@@ -9,6 +10,36 @@ enum EncodedString {
9
10
Unknown ( BString ) ,
10
11
}
11
12
13
+ impl EncodedString {
14
+ fn cmp_ref ( & self , other : EncodedStringRef < ' _ > ) -> Ordering {
15
+ match ( self , other) {
16
+ ( EncodedString :: Utf8 ( a) , EncodedStringRef :: Utf8 ( b) ) => {
17
+ let a = a. chars ( ) . map ( |c| c. to_ascii_lowercase ( ) ) ;
18
+ let b = b. chars ( ) . map ( |c| c. to_ascii_lowercase ( ) ) ;
19
+ a. cmp ( b)
20
+ }
21
+ ( EncodedString :: Unknown ( a) , EncodedStringRef :: Unknown ( b) ) => a. deref ( ) . as_bstr ( ) . cmp ( b) ,
22
+ ( EncodedString :: Utf8 ( a) , EncodedStringRef :: Unknown ( b) ) => a. as_bytes ( ) . cmp ( b. as_ref ( ) ) ,
23
+ ( EncodedString :: Unknown ( a) , EncodedStringRef :: Utf8 ( b) ) => a. deref ( ) . as_bytes ( ) . cmp ( b. as_bytes ( ) ) ,
24
+ }
25
+ }
26
+ }
27
+
28
+ #[ cfg_attr( test, derive( Debug ) ) ]
29
+ enum EncodedStringRef < ' a > {
30
+ Utf8 ( & ' a str ) ,
31
+ Unknown ( & ' a BStr ) ,
32
+ }
33
+
34
+ impl EncodedString {
35
+ fn to_ref ( & self ) -> EncodedStringRef < ' _ > {
36
+ match self {
37
+ EncodedString :: Unknown ( v) => EncodedStringRef :: Unknown ( v. deref ( ) . as_bstr ( ) ) ,
38
+ EncodedString :: Utf8 ( v) => EncodedStringRef :: Utf8 ( v) ,
39
+ }
40
+ }
41
+ }
42
+
12
43
impl Eq for EncodedString { }
13
44
14
45
impl PartialEq < Self > for EncodedString {
@@ -25,22 +56,12 @@ impl PartialOrd<Self> for EncodedString {
25
56
26
57
impl Ord for EncodedString {
27
58
fn cmp ( & self , other : & Self ) -> Ordering {
28
- use EncodedString :: * ;
29
- match ( self , other) {
30
- ( Utf8 ( a) , Utf8 ( b) ) => {
31
- let a = a. chars ( ) . map ( |c| c. to_ascii_lowercase ( ) ) ;
32
- let b = b. chars ( ) . map ( |c| c. to_ascii_lowercase ( ) ) ;
33
- a. cmp ( b)
34
- }
35
- ( Unknown ( a) , Unknown ( b) ) => a. cmp ( b) ,
36
- ( Utf8 ( a) , Unknown ( b) ) => a. as_bytes ( ) . cmp ( b. as_ref ( ) ) ,
37
- ( Unknown ( a) , Utf8 ( b) ) => a. deref ( ) . as_bytes ( ) . cmp ( b. as_bytes ( ) ) ,
38
- }
59
+ self . cmp_ref ( other. to_ref ( ) )
39
60
}
40
61
}
41
62
42
63
#[ derive( Clone ) ]
43
- pub ( crate ) struct NameEntry {
64
+ struct NameEntry {
44
65
new_name : Option < BString > ,
45
66
new_email : Option < BString > ,
46
67
old_name : EncodedString ,
@@ -55,6 +76,30 @@ pub(crate) struct EmailEntry {
55
76
entries_by_old_name : Vec < NameEntry > ,
56
77
}
57
78
79
+ impl Snapshot {
80
+ pub fn from_bytes ( buf : & [ u8 ] ) -> Self {
81
+ Self :: new ( crate :: parse_ignore_errors ( buf) )
82
+ }
83
+
84
+ pub fn new < ' a > ( entries : impl IntoIterator < Item = crate :: Entry < ' a > > ) -> Self {
85
+ let mut snapshot = Self :: default ( ) ;
86
+ snapshot. extend ( entries) ;
87
+ snapshot
88
+ }
89
+
90
+ pub fn extend < ' a > ( & mut self , entries : impl IntoIterator < Item = crate :: Entry < ' a > > ) -> & mut Self {
91
+ todo ! ( )
92
+ }
93
+
94
+ pub fn try_resolve ( & self , signature : & git_actor:: SignatureRef < ' _ > ) -> Option < git_actor:: Signature > {
95
+ todo ! ( )
96
+ }
97
+
98
+ pub fn resolve ( & self , signature : & git_actor:: SignatureRef < ' _ > ) -> git_actor:: Signature {
99
+ self . try_resolve ( signature) . unwrap_or_else ( || signature. to_owned ( ) )
100
+ }
101
+ }
102
+
58
103
#[ cfg( test) ]
59
104
mod encoded_string {
60
105
use crate :: snapshot:: EncodedString ;
0 commit comments