-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
131 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +0,0 @@ | ||
---- | ||
|
||
Ok for [Byron](https://github.com/Byron) review the PR on video? | ||
|
||
- [ ] I give my permission to record review and upload on YouTube publicly | ||
|
||
If I think the review will be helpful for the community, then I might record and publish a video. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use std::io; | ||
|
||
use anyhow::bail; | ||
use gix::prelude::FindExt; | ||
|
||
use crate::OutputFormat; | ||
|
||
pub mod query { | ||
use crate::OutputFormat; | ||
|
||
pub struct Options { | ||
pub format: OutputFormat, | ||
pub statistics: bool, | ||
} | ||
} | ||
|
||
pub fn query( | ||
repo: gix::Repository, | ||
pathspecs: impl Iterator<Item = gix::path::Spec>, | ||
mut out: impl io::Write, | ||
mut err: impl io::Write, | ||
query::Options { format, statistics }: query::Options, | ||
) -> anyhow::Result<()> { | ||
if format != OutputFormat::Human { | ||
bail!("JSON output isn't implemented yet"); | ||
} | ||
|
||
let index = repo.index()?; | ||
let mut cache = repo.attributes( | ||
&index, | ||
gix::worktree::cache::state::attributes::Source::WorktreeThenIdMapping, | ||
gix::worktree::cache::state::ignore::Source::IdMapping, | ||
None, | ||
)?; | ||
|
||
let prefix = repo.prefix().expect("worktree - we have an index by now")?; | ||
let mut matches = cache.attribute_matches(); | ||
|
||
for mut spec in pathspecs { | ||
for path in spec.apply_prefix(&prefix).items() { | ||
let is_dir = gix::path::from_bstr(path).metadata().ok().map(|m| m.is_dir()); | ||
let entry = cache.at_entry(path, is_dir, |oid, buf| repo.objects.find_blob(oid, buf))?; | ||
|
||
if !entry.matching_attributes(&mut matches) { | ||
continue; | ||
} | ||
for m in matches.iter() { | ||
writeln!( | ||
out, | ||
"{}:{}:{}\t{}\t{}", | ||
m.location.source.map(|p| p.to_string_lossy()).unwrap_or_default(), | ||
m.location.sequence_number, | ||
m.pattern, | ||
path, | ||
m.assignment | ||
)?; | ||
} | ||
} | ||
} | ||
|
||
if let Some(stats) = statistics.then(|| cache.take_statistics()) { | ||
out.flush()?; | ||
writeln!(err, "{:#?}", stats).ok(); | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters