Skip to content

Commit d50bfa9

Browse files
committed
improve tests related to the handling of shallow repos
When commit-graphs are used, it's easily possible for it to point to commits that don't exist anymore as the repo has been shallowed after generating it. Also we should be sure that we can deal with mixed commit-graph present/not-present situations.
1 parent fdee9a2 commit d50bfa9

File tree

7 files changed

+100
-80
lines changed

7 files changed

+100
-80
lines changed

gix/src/revision/walk.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ impl<'repo> Platform<'repo> {
170170
gix_traverse::commit::ancestors::State::default(),
171171
move |oid, buf| repo.objects.find_commit_iter(oid, buf),
172172
{
173+
// Note that specific shallow handling for commit-graphs isn't needed as these contain
174+
// all information there is, and exclude shallow parents to be structurally consistent.
173175
let shallow_commits = repo.shallow_commits()?;
174176
let mut grafted_parents_to_skip = Vec::new();
175177
let mut buf = Vec::new();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:2898513038dbd39a50856789cea432ddc48e8bf545e33dc5af394f7834cdb857
3-
size 10520
2+
oid sha256:1edbe089c9931dc56e9089683324a73b03fb51d10b3405f2d61487ddb22f4da8
3+
size 10588
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:c56c269562ef67b1f8bd46640e6ad9d196cbc9c7c609300ffd6a8da3bc501852
3-
size 12632
2+
oid sha256:89bc9094b1e483b928fd734b4d39a3e4f25e9c6ed35aa4d900a4198d209948dc
3+
size 12636

gix/tests/fixtures/make_repo_with_fork_and_dates.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ GIT_COMMITTER_DATE="2001-01-02 00:00:00 +0000" git commit -q --allow-empty -m b1
1616
git checkout -q main
1717
GIT_COMMITTER_DATE="2000-01-02 00:00:00 +0000" git commit -q --allow-empty -m c2 #9902e3c3e8f0c569b4ab295ddf473e6de763e1e7-
1818

19-
# Commit from branch1 made in 2001 merged in 2002
20-
GIT_COMMITTER_DATE="2002-01-02 00:00:00 +0000" git merge branch1 -m m1b1 #288e509293165cb5630d08f4185bdf2445bf6170-
2119

2220
git commit-graph write --no-progress --reachable
2321
git repack -adq
22+
23+
# Commit from branch1 made in 2001 merged in 2002
24+
GIT_COMMITTER_DATE="2002-01-02 00:00:00 +0000" git merge branch1 -m m1b1 #288e509293165cb5630d08f4185bdf2445bf6170-

gix/tests/fixtures/make_shallow_repo.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ mkdir empty
2525
)
2626

2727
git clone --depth 1 --bare file://$PWD/base shallow.git
28+
git -C shallow.git commit-graph write --no-progress --reachable
29+
2830
git clone --depth 1 file://$PWD/base shallow
31+
git -C shallow commit-graph write --no-progress --reachable

gix/tests/id/mod.rs

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,35 +74,43 @@ mod ancestors {
7474
#[test]
7575
fn all() -> crate::Result {
7676
let repo = crate::repo("make_repo_with_fork_and_dates.sh")?.to_thread_local();
77-
let head = repo.head()?.into_fully_peeled_id().expect("born")?;
78-
let commits_graph_order = head
79-
.ancestors()
80-
.all()?
81-
.map(|c| c.map(|c| c.detach()))
82-
.collect::<Result<Vec<_>, _>>()?;
83-
assert_eq!(commits_graph_order.len(), 4, "need a specific amount of commits");
77+
for toggle in [false, true] {
78+
let head = repo.head()?.into_fully_peeled_id().expect("born")?;
79+
let commits_graph_order = head
80+
.ancestors()
81+
.use_commit_graph(toggle)
82+
.all()?
83+
.map(|c| c.map(|c| c.detach()))
84+
.collect::<Result<Vec<_>, _>>()?;
85+
assert_eq!(commits_graph_order.len(), 4, "need a specific amount of commits");
8486

85-
let commits_by_commit_date = head
86-
.ancestors()
87-
.sorting(commit::Sorting::ByCommitTimeNewestFirst)
88-
.all()?
89-
.map(|c| c.map(|c| c.detach()))
90-
.collect::<Result<Vec<_>, _>>()?;
91-
assert_eq!(
92-
commits_by_commit_date.len(),
93-
4,
94-
"need a specific amount of commits, ordering doesn't affect that"
95-
);
96-
assert_ne!(
97-
commits_by_commit_date, commits_graph_order,
98-
"these are ordered differently"
99-
);
87+
let commits_by_commit_date = head
88+
.ancestors()
89+
.use_commit_graph(!toggle)
90+
.sorting(commit::Sorting::ByCommitTimeNewestFirst)
91+
.all()?
92+
.map(|c| c.map(|c| c.detach()))
93+
.collect::<Result<Vec<_>, _>>()?;
94+
assert_eq!(
95+
commits_by_commit_date.len(),
96+
4,
97+
"need a specific amount of commits, ordering doesn't affect that"
98+
);
99+
assert_ne!(
100+
commits_by_commit_date, commits_graph_order,
101+
"these are ordered differently"
102+
);
100103

101-
assert_eq!(
102-
head.ancestors().first_parent_only().all()?.count(),
103-
3,
104-
"It skips merges this way."
105-
);
104+
assert_eq!(
105+
head.ancestors()
106+
.first_parent_only()
107+
.use_commit_graph(toggle)
108+
.all()?
109+
.count(),
110+
3,
111+
"It skips merges this way."
112+
);
113+
}
106114
Ok(())
107115
}
108116

gix/tests/repository/shallow.rs

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,18 @@ mod traverse {
5252
#[test]
5353
#[parallel]
5454
fn boundary_is_detected_triggering_no_error() -> crate::Result {
55-
for name in ["shallow.git", "shallow"] {
56-
let repo = named_subrepo_opts("make_shallow_repo.sh", name, crate::restricted())?;
57-
let commits: Vec<_> = repo
58-
.head_id()?
59-
.ancestors()
60-
.all()?
61-
.map(|c| c.map(|c| c.id))
62-
.collect::<Result<_, _>>()?;
63-
assert_eq!(commits, [hex_to_id("30887839de28edf7ab66c860e5c58b4d445f6b12")]);
55+
for toggle in [false, true] {
56+
for name in ["shallow.git", "shallow"] {
57+
let repo = named_subrepo_opts("make_shallow_repo.sh", name, crate::restricted())?;
58+
let commits: Vec<_> = repo
59+
.head_id()?
60+
.ancestors()
61+
.use_commit_graph(toggle)
62+
.all()?
63+
.map(|c| c.map(|c| c.id))
64+
.collect::<Result<_, _>>()?;
65+
assert_eq!(commits, [hex_to_id("30887839de28edf7ab66c860e5c58b4d445f6b12")]);
66+
}
6467
}
6568
Ok(())
6669
}
@@ -73,45 +76,48 @@ mod traverse {
7376
"make_complex_shallow_repo.sh",
7477
Some(base.to_string_lossy()),
7578
)?;
76-
for name in ["shallow.git", "shallow"] {
77-
let repo = gix::open_opts(shallow_base.join(name), crate::restricted())?;
78-
assert_eq!(
79-
repo.shallow_commits()?.expect("present").as_slice(),
80-
[
81-
hex_to_id("27e71576a6335294aa6073ab767f8b36bdba81d0"),
82-
hex_to_id("82024b2ef7858273337471cbd1ca1cedbdfd5616"),
83-
hex_to_id("b5152869aedeb21e55696bb81de71ea1bb880c85"),
84-
]
85-
);
86-
let commits: Vec<_> = repo
87-
.head_id()?
88-
.ancestors()
89-
.sorting(Sorting::ByCommitTimeNewestFirst)
90-
.all()?
91-
.map(|c| c.map(|c| c.id))
92-
.collect::<Result<_, _>>()?;
93-
assert_eq!(
94-
commits,
95-
[
96-
"f99771fe6a1b535783af3163eba95a927aae21d5",
97-
"2d9d136fb0765f2e24c44a0f91984318d580d03b",
98-
"dfd0954dabef3b64f458321ef15571cc1a46d552",
99-
"b5152869aedeb21e55696bb81de71ea1bb880c85",
100-
"27e71576a6335294aa6073ab767f8b36bdba81d0",
101-
"82024b2ef7858273337471cbd1ca1cedbdfd5616",
102-
]
103-
.into_iter()
104-
.map(hex_to_id)
105-
.collect::<Vec<_>>()
106-
);
79+
for toggle in [false, true] {
80+
for name in ["shallow.git", "shallow"] {
81+
let repo = gix::open_opts(shallow_base.join(name), crate::restricted())?;
82+
assert_eq!(
83+
repo.shallow_commits()?.expect("present").as_slice(),
84+
[
85+
hex_to_id("27e71576a6335294aa6073ab767f8b36bdba81d0"),
86+
hex_to_id("82024b2ef7858273337471cbd1ca1cedbdfd5616"),
87+
hex_to_id("b5152869aedeb21e55696bb81de71ea1bb880c85"),
88+
]
89+
);
90+
let commits: Vec<_> = repo
91+
.head_id()?
92+
.ancestors()
93+
.use_commit_graph(toggle)
94+
.sorting(Sorting::ByCommitTimeNewestFirst)
95+
.all()?
96+
.map(|c| c.map(|c| c.id))
97+
.collect::<Result<_, _>>()?;
98+
assert_eq!(
99+
commits,
100+
[
101+
"f99771fe6a1b535783af3163eba95a927aae21d5",
102+
"2d9d136fb0765f2e24c44a0f91984318d580d03b",
103+
"dfd0954dabef3b64f458321ef15571cc1a46d552",
104+
"b5152869aedeb21e55696bb81de71ea1bb880c85",
105+
"27e71576a6335294aa6073ab767f8b36bdba81d0",
106+
"82024b2ef7858273337471cbd1ca1cedbdfd5616",
107+
]
108+
.into_iter()
109+
.map(hex_to_id)
110+
.collect::<Vec<_>>()
111+
);
107112

108-
// should be
109-
// * f99771f - (HEAD -> main, origin/main, origin/HEAD) A (18 years ago) <A U Thor>
110-
// | * 2d9d136 - C (18 years ago) <A U Thor>
111-
// *-. | dfd0954 - (tag: b-tag) B (18 years ago) <A U Thor>
112-
// | | * 27e7157 - (grafted) F (18 years ago) <A U Thor>
113-
// | * b515286 - (grafted) E (18 years ago) <A U Thor>
114-
// * 82024b2 - (grafted) D (18 years ago) <A U Thor>
113+
// should be
114+
// * f99771f - (HEAD -> main, origin/main, origin/HEAD) A (18 years ago) <A U Thor>
115+
// | * 2d9d136 - C (18 years ago) <A U Thor>
116+
// *-. | dfd0954 - (tag: b-tag) B (18 years ago) <A U Thor>
117+
// | | * 27e7157 - (grafted) F (18 years ago) <A U Thor>
118+
// | * b515286 - (grafted) E (18 years ago) <A U Thor>
119+
// * 82024b2 - (grafted) D (18 years ago) <A U Thor>
120+
}
115121
}
116122
Ok(())
117123
}

0 commit comments

Comments
 (0)