Skip to content

Commit

Permalink
Merge branch 'mailmap-config-section'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Dec 10, 2023
2 parents 58ed530 + 7f65ffd commit 8dda069
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 33 deletions.
2 changes: 1 addition & 1 deletion gix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ excludes = ["dep:gix-ignore", "dep:gix-worktree", "index"]
attributes = ["excludes", "dep:gix-filter", "dep:gix-pathspec", "dep:gix-attributes", "dep:gix-submodule", "gix-worktree?/attributes", "dep:gix-command"]

## Add support for mailmaps, as way of determining the final name of commmiters and authors.
mailmap = ["dep:gix-mailmap"]
mailmap = ["dep:gix-mailmap", "revision"]

## Make revspec parsing possible, as well describing revision.
revision = ["gix-revision/describe", "index"]
Expand Down
4 changes: 2 additions & 2 deletions gix/src/config/snapshot/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'repo> Snapshot<'repo> {
///
/// Note that this method takes the most recent value at `key` even if it is from a file with reduced trust.
#[momo]
pub fn string<'a>(&self, key: impl Into<&'a BStr>) -> Option<Cow<'_, BStr>> {
pub fn string<'a>(&self, key: impl Into<&'a BStr>) -> Option<Cow<'repo, BStr>> {
self.repo.config.resolved.string_by_key(key)
}

Expand All @@ -62,7 +62,7 @@ impl<'repo> Snapshot<'repo> {
pub fn trusted_path<'a>(
&self,
key: impl Into<&'a BStr>,
) -> Option<Result<Cow<'_, std::path::Path>, gix_config::path::interpolate::Error>> {
) -> Option<Result<Cow<'repo, std::path::Path>, gix_config::path::interpolate::Error>> {
let key = gix_config::parse::key(key.into())?;
self.repo
.config
Expand Down
7 changes: 5 additions & 2 deletions gix/src/config/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub(crate) mod root {
pub const INDEX: sections::Index = sections::Index;
/// The `init` section.
pub const INIT: sections::Init = sections::Init;
/// The `mailmap` section.
pub const MAILMAP: sections::Mailmap = sections::Mailmap;
/// The `pack` section.
pub const PACK: sections::Pack = sections::Pack;
/// The `protocol` section.
Expand Down Expand Up @@ -78,6 +80,7 @@ pub(crate) mod root {
&Self::HTTP,
&Self::INDEX,
&Self::INIT,
&Self::MAILMAP,
&Self::PACK,
&Self::PROTOCOL,
&Self::REMOTE,
Expand All @@ -93,8 +96,8 @@ pub(crate) mod root {
mod sections;
pub use sections::{
branch, checkout, core, credential, extensions, fetch, gitoxide, http, index, protocol, remote, ssh, Author,
Branch, Checkout, Clone, Committer, Core, Credential, Extensions, Fetch, Gitoxide, Http, Index, Init, Pack,
Protocol, Remote, Safe, Ssh, Url, User,
Branch, Checkout, Clone, Committer, Core, Credential, Extensions, Fetch, Gitoxide, Http, Index, Init, Mailmap,
Pack, Protocol, Remote, Safe, Ssh, Url, User,
};
#[cfg(feature = "blob-diff")]
pub use sections::{diff, Diff};
Expand Down
21 changes: 21 additions & 0 deletions gix/src/config/tree/sections/mailmap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::config::{
tree::{keys, Key, Mailmap, Section},
Tree,
};

impl Mailmap {
/// The `mailmap.blob` key
pub const BLOB: keys::String = keys::String::new_string("blob", &Tree::MAILMAP);
/// The `mailmap.file` key
pub const FILE: keys::Path = keys::Path::new_path("file", &Tree::MAILMAP);
}

impl Section for Mailmap {
fn name(&self) -> &str {
"mailmap"
}

fn keys(&self) -> &[&dyn Key] {
&[&Self::BLOB, &Self::FILE]
}
}
4 changes: 4 additions & 0 deletions gix/src/config/tree/sections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ pub mod index;
pub struct Init;
mod init;

#[derive(Copy, Clone, Default)]
pub struct Mailmap;
mod mailmap;

/// The `pack` top-level section.
#[derive(Copy, Clone, Default)]
pub struct Pack;
Expand Down
2 changes: 1 addition & 1 deletion gix/src/mailmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod load {
#[error("The mailmap file declared in `mailmap.file` could not be read")]
Io(#[from] std::io::Error),
#[error("The configured mailmap.blob could not be parsed")]
BlobSpec(#[from] gix_hash::decode::Error),
BlobSpec(#[from] crate::revision::spec::parse::single::Error),
#[error(transparent)]
PathInterpolate(#[from] gix_config::path::interpolate::Error),
#[error("Could not find object configured in `mailmap.blob`")]
Expand Down
36 changes: 9 additions & 27 deletions gix/src/repository/mailmap.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use crate::config::tree::{Key, Mailmap};
use crate::Id;

impl crate::Repository {
// TODO: tests
/// Similar to [`open_mailmap_into()`][crate::Repository::open_mailmap_into()], but ignores all errors and returns at worst
Expand Down Expand Up @@ -27,12 +30,11 @@ impl crate::Repository {
let mut blob_id = self
.config
.resolved
.raw_value("mailmap", None, "blob")
.ok()
.string("mailmap", None, Mailmap::BLOB.name)
.and_then(|spec| {
// TODO: actually resolve this as spec (once we can do that)
gix_hash::ObjectId::from_hex(spec.as_ref())
self.rev_parse_single(spec.as_ref())
.map_err(|e| err.get_or_insert(e.into()))
.map(Id::detach)
.ok()
});
match self.work_dir() {
Expand Down Expand Up @@ -69,29 +71,9 @@ impl crate::Repository {
}

let configured_path = self
.config
.resolved
.value::<gix_config::Path<'_>>("mailmap", None, "file")
.ok()
.and_then(|path| {
let install_dir = self.install_dir().ok()?;
let home = self.config.home_dir();
match path.interpolate(gix_config::path::interpolate::Context {
git_install_dir: Some(install_dir.as_path()),
home_dir: home.as_deref(),
home_for_user: if self.options.git_dir_trust.expect("trust is set") == gix_sec::Trust::Full {
Some(gix_config::path::interpolate::home_for_user)
} else {
None
},
}) {
Ok(path) => Some(path),
Err(e) => {
err.get_or_insert(e.into());
None
}
}
});
.config_snapshot()
.trusted_path(Mailmap::FILE.logical_name().as_str())
.and_then(|res| res.map_err(|e| err.get_or_insert(e.into())).ok());

if let Some(mut file) =
configured_path.and_then(|path| std::fs::File::open(path).map_err(|e| err.get_or_insert(e.into())).ok())
Expand Down

0 comments on commit 8dda069

Please sign in to comment.