public function testByteFormatting()
 {
     $tests = array(1 => '1 B', 1000 => '1 KB', 1000000 => '1 MB', 10000000 => '10 MB', 100000000 => '100 MB', 1000000000 => '1 GB', 999 => '999 B');
     foreach ($tests as $input => $expect) {
         $this->assertEqual($expect, phabricator_format_bytes($input), 'phabricator_format_bytes(' . $input . ')');
     }
 }
 public static function renderUploadLimit()
 {
     $limit = PhabricatorEnv::getEnvConfig('storage.upload-size-limit');
     $limit = phabricator_parse_bytes($limit);
     if ($limit) {
         $formatted = phabricator_format_bytes($limit);
         return 'Maximum file size: ' . phutil_escape_html($formatted);
     }
     $doc_href = PhabricatorEnv::getDocLink('article/Configuring_File_Upload_Limits.html');
     $doc_link = phutil_render_tag('a', array('href' => $doc_href, 'target' => '_blank'), 'Configuring File Upload Limits');
     return 'Upload limit is not configured, see ' . $doc_link . '.';
 }
 private function loadRawPatchText(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     $drequest = DiffusionRequest::newFromDictionary(array('repository' => $repository, 'commit' => $commit->getCommitIdentifier()));
     $raw_query = DiffusionRawDiffQuery::newFromDiffusionRequest($drequest);
     $raw_query->setLinesOfContext(3);
     $time_key = 'metamta.diffusion.time-limit';
     $byte_key = 'metamta.diffusion.byte-limit';
     $time_limit = PhabricatorEnv::getEnvConfig($time_key);
     $byte_limit = PhabricatorEnv::getEnvConfig($byte_key);
     if ($time_limit) {
         $raw_query->setTimeout($time_limit);
     }
     $raw_diff = $raw_query->loadRawDiff();
     $size = strlen($raw_diff);
     if ($byte_limit && $size > $byte_limit) {
         $pretty_size = phabricator_format_bytes($size);
         $pretty_limit = phabricator_format_bytes($byte_limit);
         throw new Exception("Patch size of {$pretty_size} exceeds configured byte size limit of " . "{$pretty_limit}.");
     }
     return $raw_diff;
 }