1
1
use crate :: index:: index_ro;
2
2
use crates_index_diff:: { Change , CrateVersion , Index } ;
3
3
use git_repository as git;
4
- use git_repository:: prelude:: ObjectIdExt ;
5
4
6
5
#[ test]
7
6
fn addition ( ) -> crate :: Result {
8
- let changes = changes ( & index_ro ( ) ?, ":/initial commit" ) ?;
7
+ let changes = changes ( index_ro ( ) ?, ":/initial commit" ) ?;
9
8
assert_eq ! ( changes. len( ) , 3228 ) ;
10
9
assert ! ( matches!(
11
10
changes
@@ -39,7 +38,7 @@ fn addition2() -> crate::Result {
39
38
40
39
#[ test]
41
40
fn deletion ( ) -> crate :: Result {
42
- let changes = changes ( & index_ro ( ) ?, "@~326" ) ?;
41
+ let changes = changes ( index_ro ( ) ?, "@~326" ) ?;
43
42
assert_eq ! ( changes. len( ) , 1 ) ;
44
43
assert_eq ! ( changes. first( ) . and_then( |c| c. deleted( ) ) , Some ( "girl" ) ) ;
45
44
Ok ( ( ) )
@@ -55,7 +54,7 @@ fn deletion2() -> crate::Result {
55
54
56
55
#[ test]
57
56
fn new_version ( ) -> crate :: Result {
58
- let changes = changes ( & index_ro ( ) ?, ":/Updating crate `git-repository#0.22.1`" ) ?;
57
+ let changes = changes ( index_ro ( ) ?, ":/Updating crate `git-repository#0.22.1`" ) ?;
59
58
assert_eq ! ( changes. len( ) , 1 ) ;
60
59
assert_eq ! (
61
60
changes
@@ -81,7 +80,7 @@ fn new_version2() -> crate::Result {
81
80
82
81
#[ test]
83
82
fn yanked ( ) -> crate :: Result {
84
- let changes = changes ( & index_ro ( ) ?, ":/Yanking crate `github_release_rs#0.1.0`" ) ?;
83
+ let changes = changes ( index_ro ( ) ?, ":/Yanking crate `github_release_rs#0.1.0`" ) ?;
85
84
assert_eq ! ( changes. len( ) , 1 ) ;
86
85
assert_eq ! (
87
86
changes
@@ -107,7 +106,7 @@ fn yanked2() -> crate::Result {
107
106
108
107
#[ test]
109
108
fn unyanked_crates_recognized_as_added ( ) -> crate :: Result {
110
- let changes = changes ( & index_ro ( ) ?, ":/Unyanking crate `git2mail#0.3.2`" ) ?;
109
+ let changes = changes ( index_ro ( ) ?, ":/Unyanking crate `git2mail#0.3.2`" ) ?;
111
110
assert_eq ! ( changes. len( ) , 1 ) ;
112
111
assert_eq ! (
113
112
changes
@@ -133,7 +132,7 @@ fn unyanked_crates_recognized_as_added2() -> crate::Result {
133
132
134
133
#[ test]
135
134
fn normalization ( ) -> crate :: Result {
136
- let changes = changes ( & index_ro ( ) ?, ":/normalize" ) ?;
135
+ let changes = changes ( index_ro ( ) ?, ":/normalize" ) ?;
137
136
assert_eq ! (
138
137
changes. len( ) ,
139
138
2356 , // should be 0
@@ -153,27 +152,52 @@ fn normalization2() -> crate::Result {
153
152
Ok ( ( ) )
154
153
}
155
154
156
- fn changes ( index : & Index , revspec : & str ) -> crate :: Result < Vec < Change > > {
157
- let repo = git:: open ( index. repository ( ) . path ( ) ) ?;
158
- let commit = repo. rev_parse ( revspec) ?. single ( ) . unwrap ( ) ;
159
- let ancestor_tree = commit
160
- . object ( ) ?
161
- . into_commit ( )
162
- . parent_ids ( )
163
- . next ( )
164
- . and_then ( |parent| parent. object ( ) . ok ( ) ?. into_commit ( ) . tree_id ( ) . ok ( ) )
165
- . unwrap_or_else ( || git:: hash:: ObjectId :: empty_tree ( repo. object_hash ( ) ) . attach ( & repo) ) ;
166
- Ok ( index. changes_between_commits ( ancestor_tree, commit) ?)
155
+ fn changes ( mut index : Index , revspec : & str ) -> crate :: Result < Vec < Change > > {
156
+ let ( prev, current) = {
157
+ let repo = index. repository_mut ( ) ;
158
+ repo. object_cache_size_if_unset ( 4 * 1024 * 1024 ) ;
159
+ let commit = repo. rev_parse ( revspec) ?. single ( ) . unwrap ( ) ;
160
+ let ancestor_tree = commit
161
+ . object ( ) ?
162
+ . into_commit ( )
163
+ . parent_ids ( )
164
+ . next ( )
165
+ . and_then ( |parent| {
166
+ parent
167
+ . object ( )
168
+ . ok ( ) ?
169
+ . into_commit ( )
170
+ . tree_id ( )
171
+ . ok ( )
172
+ . map ( |id| id. detach ( ) )
173
+ } )
174
+ . unwrap_or_else ( || git:: hash:: ObjectId :: empty_tree ( repo. object_hash ( ) ) ) ;
175
+ ( ancestor_tree, commit. detach ( ) )
176
+ } ;
177
+ Ok ( index. changes_between_commits ( prev, current) ?)
167
178
}
179
+
168
180
fn changes2 ( mut index : Index , revspec : & str ) -> crate :: Result < Vec < Change > > {
169
- let repo = git:: open ( index. repository ( ) . path ( ) ) ?;
170
- let commit = repo. rev_parse ( revspec) ?. single ( ) . unwrap ( ) ;
171
- let ancestor_tree = commit
172
- . object ( ) ?
173
- . into_commit ( )
174
- . parent_ids ( )
175
- . next ( )
176
- . and_then ( |parent| parent. object ( ) . ok ( ) ?. into_commit ( ) . tree_id ( ) . ok ( ) )
177
- . unwrap_or_else ( || git:: hash:: ObjectId :: empty_tree ( repo. object_hash ( ) ) . attach ( & repo) ) ;
178
- Ok ( index. changes_between_commits2 ( ancestor_tree, commit) ?)
181
+ let ( prev, current) = {
182
+ let repo = index. repository_mut ( ) ;
183
+ repo. object_cache_size_if_unset ( 4 * 1024 * 1024 ) ;
184
+ let commit = repo. rev_parse ( revspec) ?. single ( ) . unwrap ( ) ;
185
+ let ancestor_tree = commit
186
+ . object ( ) ?
187
+ . into_commit ( )
188
+ . parent_ids ( )
189
+ . next ( )
190
+ . and_then ( |parent| {
191
+ parent
192
+ . object ( )
193
+ . ok ( ) ?
194
+ . into_commit ( )
195
+ . tree_id ( )
196
+ . ok ( )
197
+ . map ( |id| id. detach ( ) )
198
+ } )
199
+ . unwrap_or_else ( || git:: hash:: ObjectId :: empty_tree ( repo. object_hash ( ) ) ) ;
200
+ ( ancestor_tree, commit. detach ( ) )
201
+ } ;
202
+ Ok ( index. changes_between_commits2 ( prev, current) ?)
179
203
}
0 commit comments