Build a real Git repository with a linear chain of commits, each committed at the exact same committer time (so every ordering decision inside a level must come from the tie-break rules).
(commits: usize, committer_time: i64)
| 10406 | /// committed at the exact same committer time (so every ordering decision |
| 10407 | /// inside a level must come from the tie-break rules). |
| 10408 | fn chained_git_repo(commits: usize, committer_time: i64) -> (tempfile::TempDir, GitRepository) { |
| 10409 | let temp = tempfile::TempDir::new().unwrap(); |
| 10410 | let repo = GitRepository::init(temp.path()).unwrap(); |
| 10411 | repo.set_head("refs/heads/main").unwrap(); |
| 10412 | let signature = git2::Signature::new( |
| 10413 | "Shim", |
| 10414 | "shim@example.com", |
| 10415 | &git2::Time::new(committer_time, 0), |
| 10416 | ) |
| 10417 | .unwrap(); |
| 10418 | let mut parent: Option<git2::Oid> = None; |
| 10419 | for index in 0..commits { |
| 10420 | let name = format!("file-{index:04}.txt"); |
| 10421 | fs::write( |
| 10422 | temp.path().join(&name), |
| 10423 | format!("content {index}\n").as_bytes(), |
| 10424 | ) |
| 10425 | .unwrap(); |
| 10426 | let mut tree_index = repo.index().unwrap(); |
| 10427 | tree_index.add_path(Path::new(&name)).unwrap(); |
| 10428 | tree_index.write().unwrap(); |
| 10429 | let tree = repo.find_tree(tree_index.write_tree().unwrap()).unwrap(); |
| 10430 | let parent_commit = parent.map(|oid| repo.find_commit(oid).unwrap()); |
| 10431 | let parents: Vec<&git2::Commit> = match &parent_commit { |
| 10432 | Some(commit) => vec![commit], |
| 10433 | None => Vec::new(), |
| 10434 | }; |
| 10435 | parent = Some( |
| 10436 | repo.commit( |
| 10437 | Some("refs/heads/main"), |
| 10438 | &signature, |
| 10439 | &signature, |
| 10440 | &name, |
| 10441 | &tree, |
| 10442 | &parents, |
| 10443 | ) |
| 10444 | .unwrap(), |
| 10445 | ); |
| 10446 | } |
| 10447 | (temp, repo) |
| 10448 | } |
| 10449 | |
| 10450 | #[test] |
| 10451 | fn shim_sequencing_orders_parents_before_children_and_is_deterministic() { |