Skip to content

Commit 68fd5b3

Browse files
committed
Merge branch 'status'
2 parents 977346e + 28a7afc commit 68fd5b3

File tree

8 files changed

+86
-50
lines changed

8 files changed

+86
-50
lines changed

Cargo.lock

+12-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deny.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ yanked = "warn"
2222
# 2019-12-17 there are no security notice advisories in
2323
# https://github.com/rustsec/advisory-db
2424
notice = "warn"
25-
ignore = []
25+
ignore = [
26+
# this is `[email protected]` coming in with `curl`, which doesn't have an update yet. It's only active optionally, not by default.
27+
"RUSTSEC-2024-0336",
28+
]
2629

2730

2831

gix-date/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ pub use parse::function::parse;
2323
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
2424
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2525
pub struct Time {
26-
/// time in seconds since epoch.
26+
/// The seconds that passed since UNIX epoch. This makes it UTC, or `<seconds>+0000`.
2727
pub seconds: SecondsSinceUnixEpoch,
28-
/// time offset in seconds, may be negative to match the `sign` field.
28+
/// The time's offset in seconds, which may be negative to match the `sign` field.
2929
pub offset: OffsetInSeconds,
30-
/// the sign of `offset`, used to encode `-0000` which would otherwise loose sign information.
30+
/// the sign of `offset`, used to encode `-0000` which would otherwise lose sign information.
3131
pub sign: time::Sign,
3232
}
3333

gix-dir/src/walk/classify.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ pub fn root(
2121
let mut path_buf = worktree_root.to_owned();
2222
// These initial values kick in if worktree_relative_root.is_empty();
2323
let file_kind = path_buf.symlink_metadata().map(|m| m.file_type().into()).ok();
24-
let pathspec_orig = std::mem::replace(
25-
ctx.pathspec,
26-
gix_pathspec::Search::from_specs(None, None, "".as_ref()).expect("empty is valid"),
27-
);
28-
let res = path(&mut path_buf, buf, 0, file_kind, || None, options, ctx);
29-
*ctx.pathspec = pathspec_orig;
30-
let mut out = res?;
24+
let mut out = path(&mut path_buf, buf, 0, file_kind, || None, options, ctx)?;
3125
let worktree_root_is_repository = out
3226
.disk_kind
3327
.map_or(false, |kind| matches!(kind, entry::Kind::Repository));
@@ -59,9 +53,6 @@ pub fn root(
5953
}
6054
last_length = Some(buf.len());
6155
}
62-
if out.pathspec_match.is_none() {
63-
out.pathspec_match = Some(PathspecMatch::Always);
64-
}
6556
Ok((out, worktree_root_is_repository))
6657
}
6758
/// The product of [`path()`] calls.
@@ -181,10 +172,9 @@ pub fn path(
181172
out.property = entry::Property::DotGit.into();
182173
return Ok(out);
183174
}
184-
let pathspec_could_match = rela_path.is_empty()
185-
|| ctx
186-
.pathspec
187-
.can_match_relative_path(rela_path.as_bstr(), disk_kind.map(|ft| ft.is_dir()));
175+
let pathspec_could_match = ctx
176+
.pathspec
177+
.can_match_relative_path(rela_path.as_bstr(), disk_kind.map(|ft| ft.is_dir()));
188178
if !pathspec_could_match {
189179
return Ok(out.with_status(entry::Status::Pruned));
190180
}

gix-dir/tests/walk/mod.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -2732,7 +2732,7 @@ fn worktree_root_can_be_symlink() -> crate::Result {
27322732
#[test]
27332733
fn root_may_not_go_through_dot_git() -> crate::Result {
27342734
let root = fixture("with-nested-dot-git");
2735-
for (dir, expected_pathspec) in [("", Verbatim), ("subdir", Always)] {
2735+
for (dir, expected_pathspec) in [("", Some(Verbatim)), ("subdir", None)] {
27362736
let troot = root.join("dir").join(".git").join(dir);
27372737
let ((out, _root), entries) = collect(&root, Some(&troot), |keep, ctx| {
27382738
walk(&root, ctx, options_emit_all(), keep)
@@ -2747,9 +2747,11 @@ fn root_may_not_go_through_dot_git() -> crate::Result {
27472747
);
27482748
assert_eq!(
27492749
entries,
2750-
[entry("dir/.git", Pruned, Directory)
2751-
.with_property(DotGit)
2752-
.with_match(expected_pathspec)],
2750+
[{
2751+
let mut e = entry("dir/.git", Pruned, Directory).with_property(DotGit);
2752+
e.0.pathspec_match = expected_pathspec;
2753+
e
2754+
}],
27532755
"{dir}: no traversal happened as root passes though .git"
27542756
);
27552757
}
@@ -3165,7 +3167,7 @@ fn root_can_be_pruned_early_with_pathspec() -> crate::Result {
31653167

31663168
assert_eq!(
31673169
entries,
3168-
[entry("dir", Pruned, Directory)],
3170+
[entry_nomatch("dir", Pruned, Directory)],
31693171
"the pathspec didn't match the root, early abort"
31703172
);
31713173
Ok(())
@@ -3927,7 +3929,7 @@ fn untracked_and_ignored_collapse_mix() {
39273929
#[test]
39283930
fn root_cannot_pass_through_case_altered_capital_dot_git_if_case_insensitive() -> crate::Result {
39293931
let root = fixture("with-nested-capitalized-dot-git");
3930-
for (dir, expected_pathspec) in [("", Verbatim), ("subdir", Always)] {
3932+
for (dir, expected_pathspec) in [("", Some(Verbatim)), ("subdir", None)] {
39313933
let troot = root.join("dir").join(".GIT").join(dir);
39323934
let ((out, _root), entries) = collect(&root, Some(&troot), |keep, ctx| {
39333935
walk(
@@ -3950,9 +3952,11 @@ fn root_cannot_pass_through_case_altered_capital_dot_git_if_case_insensitive() -
39503952
);
39513953
assert_eq!(
39523954
entries,
3953-
[entry("dir/.GIT", Pruned, Directory)
3954-
.with_property(DotGit)
3955-
.with_match(expected_pathspec)],
3955+
[{
3956+
let mut e = entry("dir/.GIT", Pruned, Directory).with_property(DotGit);
3957+
e.0.pathspec_match = expected_pathspec;
3958+
e
3959+
}],
39563960
"{dir}: no traversal happened as root passes though .git, it compares in a case-insensitive fashion"
39573961
);
39583962
}

gix-pathspec/src/search/matching.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ impl Search {
3131
is_dir: Option<bool>,
3232
attributes: &mut dyn FnMut(&BStr, Case, bool, &mut gix_attributes::search::Outcome) -> bool,
3333
) -> Option<Match<'_>> {
34+
static MATCH_ALL_STAND_IN: Pattern = Pattern {
35+
path: BString::new(Vec::new()),
36+
signature: MagicSignature::empty(),
37+
search_mode: SearchMode::ShellGlob,
38+
attributes: Vec::new(),
39+
prefix_len: 0,
40+
nil: true,
41+
};
42+
if relative_path.is_empty() {
43+
return Some(Match {
44+
pattern: &MATCH_ALL_STAND_IN,
45+
sequence_number: 0,
46+
kind: Always,
47+
});
48+
}
3449
let basename_not_important = None;
3550
if relative_path
3651
.get(..self.common_prefix_len)
@@ -106,14 +121,6 @@ impl Search {
106121
});
107122

108123
if res.is_none() && self.all_patterns_are_excluded {
109-
static MATCH_ALL_STAND_IN: Pattern = Pattern {
110-
path: BString::new(Vec::new()),
111-
signature: MagicSignature::empty(),
112-
search_mode: SearchMode::ShellGlob,
113-
attributes: Vec::new(),
114-
prefix_len: 0,
115-
nil: true,
116-
};
117124
Some(Match {
118125
pattern: &MATCH_ALL_STAND_IN,
119126
sequence_number: patterns_len,
@@ -133,7 +140,7 @@ impl Search {
133140
/// is ignored.
134141
/// Returns `false` if this pathspec has no chance of ever matching `relative_path`.
135142
pub fn can_match_relative_path(&self, relative_path: &BStr, is_dir: Option<bool>) -> bool {
136-
if self.patterns.is_empty() {
143+
if self.patterns.is_empty() || relative_path.is_empty() {
137144
return true;
138145
}
139146
let common_prefix_len = self.common_prefix_len.min(relative_path.len());
@@ -194,7 +201,7 @@ impl Search {
194201
/// When `leading` is `true`, then `d` matches `d/d` as well. Thus, `relative_path` must may be
195202
/// partially included in `pathspec`, otherwise it has to be fully included.
196203
pub fn directory_matches_prefix(&self, relative_path: &BStr, leading: bool) -> bool {
197-
if self.patterns.is_empty() {
204+
if self.patterns.is_empty() || relative_path.is_empty() {
198205
return true;
199206
}
200207
let common_prefix_len = self.common_prefix_len.min(relative_path.len());

gix-pathspec/tests/search/mod.rs

+25
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,31 @@ fn directory_matches_prefix_starting_wildcards_always_match() -> crate::Result {
5757
Ok(())
5858
}
5959

60+
#[test]
61+
fn empty_dir_always_matches() -> crate::Result {
62+
for specs in [
63+
&["*ir"] as &[_],
64+
&[],
65+
&["included", ":!excluded"],
66+
&[":!all", ":!excluded"],
67+
] {
68+
let mut search = gix_pathspec::Search::from_specs(pathspecs(specs), None, Path::new(""))?;
69+
assert_eq!(
70+
search
71+
.pattern_matching_relative_path("".into(), None, &mut no_attrs)
72+
.map(|m| m.kind),
73+
Some(Always),
74+
"{specs:?}"
75+
);
76+
assert!(search.directory_matches_prefix("".into(), false));
77+
assert!(search.directory_matches_prefix("".into(), false));
78+
for is_dir in [Some(true), Some(false), None] {
79+
assert!(search.can_match_relative_path("".into(), is_dir));
80+
}
81+
}
82+
Ok(())
83+
}
84+
6085
#[test]
6186
fn directory_matches_prefix_leading() -> crate::Result {
6287
let search = gix_pathspec::Search::from_specs(pathspecs(&["d/d/generated/b"]), None, Path::new(""))?;

gix-ref/src/store/file/packed.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,14 @@ pub(crate) mod modifiable {
8484
pub(crate) type MutableSharedBuffer = OwnShared<gix_fs::SharedFileSnapshotMut<packed::Buffer>>;
8585

8686
impl file::Store {
87-
pub(crate) fn force_refresh_packed_buffer(&self) -> Result<(), packed::buffer::open::Error> {
87+
/// Forcefully reload the packed refs buffer.
88+
///
89+
/// This method should be used if it's clear that the buffer on disk has changed, to
90+
/// make the latest changes visible before other operations are done on this instance.
91+
///
92+
/// As some filesystems don't have nanosecond granularity, changes are likely to be missed
93+
/// if they happen within one second otherwise.
94+
pub fn force_refresh_packed_buffer(&self) -> Result<(), packed::buffer::open::Error> {
8895
self.packed.force_refresh(|| {
8996
let modified = self.packed_refs_path().metadata()?.modified()?;
9097
self.open_packed_buffer().map(|packed| Some(modified).zip(packed))

0 commit comments

Comments
 (0)