Skip to content

Commit 7f65ffd

Browse files
committed
use new mailmap keys and make a few improvements.
1 parent 1bf3e88 commit 7f65ffd

File tree

4 files changed

+13
-31
lines changed

4 files changed

+13
-31
lines changed

gix/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ excludes = ["dep:gix-ignore", "dep:gix-worktree", "index"]
8484
attributes = ["excludes", "dep:gix-filter", "dep:gix-pathspec", "dep:gix-attributes", "dep:gix-submodule", "gix-worktree?/attributes", "dep:gix-command"]
8585

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

8989
## Make revspec parsing possible, as well describing revision.
9090
revision = ["gix-revision/describe", "index"]

gix/src/config/snapshot/access.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'repo> Snapshot<'repo> {
5151
///
5252
/// Note that this method takes the most recent value at `key` even if it is from a file with reduced trust.
5353
#[momo]
54-
pub fn string<'a>(&self, key: impl Into<&'a BStr>) -> Option<Cow<'_, BStr>> {
54+
pub fn string<'a>(&self, key: impl Into<&'a BStr>) -> Option<Cow<'repo, BStr>> {
5555
self.repo.config.resolved.string_by_key(key)
5656
}
5757

@@ -62,7 +62,7 @@ impl<'repo> Snapshot<'repo> {
6262
pub fn trusted_path<'a>(
6363
&self,
6464
key: impl Into<&'a BStr>,
65-
) -> Option<Result<Cow<'_, std::path::Path>, gix_config::path::interpolate::Error>> {
65+
) -> Option<Result<Cow<'repo, std::path::Path>, gix_config::path::interpolate::Error>> {
6666
let key = gix_config::parse::key(key.into())?;
6767
self.repo
6868
.config

gix/src/mailmap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub mod load {
99
#[error("The mailmap file declared in `mailmap.file` could not be read")]
1010
Io(#[from] std::io::Error),
1111
#[error("The configured mailmap.blob could not be parsed")]
12-
BlobSpec(#[from] gix_hash::decode::Error),
12+
BlobSpec(#[from] crate::revision::spec::parse::single::Error),
1313
#[error(transparent)]
1414
PathInterpolate(#[from] gix_config::path::interpolate::Error),
1515
#[error("Could not find object configured in `mailmap.blob`")]

gix/src/repository/mailmap.rs

+9-27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use crate::config::tree::{Key, Mailmap};
2+
use crate::Id;
3+
14
impl crate::Repository {
25
// TODO: tests
36
/// Similar to [`open_mailmap_into()`][crate::Repository::open_mailmap_into()], but ignores all errors and returns at worst
@@ -27,12 +30,11 @@ impl crate::Repository {
2730
let mut blob_id = self
2831
.config
2932
.resolved
30-
.raw_value("mailmap", None, "blob")
31-
.ok()
33+
.string("mailmap", None, Mailmap::BLOB.name)
3234
.and_then(|spec| {
33-
// TODO: actually resolve this as spec (once we can do that)
34-
gix_hash::ObjectId::from_hex(spec.as_ref())
35+
self.rev_parse_single(spec.as_ref())
3536
.map_err(|e| err.get_or_insert(e.into()))
37+
.map(Id::detach)
3638
.ok()
3739
});
3840
match self.work_dir() {
@@ -69,29 +71,9 @@ impl crate::Repository {
6971
}
7072

7173
let configured_path = self
72-
.config
73-
.resolved
74-
.value::<gix_config::Path<'_>>("mailmap", None, "file")
75-
.ok()
76-
.and_then(|path| {
77-
let install_dir = self.install_dir().ok()?;
78-
let home = self.config.home_dir();
79-
match path.interpolate(gix_config::path::interpolate::Context {
80-
git_install_dir: Some(install_dir.as_path()),
81-
home_dir: home.as_deref(),
82-
home_for_user: if self.options.git_dir_trust.expect("trust is set") == gix_sec::Trust::Full {
83-
Some(gix_config::path::interpolate::home_for_user)
84-
} else {
85-
None
86-
},
87-
}) {
88-
Ok(path) => Some(path),
89-
Err(e) => {
90-
err.get_or_insert(e.into());
91-
None
92-
}
93-
}
94-
});
74+
.config_snapshot()
75+
.trusted_path(Mailmap::FILE.logical_name().as_str())
76+
.and_then(|res| res.map_err(|e| err.get_or_insert(e.into())).ok());
9577

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

0 commit comments

Comments
 (0)