Skip to content

Commit

Permalink
fix: always use path when handling path logics
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Jun 11, 2024
1 parent 9d86fe5 commit bffe6c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
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

0 comments on commit bffe6c9

Please sign in to comment.