diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-23 15:45:33 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-23 15:48:00 +0900 |
| commit | bd6d0186d2c01a3e1d6324ad5a0bcdd71de53098 (patch) | |
| tree | 939eb1dccbfb3341a2f618e734ca23ef84a8e5cc /crates/shirabe/src/package | |
| parent | e068a9d644fde6659a88accd55b3f1d0d9d7cf46 (diff) | |
| download | php-shirabe-bd6d0186d2c01a3e1d6324ad5a0bcdd71de53098.tar.gz php-shirabe-bd6d0186d2c01a3e1d6324ad5a0bcdd71de53098.tar.zst php-shirabe-bd6d0186d2c01a3e1d6324ad5a0bcdd71de53098.zip | |
refactor(promise): drop \React\Promise
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/package')
| -rw-r--r-- | crates/shirabe/src/package/archiver/archive_manager.rs | 30 | ||||
| -rw-r--r-- | crates/shirabe/src/package/version/version_guesser.rs | 47 |
2 files changed, 45 insertions, 32 deletions
diff --git a/crates/shirabe/src/package/archiver/archive_manager.rs b/crates/shirabe/src/package/archiver/archive_manager.rs index 390efc4..e198a03 100644 --- a/crates/shirabe/src/package/archiver/archive_manager.rs +++ b/crates/shirabe/src/package/archiver/archive_manager.rs @@ -164,16 +164,26 @@ impl ArchiveManager { filesystem.ensure_directory_exists(&source_path)?; let download_result = (|| -> anyhow::Result<()> { - let promise = - self.download_manager - .borrow() - .download(package, &source_path, None)?; - SyncHelper::r#await(&self.r#loop, Some(promise))?; - let promise = self - .download_manager - .borrow() - .install(package, &source_path)?; - SyncHelper::r#await(&self.r#loop, Some(promise))?; + SyncHelper::r#await( + &self.r#loop, + Some(Box::pin(async { + self.download_manager + .borrow() + .download(package, &source_path, None) + .await + .map(|_| ()) + })), + )?; + SyncHelper::r#await( + &self.r#loop, + Some(Box::pin(async { + self.download_manager + .borrow() + .install(package, &source_path) + .await + .map(|_| ()) + })), + )?; Ok(()) })(); diff --git a/crates/shirabe/src/package/version/version_guesser.rs b/crates/shirabe/src/package/version/version_guesser.rs index 79f9d6d..47054a4 100644 --- a/crates/shirabe/src/package/version/version_guesser.rs +++ b/crates/shirabe/src/package/version/version_guesser.rs @@ -518,18 +518,14 @@ impl VersionGuesser { strnatcasecmp(b, a) }); - // TODO(phase-c-promise): execute_async is now async; the .then continuation captures and mutates shared - // state (last_index, length, version, pretty_version, promises) and cancels sibling promises, while the - // loop is driven by process.wait(). This concurrent job/cancellation machinery needs design before it can - // become an await-based form, so the promise body (including the inner todo!()) is left as-is. - let mut promises: Vec< - Box<dyn shirabe_external_packages::react::promise::PromiseInterface>, - > = vec![]; self.process.borrow_mut().set_max_jobs(30); - // TODO(phase-b): try/finally with resetMaxJobs + // PHP runs every candidate diff in parallel and cancels the siblings once a zero-length + // diff is found; the single-threaded sync bridge block_on's each diff serially and stops + // at the first zero-length match. let result: Result<()> = (|| -> Result<()> { let mut last_index: i64 = -1; for (index, candidate) in branches.iter().enumerate() { + let index = index as i64; let candidate_version = Preg::replace(r"{^remotes/\S+/}", "", candidate).unwrap_or_default(); @@ -550,22 +546,29 @@ impl VersionGuesser { }, &scm_cmdline, ); - let async_promise = self.process.borrow_mut().execute_async(&cmd_line, path)?; - // TODO(phase-b): closure receives Process in PHP but PromiseInterface::then expects fn(Option<PhpMixed>) -> Option<PhpMixed>; - // closure captures need shared mutable state (last_index, length, version, pretty_version, promises) - promises.push(async_promise.then( - Some(Box::new( - move |_value: Option<PhpMixed>| -> Option<PhpMixed> { - todo!( - "mutate last_index/length/version/pretty_version and possibly cancel promises" - ) - }, - )), - None, - )); + let process = tokio::runtime::Runtime::new() + .unwrap() + .block_on(self.process.borrow_mut().execute_async(&cmd_line, path))?; + if !process.is_successful() { + continue; + } + + let output = process.get_output(); + // overwrite existing if we have a shorter diff, or we have an equal diff and an index that comes later in the array (i.e. older version) + // as newer versions typically have more commits, if the feature branch is based on a newer branch it should have a longer diff to the old version + // but if it doesn't and they have equal diffs, then it probably is based on the old version + if strlen(&output) < length || (strlen(&output) == length && last_index < index) + { + last_index = index; + length = strlen(&output); + version = Some(self.version_parser.normalize_branch(&candidate_version)?); + pretty_version = Some(format!("dev-{}", candidate_version)); + if length == 0 { + break; + } + } } - self.process.borrow_mut().wait(); Ok(()) })(); self.process.borrow_mut().reset_max_jobs(); |
