1From bb2e9a0394a48f4ef3576e8d91607e8129b2b716 Mon Sep 17 00:00:00 2001 2From: Nick Desaulniers <ndesaulniers@google.com> 3Date: Fri, 8 Jul 2022 14:55:46 -0700 4Subject: [PATCH] Fix PHP 8.1 incompatibility with `arc patch D<12345>` 5 6Fixes the following observed error with PHP 8.1: 7 8 EXCEPTION: (RuntimeException) preg_match(): Passing null to parameter phacility#2 ($subject) of type string is deprecated at [<arcanist>/src/error/PhutilErrorHandler.php:261] 9 arcanist(head=master, ref.master=acec17af414f) 10 #0 PhutilErrorHandler::handleError(integer, string, string, integer) 11 phacility#1 preg_match(string, NULL, NULL) called at [<arcanist>/src/repository/api/ArcanistGitAPI.php:603] 12 phacility#2 ArcanistGitAPI::getCanonicalRevisionName(NULL) called at [<arcanist>/src/repository/api/ArcanistGitAPI.php:1146] 13 phacility#3 ArcanistGitAPI::hasLocalCommit(NULL) called at [<arcanist>/src/workflow/ArcanistPatchWorkflow.php:433] 14 phacility#4 ArcanistPatchWorkflow::run() called at [<arcanist>/src/workflow/ArcanistPatchWorkflow.php:398] 15 phacility#5 ArcanistPatchWorkflow::run() called at [<arcanist>/scripts/arcanist.php:427] 16 17Link: https://secure.phabricator.com/book/phabcontrib/article/contributing_code/ 18Link: https://reviews.llvm.org/D129232#3634072 19Suggested-by: Yuanfang Chen <yuanfang.chen@sony.com> 20Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> 21--- 22 src/differential/ArcanistDifferentialDependencyGraph.php | 3 ++- 23 src/lint/linter/ArcanistScriptAndRegexLinter.php | 2 +- 24 src/repository/api/ArcanistGitAPI.php | 3 ++- 25 3 files changed, 5 insertions(+), 3 deletions(-) 26 27diff --git a/src/differential/ArcanistDifferentialDependencyGraph.php b/src/differential/ArcanistDifferentialDependencyGraph.php 28index 64e2f9c71c20..fbc4e6594f0e 100644 29--- a/src/differential/ArcanistDifferentialDependencyGraph.php 30+++ b/src/differential/ArcanistDifferentialDependencyGraph.php 31@@ -42,7 +42,8 @@ final class ArcanistDifferentialDependencyGraph extends AbstractDirectedGraph { 32 $edges = array(); 33 foreach ($dependencies as $dependency) { 34 $dependency_revision = $this->getCommitHashFromDict($dependency); 35- if ($repository_api->hasLocalCommit($dependency_revision)) { 36+ if (phutil_nonempty_string($dependency_revision) && 37+ $repository_api->hasLocalCommit($dependency_revision)) { 38 $edges[$dependency['phid']] = array(); 39 continue; 40 } 41diff --git a/src/lint/linter/ArcanistScriptAndRegexLinter.php b/src/lint/linter/ArcanistScriptAndRegexLinter.php 42index 0c3d9d9a11ca..b9f6924ec997 100644 43--- a/src/lint/linter/ArcanistScriptAndRegexLinter.php 44+++ b/src/lint/linter/ArcanistScriptAndRegexLinter.php 45@@ -338,7 +338,7 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter { 46 } 47 48 $line = idx($match, 'line'); 49- if (strlen($line)) { 50+ if (phutil_nonempty_string($line) && strlen($line)) { 51 $line = (int)$line; 52 if (!$line) { 53 $line = 1; 54diff --git a/src/repository/api/ArcanistGitAPI.php b/src/repository/api/ArcanistGitAPI.php 55index 6c6d2ac42a19..13907d5634be 100644 56--- a/src/repository/api/ArcanistGitAPI.php 57+++ b/src/repository/api/ArcanistGitAPI.php 58@@ -1143,7 +1143,8 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI { 59 60 public function hasLocalCommit($commit) { 61 try { 62- if (!$this->getCanonicalRevisionName($commit)) { 63+ if (!phutil_nonempty_string($commit) || 64+ !$this->getCanonicalRevisionName($commit)) { 65 return false; 66 } 67 } catch (CommandException $exception) { 68-- 692.37.0.rc0.161.g10f37bed90-goog 70 71