Skip to content

Commit 8dda069

Browse files
committed
Merge branch 'mailmap-config-section'
2 parents 58ed530 + 7f65ffd commit 8dda069

File tree

7 files changed

+43
-33
lines changed

7 files changed

+43
-33
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/config/tree/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub(crate) mod root {
4545
pub const INDEX: sections::Index = sections::Index;
4646
/// The `init` section.
4747
pub const INIT: sections::Init = sections::Init;
48+
/// The `mailmap` section.
49+
pub const MAILMAP: sections::Mailmap = sections::Mailmap;
4850
/// The `pack` section.
4951
pub const PACK: sections::Pack = sections::Pack;
5052
/// The `protocol` section.
@@ -78,6 +80,7 @@ pub(crate) mod root {
7880
&Self::HTTP,
7981
&Self::INDEX,
8082
&Self::INIT,
83+
&Self::MAILMAP,
8184
&Self::PACK,
8285
&Self::PROTOCOL,
8386
&Self::REMOTE,
@@ -93,8 +96,8 @@ pub(crate) mod root {
9396
mod sections;
9497
pub use sections::{
9598
branch, checkout, core, credential, extensions, fetch, gitoxide, http, index, protocol, remote, ssh, Author,
96-
Branch, Checkout, Clone, Committer, Core, Credential, Extensions, Fetch, Gitoxide, Http, Index, Init, Pack,
97-
Protocol, Remote, Safe, Ssh, Url, User,
99+
Branch, Checkout, Clone, Committer, Core, Credential, Extensions, Fetch, Gitoxide, Http, Index, Init, Mailmap,
100+
Pack, Protocol, Remote, Safe, Ssh, Url, User,
98101
};
99102
#[cfg(feature = "blob-diff")]
100103
pub use sections::{diff, Diff};
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::config::{
2+
tree::{keys, Key, Mailmap, Section},
3+
Tree,
4+
};
5+
6+
impl Mailmap {
7+
/// The `mailmap.blob` key
8+
pub const BLOB: keys::String = keys::String::new_string("blob", &Tree::MAILMAP);
9+
/// The `mailmap.file` key
10+
pub const FILE: keys::Path = keys::Path::new_path("file", &Tree::MAILMAP);
11+
}
12+
13+
impl Section for Mailmap {
14+
fn name(&self) -> &str {
15+
"mailmap"
16+
}
17+
18+
fn keys(&self) -> &[&dyn Key] {
19+
&[&Self::BLOB, &Self::FILE]
20+
}
21+
}

gix/src/config/tree/sections/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ pub mod index;
7272
pub struct Init;
7373
mod init;
7474

75+
#[derive(Copy, Clone, Default)]
76+
pub struct Mailmap;
77+
mod mailmap;
78+
7579
/// The `pack` top-level section.
7680
#[derive(Copy, Clone, Default)]
7781
pub struct Pack;

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)