@@ -24,7 +24,8 @@ pub trait Diff: Send + Sync {
24
24
) -> Result < Option < Self :: Output > , E > ;
25
25
}
26
26
27
- /// compares to blobs by comparing their size and oid very fast
27
+ /// compares to blobs by comparing their size and oid, only looks at the file if
28
+ /// the size matches, therefore very fast
28
29
pub struct Fast ;
29
30
30
31
impl Diff for Fast {
@@ -46,20 +47,17 @@ impl Diff for Fast {
46
47
}
47
48
let blob = blob. read ( ) ?;
48
49
let header = loose_header ( gix_object:: Kind :: Blob , blob. len ( ) ) ;
49
- match entry. id {
50
- ObjectId :: Sha1 ( entry_hash) => {
51
- let mut file_hash = hash:: Sha1 :: default ( ) ;
52
- file_hash. update ( & header) ;
53
- file_hash. update ( blob) ;
54
- let file_hash = file_hash. digest ( ) ;
55
- Ok ( ( entry_hash != file_hash) . then_some ( ( ) ) )
56
- }
57
- }
50
+ let mut hasher = hash:: hasher ( entry. id . kind ( ) ) ;
51
+ hasher. update ( & header) ;
52
+ hasher. update ( blob) ;
53
+ let file_hash: ObjectId = hasher. digest ( ) . into ( ) ;
54
+ Ok ( ( entry. id != file_hash) . then_some ( ( ) ) )
58
55
}
59
56
}
60
57
61
- /// compares to blobs by comparing their oid
62
- /// Same as [`FastEq`] but always
58
+ /// Compares files to blobs by comparing their oids. Same as [`Fast`] but does
59
+ /// not contain a fast path for files with mismatched files and therefore always
60
+ /// returns an OID that can be reused later
63
61
pub struct Hash ;
64
62
65
63
impl Diff for Hash {
@@ -74,14 +72,10 @@ impl Diff for Hash {
74
72
) -> Result < Option < Self :: Output > , E > {
75
73
let blob = blob. read ( ) ?;
76
74
let header = loose_header ( gix_object:: Kind :: Blob , blob. len ( ) ) ;
77
- match entry. id {
78
- ObjectId :: Sha1 ( entry_hash) => {
79
- let mut file_hash = hash:: Sha1 :: default ( ) ;
80
- file_hash. update ( & header) ;
81
- file_hash. update ( blob) ;
82
- let file_hash = file_hash. digest ( ) ;
83
- Ok ( ( entry_hash != file_hash) . then_some ( ObjectId :: Sha1 ( file_hash) ) )
84
- }
85
- }
75
+ let mut hasher = hash:: hasher ( entry. id . kind ( ) ) ;
76
+ hasher. update ( & header) ;
77
+ hasher. update ( blob) ;
78
+ let file_hash: ObjectId = hasher. digest ( ) . into ( ) ;
79
+ Ok ( ( entry. id != file_hash) . then_some ( file_hash) )
86
80
}
87
81
}
0 commit comments