|  | 
| 29 | 29 | final class PhabricatorRepositoryPullLocalDaemon | 
| 30 | 30 |   extends PhabricatorDaemon { | 
| 31 | 31 | 
 | 
| 32 |  | -  private $discoveryEngines = array(); | 
| 33 |  | - | 
| 34 | 32 | 
 | 
| 35 | 33 | /* -(  Pulling Repositories  )----------------------------------------------- */ | 
| 36 | 34 | 
 | 
| @@ -122,49 +120,28 @@ public function run() { | 
| 122 | 120 |         try { | 
| 123 | 121 |           $this->log("Updating repository '{$callsign}'."); | 
| 124 | 122 | 
 | 
| 125 |  | -          id(new PhabricatorRepositoryPullEngine()) | 
| 126 |  | -            ->setRepository($repository) | 
| 127 |  | -            ->pullRepository(); | 
| 128 |  | - | 
| 129 |  | -          if (!$no_discovery) { | 
| 130 |  | -            // TODO: It would be nice to discover only if we pulled something, | 
| 131 |  | -            // but this isn't totally trivial. It's slightly more complicated | 
| 132 |  | -            // with hosted repositories, too. | 
| 133 |  | - | 
| 134 |  | -            $lock_name = get_class($this).':'.$callsign; | 
| 135 |  | -            $lock = PhabricatorGlobalLock::newLock($lock_name); | 
| 136 |  | -            $lock->lock(); | 
| 137 |  | - | 
| 138 |  | -            try { | 
| 139 |  | -              $repository->writeStatusMessage( | 
| 140 |  | -                PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE, | 
| 141 |  | -                null); | 
| 142 |  | -              $this->discoverRepository($repository); | 
| 143 |  | -              $this->updateRepositoryRefs($repository); | 
| 144 |  | -              $this->mirrorRepository($repository); | 
| 145 |  | -              $repository->writeStatusMessage( | 
| 146 |  | -                PhabricatorRepositoryStatusMessage::TYPE_FETCH, | 
| 147 |  | -                PhabricatorRepositoryStatusMessage::CODE_OKAY); | 
| 148 |  | -            } catch (Exception $ex) { | 
| 149 |  | -              $repository->writeStatusMessage( | 
| 150 |  | -                PhabricatorRepositoryStatusMessage::TYPE_FETCH, | 
| 151 |  | -                PhabricatorRepositoryStatusMessage::CODE_ERROR, | 
| 152 |  | -                array( | 
| 153 |  | -                  'message' => pht( | 
| 154 |  | -                    'Error updating working copy: %s', $ex->getMessage()), | 
| 155 |  | -                )); | 
| 156 |  | -              $lock->unlock(); | 
| 157 |  | -              throw $ex; | 
| 158 |  | -            } | 
| 159 |  | - | 
| 160 |  | -            $lock->unlock(); | 
|  | 123 | +          $bin_dir = dirname(phutil_get_library_root('phabricator')).'/bin'; | 
|  | 124 | +          $flags = array(); | 
|  | 125 | +          if ($no_discovery) { | 
|  | 126 | +            $flags[] = '--no-discovery'; | 
|  | 127 | +          } | 
|  | 128 | + | 
|  | 129 | +          list($stdout, $stderr) = execx( | 
|  | 130 | +            '%s/repository update %Ls -- %s', | 
|  | 131 | +            $bin_dir, | 
|  | 132 | +            $flags, | 
|  | 133 | +            $callsign); | 
|  | 134 | + | 
|  | 135 | +          if (strlen($stderr)) { | 
|  | 136 | +            $stderr_msg = pht( | 
|  | 137 | +              'Unexpected output while updating the %s repository: %s', | 
|  | 138 | +              $callsign, | 
|  | 139 | +              $stderr); | 
|  | 140 | +            phlog($stderr_msg); | 
| 161 | 141 |           } | 
| 162 | 142 | 
 | 
| 163 | 143 |           $sleep_for = $repository->getDetail('pull-frequency', $min_sleep); | 
| 164 | 144 |           $retry_after[$id] = time() + $sleep_for; | 
| 165 |  | -        } catch (PhutilLockException $ex) { | 
| 166 |  | -          $retry_after[$id] = time() + $min_sleep; | 
| 167 |  | -          $this->log("Failed to acquire lock."); | 
| 168 | 145 |         } catch (Exception $ex) { | 
| 169 | 146 |           $retry_after[$id] = time() + $min_sleep; | 
| 170 | 147 | 
 | 
| @@ -224,85 +201,4 @@ protected function loadRepositories(array $names) { | 
| 224 | 201 |     return $repos; | 
| 225 | 202 |   } | 
| 226 | 203 | 
 | 
| 227 |  | -  public function discoverRepository(PhabricatorRepository $repository) { | 
| 228 |  | -    $refs = $this->getDiscoveryEngine($repository) | 
| 229 |  | -      ->discoverCommits(); | 
| 230 |  | - | 
| 231 |  | -    $this->checkIfRepositoryIsFullyImported($repository); | 
| 232 |  | - | 
| 233 |  | -    return (bool)count($refs); | 
| 234 |  | -  } | 
| 235 |  | - | 
| 236 |  | -  private function mirrorRepository(PhabricatorRepository $repository) { | 
| 237 |  | -    try { | 
| 238 |  | -      id(new PhabricatorRepositoryMirrorEngine()) | 
| 239 |  | -        ->setRepository($repository) | 
| 240 |  | -        ->pushToMirrors(); | 
| 241 |  | -    } catch (Exception $ex) { | 
| 242 |  | -      // TODO: We should report these into the UI properly, but for | 
| 243 |  | -      // now just complain. These errors are much less severe than | 
| 244 |  | -      // pull errors. | 
| 245 |  | -      $proxy = new PhutilProxyException( | 
| 246 |  | -        pht( | 
| 247 |  | -          'Error while pushing "%s" repository to mirrors.', | 
| 248 |  | -          $repository->getCallsign()), | 
| 249 |  | -        $ex); | 
| 250 |  | -      phlog($proxy); | 
| 251 |  | -    } | 
| 252 |  | -  } | 
| 253 |  | - | 
| 254 |  | -  private function updateRepositoryRefs(PhabricatorRepository $repository) { | 
| 255 |  | -    id(new PhabricatorRepositoryRefEngine()) | 
| 256 |  | -      ->setRepository($repository) | 
| 257 |  | -      ->updateRefs(); | 
| 258 |  | -  } | 
| 259 |  | - | 
| 260 |  | -  private function getDiscoveryEngine(PhabricatorRepository $repository) { | 
| 261 |  | -    $id = $repository->getID(); | 
| 262 |  | -    if (empty($this->discoveryEngines[$id])) { | 
| 263 |  | -      $engine = id(new PhabricatorRepositoryDiscoveryEngine()) | 
| 264 |  | -        ->setRepository($repository) | 
| 265 |  | -        ->setVerbose($this->getVerbose()); | 
| 266 |  | - | 
| 267 |  | -      $this->discoveryEngines[$id] = $engine; | 
| 268 |  | -    } | 
| 269 |  | -    return $this->discoveryEngines[$id]; | 
| 270 |  | -  } | 
| 271 |  | - | 
| 272 |  | -  private function checkIfRepositoryIsFullyImported( | 
| 273 |  | -    PhabricatorRepository $repository) { | 
| 274 |  | - | 
| 275 |  | -    // Check if the repository has the "Importing" flag set. We want to clear | 
| 276 |  | -    // the flag if we can. | 
| 277 |  | -    $importing = $repository->getDetail('importing'); | 
| 278 |  | -    if (!$importing) { | 
| 279 |  | -      // This repository isn't marked as "Importing", so we're done. | 
| 280 |  | -      return; | 
| 281 |  | -    } | 
| 282 |  | - | 
| 283 |  | -    // Look for any commit which hasn't imported. | 
| 284 |  | -    $unparsed_commit = queryfx_one( | 
| 285 |  | -      $repository->establishConnection('r'), | 
| 286 |  | -      'SELECT * FROM %T WHERE repositoryID = %d AND (importStatus & %d) != %d | 
| 287 |  | -        LIMIT 1', | 
| 288 |  | -      id(new PhabricatorRepositoryCommit())->getTableName(), | 
| 289 |  | -      $repository->getID(), | 
| 290 |  | -      PhabricatorRepositoryCommit::IMPORTED_ALL, | 
| 291 |  | -      PhabricatorRepositoryCommit::IMPORTED_ALL); | 
| 292 |  | -    if ($unparsed_commit) { | 
| 293 |  | -      // We found a commit which still needs to import, so we can't clear the | 
| 294 |  | -      // flag. | 
| 295 |  | -      return; | 
| 296 |  | -    } | 
| 297 |  | - | 
| 298 |  | -    // Clear the "importing" flag. | 
| 299 |  | -    $repository->openTransaction(); | 
| 300 |  | -      $repository->beginReadLocking(); | 
| 301 |  | -        $repository = $repository->reload(); | 
| 302 |  | -        $repository->setDetail('importing', false); | 
| 303 |  | -        $repository->save(); | 
| 304 |  | -      $repository->endReadLocking(); | 
| 305 |  | -    $repository->saveTransaction(); | 
| 306 |  | -  } | 
| 307 |  | - | 
| 308 | 204 | } | 
0 commit comments