From a028291f8e5e79b6446ad67ed8b0be9c5ec8f029 Mon Sep 17 00:00:00 2001 From: Christopher Speck Date: Thu, 16 Sep 2021 14:50:01 -0400 Subject: [PATCH] Make corrections to the "arc amend" workflow in Mercurial repositories to be compatible with PHP 5+ Summary: Refs T13665 In the update to D21716 the `str_starts_with` function was added which is only available in PHP 8. This changes it to use `strncmp()` which is compatible back to PHP 4. Additionally fixed running into an error when trying to run `arc amend` on a commit which already matches the content known in Phabricator. Mercurial throws an error when running `amend` without file changes and using the exact same commit message it already has. Test Plan: I created a commit and revision then used `hg amend -e` to modify the commit message locally. I used `arc amend` to update the commit message back to the appropriate message from Phabricator. I ran `arc amend` again to verify that the command did not fail even though the commit message is unchanged. I ran `arc inspect --explore -- 'commit(674492bb460)'` and verified it matched the appropriate commit, to verify the substring matching works properly. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T13665 Differential Revision: https://secure.phabricator.com/D21723 --- .../ArcanistMercurialCommitSymbolCommitHardpointQuery.php | 2 +- src/repository/api/ArcanistMercurialAPI.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ref/commit/ArcanistMercurialCommitSymbolCommitHardpointQuery.php b/src/ref/commit/ArcanistMercurialCommitSymbolCommitHardpointQuery.php index b561247d..db27e8fb 100644 --- a/src/ref/commit/ArcanistMercurialCommitSymbolCommitHardpointQuery.php +++ b/src/ref/commit/ArcanistMercurialCommitSymbolCommitHardpointQuery.php @@ -159,7 +159,7 @@ final class ArcanistMercurialCommitSymbolCommitHardpointQuery // a spot which a marker might match. foreach ($node_list as $node) { foreach ($symbol_set as $symbol) { - if (str_starts_with($node, $symbol)) { + if (strncmp($node, $symbol, strlen($symbol)) === 0) { if (!isset($hash_map[$symbol])) { $hash_map[$symbol] = $node; } diff --git a/src/repository/api/ArcanistMercurialAPI.php b/src/repository/api/ArcanistMercurialAPI.php index df6bdc1c..7e35a1e3 100644 --- a/src/repository/api/ArcanistMercurialAPI.php +++ b/src/repository/api/ArcanistMercurialAPI.php @@ -672,7 +672,10 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI { public function amendCommit($message = null) { $path_statuses = $this->buildUncommittedStatus(); - if ($message === null) { + $existing_message = $this->getCommitMessage( + $this->getWorkingCopyRevision()); + + if ($message === null || $message == $existing_message) { if (empty($path_statuses)) { // If there are no changes to the working directory and the message is // not being changed then there's nothing to amend. Notably Mercurial