Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always use path when handling path logics #151

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions fmt/src/document/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use std::{
borrow::Cow,
collections::{HashMap, HashSet},
path::Path,
path::{Path, PathBuf},
};

use snafu::ResultExt;
Expand All @@ -35,7 +35,7 @@ pub struct DocumentFactory {
properties: HashMap<String, String>,

keywords: Vec<String>,
git_file_attrs: HashMap<String, GitFileAttrs>,
git_file_attrs: HashMap<PathBuf, GitFileAttrs>,
year_formatter: Vec<FormatItem<'static>>,
}

Expand All @@ -45,7 +45,7 @@ impl DocumentFactory {
definitions: HashMap<String, HeaderDef>,
properties: HashMap<String, String>,
keywords: Vec<String>,
git_file_attrs: HashMap<String, GitFileAttrs>,
git_file_attrs: HashMap<PathBuf, GitFileAttrs>,
) -> Self {
let year_formatter = format_description::parse("[year]").expect("cannot parse format");
Self {
Expand Down Expand Up @@ -86,10 +86,7 @@ impl DocumentFactory {
.to_string();
properties.insert("hawkeye.core.filename".to_string(), filename);

if let Some(attrs) = self
.git_file_attrs
.get(filepath.to_str().expect("path is never empty"))
{
if let Some(attrs) = self.git_file_attrs.get(filepath) {
properties.insert(
"hawkeye.git.fileCreatedYear".to_string(),
attrs.created_time.format(self.year_formatter.as_slice()),
Expand Down
9 changes: 4 additions & 5 deletions fmt/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use std::{
collections::{hash_map::Entry, HashMap},
convert::Infallible,
path::Path,
path::{Path, PathBuf},
};

use gix::Repository;
Expand Down Expand Up @@ -98,7 +98,7 @@ pub struct GitFileAttrs {

pub fn resolve_file_attrs(
git_context: GitContext,
) -> anyhow::Result<HashMap<String, GitFileAttrs>> {
) -> anyhow::Result<HashMap<PathBuf, GitFileAttrs>> {
let mut attrs = HashMap::new();

if git_context.config.attrs.is_disable() {
Expand Down Expand Up @@ -130,9 +130,8 @@ pub fn resolve_file_attrs(
&prev_commit.tree()?,
&mut cache,
|change| {
let filepath = workdir.join(change.location.to_string());
let filepath = filepath.display().to_string();

let filepath = gix::path::from_bstr(change.location);
let filepath = workdir.join(filepath);
match attrs.entry(filepath) {
Entry::Occupied(mut ent) => {
let attrs: &GitFileAttrs = ent.get();
Expand Down