This leads to greater correctness of generation numbers when dealing with certain kinds of commit-graphs.
Showing the changes to gix-commitgraph/tests/commitgraph.rs (1 of 10 files). Show all
Unified · Split
| @@ -8,12 +8,13 @@ use std::{ · 7 unmodified lines | ||
| 8 | 8 | }; |
| 9 | 9 | |
| 10 | 10 | 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; | |
| 13 | 12 | |
| 14 | 13 | mod access; |
| 15 | 14 | |
| 16 | 15 | 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"); | |
| 17 | 18 | assert_eq!( |
| 18 | 19 | usize::try_from(cg.num_commits()).expect("an architecture able to hold 32 bits of integer"), |
| 19 | 20 | expected.len() |
| @@ -39,6 +40,7 @@ pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHa · 19 unmodified lines | ||
| 39 | 40 | |
| 40 | 41 | let commit = cg.commit_at(ref_info.pos()); |
| 41 | 42 | assert_eq!(commit.id(), ref_info.id()); |
| 43 | + assert_eq!(commit.committer_timestamp(), ref_info.time.seconds); | |
| 42 | 44 | assert_eq!(commit.root_tree_id(), ref_info.root_tree_id()); |
| 43 | 45 | assert_eq!( |
| 44 | 46 | 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 | ||
| 59 | 61 | ); |
| 60 | 62 | } |
| 61 | 63 | |
| 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) | |
| 65 | 82 | } |
| 66 | 83 | |
| 67 | 84 | pub struct RefInfo { |
| 68 | 85 | id: gix_hash::ObjectId, |
| 86 | + pub time: gix_date::Time, | |
| 69 | 87 | parent_ids: Vec<gix_hash::ObjectId>, |
| 70 | 88 | pos: GraphPosition, |
| 71 | 89 | root_tree_id: gix_hash::ObjectId, |
| @@ -89,13 +107,13 @@ impl RefInfo { · 17 unmodified lines | ||
| 89 | 107 | } |
| 90 | 108 | } |
| 91 | 109 | |
| 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> { | |
| 93 | 111 | let output = Command::new("git") |
| 94 | 112 | .arg("-C") |
| 95 | 113 | .arg(repo_dir.as_ref()) |
| 96 | 114 | .arg("show") |
| 97 | 115 | .arg("--no-patch") |
| 98 | − .arg("--pretty=format:%S %H %T %P") | |
| 116 | + .arg("--pretty=format:%S %H %T %ct %P") | |
| 99 | 117 | .args(refs) |
| 100 | 118 | .arg("--") |
| 101 | 119 | .env_remove("GIT_DIR") |
| @@ -111,7 +129,8 @@ pub fn inspect_refs(repo_dir: impl AsRef<Path>, refs: &[&'static str]) -> HashMa · 9 unmodified lines | ||
| 111 | 129 | parts[0].to_string(), |
| 112 | 130 | gix_hash::ObjectId::from_hex(parts[1].as_bytes()).expect("40 bytes hex"), |
| 113 | 131 | 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..] | |
| 115 | 134 | .iter() |
| 116 | 135 | .map(|x| gix_hash::ObjectId::from_hex(x.as_bytes()).expect("40 bytes hex")) |
| 117 | 136 | .collect(), |
| @@ -132,13 +151,14 @@ pub fn inspect_refs(repo_dir: impl AsRef<Path>, refs: &[&'static str]) -> HashMa · 14 unmodified lines | ||
| 132 | 151 | infos |
| 133 | 152 | .iter() |
| 134 | 153 | .cloned() |
| 135 | − .map(|(name, id, root_tree_id, parent_ids)| { | |
| 154 | + .map(|(name, id, root_tree_id, time, parent_ids)| { | |
| 136 | 155 | ( |
| 137 | 156 | name, |
| 138 | 157 | RefInfo { |
| 139 | 158 | id, |
| 140 | 159 | parent_ids, |
| 141 | 160 | root_tree_id, |
| 161 | + time, | |
| 142 | 162 | pos: get_pos(&id), |
| 143 | 163 | }, |
| 144 | 164 | ) |