/** * @inheritdoc */ public function getGraphHistory($limit, $skip, $path = null, $branch = null) { $ret = new Graph(); $rawHistory = $this->getHistory($limit, $skip); $command = ['log', '--graph', '--format' => 'format:""', '-n', (int) $limit, '--skip' => (int) $skip]; if (is_null($branch)) { $command['--branches'] = '*'; } else { $command['--branches'] = '*' . escapeshellcmd($branch) . '*'; } if (!is_null($path)) { $command[] = '-- ' . escapeshellcmd($path); } $result = $this->wrapper->execute($command, $this->projectPath, true); $cursor = 0; foreach ($result as $row) { $row = str_replace(' ', '', $row); if (strpos($row, '*') !== false && isset($rawHistory[$cursor])) { $rawHistory[$cursor]->graphLevel = strpos($row, '*'); $ret->pushCommit($rawHistory[$cursor]); $cursor++; } } return $ret; }
/** * @inheritdoc * * @todo fix graph level * all commits at null-level, because -G (graph) hg option * uses if it's enabled at config */ public function getGraphHistory($limit, $skip, $path = null, $branch = null) { $ret = new Graph(); $rawHistory = $this->getHistory($limit, $skip); // attempt to use -G option // if it will be fail - return null-level history $command = ['log', '--encoding' => 'utf-8', '-G', '--template' => ' ', '--limit' => (int) $limit]; if (!is_null($branch)) { $command['--branch'] = escapeshellcmd($branch); } // detect begin revision number $fromRevision = $this->calculateBeginRevisionLog((int) $skip); if ($fromRevision === -1) { // the end of search return $ret; } else { if (!is_null($fromRevision)) { $command['--rev'] = $fromRevision . ':0'; } } if (!empty($path)) { $command[] = escapeshellcmd($path); } try { $result = $this->wrapper->execute($command, $this->projectPath, true); } catch (CommonException $ex) { foreach ($rawHistory as $commit) { $commit->graphLevel = 0; $ret->pushCommit($commit); } return $ret; } $cursor = 0; foreach ($result as $row) { $row = str_replace(' ', '', $row); if (strpos($row, 'o') !== false && isset($rawHistory[$cursor])) { $rawHistory[$cursor]->graphLevel = strpos($row, 'o'); $ret->pushCommit($rawHistory[$cursor]); $cursor++; } } return $ret; }