This repository has no description
1.6 kB
53 lines
1use knot_git::{EntryKind, Identity, NewCommit, Repo, StagedAction, StagedChange};
2use knot_types::{AuthorName, Email, ObjectFormat, Oid, UnixSeconds};
3
4use crate::{GeometricFactor, ObjectCount, Options, PruneGrace, ReflogRetention};
5
6pub fn identity() -> Identity {
7 Identity {
8 name: AuthorName::new("nel"),
9 email: Email::new("nel@oyster.cafe"),
10 time: UnixSeconds::new(1_700_000_000),
11 offset_seconds: 0,
12 }
13}
14
15pub fn empty_tree(format: ObjectFormat) -> Oid {
16 Oid::from(gix::ObjectId::empty_tree(format.kind()))
17}
18
19pub fn commit_on(repo: &Repo, empty_tree: Oid, parents: Vec<Oid>, marker: &str) -> Oid {
20 let tree = repo
21 .write_staged_tree(
22 empty_tree,
23 &[StagedChange {
24 path: knot_types::RepoPath::new(format!("{marker}.txt")).unwrap(),
25 action: StagedAction::Put {
26 content: marker.as_bytes().to_vec(),
27 kind: EntryKind::Blob,
28 },
29 }],
30 )
31 .unwrap();
32 repo.write_commit(&NewCommit {
33 tree,
34 parents,
35 author: identity(),
36 committer: identity(),
37 message: marker.to_string(),
38 extra_headers: Vec::new(),
39 })
40 .unwrap()
41}
42
43pub fn options() -> Options {
44 Options {
45 repack_max_objects: ObjectCount::new(1_000_000),
46 geometric_factor: GeometricFactor::full_repack(),
47 prune_grace: PruneGrace::from_secs(0),
48 reflog_floor: ReflogRetention::from_secs(i64::MAX as u64 / 4),
49 commit_graph: true,
50 multi_pack_index: true,
51 bitmap: true,
52 }
53}