Skip to content

Commit 56a8ea8

Browse files
committed
adapt to changes in gix
1 parent 33065b6 commit 56a8ea8

File tree

6 files changed

+55
-43
lines changed

6 files changed

+55
-43
lines changed

gitoxide-core/src/query/engine/command.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ impl query::Engine {
2323
let relpath = self
2424
.repo
2525
.pathspec(
26+
true,
2627
Some(spec.to_bstring()),
2728
false,
2829
&gix::index::State::new(self.repo.object_hash()),

gitoxide-core/src/repository/attributes/query.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct Options {
1010
pub(crate) mod function {
1111
use std::{borrow::Cow, io, path::Path};
1212

13-
use anyhow::{anyhow, bail};
13+
use anyhow::bail;
1414
use gix::bstr::BStr;
1515

1616
use crate::{
@@ -52,43 +52,45 @@ pub(crate) mod function {
5252
}
5353
PathsOrPatterns::Patterns(patterns) => {
5454
let mut pathspec = repo.pathspec(
55+
true,
5556
patterns.iter(),
5657
true,
5758
&index,
5859
gix::worktree::stack::state::attributes::Source::WorktreeThenIdMapping
5960
.adjust_for_bare(repo.is_bare()),
6061
)?;
6162
let mut pathspec_matched_entry = false;
62-
for (path, _entry) in pathspec
63-
.index_entries_with_paths(&index)
64-
.ok_or_else(|| anyhow!("Pathspec didn't match a single path in the index"))?
65-
{
66-
pathspec_matched_entry = true;
67-
let entry = cache.at_entry(path, Some(false))?;
68-
if !entry.matching_attributes(&mut matches) {
69-
continue;
63+
if let Some(it) = pathspec.index_entries_with_paths(&index) {
64+
for (path, _entry) in it {
65+
pathspec_matched_entry = true;
66+
let entry = cache.at_entry(path, Some(false))?;
67+
if !entry.matching_attributes(&mut matches) {
68+
continue;
69+
}
70+
print_match(&matches, path, &mut out)?;
7071
}
71-
print_match(&matches, path, &mut out)?;
7272
}
7373

7474
if !pathspec_matched_entry {
7575
// TODO(borrowchk): this shouldn't be necessary at all, but `pathspec` stays borrowed mutably for some reason.
7676
// It's probably due to the strange lifetimes of `index_entries_with_paths()`.
7777
let pathspec = repo.pathspec(
78+
true,
7879
patterns.iter(),
7980
true,
8081
&index,
8182
gix::worktree::stack::state::attributes::Source::WorktreeThenIdMapping
8283
.adjust_for_bare(repo.is_bare()),
8384
)?;
85+
let workdir = repo.work_dir();
8486
for pattern in pathspec.search().patterns() {
8587
let path = pattern.path();
8688
let entry = cache.at_entry(
8789
path,
88-
pattern
89-
.signature
90-
.contains(gix::pathspec::MagicSignature::MUST_BE_DIR)
91-
.into(),
90+
Some(
91+
workdir.map_or(false, |wd| wd.join(gix::path::from_bstr(path)).is_dir())
92+
|| pattern.signature.contains(gix::pathspec::MagicSignature::MUST_BE_DIR),
93+
),
9294
)?;
9395
if !entry.matching_attributes(&mut matches) {
9496
continue;

gitoxide-core/src/repository/clean.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,10 @@ pub(crate) mod function {
7474
.classify_untracked_bare_repositories(matches!(find_untracked_repositories, FindRepository::All))
7575
.emit_untracked(collapse_directories)
7676
.emit_ignored(Some(collapse_directories))
77+
.empty_patterns_match_prefix(true)
7778
.emit_empty_directories(true);
7879
repo.dirwalk(&index, patterns, options, &mut collect)?;
7980
let prefix = repo.prefix()?.unwrap_or(Path::new(""));
80-
let prefix_len = if prefix.as_os_str().is_empty() {
81-
0
82-
} else {
83-
prefix.to_str().map_or(0, |s| s.len() + 1 /* slash */)
84-
};
8581

8682
let entries = collect.inner.into_entries_by_path();
8783
let mut entries_to_clean = 0;
@@ -173,15 +169,16 @@ pub(crate) mod function {
173169
};
174170

175171
let is_ignored = matches!(entry.status, gix::dir::entry::Status::Ignored(_));
176-
let display_path = entry.rela_path[prefix_len..].as_bstr();
172+
let entry_path = gix::path::from_bstr(entry.rela_path);
173+
let display_path = gix::path::relativize_with_prefix(&entry_path, prefix);
177174
if disk_kind == gix::dir::entry::Kind::Directory {
178175
saw_ignored_directory |= is_ignored;
179176
saw_untracked_directory |= entry.status == gix::dir::entry::Status::Untracked;
180177
}
181178
writeln!(
182179
out,
183180
"{maybe}{suffix} {}{} {status}",
184-
display_path,
181+
display_path.display(),
185182
disk_kind.is_dir().then_some("/").unwrap_or_default(),
186183
status = match entry.status {
187184
Status::Ignored(kind) => {
@@ -221,7 +218,7 @@ pub(crate) mod function {
221218
execute = false;
222219
}
223220
if execute {
224-
let path = workdir.join(gix::path::from_bstr(entry.rela_path));
221+
let path = workdir.join(entry_path);
225222
if disk_kind.is_dir() {
226223
std::fs::remove_dir_all(path)?;
227224
} else {

gitoxide-core/src/repository/exclude.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{borrow::Cow, io};
22

3-
use anyhow::{anyhow, bail};
3+
use anyhow::bail;
44
use gix::bstr::BStr;
55

66
use crate::{repository::PathsOrPatterns, OutputFormat};
@@ -58,42 +58,44 @@ pub fn query(
5858
PathsOrPatterns::Patterns(patterns) => {
5959
let mut pathspec_matched_something = false;
6060
let mut pathspec = repo.pathspec(
61+
true,
6162
patterns.iter(),
6263
repo.work_dir().is_some(),
6364
&index,
6465
gix::worktree::stack::state::attributes::Source::WorktreeThenIdMapping.adjust_for_bare(repo.is_bare()),
6566
)?;
6667

67-
for (path, _entry) in pathspec
68-
.index_entries_with_paths(&index)
69-
.ok_or_else(|| anyhow!("Pathspec didn't yield any entry"))?
70-
{
71-
pathspec_matched_something = true;
72-
let entry = cache.at_entry(path, Some(false))?;
73-
let match_ = entry
74-
.matching_exclude_pattern()
75-
.and_then(|m| (show_ignore_patterns || !m.pattern.is_negative()).then_some(m));
76-
print_match(match_, path, &mut out)?;
68+
if let Some(it) = pathspec.index_entries_with_paths(&index) {
69+
for (path, _entry) in it {
70+
pathspec_matched_something = true;
71+
let entry = cache.at_entry(path, Some(false))?;
72+
let match_ = entry
73+
.matching_exclude_pattern()
74+
.and_then(|m| (show_ignore_patterns || !m.pattern.is_negative()).then_some(m));
75+
print_match(match_, path, &mut out)?;
76+
}
7777
}
7878

7979
if !pathspec_matched_something {
8080
// TODO(borrowchk): this shouldn't be necessary at all, but `pathspec` stays borrowed mutably for some reason.
8181
// It's probably due to the strange lifetimes of `index_entries_with_paths()`.
8282
let pathspec = repo.pathspec(
83+
true,
8384
patterns.iter(),
8485
repo.work_dir().is_some(),
8586
&index,
8687
gix::worktree::stack::state::attributes::Source::WorktreeThenIdMapping
8788
.adjust_for_bare(repo.is_bare()),
8889
)?;
90+
let workdir = repo.work_dir();
8991
for pattern in pathspec.search().patterns() {
9092
let path = pattern.path();
9193
let entry = cache.at_entry(
9294
path,
93-
pattern
94-
.signature
95-
.contains(gix::pathspec::MagicSignature::MUST_BE_DIR)
96-
.into(),
95+
Some(
96+
workdir.map_or(false, |wd| wd.join(gix::path::from_bstr(path)).is_dir())
97+
|| pattern.signature.contains(gix::pathspec::MagicSignature::MUST_BE_DIR),
98+
),
9799
)?;
98100
let match_ = entry
99101
.matching_exclude_pattern()

gitoxide-core/src/repository/index/entries.rs

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ pub(crate) mod function {
256256
)> {
257257
let index = repo.index_or_load_from_head()?;
258258
let pathspec = repo.pathspec(
259+
true,
259260
pathspecs,
260261
false,
261262
&index,

gitoxide-core/src/repository/status.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use gix::{
66
Progress,
77
};
88
use gix_status::index_as_worktree::{traits::FastEq, Change, Conflict, EntryStatus};
9+
use std::path::{Path, PathBuf};
910

1011
use crate::OutputFormat;
1112

@@ -54,15 +55,19 @@ pub fn show(
5455
gix::worktree::stack::state::attributes::Source::WorktreeThenIdMapping,
5556
)?
5657
.detach();
57-
let pathspec = gix::Pathspec::new(&repo, pathspecs.iter().map(|p| p.as_bstr()), true, || Ok(stack.clone()))?;
58+
let pathspec = gix::Pathspec::new(&repo, false, pathspecs.iter().map(|p| p.as_bstr()), true, || {
59+
Ok(stack.clone())
60+
})?;
5861
let options = gix_status::index_as_worktree::Options {
5962
fs: repo.filesystem_options()?,
6063
thread_limit,
6164
stat: repo.stat_options()?,
6265
};
66+
let prefix = repo.prefix()?.unwrap_or(Path::new(""));
6367
let mut printer = Printer {
6468
out,
6569
changes: Vec::new(),
70+
prefix: prefix.to_owned(),
6671
};
6772
let filter_pipeline = repo
6873
.filter_pipeline(Some(gix::hash::ObjectId::empty_tree(repo.object_hash())))?
@@ -87,15 +92,16 @@ pub fn show(
8792
let repo = repo.clone().into_sync();
8893
let index = &index;
8994
let collect = &mut collect;
90-
move || {
95+
move || -> anyhow::Result<_> {
9196
let repo = repo.to_thread_local();
92-
repo.dirwalk(
97+
let outcome = repo.dirwalk(
9398
index,
9499
pathspecs,
95100
repo.dirwalk_options()?
96101
.emit_untracked(gix::dir::walk::EmissionMode::CollapseDirectory),
97102
collect,
98-
)
103+
)?;
104+
Ok(outcome.dirwalk)
99105
}
100106
})?;
101107

@@ -125,7 +131,7 @@ pub fn show(
125131
printer.out,
126132
"{status: >3} {rela_path}",
127133
status = "?",
128-
rela_path = entry.rela_path
134+
rela_path = gix::path::relativize_with_prefix(&gix::path::from_bstr(entry.rela_path), prefix).display()
129135
)?;
130136
}
131137

@@ -175,6 +181,7 @@ impl gix_status::index_as_worktree::traits::SubmoduleStatus for Submodule {
175181
struct Printer<W> {
176182
out: W,
177183
changes: Vec<(usize, ApplyChange)>,
184+
prefix: PathBuf,
178185
}
179186

180187
enum ApplyChange {
@@ -226,7 +233,9 @@ impl<W: std::io::Write> Printer<W> {
226233
EntryStatus::IntentToAdd => "A",
227234
};
228235

229-
writeln!(&mut self.out, "{status: >3} {rela_path}")
236+
let rela_path = gix::path::from_bstr(rela_path);
237+
let display_path = gix::path::relativize_with_prefix(&rela_path, &self.prefix);
238+
writeln!(&mut self.out, "{status: >3} {}", display_path.display())
230239
}
231240
}
232241

0 commit comments

Comments
 (0)