History

feat: support for 'generation v2' format for overlow correction in generations.

This leads to greater correctness of generation numbers when dealing with certain kinds of commit-graphs.

Sebastian Thiel committed 3 years ago

Commit 101dec01 parent b82edc810 files · +178 −38Browse files

Showing the changes to gix-commitgraph/tests/commitgraph.rs (1 of 10 files). Show all

Unified · Split

gix-commitgraph/tests/commitgraph.rs+29−9
@@ -8,12 +8,13 @@ use std::{ · 7 unmodified lines
88 };
99
1010 use gix_commitgraph::{Graph, Position as GraphPosition};
11−
12−type Result = std::result::Result<(), Box<dyn std::error::Error>>;
11+use gix_testtools::scripted_fixture_read_only;
1312
1413 mod access;
1514
1615 pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHasher>) {
16+ cg.verify_integrity(|_| Ok::<_, std::convert::Infallible>(()))
17+ .expect("graph is valid");
1718 assert_eq!(
1819 usize::try_from(cg.num_commits()).expect("an architecture able to hold 32 bits of integer"),
1920 expected.len()
@@ -39,6 +40,7 @@ pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHa · 19 unmodified lines
3940
4041 let commit = cg.commit_at(ref_info.pos());
4142 assert_eq!(commit.id(), ref_info.id());
43+ assert_eq!(commit.committer_timestamp(), ref_info.time.seconds);
4244 assert_eq!(commit.root_tree_id(), ref_info.root_tree_id());
4345 assert_eq!(
4446 commit.parent1().expect("failed to access commit's parent1"),
@@ -59,13 +61,29 @@ pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHa · 14 unmodified lines
5961 );
6062 }
6163
62−use gix_testtools::scripted_fixture_read_only;
63−pub fn make_readonly_repo(script_path: &str) -> std::path::PathBuf {
64− scripted_fixture_read_only(script_path).expect("script succeeds all the time")
64+pub fn graph_and_expected(
65+ script_path: &str,
66+ refs: &[&'static str],
67+) -> (gix_commitgraph::Graph, HashMap<String, RefInfo>) {
68+ graph_and_expected_named(script_path, "", refs)
69+}
70+
71+pub fn graph_and_expected_named(
72+ script_path: &str,
73+ name: &str,
74+ refs: &[&'static str],
75+) -> (gix_commitgraph::Graph, HashMap<String, RefInfo>) {
76+ let repo_dir = scripted_fixture_read_only(script_path)
77+ .expect("script succeeds all the time")
78+ .join(name);
79+ let expected = inspect_refs(&repo_dir, refs);
80+ let cg = Graph::from_info_dir(repo_dir.join(".git").join("objects").join("info")).expect("graph present and valid");
81+ (cg, expected)
6582 }
6683
6784 pub struct RefInfo {
6885 id: gix_hash::ObjectId,
86+ pub time: gix_date::Time,
6987 parent_ids: Vec<gix_hash::ObjectId>,
7088 pos: GraphPosition,
7189 root_tree_id: gix_hash::ObjectId,
@@ -89,13 +107,13 @@ impl RefInfo { · 17 unmodified lines
89107 }
90108 }
91109
92−pub fn inspect_refs(repo_dir: impl AsRef<Path>, refs: &[&'static str]) -> HashMap<String, RefInfo> {
110+fn inspect_refs(repo_dir: impl AsRef<Path>, refs: &[&'static str]) -> HashMap<String, RefInfo> {
93111 let output = Command::new("git")
94112 .arg("-C")
95113 .arg(repo_dir.as_ref())
96114 .arg("show")
97115 .arg("--no-patch")
98− .arg("--pretty=format:%S %H %T %P")
116+ .arg("--pretty=format:%S %H %T %ct %P")
99117 .args(refs)
100118 .arg("--")
101119 .env_remove("GIT_DIR")
@@ -111,7 +129,8 @@ pub fn inspect_refs(repo_dir: impl AsRef<Path>, refs: &[&'static str]) -> HashMa · 9 unmodified lines
111129 parts[0].to_string(),
112130 gix_hash::ObjectId::from_hex(parts[1].as_bytes()).expect("40 bytes hex"),
113131 gix_hash::ObjectId::from_hex(parts[2].as_bytes()).expect("40 bytes hex"),
114− parts[3..]
132+ gix_date::Time::new(parts[3].parse().expect("valid stamp"), 0),
133+ parts[4..]
115134 .iter()
116135 .map(|x| gix_hash::ObjectId::from_hex(x.as_bytes()).expect("40 bytes hex"))
117136 .collect(),
@@ -132,13 +151,14 @@ pub fn inspect_refs(repo_dir: impl AsRef<Path>, refs: &[&'static str]) -> HashMa · 14 unmodified lines
132151 infos
133152 .iter()
134153 .cloned()
135− .map(|(name, id, root_tree_id, parent_ids)| {
154+ .map(|(name, id, root_tree_id, time, parent_ids)| {
136155 (
137156 name,
138157 RefInfo {
139158 id,
140159 parent_ids,
141160 root_tree_id,
161+ time,
142162 pos: get_pos(&id),
143163 },
144164 )