1
- use gix_commitgraph:: Graph ;
2
-
3
- use crate :: { check_common, inspect_refs, make_readonly_repo} ;
1
+ use crate :: { check_common, graph_and_expected, graph_and_expected_named} ;
4
2
5
3
#[ test]
6
- fn single_parent ( ) -> crate :: Result {
7
- let repo_dir = make_readonly_repo ( "single_parent.sh" ) ;
8
- let refs = inspect_refs ( & repo_dir, & [ "parent" , "child" ] ) ;
9
- let cg = Graph :: from_info_dir ( repo_dir. join ( ".git" ) . join ( "objects" ) . join ( "info" ) ) ?;
4
+ fn single_parent ( ) {
5
+ let ( cg, refs) = graph_and_expected ( "single_parent.sh" , & [ "parent" , "child" ] ) ;
10
6
check_common ( & cg, & refs) ;
11
7
12
8
assert_eq ! ( cg. commit_at( refs[ "parent" ] . pos( ) ) . generation( ) , 1 ) ;
13
9
assert_eq ! ( cg. commit_at( refs[ "child" ] . pos( ) ) . generation( ) , 2 ) ;
10
+ }
11
+
12
+ #[ test]
13
+ fn single_commit_huge_dates_generation_v2_also_do_not_allow_huge_dates ( ) {
14
+ let ( cg, refs) = graph_and_expected_named ( "single_commit_huge_dates.sh" , "v2" , & [ "HEAD" ] ) ;
15
+ let info = & refs[ "HEAD" ] ;
16
+ let actual = cg. commit_by_id ( info. id ) . expect ( "present" ) ;
17
+ assert_eq ! (
18
+ actual. committer_timestamp( ) ,
19
+ 1 ,
20
+ "overflow happened, can't represent huge dates"
21
+ ) ;
22
+ assert_eq ! (
23
+ info. time. seconds, 68719476737 ,
24
+ "this is the value we would want to see, but it's not possible in V2 either, as that is just about generations"
25
+ ) ;
26
+ assert_eq ! ( actual. generation( ) , 1 , "generations are fine though" ) ;
27
+ }
14
28
15
- Ok ( ( ) )
29
+ #[ test]
30
+ fn single_commit_huge_dates_overflow_v1 ( ) {
31
+ let ( cg, refs) = graph_and_expected_named ( "single_commit_huge_dates.sh" , "v1" , & [ "HEAD" ] ) ;
32
+ let info = & refs[ "HEAD" ] ;
33
+ let actual = cg. commit_by_id ( info. id ) . expect ( "present" ) ;
34
+ assert_eq ! ( actual. committer_timestamp( ) , 1 , "overflow happened" ) ;
35
+ assert_eq ! (
36
+ info. time. seconds, 68719476737 ,
37
+ "this is the value we would want to see, but it's not possible in V1"
38
+ ) ;
39
+ assert_eq ! ( actual. generation( ) , 1 , "generations are fine though" ) ;
16
40
}
17
41
18
42
#[ test]
19
- fn octupus_merges ( ) -> crate :: Result {
20
- let repo_dir = make_readonly_repo ( "octopus_merges.sh" ) ;
21
- let refs = inspect_refs (
22
- & repo_dir,
43
+ fn single_commit_future_64bit_dates_work ( ) {
44
+ let ( cg, refs) = graph_and_expected_named ( "single_commit_huge_dates.sh" , "max-date" , & [ "HEAD" ] ) ;
45
+ let info = & refs[ "HEAD" ] ;
46
+ let actual = cg. commit_by_id ( info. id ) . expect ( "present" ) ;
47
+ assert_eq ! (
48
+ actual. committer_timestamp( ) ,
49
+ info. time. seconds,
50
+ "this is close the the highest representable value in the graph, like year 2500, so we are good for longer than I should care about"
51
+ ) ;
52
+ assert_eq ! ( actual. generation( ) , 1 ) ;
53
+ }
54
+
55
+ #[ test]
56
+ fn generation_numbers_overflow_is_handled ( ) {
57
+ let names = [ "extra" , "old-2" , "future-2" , "old-1" , "future-1" ] ;
58
+ let ( cg, mut refs) = graph_and_expected ( "generation_number_overflow.sh" , & names) ;
59
+ for ( r, expected) in names
60
+ . iter ( )
61
+ . map ( |n| refs. remove ( n. to_owned ( ) ) . expect ( "present" ) )
62
+ . zip ( ( 1 ..=5 ) . rev ( ) )
63
+ {
64
+ assert_eq ! (
65
+ cg. commit_at( r. pos) . generation( ) ,
66
+ expected,
67
+ "actually, this test seems to have valid generation numbers from the get-go. How to repro the actual issue?"
68
+ ) ;
69
+ }
70
+ }
71
+
72
+ #[ test]
73
+ fn octupus_merges ( ) {
74
+ let ( cg, refs) = graph_and_expected (
75
+ "octopus_merges.sh" ,
23
76
& [
24
77
"root" ,
25
78
"parent1" ,
@@ -30,7 +83,6 @@ fn octupus_merges() -> crate::Result {
30
83
"four_parents" ,
31
84
] ,
32
85
) ;
33
- let cg = Graph :: at ( repo_dir. join ( ".git" ) . join ( "objects" ) . join ( "info" ) ) ?;
34
86
check_common ( & cg, & refs) ;
35
87
36
88
assert_eq ! ( cg. commit_at( refs[ "root" ] . pos( ) ) . generation( ) , 1 ) ;
@@ -40,32 +92,22 @@ fn octupus_merges() -> crate::Result {
40
92
assert_eq ! ( cg. commit_at( refs[ "parent4" ] . pos( ) ) . generation( ) , 2 ) ;
41
93
assert_eq ! ( cg. commit_at( refs[ "three_parents" ] . pos( ) ) . generation( ) , 3 ) ;
42
94
assert_eq ! ( cg. commit_at( refs[ "four_parents" ] . pos( ) ) . generation( ) , 3 ) ;
43
-
44
- Ok ( ( ) )
45
95
}
46
96
47
97
#[ test]
48
- fn single_commit ( ) -> crate :: Result {
49
- let repo_dir = make_readonly_repo ( "single_commit.sh" ) ;
50
- let refs = inspect_refs ( & repo_dir, & [ "commit" ] ) ;
51
- let cg = gix_commitgraph:: at ( repo_dir. join ( ".git" ) . join ( "objects" ) . join ( "info" ) ) ?;
98
+ fn single_commit ( ) {
99
+ let ( cg, refs) = graph_and_expected ( "single_commit.sh" , & [ "commit" ] ) ;
52
100
check_common ( & cg, & refs) ;
53
101
54
102
assert_eq ! ( cg. commit_at( refs[ "commit" ] . pos( ) ) . generation( ) , 1 ) ;
55
-
56
- Ok ( ( ) )
57
103
}
58
104
59
105
#[ test]
60
- fn two_parents ( ) -> crate :: Result {
61
- let repo_dir = make_readonly_repo ( "two_parents.sh" ) ;
62
- let refs = inspect_refs ( & repo_dir, & [ "parent1" , "parent2" , "child" ] ) ;
63
- let cg = Graph :: from_info_dir ( repo_dir. join ( ".git" ) . join ( "objects" ) . join ( "info" ) ) ?;
106
+ fn two_parents ( ) {
107
+ let ( cg, refs) = graph_and_expected ( "two_parents.sh" , & [ "parent1" , "parent2" , "child" ] ) ;
64
108
check_common ( & cg, & refs) ;
65
109
66
110
assert_eq ! ( cg. commit_at( refs[ "parent1" ] . pos( ) ) . generation( ) , 1 ) ;
67
111
assert_eq ! ( cg. commit_at( refs[ "parent2" ] . pos( ) ) . generation( ) , 1 ) ;
68
112
assert_eq ! ( cg. commit_at( refs[ "child" ] . pos( ) ) . generation( ) , 2 ) ;
69
-
70
- Ok ( ( ) )
71
113
}
0 commit comments