aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-12 04:18:58 +0900
committernsfisis <nsfisis@gmail.com>2026-05-12 04:18:58 +0900
commit698bccd425ccefcb4728c4035fa08ebd9dd258f6 (patch)
tree991428d2d481da2ef9930b2280070a1950c0e437 /crates/shirabe
parent37da0a85a208eada01f61a5c28c945083799f97c (diff)
downloadphp-shirabe-698bccd425ccefcb4728c4035fa08ebd9dd258f6.tar.gz
php-shirabe-698bccd425ccefcb4728c4035fa08ebd9dd258f6.tar.zst
php-shirabe-698bccd425ccefcb4728c4035fa08ebd9dd258f6.zip
feat(port): port GitExcludeFilter.php
Diffstat (limited to 'crates/shirabe')
-rw-r--r--crates/shirabe/src/package/archiver/git_exclude_filter.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/crates/shirabe/src/package/archiver/git_exclude_filter.rs b/crates/shirabe/src/package/archiver/git_exclude_filter.rs
index dcde08a..b3e43dc 100644
--- a/crates/shirabe/src/package/archiver/git_exclude_filter.rs
+++ b/crates/shirabe/src/package/archiver/git_exclude_filter.rs
@@ -1 +1,50 @@
//! ref: composer/src/Composer/Package/Archiver/GitExcludeFilter.php
+
+use std::path::Path;
+use shirabe_external_packages::composer::pcre::preg::Preg;
+use crate::package::archiver::base_exclude_filter::BaseExcludeFilter;
+
+pub struct GitExcludeFilter {
+ inner: BaseExcludeFilter,
+}
+
+impl GitExcludeFilter {
+ pub fn new(source_path: String) -> Self {
+ let inner = BaseExcludeFilter::new(source_path.clone());
+ let mut filter = Self { inner };
+
+ let gitattributes_path = format!("{}/.gitattributes", source_path);
+ if Path::new(&gitattributes_path).exists() {
+ let lines: Vec<String> = std::fs::read_to_string(&gitattributes_path)
+ .unwrap_or_default()
+ .lines()
+ .map(|l| l.to_string())
+ .collect();
+ let patterns = filter.inner.parse_lines(
+ lines,
+ |line| GitExcludeFilter::parse_git_attributes_line_static(line),
+ );
+ filter.inner.exclude_patterns.extend(patterns);
+ }
+
+ filter
+ }
+
+ pub fn parse_git_attributes_line(&self, line: &str) -> Option<(String, bool, bool)> {
+ Self::parse_git_attributes_line_static(line)
+ }
+
+ fn parse_git_attributes_line_static(line: &str) -> Option<(String, bool, bool)> {
+ let parts = Preg::split(r"\s+", line);
+
+ if parts.len() == 2 && parts[1] == "export-ignore" {
+ return BaseExcludeFilter::generate_pattern(&parts[0]);
+ }
+
+ if parts.len() == 2 && parts[1] == "-export-ignore" {
+ return BaseExcludeFilter::generate_pattern(&format!("!{}", parts[0]));
+ }
+
+ None
+ }
+}