Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

reproduce and fix 1850 #1851

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion gix-features/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,21 @@ pub mod walkdir {
///
/// Use `precompose_unicode` to represent the `core.precomposeUnicode` configuration option.
pub fn walkdir_sorted_new(root: &Path, _: Parallelism, precompose_unicode: bool) -> WalkDir {
fn ft_to_number(ft: std::fs::FileType) -> usize {
if ft.is_file() {
1
} else {
2
}
}
WalkDir {
inner: WalkDirImpl::new(root).sort_by_file_name().into(),
inner: WalkDirImpl::new(root)
.sort_by(|a, b| {
ft_to_number(a.file_type())
.cmp(&ft_to_number(b.file_type()))
.then_with(|| a.file_name().cmp(b.file_name()))
})
.into(),
precompose_unicode,
}
}
Expand Down
1 change: 1 addition & 0 deletions gix-ref/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ gix-hash = { path = "../../gix-hash" }
gix-validate = { path = "../../gix-validate" }
gix-lock = { path = "../../gix-lock" }
gix-object = { path = "../../gix-object" }
insta = "1.42.1"
Binary file not shown.
17 changes: 17 additions & 0 deletions gix-ref/tests/fixtures/make_repo_for_1850_repro.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -eu -o pipefail

git init -q

cat <<EOF >.git/packed-refs
# pack-refs with: peeled fully-peeled sorted
17dad46c0ce3be4d4b6d45def031437ab2e40666 refs/heads/ig-branch-remote
83a70366fcc1255d35a00102138293bac673b331 refs/heads/ig-inttest
21b57230833a1733f6685e14eabe936a09689a1b refs/heads/ig-pr4021
d773228d0ee0012fcca53fffe581b0fce0b1dc56 refs/heads/ig/aliases
ba37abe04f91fec76a6b9a817d40ee2daec47207 refs/heads/ig/cifail
EOF

mkdir -p .git/refs/heads/ig/pr
echo d22f46f3d7d2504d56c573b5fe54919bd16be48a >.git/refs/heads/ig/push-name
echo 4dec145966c546402c5a9e28b932e7c8c939e01e >.git/refs/heads/ig-pr4021
67 changes: 59 additions & 8 deletions gix-ref/tests/refs/file/store/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ mod with_namespace {
.map(|r: gix_ref::Reference| r.name)
.collect::<Vec<_>>();
let expected_namespaced_refs = vec![
"refs/namespaces/bar/refs/heads/multi-link-target1",
"refs/namespaces/bar/refs/multi-link",
"refs/namespaces/bar/refs/heads/multi-link-target1",
"refs/namespaces/bar/refs/remotes/origin/multi-link-target3",
"refs/namespaces/bar/refs/tags/multi-link-target2",
];
Expand All @@ -50,8 +50,8 @@ mod with_namespace {
.map(|r| r.name.into_inner())
.collect::<Vec<_>>(),
[
"refs/namespaces/bar/refs/heads/multi-link-target1",
"refs/namespaces/bar/refs/multi-link",
"refs/namespaces/bar/refs/heads/multi-link-target1",
"refs/namespaces/bar/refs/tags/multi-link-target2"
]
);
Expand Down Expand Up @@ -149,8 +149,8 @@ mod with_namespace {
let packed = ns_store.open_packed_buffer()?;

let expected_refs = vec![
"refs/heads/multi-link-target1",
"refs/multi-link",
"refs/heads/multi-link-target1",
"refs/remotes/origin/multi-link-target3",
"refs/tags/multi-link-target2",
];
Expand Down Expand Up @@ -198,8 +198,8 @@ mod with_namespace {
.map(|r| r.name.into_inner())
.collect::<Vec<_>>(),
[
"refs/heads/multi-link-target1",
"refs/multi-link",
"refs/heads/multi-link-target1",
"refs/tags/multi-link-target2",
],
"loose iterators have namespace support as well"
Expand All @@ -214,8 +214,8 @@ mod with_namespace {
.map(|r| r.name.into_inner())
.collect::<Vec<_>>(),
[
"refs/namespaces/bar/refs/heads/multi-link-target1",
"refs/namespaces/bar/refs/multi-link",
"refs/namespaces/bar/refs/heads/multi-link-target1",
"refs/namespaces/bar/refs/tags/multi-link-target2",
"refs/namespaces/foo/refs/remotes/origin/HEAD"
],
Expand Down Expand Up @@ -291,14 +291,14 @@ fn loose_iter_with_broken_refs() -> crate::Result {
ref_paths,
vec![
"d1",
"loop-a",
"loop-b",
"multi-link",
"heads/A",
"heads/d1",
"heads/dt1",
"heads/main",
"heads/multi-link-target1",
"loop-a",
"loop-b",
"multi-link",
"remotes/origin/HEAD",
"remotes/origin/main",
"remotes/origin/multi-link-target3",
Expand Down Expand Up @@ -413,6 +413,57 @@ fn overlay_iter() -> crate::Result {
Ok(())
}

#[test]
fn overlay_iter_reproduce_1850() -> crate::Result {
let store = store_at("make_repo_for_1850_repro.sh")?;
let ref_names = store
.iter()?
.all()?
.map(|r| r.map(|r| (r.name.as_bstr().to_owned(), r.target)))
.collect::<Result<Vec<_>, _>>()?;
insta::assert_debug_snapshot!(ref_names, @r#"
[
(
"refs/heads/ig-branch-remote",
Object(
Sha1(17dad46c0ce3be4d4b6d45def031437ab2e40666),
),
),
(
"refs/heads/ig-inttest",
Object(
Sha1(83a70366fcc1255d35a00102138293bac673b331),
),
),
(
"refs/heads/ig-pr4021",
Object(
Sha1(4dec145966c546402c5a9e28b932e7c8c939e01e),
),
),
(
"refs/heads/ig/aliases",
Object(
Sha1(d773228d0ee0012fcca53fffe581b0fce0b1dc56),
),
),
(
"refs/heads/ig/cifail",
Object(
Sha1(ba37abe04f91fec76a6b9a817d40ee2daec47207),
),
),
(
"refs/heads/ig/push-name",
Object(
Sha1(d22f46f3d7d2504d56c573b5fe54919bd16be48a),
),
),
]
"#);
Ok(())
}

#[test]
fn overlay_iter_with_prefix_wont_allow_absolute_paths() -> crate::Result {
let store = store_with_packed_refs()?;
Expand Down
2 changes: 1 addition & 1 deletion gix/tests/gix/repository/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ mod iter_references {
"refs/heads/d1",
"refs/heads/dt1",
"refs/heads/main",
"refs/heads/multi-link-target1",
"refs/loop-a",
"refs/loop-b",
"refs/multi-link",
"refs/heads/multi-link-target1",
"refs/remotes/origin/HEAD",
"refs/remotes/origin/main",
"refs/remotes/origin/multi-link-target3",
Expand Down
Loading