Skip to content

Commit

Permalink
Merge branch 'gix-repo-config'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 22, 2022
2 parents f144eaf + 48b3f4a commit afecb63
Show file tree
Hide file tree
Showing 92 changed files with 1,564 additions and 2,017 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ resolver = "2"

[[bin]]
name = "ein"
path = "src/porcelain-cli.rs"
path = "src/ein.rs"
test = false
doctest = false


[[bin]]
name = "gix"
path = "src/plumbing-cli.rs"
path = "src/gix.rs"
test = false
doctest = false

Expand Down
91 changes: 46 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,52 +27,53 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
* Based on the [git-hours] algorithm.
* See the [discussion][git-hours-discussion] for some performance data.
* **the `gix` program** _(plumbing)_ - lower level commands for use in automation
* **pack**
* [x] [verify](https://asciinema.org/a/352942)
* [x] [index verify](https://asciinema.org/a/352945) including each object sha1 and statistics
* [x] [explode](https://asciinema.org/a/352951), useful for transforming packs into loose objects for inspection or restoration
* [x] verify written objects (by reading them back from disk)
* [x] [receive](https://asciinema.org/a/359321) - receive a whole pack produced by **pack-send** or _git-upload-pack_, useful for `clone` like operations.
* [x] **create** - create a pack from given objects or tips of the commit graph.
* [ ] **send** - create a pack and send it using the pack protocol to stdout, similar to 'git-upload-pack',
for consumption by **pack-receive** or _git-receive-pack_
- **multi-index**
* [x] **info** - print information about the file
* [x] **create** - create a multi-index from pack indices
* [x] **verify** - check the file for consistency
* [x] **entries** - list all entries of the file
- **index**
* [x] [create](https://asciinema.org/a/352941) - create an index file by streaming a pack file as done during clone
* [x] support for thin packs (as needed for fetch/pull)
* **commit-graph**
* [x] **verify** - assure that a commit-graph is consistent
* **config** - list the complete git configuration in human-readable form and optionally filter sections by name.
* **exclude**
* [x] **query** - check if path specs are excluded via gits exclusion rules like `.gitignore`.
* **verify** - validate a whole repository, for now only the object database.
* **commit**
* [x] **describe** - identify a commit by its closest tag in its past
* **tree**
* [x] **entries** - list tree entries for a single tree or recursively
* [x] **info** - display tree statistics
* **odb**
* [x] **info** - display odb statistics
* [x] **entries** - display all object ids in the object database
* **mailmap**
* [x] **verify** - check entries of a mailmap file for parse errors and display them
* **repository**
* **exclude**
* [x] **query** - check if path specs are excluded via gits exclusion rules like `.gitignore`.
* **verify** - validate a whole repository, for now only the object database.
* **commit**
* [x] **describe** - identify a commit by its closest tag in its past
* **tree**
* [x] **entries** - list tree entries for a single tree or recursively
* [x] **info** - display tree statistics
* **odb**
* [x] **info** - display odb statistics
* [x] **entries** - display all object ids in the object database
* **mailmap**
* [x] **entries** - display all entries of the aggregated mailmap git would use for substitution
* **revision**
* [ ] **explain** - show what would be done while parsing a revision specification like `HEAD~1`
* **index**
* [x] **entries** - show detailed entry information for human or machine consumption (via JSON)
* [x] **verify** - check the index for consistency
* [x] **info** - display general information about the index itself, with detailed extension information by default
* [x] detailed information about the TREE extension
* [ ] …other extensions details aren't implemented yet
* [x] **checkout-exclusive** - a predecessor of `git worktree`, providing flexible options to evaluate checkout performance from an index and/or an object database.
* **remote**
* [ref-list](https://asciinema.org/a/359320) - list all (or given) references from a remote at the given URL
* [x] **entries** - display all entries of the aggregated mailmap git would use for substitution
* **revision**
* [ ] **explain** - show what would be done while parsing a revision specification like `HEAD~1`
* **free** - no git repository necessary
* **pack**
* [x] [verify](https://asciinema.org/a/352942)
* [x] [index verify](https://asciinema.org/a/352945) including each object sha1 and statistics
* [x] [explode](https://asciinema.org/a/352951), useful for transforming packs into loose objects for inspection or restoration
* [x] verify written objects (by reading them back from disk)
* [x] [receive](https://asciinema.org/a/359321) - receive a whole pack produced by **pack-send** or _git-upload-pack_, useful for `clone` like operations.
* [x] **create** - create a pack from given objects or tips of the commit graph.
* [ ] **send** - create a pack and send it using the pack protocol to stdout, similar to 'git-upload-pack',
for consumption by **pack-receive** or _git-receive-pack_
- **multi-index**
* [x] **info** - print information about the file
* [x] **create** - create a multi-index from pack indices
* [x] **verify** - check the file for consistency
* [x] **entries** - list all entries of the file
- **index**
* [x] [create](https://asciinema.org/a/352941) - create an index file by streaming a pack file as done during clone
* [x] support for thin packs (as needed for fetch/pull)
* **commit-graph**
* [x] **verify** - assure that a commit-graph is consistent
* **mailmap**
* [x] **verify** - check entries of a mailmap file for parse errors and display them
* **index**
* [x] **entries** - show detailed entry information for human or machine consumption (via JSON)
* [x] **verify** - check the index for consistency
* [x] **info** - display general information about the index itself, with detailed extension information by default
* [x] detailed information about the TREE extension
* [ ] …other extensions details aren't implemented yet
* [x] **checkout-exclusive** - a predecessor of `git worktree`, providing flexible options to evaluate checkout performance from an index and/or an object database.
* **remote**
* [ref-list](https://asciinema.org/a/359320) - list all (or given) references from a remote at the given URL

[skim]: https://github.com/lotabout/skim
[git-hours]: https://github.com/kimmobrunfeldt/git-hours/blob/8aaeee237cb9d9028e7a2592a25ad8468b1f45e4/index.js#L114-L143
Expand Down
4 changes: 4 additions & 0 deletions git-repository/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::repository::identity;
use crate::{bstr::BString, permission, Repository};
use git_features::threading::OnceCell;

pub use git_config::*;

pub(crate) mod cache;
mod snapshot;

Expand All @@ -18,7 +20,9 @@ pub(crate) mod section {
}
}

/// The error returned when failing to initialize the repository configuration.
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Could not read configuration file")]
Io(#[from] std::io::Error),
Expand Down
2 changes: 1 addition & 1 deletion git-repository/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pub mod create;
pub mod open;

///
mod config;
pub mod config;

///
pub mod mailmap {
Expand Down
1 change: 1 addition & 0 deletions git-repository/src/repository/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::config;

/// Configuration
impl crate::Repository {
/// Return
/// Return a snapshot of the configuration as seen upon opening the repository.
pub fn config_snapshot(&self) -> config::Snapshot<'_> {
config::Snapshot { repo: self }
Expand Down
97 changes: 97 additions & 0 deletions gitoxide-core/src/repository/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
use crate::OutputFormat;
use anyhow::{bail, Result};
use git_repository as git;

pub fn list(
repo: git::Repository,
filters: Vec<String>,
format: OutputFormat,
mut out: impl std::io::Write,
) -> Result<()> {
if format != OutputFormat::Human {
bail!("Only human output format is supported at the moment");
}
let config = repo.config_snapshot();
let config = config.plumbing();
if let Some(frontmatter) = config.frontmatter() {
for event in frontmatter {
event.write_to(&mut out)?;
}
}
let filters: Vec<_> = filters.into_iter().map(Filter::new).collect();
let mut last_meta = None;
for (section, matter) in config.sections_and_postmatter() {
if !filters.is_empty() && !filters.iter().any(|filter| filter.matches_section(section)) {
continue;
}

let meta = section.meta();
if last_meta.map_or(true, |last| last != meta) {
write_meta(meta, &mut out)?;
}
last_meta = Some(meta);

section.write_to(&mut out)?;
for event in matter {
event.write_to(&mut out)?;
}
writeln!(&mut out)?;
}
Ok(())
}

struct Filter {
name: String,
subsection: Option<String>,
}

impl Filter {
fn new(input: String) -> Self {
match git::config::parse::key(&input) {
Some(key) => Filter {
name: key.section_name.into(),
subsection: key.subsection_name.map(ToOwned::to_owned),
},
None => Filter {
name: input,
subsection: None,
},
}
}

fn matches_section(&self, section: &git::config::file::Section<'_>) -> bool {
let ignore_case = git::glob::wildmatch::Mode::IGNORE_CASE;

if !git::glob::wildmatch(self.name.as_bytes().into(), section.header().name(), ignore_case) {
return false;
}
match (self.subsection.as_deref(), section.header().subsection_name()) {
(Some(filter), Some(name)) => {
if !git::glob::wildmatch(filter.as_bytes().into(), name, ignore_case) {
return false;
}
}
(None, None) | (None, Some(_)) => {}
_ => return false,
};
true
}
}

fn write_meta(meta: &git::config::file::Metadata, out: &mut impl std::io::Write) -> std::io::Result<()> {
writeln!(
out,
"# From '{}' ({:?}{}{})",
meta.path
.as_deref()
.map(|p| p.display().to_string())
.unwrap_or_else(|| "memory".into()),
meta.source,
(meta.level != 0)
.then(|| format!(", include level {}", meta.level))
.unwrap_or_default(),
(meta.trust != git::sec::Trust::Full)
.then(|| ", untrusted")
.unwrap_or_default()
)
}
2 changes: 2 additions & 0 deletions gitoxide-core/src/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub fn init(directory: Option<PathBuf>) -> Result<git::discover::repository::Pat
.with_context(|| "Repository initialization failed")
}

pub mod config;

pub mod tree;

pub mod commit;
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit afecb63

Please sign in to comment.