Addressing some PHP8 incompatibilities - Diffusion & Differential

Summary: Running through setting up and using Diffusion repositories and addressing PHP8 issues that come up.

Test Plan:
I set up a hosted mercurial repository and pushed commits to it over ssh.
I set up a hosted git repository and pushed commits to it over ssh.
I set up a mirrored mercurial repository over ssh.
I set up a mirrored git repository over ssh.

I created a diff on a git repository and landed it.
I created a diff on a mercurial repository and landed it.

I cloned and pushed a commit to a mercurial repo over http.
I cloned and pushed a commit to a git repo over http.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D21864
This commit is contained in:
Christopher Speck 2023-05-18 00:05:18 -04:00
parent 58995268dd
commit ce3d484b0e
51 changed files with 153 additions and 85 deletions

View file

@ -36,7 +36,7 @@ $authstruct_raw = $cache->getKey($authstruct_key);
$authstruct = null; $authstruct = null;
if (strlen($authstruct_raw)) { if ($authstruct_raw !== null && strlen($authstruct_raw)) {
try { try {
$authstruct = phutil_json_decode($authstruct_raw); $authstruct = phutil_json_decode($authstruct_raw);
} catch (Exception $ex) { } catch (Exception $ex) {
@ -135,7 +135,7 @@ foreach ($authstruct['keys'] as $key_struct) {
$cmd = csprintf('%s %Ls', $bin, $key_argv); $cmd = csprintf('%s %Ls', $bin, $key_argv);
if (strlen($instance)) { if ($instance !== null && strlen($instance)) {
$cmd = csprintf('PHABRICATOR_INSTANCE=%s %C', $instance, $cmd); $cmd = csprintf('PHABRICATOR_INSTANCE=%s %C', $instance, $cmd);
} }

View file

@ -58,7 +58,7 @@ final class AlmanacKeys extends Phobject {
public static function getClusterSSHUser() { public static function getClusterSSHUser() {
$username = PhabricatorEnv::getEnvConfig('diffusion.ssh-user'); $username = PhabricatorEnv::getEnvConfig('diffusion.ssh-user');
if (strlen($username)) { if ($username !== null && strlen($username)) {
return $username; return $username;
} }

View file

@ -39,7 +39,7 @@ final class PhabricatorConduitSearchEngine
$query->withIsInternal(false); $query->withIsInternal(false);
$contains = $saved->getParameter('nameContains'); $contains = $saved->getParameter('nameContains');
if (strlen($contains)) { if ($contains !== null && strlen($contains)) {
$query->withNameContains($contains); $query->withNameContains($contains);
} }

View file

@ -9,7 +9,7 @@ final class PhabricatorConfigModuleController
$all_modules = PhabricatorConfigModule::getAllModules(); $all_modules = PhabricatorConfigModule::getAllModules();
if (!strlen($key)) { if ($key === null || !strlen($key)) {
$key = head_key($all_modules); $key = head_key($all_modules);
} }

View file

@ -56,7 +56,7 @@ final class DifferentialGetCommitMessageConduitAPIMethod
// show "Field:" templates for some fields even if they are empty. // show "Field:" templates for some fields even if they are empty.
$edit_mode = $request->getValue('edit'); $edit_mode = $request->getValue('edit');
$is_any_edit = (bool)strlen($edit_mode); $is_any_edit = $edit_mode !== null && (bool)strlen($edit_mode);
$is_create = ($edit_mode == 'create'); $is_create = ($edit_mode == 'create');
$field_list = DifferentialCommitMessageField::newEnabledFields($viewer); $field_list = DifferentialCommitMessageField::newEnabledFields($viewer);
@ -115,7 +115,7 @@ final class DifferentialGetCommitMessageConduitAPIMethod
$is_title = ($field_key == $key_title); $is_title = ($field_key == $key_title);
if (!strlen($value)) { if ($value === null || !strlen($value)) {
if ($is_template) { if ($is_template) {
$commit_message[] = $label.': '; $commit_message[] = $label.': ';
} }

View file

@ -39,13 +39,20 @@ final class DifferentialBranchField
$branch = $diff->getBranch(); $branch = $diff->getBranch();
$bookmark = $diff->getBookmark(); $bookmark = $diff->getBookmark();
if ($branch === null) {
$branch = '';
}
if ($bookmark === null) {
$bookmark = '';
}
if (strlen($branch) && strlen($bookmark)) { if (strlen($branch) && strlen($bookmark)) {
return pht('%s (bookmark) on %s (branch)', $bookmark, $branch); return pht('%s (bookmark) on %s (branch)', $bookmark, $branch);
} else if (strlen($bookmark)) { } else if (strlen($bookmark)) {
return pht('%s (bookmark)', $bookmark); return pht('%s (bookmark)', $bookmark);
} else if (strlen($branch)) { } else if (strlen($branch)) {
$onto = $diff->loadTargetBranch(); $onto = $diff->loadTargetBranch();
if (strlen($onto) && ($onto !== $branch)) { if ($onto !== null && strlen($onto) && ($onto !== $branch)) {
return pht( return pht(
'%s (branched from %s)', '%s (branched from %s)',
$branch, $branch,

View file

@ -60,7 +60,7 @@ abstract class DifferentialCommitMessageField
} }
public function renderFieldValue($value) { public function renderFieldValue($value) {
if (!strlen($value)) { if ($value === null || !strlen($value)) {
return null; return null;
} }

View file

@ -72,7 +72,7 @@ final class DifferentialRevisionIDCommitMessageField
} }
public function renderFieldValue($value) { public function renderFieldValue($value) {
if (!strlen($value)) { if ($value === null || !strlen($value)) {
return null; return null;
} }

View file

@ -325,7 +325,7 @@ final class DifferentialChangeset
public function getOldStatePathVector() { public function getOldStatePathVector() {
$path = $this->getOldFile(); $path = $this->getOldFile();
if (!strlen($path)) { if ($path === null || !strlen($path)) {
$path = $this->getFilename(); $path = $this->getFilename();
} }

View file

@ -251,6 +251,7 @@ final class DifferentialRevisionUpdateHistoryView extends AphrontView {
$content = phabricator_form( $content = phabricator_form(
$this->getUser(), $this->getUser(),
array( array(
'method' => 'GET',
'action' => '/D'.$revision_id.'#toc', 'action' => '/D'.$revision_id.'#toc',
), ),
array( array(

View file

@ -30,7 +30,7 @@ final class DiffusionBranchQueryConduitAPIMethod
$repository = $drequest->getRepository(); $repository = $drequest->getRepository();
$contains = $request->getValue('contains'); $contains = $request->getValue('contains');
if (strlen($contains)) { if ($contains !== null && strlen($contains)) {
// See PHI958 (and, earlier, PHI720). If "patterns" are provided, pass // See PHI958 (and, earlier, PHI720). If "patterns" are provided, pass
// them to "git branch ..." to let callers test for reachability from // them to "git branch ..." to let callers test for reachability from
@ -80,7 +80,7 @@ final class DiffusionBranchQueryConduitAPIMethod
->setRepository($repository); ->setRepository($repository);
$contains = $request->getValue('contains'); $contains = $request->getValue('contains');
if (strlen($contains)) { if ($contains !== null && strlen($contains)) {
$query->withContainsCommit($contains); $query->withContainsCommit($contains);
} }

View file

@ -37,7 +37,7 @@ final class DiffusionBrowseQueryConduitAPIMethod
$repository = $drequest->getRepository(); $repository = $drequest->getRepository();
$path = $request->getValue('path'); $path = $request->getValue('path');
if (!strlen($path) || $path === '/') { if ($path === null || !strlen($path) || $path === '/') {
$path = null; $path = null;
} }
@ -282,8 +282,13 @@ final class DiffusionBrowseQueryConduitAPIMethod
$results = array(); $results = array();
$match_against = trim($path, '/'); if ($path !== null) {
$match_len = strlen($match_against); $match_against = trim($path, '/');
$match_len = strlen($match_against);
} else {
$match_against = '';
$match_len = 0;
}
// For the root, don't trim. For other paths, trim the "/" after we match. // For the root, don't trim. For other paths, trim the "/" after we match.
// We need this because Mercurial's canonical paths have no leading "/", // We need this because Mercurial's canonical paths have no leading "/",
@ -295,7 +300,7 @@ final class DiffusionBrowseQueryConduitAPIMethod
if (strncmp($path, $match_against, $match_len)) { if (strncmp($path, $match_against, $match_len)) {
continue; continue;
} }
if (!strlen($path)) { if ($path === null || !strlen($path)) {
continue; continue;
} }
$remainder = substr($path, $trim_len); $remainder = substr($path, $trim_len);

View file

@ -45,16 +45,15 @@ final class DiffusionHistoryQueryConduitAPIMethod
$repository = $drequest->getRepository(); $repository = $drequest->getRepository();
$commit_hash = $request->getValue('commit'); $commit_hash = $request->getValue('commit');
$against_hash = $request->getValue('against'); $against_hash = $request->getValue('against');
$path = $request->getValue('path');
if (!strlen($path)) {
$path = null;
}
$offset = $request->getValue('offset'); $offset = $request->getValue('offset');
$limit = $request->getValue('limit'); $limit = $request->getValue('limit');
if (strlen($against_hash)) { $path = $request->getValue('path');
if ($path === null || !strlen($path)) {
$path = null;
}
if ($against_hash !== null && strlen($against_hash)) {
$commit_range = "{$against_hash}..{$commit_hash}"; $commit_range = "{$against_hash}..{$commit_hash}";
} else { } else {
$commit_range = $commit_hash; $commit_range = $commit_hash;

View file

@ -26,7 +26,7 @@ final class DiffusionBranchTableController extends DiffusionController {
); );
$contains = $drequest->getSymbolicCommit(); $contains = $drequest->getSymbolicCommit();
if (strlen($contains)) { if ($contains !== null && strlen($contains)) {
$params['contains'] = $contains; $params['contains'] = $contains;
} }

View file

@ -22,7 +22,7 @@ final class DiffusionBrowseController extends DiffusionController {
// list. // list.
$grep = $request->getStr('grep'); $grep = $request->getStr('grep');
if (strlen($grep)) { if (phutil_nonempty_string($grep)) {
return $this->browseSearch(); return $this->browseSearch();
} }
@ -290,6 +290,11 @@ final class DiffusionBrowseController extends DiffusionController {
$header = $this->buildHeaderView($drequest); $header = $this->buildHeaderView($drequest);
$header->setHeaderIcon('fa-folder-open'); $header->setHeaderIcon('fa-folder-open');
$title = '/';
if ($drequest->getPath() !== null) {
$title = nonempty(basename($drequest->getPath()), '/');
}
$empty_result = null; $empty_result = null;
$browse_panel = null; $browse_panel = null;
if (!$results->isValidResults()) { if (!$results->isValidResults()) {
@ -303,7 +308,6 @@ final class DiffusionBrowseController extends DiffusionController {
->setPaths($results->getPaths()) ->setPaths($results->getPaths())
->setUser($request->getUser()); ->setUser($request->getUser());
$title = nonempty(basename($drequest->getPath()), '/');
$icon = 'fa-folder-open'; $icon = 'fa-folder-open';
$browse_header = $this->buildPanelHeaderView($title, $icon); $browse_header = $this->buildPanelHeaderView($title, $icon);
@ -351,7 +355,7 @@ final class DiffusionBrowseController extends DiffusionController {
return $this->newPage() return $this->newPage()
->setTitle(array( ->setTitle(array(
nonempty(basename($drequest->getPath()), '/'), $title,
$repository->getDisplayName(), $repository->getDisplayName(),
)) ))
->setCrumbs($crumbs) ->setCrumbs($crumbs)

View file

@ -27,8 +27,11 @@ final class DiffusionCommitController extends DiffusionController {
// If this page is being accessed via "/source/xyz/commit/...", redirect // If this page is being accessed via "/source/xyz/commit/...", redirect
// to the canonical URI. // to the canonical URI.
$has_callsign = strlen($request->getURIData('repositoryCallsign')); $repo_callsign = $request->getURIData('repositoryCallsign');
$has_id = strlen($request->getURIData('repositoryID')); $has_callsign = $repo_callsign !== null && strlen($repo_callsign);
$repo_id = $request->getURIData('repositoryID');
$has_id = $repo_id !== null && strlen($repo_id);
if (!$has_callsign && !$has_id) { if (!$has_callsign && !$has_id) {
$canonical_uri = $repository->getCommitURI($commit_identifier); $canonical_uri = $repository->getCommitURI($commit_identifier);
return id(new AphrontRedirectResponse()) return id(new AphrontRedirectResponse())
@ -922,7 +925,7 @@ final class DiffusionCommitController extends DiffusionController {
private function linkBugtraq($corpus) { private function linkBugtraq($corpus) {
$url = PhabricatorEnv::getEnvConfig('bugtraq.url'); $url = PhabricatorEnv::getEnvConfig('bugtraq.url');
if (!strlen($url)) { if ($url === null || !strlen($url)) {
return $corpus; return $corpus;
} }

View file

@ -265,7 +265,10 @@ abstract class DiffusionController extends PhabricatorController {
protected function renderPathLinks(DiffusionRequest $drequest, $action) { protected function renderPathLinks(DiffusionRequest $drequest, $action) {
$path = $drequest->getPath(); $path = $drequest->getPath();
$path_parts = array_filter(explode('/', trim($path, '/'))); $path_parts = array();
if ($path !== null && strlen($path)) {
$path_parts = array_filter(explode('/', trim($path, '/')));
}
$divider = phutil_tag( $divider = phutil_tag(
'span', 'span',

View file

@ -50,7 +50,8 @@ final class DiffusionHistoryController extends DiffusionController {
// ancestors appropriately, but this would currrently be prohibitively // ancestors appropriately, but this would currrently be prohibitively
// expensive in the general case. // expensive in the general case.
$show_graph = !strlen($drequest->getPath()); $show_graph = ($drequest->getPath() === null
|| !strlen($drequest->getPath()));
if ($show_graph) { if ($show_graph) {
$history_list $history_list
->setParents($history_results['parents']) ->setParents($history_results['parents'])
@ -98,7 +99,7 @@ final class DiffusionHistoryController extends DiffusionController {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$repository = $drequest->getRepository(); $repository = $drequest->getRepository();
$no_path = !strlen($drequest->getPath()); $no_path = $drequest->getPath() === null || !strlen($drequest->getPath());
if ($no_path) { if ($no_path) {
$header_text = pht('History'); $header_text = pht('History');
} else { } else {

View file

@ -40,7 +40,7 @@ final class DiffusionRepositoryManagePanelsController
} }
$selected = $request->getURIData('panel'); $selected = $request->getURIData('panel');
if (!strlen($selected)) { if ($selected === null || !strlen($selected)) {
$selected = head_key($panels); $selected = head_key($panels);
} }

View file

@ -183,11 +183,13 @@ final class DiffusionServeController extends DiffusionController {
// won't prompt users who provide a username but no password otherwise. // won't prompt users who provide a username but no password otherwise.
// See T10797 for discussion. // See T10797 for discussion.
$have_user = strlen(idx($_SERVER, 'PHP_AUTH_USER')); $http_user = idx($_SERVER, 'PHP_AUTH_USER');
$have_pass = strlen(idx($_SERVER, 'PHP_AUTH_PW')); $http_pass = idx($_SERVER, 'PHP_AUTH_PW');
$have_user = $http_user !== null && strlen($http_user);
$have_pass = $http_pass !== null && strlen($http_pass);
if ($have_user && $have_pass) { if ($have_user && $have_pass) {
$username = $_SERVER['PHP_AUTH_USER']; $username = $http_user;
$password = new PhutilOpaqueEnvelope($_SERVER['PHP_AUTH_PW']); $password = new PhutilOpaqueEnvelope($http_pass);
// Try Git LFS auth first since we can usually reject it without doing // Try Git LFS auth first since we can usually reject it without doing
// any queries, since the username won't match the one we expect or the // any queries, since the username won't match the one we expect or the
@ -524,9 +526,15 @@ final class DiffusionServeController extends DiffusionController {
break; break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$cmd = $request->getStr('cmd'); $cmd = $request->getStr('cmd');
if ($cmd === null) {
return false;
}
if ($cmd == 'batch') { if ($cmd == 'batch') {
$cmds = idx($this->getMercurialArguments(), 'cmds'); $cmds = idx($this->getMercurialArguments(), 'cmds');
return DiffusionMercurialWireProtocol::isReadOnlyBatchCommand($cmds); if ($cmds !== null) {
return DiffusionMercurialWireProtocol::isReadOnlyBatchCommand(
$cmds);
}
} }
return DiffusionMercurialWireProtocol::isReadOnlyCommand($cmd); return DiffusionMercurialWireProtocol::isReadOnlyCommand($cmd);
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:

View file

@ -25,7 +25,9 @@ final class DiffusionTagListController extends DiffusionController {
'offset' => $pager->getOffset(), 'offset' => $pager->getOffset(),
); );
if (strlen($drequest->getSymbolicCommit())) { if ($drequest->getSymbolicCommit() !== null
&& strlen($drequest->getSymbolicCommit())) {
$is_commit = true; $is_commit = true;
$params['commit'] = $drequest->getSymbolicCommit(); $params['commit'] = $drequest->getSymbolicCommit();
} else { } else {

View file

@ -131,6 +131,13 @@ final class DiffusionCommitRef extends Phobject {
} }
private function formatUser($name, $email) { private function formatUser($name, $email) {
if ($name === null) {
$name = '';
}
if ($email === null) {
$email = '';
}
if (strlen($name) && strlen($email)) { if (strlen($name) && strlen($email)) {
return "{$name} <{$email}>"; return "{$name} <{$email}>";
} else if (strlen($email)) { } else if (strlen($email)) {

View file

@ -87,7 +87,7 @@ final class DiffusionDocumentRenderingEngine
$ref->setSymbolMetadata($this->getSymbolMetadata()); $ref->setSymbolMetadata($this->getSymbolMetadata());
$coverage = $drequest->loadCoverage(); $coverage = $drequest->loadCoverage();
if (strlen($coverage)) { if ($coverage !== null && strlen($coverage)) {
$ref->addCoverage($coverage); $ref->addCoverage($coverage);
} }
} }

View file

@ -1133,7 +1133,7 @@ final class DiffusionCommitHookEngine extends Phobject {
->setHookWait(phutil_microseconds_since($hook_start)); ->setHookWait(phutil_microseconds_since($hook_start));
$identifier = $this->getRequestIdentifier(); $identifier = $this->getRequestIdentifier();
if (strlen($identifier)) { if ($identifier !== null && strlen($identifier)) {
$event->setRequestIdentifier($identifier); $event->setRequestIdentifier($identifier);
} }

View file

@ -92,7 +92,10 @@ abstract class DiffusionFileFutureQuery
$drequest = $this->getRequest(); $drequest = $this->getRequest();
$name = basename($drequest->getPath()); $name = '';
if ($drequest->getPath() !== null) {
$name = basename($drequest->getPath());
}
$relative_ttl = phutil_units('48 hours in seconds'); $relative_ttl = phutil_units('48 hours in seconds');
try { try {

View file

@ -32,8 +32,12 @@ final class DiffusionLowLevelMercurialPathsQuery
$hg_paths_command = 'locate --print0 --rev %s -I %s'; $hg_paths_command = 'locate --print0 --rev %s -I %s';
} }
$match_against = trim($path, '/'); if ($path !== null) {
$prefix = trim('./'.$match_against, '/'); $match_against = trim($path, '/');
$prefix = trim('./'.$match_against, '/');
} else {
$prefix = '.';
}
list($entire_manifest) = $repository->execxLocalCommand( list($entire_manifest) = $repository->execxLocalCommand(
$hg_paths_command, $hg_paths_command,
hgsprintf('%s', $commit), hgsprintf('%s', $commit),

View file

@ -48,6 +48,10 @@ final class DiffusionPathIDQuery extends Phobject {
*/ */
public static function normalizePath($path) { public static function normalizePath($path) {
if ($path === null) {
return '/';
}
// Normalize to single slashes, e.g. "///" => "/". // Normalize to single slashes, e.g. "///" => "/".
$path = preg_replace('@[/]{2,}@', '/', $path); $path = preg_replace('@[/]{2,}@', '/', $path);

View file

@ -35,7 +35,7 @@ final class DiffusionGitRawDiffQuery extends DiffusionRawDiffQuery {
} }
$path = $drequest->getPath(); $path = $drequest->getPath();
if (!strlen($path)) { if ($path === null || !strlen($path)) {
$path = '.'; $path = '.';
} }

View file

@ -3,7 +3,7 @@
final class DiffusionGitRequest extends DiffusionRequest { final class DiffusionGitRequest extends DiffusionRequest {
protected function isStableCommit($symbol) { protected function isStableCommit($symbol) {
return preg_match('/^[a-f0-9]{40}\z/', $symbol); return $symbol !== null && preg_match('/^[a-f0-9]{40}\z/', $symbol);
} }
public function getBranch() { public function getBranch() {

View file

@ -3,7 +3,7 @@
final class DiffusionMercurialRequest extends DiffusionRequest { final class DiffusionMercurialRequest extends DiffusionRequest {
protected function isStableCommit($symbol) { protected function isStableCommit($symbol) {
return preg_match('/^[a-f0-9]{40}\z/', $symbol); return $symbol !== null && preg_match('/^[a-f0-9]{40}\z/', $symbol);
} }
public function getBranch() { public function getBranch() {

View file

@ -3,7 +3,7 @@
final class DiffusionSvnRequest extends DiffusionRequest { final class DiffusionSvnRequest extends DiffusionRequest {
protected function isStableCommit($symbol) { protected function isStableCommit($symbol) {
return preg_match('/^[1-9]\d*\z/', $symbol); return $symbol !== null && preg_match('/^[1-9]\d*\z/', $symbol);
} }
protected function didInitialize() { protected function didInitialize() {

View file

@ -15,9 +15,13 @@ final class DiffusionBrowseTableView extends DiffusionView {
$repository = $request->getRepository(); $repository = $request->getRepository();
require_celerity_resource('diffusion-css'); require_celerity_resource('diffusion-css');
$base_path = trim($request->getPath(), '/'); if ($request->getPath() !== null) {
if ($base_path) { $base_path = trim($request->getPath(), '/');
$base_path = $base_path.'/'; if ($base_path) {
$base_path = $base_path.'/';
}
} else {
$base_path = '';
} }
$need_pull = array(); $need_pull = array();

View file

@ -71,7 +71,7 @@ abstract class DiffusionView extends AphrontView {
$display_name = idx($details, 'name'); $display_name = idx($details, 'name');
unset($details['name']); unset($details['name']);
if (strlen($display_name)) { if ($display_name !== null && strlen($display_name)) {
$display_name = phutil_tag( $display_name = phutil_tag(
'span', 'span',
array( array(

View file

@ -50,7 +50,7 @@ final class PhabricatorRepositoryEditor
// If the repository does not have a local path yet, assign it one based // If the repository does not have a local path yet, assign it one based
// on its ID. We can't do this earlier because we won't have an ID yet. // on its ID. We can't do this earlier because we won't have an ID yet.
$local_path = $object->getLocalPath(); $local_path = $object->getLocalPath();
if (!strlen($local_path)) { if ($local_path === null || !strlen($local_path)) {
$local_key = 'repository.default-local-path'; $local_key = 'repository.default-local-path';
$local_root = PhabricatorEnv::getEnvConfig($local_key); $local_root = PhabricatorEnv::getEnvConfig($local_key);

View file

@ -238,7 +238,7 @@ final class PhabricatorRepositoryPullEngine
$identifier = $repository->getPHID(); $identifier = $repository->getPHID();
$instance = PhabricatorEnv::getEnvConfig('cluster.instance'); $instance = PhabricatorEnv::getEnvConfig('cluster.instance');
if (strlen($instance)) { if ($instance !== null && strlen($instance)) {
$identifier = "{$identifier}:{$instance}"; $identifier = "{$identifier}:{$instance}";
} }
@ -575,7 +575,7 @@ final class PhabricatorRepositoryPullEngine
$ref_rules); $ref_rules);
// Empty repositories don't have any refs. // Empty repositories don't have any refs.
if (!strlen(rtrim($stdout))) { if ($stdout === null || !strlen(rtrim($stdout))) {
return array(); return array();
} }

View file

@ -220,7 +220,7 @@ final class PhabricatorRepositoryManagementRebuildIdentitiesWorkflow
$committer_name = $data->getCommitterString(); $committer_name = $data->getCommitterString();
$committer_phid = $commit->getCommitterIdentityPHID(); $committer_phid = $commit->getCommitterIdentityPHID();
if (strlen($committer_name)) { if (phutil_nonempty_string($committer_name)) {
$committer_identity = $this->getIdentityForCommit( $committer_identity = $this->getIdentityForCommit(
$commit, $commit,
$committer_name); $committer_name);

View file

@ -132,7 +132,7 @@ final class PhabricatorRepositoryRefCursorQuery
$name_hashes); $name_hashes);
} }
if (strlen($this->datasourceQuery)) { if ($this->datasourceQuery !== null && strlen($this->datasourceQuery)) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'refNameRaw LIKE %>', 'refNameRaw LIKE %>',

View file

@ -345,7 +345,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
// Make some reasonable effort to produce reasonable default directory // Make some reasonable effort to produce reasonable default directory
// names from repository names. // names from repository names.
if (!strlen($name)) { if ($name === null || !strlen($name)) {
$name = $this->getName(); $name = $this->getName();
$name = phutil_utf8_strtolower($name); $name = phutil_utf8_strtolower($name);
$name = preg_replace('@[ -/:->]+@', '-', $name); $name = preg_replace('@[ -/:->]+@', '-', $name);
@ -721,14 +721,14 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
$head = idx($params, 'head'); $head = idx($params, 'head');
$against = idx($params, 'against'); $against = idx($params, 'against');
if ($req_commit && !strlen($commit)) { if ($req_commit && ($commit === null || !strlen($commit))) {
throw new Exception( throw new Exception(
pht( pht(
'Diffusion URI action "%s" requires commit!', 'Diffusion URI action "%s" requires commit!',
$action)); $action));
} }
if ($req_branch && !strlen($branch)) { if ($req_branch && ($branch === null || !strlen($branch))) {
throw new Exception( throw new Exception(
pht( pht(
'Diffusion URI action "%s" requires branch!', 'Diffusion URI action "%s" requires branch!',
@ -779,20 +779,20 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
break; break;
case 'compare': case 'compare':
$uri = $this->getPathURI("/{$action}/"); $uri = $this->getPathURI("/{$action}/");
if (strlen($head)) { if ($head !== null && strlen($head)) {
$query['head'] = $head; $query['head'] = $head;
} else if (strlen($raw_commit)) { } else if ($raw_commit !== null && strlen($raw_commit)) {
$query['commit'] = $raw_commit; $query['commit'] = $raw_commit;
} else if (strlen($raw_branch)) { } else if ($raw_branch !== null && strlen($raw_branch)) {
$query['head'] = $raw_branch; $query['head'] = $raw_branch;
} }
if (strlen($against)) { if ($against !== null && strlen($against)) {
$query['against'] = $against; $query['against'] = $against;
} }
break; break;
case 'branch': case 'branch':
if (strlen($path)) { if ($path != null && strlen($path)) {
$uri = $this->getPathURI("/repository/{$path}"); $uri = $this->getPathURI("/repository/{$path}");
} else { } else {
$uri = $this->getPathURI('/'); $uri = $this->getPathURI('/');
@ -1160,7 +1160,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
*/ */
public function getRemoteURIObject() { public function getRemoteURIObject() {
$raw_uri = $this->getDetail('remote-uri'); $raw_uri = $this->getDetail('remote-uri');
if (!strlen($raw_uri)) { if ($raw_uri === null || !strlen($raw_uri)) {
return new PhutilURI(''); return new PhutilURI('');
} }
@ -2818,7 +2818,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
$permanent_rules = $this->getStringListForConduit($permanent_rules); $permanent_rules = $this->getStringListForConduit($permanent_rules);
$default_branch = $this->getDefaultBranch(); $default_branch = $this->getDefaultBranch();
if (!strlen($default_branch)) { if ($default_branch === null || !strlen($default_branch)) {
$default_branch = null; $default_branch = null;
} }

View file

@ -478,7 +478,7 @@ final class PhabricatorRepositoryCommit
} }
$author = $this->getRawAuthorStringForDisplay(); $author = $this->getRawAuthorStringForDisplay();
if (strlen($author)) { if ($author !== null && strlen($author)) {
return DiffusionView::renderName($author); return DiffusionView::renderName($author);
} }
@ -493,7 +493,7 @@ final class PhabricatorRepositoryCommit
} }
$committer = $this->getRawCommitterStringForDisplay(); $committer = $this->getRawCommitterStringForDisplay();
if (strlen($committer)) { if ($committer !== null && strlen($committer)) {
return DiffusionView::renderName($committer); return DiffusionView::renderName($committer);
} }

View file

@ -97,7 +97,7 @@ final class PhabricatorRepositoryCommitData extends PhabricatorRepositoryDAO {
$ref = $this->getCommitRef(); $ref = $this->getCommitRef();
$author = $ref->getAuthor(); $author = $ref->getAuthor();
if (strlen($author)) { if ($author !== null && strlen($author)) {
return $author; return $author;
} }
@ -131,7 +131,7 @@ final class PhabricatorRepositoryCommitData extends PhabricatorRepositoryDAO {
$ref = $this->getCommitRef(); $ref = $this->getCommitRef();
$committer = $ref->getCommitter(); $committer = $ref->getCommitter();
if (strlen($committer)) { if ($committer !== null && strlen($committer)) {
return $committer; return $committer;
} }

View file

@ -158,6 +158,9 @@ final class PhabricatorRepositoryPushLog
} }
public function getRefName() { public function getRefName() {
if ($this->getRefNameRaw() === null) {
return null;
}
return $this->getUTF8StringFromStorage( return $this->getUTF8StringFromStorage(
$this->getRefNameRaw(), $this->getRefNameRaw(),
$this->getRefNameEncoding()); $this->getRefNameEncoding());
@ -175,6 +178,9 @@ final class PhabricatorRepositoryPushLog
if ($this->getRepository()->isSVN()) { if ($this->getRepository()->isSVN()) {
return $this->getRefOld(); return $this->getRefOld();
} }
if ($this->getRefOld() === null) {
return null;
}
return substr($this->getRefOld(), 0, 12); return substr($this->getRefOld(), 0, 12);
} }

View file

@ -752,7 +752,7 @@ final class PhabricatorRepositoryURI
// without requiring an index rebuild. // without requiring an index rebuild.
$ssh_host = PhabricatorEnv::getEnvConfig('diffusion.ssh-host'); $ssh_host = PhabricatorEnv::getEnvConfig('diffusion.ssh-host');
if (strlen($ssh_host)) { if ($ssh_host !== null && strlen($ssh_host)) {
$domain_map['<ssh-host>'] = $ssh_host; $domain_map['<ssh-host>'] = $ssh_host;
} }

View file

@ -36,7 +36,7 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
$author = $ref->getAuthor(); $author = $ref->getAuthor();
$committer = $ref->getCommitter(); $committer = $ref->getCommitter();
$has_committer = (bool)strlen($committer); $has_committer = $committer !== null && (bool)strlen($committer);
$identity_engine = id(new DiffusionRepositoryIdentityEngine()) $identity_engine = id(new DiffusionRepositoryIdentityEngine())
->setViewer($viewer) ->setViewer($viewer)

View file

@ -39,7 +39,7 @@ final class PhabricatorExternalEditorSettingsPanel
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$pattern = $viewer->getUserSetting(PhabricatorEditorSetting::SETTINGKEY); $pattern = $viewer->getUserSetting(PhabricatorEditorSetting::SETTINGKEY);
if (!strlen($pattern)) { if ($pattern === null || !strlen($pattern)) {
return null; return null;
} }

View file

@ -2363,7 +2363,9 @@ abstract class PhabricatorApplicationTransactionEditor
// Here, we don't care about processing only new mentions after an edit // Here, we don't care about processing only new mentions after an edit
// because there is no way for an object to ever "unmention" itself on // because there is no way for an object to ever "unmention" itself on
// another object, so we can ignore the old value. // another object, so we can ignore the old value.
$engine->markupText($change->getNewValue()); if ($change->getNewValue() !== null) {
$engine->markupText($change->getNewValue());
}
$mentioned_phids += $engine->getTextMetadata( $mentioned_phids += $engine->getTextMetadata(
PhabricatorObjectRemarkupRule::KEY_MENTIONED_OBJECTS, PhabricatorObjectRemarkupRule::KEY_MENTIONED_OBJECTS,

View file

@ -7,7 +7,7 @@ final class PhabricatorUnknownContentSource
public function getSourceName() { public function getSourceName() {
$source = $this->getSource(); $source = $this->getSource();
if (strlen($source)) { if ($source !== null && strlen($source)) {
return pht('Unknown ("%s")', $source); return pht('Unknown ("%s")', $source);
} else { } else {
return pht('Unknown'); return pht('Unknown');

View file

@ -30,7 +30,7 @@ final class PhabricatorStandardCustomFieldRemarkup
public function renderPropertyViewValue(array $handles) { public function renderPropertyViewValue(array $handles) {
$value = $this->getFieldValue(); $value = $this->getFieldValue();
if (!strlen($value)) { if ($value === null || !strlen($value)) {
return null; return null;
} }

View file

@ -139,7 +139,7 @@ final class PHUIDiffTableOfContentsItemView extends AphrontView {
$not_applicable = '-'; $not_applicable = '-';
$coverage = $this->getCoverage(); $coverage = $this->getCoverage();
if (!strlen($coverage)) { if ($coverage === null || !strlen($coverage)) {
return $not_applicable; return $not_applicable;
} }
@ -157,7 +157,7 @@ final class PHUIDiffTableOfContentsItemView extends AphrontView {
$not_applicable = '-'; $not_applicable = '-';
$coverage = $this->getCoverage(); $coverage = $this->getCoverage();
if (!strlen($coverage)) { if ($coverage === null || !strlen($coverage)) {
return $not_applicable; return $not_applicable;
} }

View file

@ -16,7 +16,7 @@ final class PhabricatorEditorURIEngine
$pattern = $viewer->getUserSetting(PhabricatorEditorSetting::SETTINGKEY); $pattern = $viewer->getUserSetting(PhabricatorEditorSetting::SETTINGKEY);
if (!strlen(trim($pattern))) { if ($pattern === null || !strlen(trim($pattern))) {
return null; return null;
} }

View file

@ -42,7 +42,7 @@ abstract class PhabricatorLiskDAO extends LiskDAO {
if (!strlen($namespace)) { if (!strlen($namespace)) {
$namespace = self::getDefaultStorageNamespace(); $namespace = self::getDefaultStorageNamespace();
} }
if (!strlen($namespace)) { if ($namespace === null || !strlen($namespace)) {
throw new Exception(pht('No storage namespace configured!')); throw new Exception(pht('No storage namespace configured!'));
} }
return $namespace; return $namespace;
@ -295,7 +295,7 @@ abstract class PhabricatorLiskDAO extends LiskDAO {
} }
if (function_exists('mb_detect_encoding')) { if (function_exists('mb_detect_encoding')) {
if (strlen($encoding)) { if ($encoding !== null && strlen($encoding)) {
$try_encodings = array( $try_encodings = array(
$encoding, $encoding,
); );

View file

@ -50,7 +50,12 @@ final class PHUIPagerView extends AphrontView {
public function readFromRequest(AphrontRequest $request) { public function readFromRequest(AphrontRequest $request) {
$this->uri = $request->getRequestURI(); $this->uri = $request->getRequestURI();
$this->pagingParameter = 'offset'; $this->pagingParameter = 'offset';
$this->offset = $request->getInt($this->pagingParameter);
$offset = $request->getInt($this->pagingParameter);
if ($offset === null) {
$offset = 0;
}
$this->offset = $offset;
return $this; return $this;
} }