@@ -2,23 +2,10 @@ mod changes {
2
2
mod to_obtain_tree {
3
3
use crate :: hex_to_id;
4
4
use git_diff:: visit:: recorder;
5
- use git_object:: tree:: EntryMode ;
5
+ use git_hash:: { oid, ObjectId } ;
6
+ use git_object:: { bstr:: ByteSlice , tree:: EntryMode } ;
6
7
use git_odb:: { linked, pack, Locate } ;
7
8
8
- const COMMIT_1 : & str = "055df97e18cd537da3cb16bcbdf1733fdcdfb430" ;
9
- const COMMIT_2 : & str = "a5ebf9ee3b1cac5daf3dc9056026ee848be52da2" ;
10
- const COMMIT_3 : & str = "65cd7e777303b4b3a2d41e81303b5c2dd15041fa" ;
11
- const COMMIT_5 : & str = "69bbebb6608472d98be684f4e6ef1faaac2a03bc" ;
12
- const COMMIT_6 : & str = "9bd749db486b2af4a0d4df2de1972db2f198903d" ;
13
- const COMMIT_9 : & str = "ac0a340c76810b53b23e6dc44cf1445ebbd52201" ;
14
- const COMMIT_11 : & str = "76a3f837e9b4aad1840df6be5ca413d696eabc9d" ;
15
- const COMMIT_13 : & str = "05533d594489fae72d4e7422fbdf061c1b70bc22" ;
16
- const COMMIT_14 : & str = "ac7c4c37c3939b820f3ff9003a7ed11d6143dc2b" ;
17
- const COMMIT_15 : & str = "6112ecdac98a18bcbdbd83f0b180b3e1df12e293" ;
18
- const COMMIT_16 : & str = "0ca25edc0c0b38fd6b6a0f6e4797dc08bf0c55c2" ;
19
- const COMMIT_17 : & str = "0b93c2b59feb6c9a4efa1c78a4b4b17fd1c78508" ;
20
- const COMMIT_18 : & str = "53e18fb0d3296990f05382f9c67f8bd256126c4c" ;
21
-
22
9
fn db ( ) -> crate :: Result < linked:: Db > {
23
10
linked:: Db :: at (
24
11
test_tools:: scripted_fixture_repo_read_only ( "make_diff_repo.sh" ) ?
@@ -28,8 +15,7 @@ mod changes {
28
15
. map_err ( Into :: into)
29
16
}
30
17
31
- fn diff_with_previous_commit_from ( db : & linked:: Db , commit_id : & str ) -> crate :: Result < recorder:: Changes > {
32
- let commit_id = git_hash:: ObjectId :: from_hex ( commit_id. as_bytes ( ) ) ?;
18
+ fn diff_with_previous_commit_from ( db : & linked:: Db , commit_id : & oid ) -> crate :: Result < recorder:: Changes > {
33
19
let mut buf = Vec :: new ( ) ;
34
20
let ( main_tree_id, parent_commit_id) = {
35
21
let commit = db
@@ -75,11 +61,41 @@ mod changes {
75
61
Ok ( recorder. records )
76
62
}
77
63
64
+ fn head_of ( db : & linked:: Db ) -> ObjectId {
65
+ ObjectId :: from_hex (
66
+ & std:: fs:: read (
67
+ db. dbs [ 0 ]
68
+ . loose
69
+ . path
70
+ . parent ( )
71
+ . unwrap ( )
72
+ . join ( "refs" )
73
+ . join ( "heads" )
74
+ . join ( "main" ) ,
75
+ )
76
+ . expect ( "head ref" )
77
+ . as_bstr ( )
78
+ . trim ( ) ,
79
+ )
80
+ . expect ( "valid hex id" )
81
+ }
82
+
83
+ fn all_commits ( db : & linked:: Db ) -> Vec < ObjectId > {
84
+ let head = head_of ( db) ;
85
+ git_odb:: traverse:: Ancestors :: new ( db, Some ( head) , & mut pack:: cache:: Never )
86
+ . collect :: < Vec < _ > > ( )
87
+ . into_iter ( )
88
+ . rev ( )
89
+ . collect :: < Result < Vec < _ > , _ > > ( )
90
+ . expect ( "valid iteration" )
91
+ }
92
+
78
93
#[ test]
79
94
fn many_different_states ( ) -> crate :: Result {
80
95
let db = db ( ) ?;
96
+ let all_commits = all_commits ( & db) ;
81
97
assert_eq ! (
82
- diff_with_previous_commit_from( & db, COMMIT_1 ) ?,
98
+ diff_with_previous_commit_from( & db, & all_commits [ 0 ] ) ?,
83
99
vec![ recorder:: Change :: Addition {
84
100
entry_mode: EntryMode :: Blob ,
85
101
oid: hex_to_id( "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" ) ,
@@ -88,7 +104,7 @@ mod changes {
88
104
, ":000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A f" ) ;
89
105
90
106
assert_eq ! (
91
- diff_with_previous_commit_from( & db, COMMIT_2 ) ?,
107
+ diff_with_previous_commit_from( & db, & all_commits [ 1 ] ) ?,
92
108
vec![ recorder:: Change :: Modification {
93
109
previous_entry_mode: EntryMode :: Blob ,
94
110
previous_oid: hex_to_id( "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" ) ,
@@ -99,7 +115,7 @@ mod changes {
99
115
, ":100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 28ce6a8b26aa170e1de65536fe8abe1832bd3242 M f" ) ;
100
116
101
117
assert_eq ! (
102
- diff_with_previous_commit_from( & db, COMMIT_3 ) ?,
118
+ diff_with_previous_commit_from( & db, & all_commits [ 2 ] ) ?,
103
119
vec![ recorder:: Change :: Deletion {
104
120
entry_mode: EntryMode :: Blob ,
105
121
oid: hex_to_id( "28ce6a8b26aa170e1de65536fe8abe1832bd3242" ) ,
@@ -110,7 +126,7 @@ mod changes {
110
126
) ;
111
127
112
128
assert_eq ! (
113
- diff_with_previous_commit_from( & db, COMMIT_5 ) ?,
129
+ diff_with_previous_commit_from( & db, & all_commits [ 4 ] ) ?,
114
130
vec![ recorder:: Change :: Deletion {
115
131
entry_mode: EntryMode :: Blob ,
116
132
oid: hex_to_id( "28ce6a8b26aa170e1de65536fe8abe1832bd3242" ) ,
@@ -130,7 +146,7 @@ mod changes {
130
146
:000000 100644 0000000000000000000000000000000000000000 28ce6a8b26aa170e1de65536fe8abe1832bd3242 A f/f" ) ;
131
147
132
148
assert_eq ! (
133
- diff_with_previous_commit_from( & db, COMMIT_6 ) ?,
149
+ diff_with_previous_commit_from( & db, & all_commits [ 5 ] ) ?,
134
150
vec![
135
151
recorder:: Change :: Modification {
136
152
previous_entry_mode: EntryMode :: Tree ,
@@ -151,7 +167,7 @@ mod changes {
151
167
) ;
152
168
153
169
assert_eq ! (
154
- diff_with_previous_commit_from( & db, COMMIT_9 ) ?,
170
+ diff_with_previous_commit_from( & db, & all_commits [ 8 ] ) ?,
155
171
vec![
156
172
recorder:: Change :: Modification {
157
173
previous_entry_mode: EntryMode :: Tree ,
@@ -172,7 +188,7 @@ mod changes {
172
188
) ;
173
189
174
190
assert_eq ! (
175
- diff_with_previous_commit_from( & db, COMMIT_11 ) ?,
191
+ diff_with_previous_commit_from( & db, & all_commits [ 10 ] ) ?,
176
192
vec![
177
193
recorder:: Change :: Deletion {
178
194
entry_mode: EntryMode :: Tree ,
@@ -206,7 +222,7 @@ mod changes {
206
222
:120000 000000 2e65efe2a145dda7ee51d1741299f848e5bf752e 0000000000000000000000000000000000000000 D f/f"
207
223
) ;
208
224
assert_eq ! (
209
- diff_with_previous_commit_from( & db, COMMIT_13 ) ?,
225
+ diff_with_previous_commit_from( & db, & all_commits [ 12 ] ) ?,
210
226
vec![
211
227
recorder:: Change :: Deletion {
212
228
entry_mode: EntryMode :: Tree ,
@@ -222,7 +238,7 @@ mod changes {
222
238
":100644 000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 D d/f"
223
239
) ;
224
240
assert_eq ! (
225
- diff_with_previous_commit_from( & db, COMMIT_14 ) ?,
241
+ diff_with_previous_commit_from( & db, & all_commits [ 13 ] ) ?,
226
242
vec![
227
243
recorder:: Change :: Addition {
228
244
entry_mode: EntryMode :: Blob ,
@@ -245,7 +261,7 @@ mod changes {
245
261
:000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A e"
246
262
) ;
247
263
assert_eq ! (
248
- diff_with_previous_commit_from( & db, COMMIT_15 ) ?,
264
+ diff_with_previous_commit_from( & db, & all_commits [ 14 ] ) ?,
249
265
vec![
250
266
recorder:: Change :: Addition {
251
267
entry_mode: EntryMode :: Tree ,
@@ -261,7 +277,7 @@ mod changes {
261
277
":000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A g/a"
262
278
) ;
263
279
assert_eq ! (
264
- diff_with_previous_commit_from( & db, COMMIT_16 ) ?,
280
+ diff_with_previous_commit_from( & db, & all_commits [ 15 ] ) ?,
265
281
vec![
266
282
recorder:: Change :: Deletion {
267
283
entry_mode: EntryMode :: Blob ,
@@ -284,7 +300,7 @@ mod changes {
284
300
:100644 000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 D e"
285
301
) ;
286
302
assert_eq ! (
287
- diff_with_previous_commit_from( & db, COMMIT_17 ) ?,
303
+ diff_with_previous_commit_from( & db, & all_commits [ 16 ] ) ?,
288
304
vec![
289
305
recorder:: Change :: Deletion {
290
306
entry_mode: EntryMode :: Blob ,
@@ -301,7 +317,7 @@ mod changes {
301
317
:000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A ff"
302
318
) ;
303
319
assert_eq ! (
304
- diff_with_previous_commit_from( & db, COMMIT_18 ) ?,
320
+ diff_with_previous_commit_from( & db, & all_commits [ 17 ] ) ?,
305
321
vec![
306
322
recorder:: Change :: Modification {
307
323
previous_entry_mode: EntryMode :: Tree ,
0 commit comments