Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Jan 28, 2025
1 parent 7fc3400 commit 9028400
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ All the `properties` configured will be passed to the template engine as the `pr

New properties:

* `attrs.git_authors` is a list of authors of the file. You can join them with `, ` to get a string by `{{ attrs.git_authors | join(", ") }}`.
* `attrs.git_authors` is a collection of authors of the file. You can join them with `, ` to get a string by `{{ attrs.git_authors | join(", ") }}`.

### Notable changes

Expand Down
3 changes: 2 additions & 1 deletion fmt/src/document/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::BTreeSet;
use std::collections::HashMap;
use std::fs;
use std::fs::File;
Expand All @@ -38,7 +39,7 @@ pub struct Attributes {
pub filename: Option<String>,
pub git_file_created_year: Option<String>,
pub git_file_modified_year: Option<String>,
pub git_authors: Vec<String>,
pub git_authors: BTreeSet<String>,
}

#[derive(Debug)]
Expand Down
11 changes: 8 additions & 3 deletions fmt/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use std::collections::hash_map::Entry;
use std::collections::BTreeSet;
use std::collections::HashMap;
use std::convert::Infallible;
use std::path::Path;
Expand Down Expand Up @@ -87,7 +88,7 @@ fn resolve_features(config: &config::Git) -> FeatureGate {
pub struct GitFileAttrs {
pub created_time: gix::date::Time,
pub modified_time: gix::date::Time,
pub authors: Vec<String>,
pub authors: BTreeSet<String>,
}

pub fn resolve_file_attrs(
Expand Down Expand Up @@ -133,13 +134,17 @@ pub fn resolve_file_attrs(
let attrs: &mut GitFileAttrs = ent.get_mut();
attrs.created_time = time.min(attrs.created_time);
attrs.modified_time = time.max(attrs.modified_time);
attrs.authors.push(author.clone());
attrs.authors.insert(author.clone());
}
Entry::Vacant(ent) => {
ent.insert(GitFileAttrs {
created_time: time,
modified_time: time,
authors: vec![author.clone()],
authors: {
let mut authors = BTreeSet::new();
authors.insert(author.clone());
authors
},
});
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/attrs_and_props/license.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ props["copyrightOwner"]={{props["copyrightOwner"]}}
attrs.filename={{attrs.filename}}
attrs.git_file_created_year={{attrs.git_file_created_year}}
attrs.git_file_modified_year={{attrs.git_file_modified_year}}
attrs.git_authors={{attrs.git_authors | join(", ")}}
1 change: 0 additions & 1 deletion tests/attrs_and_props/main.rs.expected
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// attrs.filename=main.rs
// attrs.git_file_created_year=2025
// attrs.git_file_modified_year=2025
// attrs.git_authors=tison

fn main() {
println!("Hello, world!");
Expand Down

0 comments on commit 9028400

Please sign in to comment.