public function testSubversionPathInfo()
 {
     $svn = PhabricatorRepositoryType::REPOSITORY_TYPE_SVN;
     $repo = new PhabricatorRepository();
     $repo->setVersionControlSystem($svn);
     $repo->setDetail('remote-uri', 'http://svn.example.com/repo');
     $this->assertEqual('http://svn.example.com/repo', $repo->getSubversionPathURI());
     $repo->setDetail('remote-uri', 'http://svn.example.com/repo/');
     $this->assertEqual('http://svn.example.com/repo', $repo->getSubversionPathURI());
     $repo->setDetail('hosting-enabled', true);
     $repo->setLocalPath('/var/repo/SVN');
     $this->assertEqual('file:///var/repo/SVN', $repo->getSubversionPathURI());
     $repo->setLocalPath('/var/repo/SVN/');
     $this->assertEqual('file:///var/repo/SVN', $repo->getSubversionPathURI());
     $this->assertEqual('file:///var/repo/SVN/a@', $repo->getSubversionPathURI('a'));
     $this->assertEqual('file:///var/repo/SVN/a@1', $repo->getSubversionPathURI('a', 1));
     $this->assertEqual('file:///var/repo/SVN/%3F@22', $repo->getSubversionPathURI('?', 22));
     $repo->setDetail('svn-subpath', 'quack/trunk/');
     $this->assertEqual('file:///var/repo/SVN/quack/trunk/@', $repo->getSubversionBaseURI());
     $this->assertEqual('file:///var/repo/SVN/quack/trunk/@HEAD', $repo->getSubversionBaseURI('HEAD'));
 }
 private function verifySubversionRoot(PhabricatorRepository $repository)
 {
     list($xml) = $repository->execxRemoteCommand('info --xml %s', $repository->getSubversionPathURI());
     $xml = phutil_utf8ize($xml);
     $xml = new SimpleXMLElement($xml);
     $remote_root = (string) $xml->entry[0]->repository[0]->root[0];
     $expect_root = $repository->getSubversionPathURI();
     $normal_type_svn = PhabricatorRepositoryURINormalizer::TYPE_SVN;
     $remote_normal = id(new PhabricatorRepositoryURINormalizer($normal_type_svn, $remote_root))->getNormalizedPath();
     $expect_normal = id(new PhabricatorRepositoryURINormalizer($normal_type_svn, $expect_root))->getNormalizedPath();
     if ($remote_normal != $expect_normal) {
         throw new Exception(pht('Repository "%s" does not have a correctly configured remote URI. ' . 'The remote URI for a Subversion repository MUST point at the ' . 'repository root. The root for this repository is "%s", but the ' . 'configured URI is "%s". To resolve this error, set the remote URI ' . 'to point at the repository root. If you want to import only part ' . 'of a Subversion repository, use the "Import Only" option.', $repository->getDisplayName(), $remote_root, $expect_root));
     }
 }
 private function lookupRecursiveFileList(PhabricatorRepository $repository, array $info)
 {
     $path = $info['rawPath'];
     $rev = $info['rawCommit'];
     $path_uri = $repository->getSubversionPathURI($path, $rev);
     $hashkey = md5($path_uri);
     // This method is quite horrible. The underlying challenge is that some
     // commits in the Facebook repository are enormous, taking multiple hours
     // to 'ls -R' out of the repository and producing XML files >1GB in size.
     // If we try to SimpleXML them, the object exhausts available memory on a
     // 64G machine. Instead, cache the XML output and then parse it line by line
     // to limit space requirements.
     $cache_loc = sys_get_temp_dir() . '/diffusion.' . $hashkey . '.svnls';
     if (!Filesystem::pathExists($cache_loc)) {
         $tmp = new TempFile();
         $repository->execxRemoteCommand('--xml ls -R %s > %s', $path_uri, $tmp);
         execx('mv %s %s', $tmp, $cache_loc);
     }
     $map = $this->parseRecursiveListFileData($cache_loc);
     Filesystem::remove($cache_loc);
     return $map;
 }