public function execute()
 {
     $repoName = $this->getArg(0);
     if ($repoName == "all") {
         $this->error("Cannot use the 'all' repo", true);
     }
     $repo = CodeRepository::newFromName($repoName);
     if (!$repo) {
         $this->error("Repo '{$repoName}' is not a valid Repository", true);
     }
     $revisions = $this->getArg(1);
     if (strpos($revisions, ':') !== false) {
         $revisionVals = explode(':', $revisions, 2);
     } else {
         $this->error("Invalid revision range", true);
     }
     $start = intval($revisionVals[0]);
     $end = intval($revisionVals[1]);
     $revisions = range($start, $end);
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('code_paths', '*', array('cp_rev_id' => $revisions, 'cp_repo_id' => $repo->getId()), __METHOD__);
     $dbw = wfGetDB(DB_MASTER);
     $dbw->begin();
     foreach ($res as $row) {
         $fragments = CodeRevision::getPathFragments(array(array('path' => $row->cp_path, 'action' => $row->cp_action)));
         CodeRevision::insertPaths($dbw, $fragments, $repo->getId(), $row->cp_rev_id);
         $this->output("r{$row->cp_rev_id}, path: " . $row->cp_path . " Fragments: " . count($fragments) . "\n");
     }
     $dbw->commit();
     $this->output("Done!\n");
 }
Beispiel #2
0
 /**
  * @static
  * @param CodeRepository $repo
  * @param  $data
  * @return CodeRevision
  */
 public static function newFromSvn(CodeRepository $repo, $data)
 {
     $rev = new CodeRevision();
     $rev->repoId = $repo->getId();
     $rev->repo = $repo;
     $rev->id = intval($data['rev']);
     $rev->author = $data['author'];
     $rev->timestamp = wfTimestamp(TS_MW, strtotime($data['date']));
     $rev->message = rtrim($data['msg']);
     $rev->paths = $data['paths'];
     $rev->status = 'new';
     $rev->oldStatus = '';
     $common = null;
     if ($rev->paths) {
         if (count($rev->paths) == 1) {
             $common = $rev->paths[0]['path'];
         } else {
             $first = array_shift($rev->paths);
             $common = explode('/', $first['path']);
             foreach ($rev->paths as $path) {
                 $compare = explode('/', $path['path']);
                 // make sure $common is the shortest path
                 if (count($compare) < count($common)) {
                     list($compare, $common) = array($common, $compare);
                 }
                 $tmp = array();
                 foreach ($common as $k => $v) {
                     if ($v == $compare[$k]) {
                         $tmp[] = $v;
                     } else {
                         break;
                     }
                 }
                 $common = $tmp;
             }
             $common = implode('/', $common);
             array_unshift($rev->paths, $first);
         }
         $rev->paths = CodeRevision::getPathFragments($rev->paths);
     }
     $rev->commonPath = $common;
     // Check for ignored paths
     global $wgCodeReviewDeferredPaths;
     if (isset($wgCodeReviewDeferredPaths[$repo->getName()])) {
         foreach ($wgCodeReviewDeferredPaths[$repo->getName()] as $defer) {
             if (preg_match($defer, $rev->commonPath)) {
                 $rev->status = 'deferred';
                 break;
             }
         }
     }
     global $wgCodeReviewAutoTagPath;
     if (isset($wgCodeReviewAutoTagPath[$repo->getName()])) {
         foreach ($wgCodeReviewAutoTagPath[$repo->getName()] as $path => $tags) {
             if (preg_match($path, $rev->commonPath)) {
                 $rev->changeTags($tags, array());
                 break;
             }
         }
     }
     return $rev;
 }