Skip to content

Commit

Permalink
use new mailmap keys and make a few improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Dec 10, 2023
1 parent 1bf3e88 commit 7f65ffd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 31 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
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 7f65ffd

Please sign in to comment.