From da0d38a8e16ebefd59ef5291b5788e6238cc78ba Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 8 Aug 2026 03:04:27 +0900 Subject: refactor(semver): replace Constraint's OP_*/STR_OP_* with CmpOp PHP's version_compare takes its operator as a string, so the shim's port did too, and Constraint carried two families of operator constants plus translation tables to convert between the string form and its own int codes. Five copies of those tables had accumulated across Constraint, CompilingMatcher and the plugin value bridge. version_compare now takes a CmpOp, which makes an invalid operator unrepresentable and removes the tables' reason to exist. Constraint stores a CmpOp and keeps only the string parsing its constructor needs; getOperator, compile and CompilingMatcher::match speak CmpOp as well. PHP's OP_* numbering stays observable: a plugin reads the raw integer off the Constraint object over RPC, so get_operator_constant and its new inverse hold that 0..5 mapping. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/src/util/git.rs | 14 +++++++------- crates/shirabe/src/util/package_sorter.rs | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'crates/shirabe/src/util') diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs index 0ee69926..a6f8d79e 100644 --- a/crates/shirabe/src/util/git.rs +++ b/crates/shirabe/src/util/git.rs @@ -16,10 +16,10 @@ use crate::util::{AuthHelper, StoreAuth}; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ - InvalidArgumentException, PHP_EOL, PhpMixed, RuntimeException, array_map, clearstatcache, - explode, implode, in_array_loose, in_array_strict, is_dir, php_regex, preg_quote, rawurldecode, - rawurlencode, str_contains, str_ends_with, str_replace_array, strlen, strpos, substr, trim, - version_compare, + CmpOp, InvalidArgumentException, PHP_EOL, PhpMixed, RuntimeException, array_map, + clearstatcache, explode, implode, in_array_loose, in_array_strict, is_dir, php_regex, + preg_quote, rawurldecode, rawurlencode, str_contains, str_ends_with, str_replace_array, strlen, + strpos, substr, trim, version_compare, }; use std::sync::Mutex; @@ -982,7 +982,7 @@ impl Git { ) -> String { let git_version = Self::get_version(process); if let Some(v) = git_version - && version_compare(&v, "2.10.0-rc0", ">=") + && version_compare(&v, "2.10.0-rc0", CmpOp::Ge) { return " --no-show-signature".to_string(); } @@ -1010,7 +1010,7 @@ impl Git { let git_version = Self::get_version(process); git_version - .map(|v| version_compare(&v, "2.33.0-rc0", ">=")) + .map(|v| version_compare(&v, "2.33.0-rc0", CmpOp::Ge)) .unwrap_or(false) } @@ -1212,7 +1212,7 @@ impl Git { // PHP: $process ?? new ProcessExecutor() let git_version = Self::get_version(process); if let Some(v) = git_version { - if version_compare(&v, "2.3.0", ">=") { + if version_compare(&v, "2.3.0", CmpOp::Ge) { // added in git 2.3.0, prevents prompting the user for username/password if Platform::get_env("GIT_TERMINAL_PROMPT").as_deref() != Some("0") { Platform::put_env("GIT_TERMINAL_PROMPT", "0"); diff --git a/crates/shirabe/src/util/package_sorter.rs b/crates/shirabe/src/util/package_sorter.rs index 4b76c2fe..5687a339 100644 --- a/crates/shirabe/src/util/package_sorter.rs +++ b/crates/shirabe/src/util/package_sorter.rs @@ -3,7 +3,7 @@ use crate::package::Link; use crate::package::PackageInterfaceHandle; use indexmap::IndexMap; -use shirabe_php_shim::{strnatcasecmp, version_compare}; +use shirabe_php_shim::{CmpOp, strnatcasecmp, version_compare}; pub struct PackageSorter; @@ -21,7 +21,7 @@ impl PackageSorter { if candidate.is_default_branch() { return Some(candidate); } - if version_compare(&highest.get_version(), &candidate.get_version(), "<") { + if version_compare(&highest.get_version(), &candidate.get_version(), CmpOp::Lt) { highest = candidate; } } -- cgit v1.3.1-4-g156e