private function loadCommitInfo(array $branches, ArcanistRepositoryAPI $repository_api) { $futures = array(); foreach ($branches as $branch) { // NOTE: "-s" is an option deep in git's diff argument parser that doesn't // seem to have much documentation and has no long form. It suppresses any // diff output. $futures[$branch['name']] = $repository_api->execFutureLocal('show -s --format=%C %s', '%H%x01%ct%x01%T%x01%s%x01%b', $branch['name']); } $branches = ipull($branches, null, 'name'); $commit_map = array(); foreach (Futures($futures) as $name => $future) { list($info) = $future->resolvex(); list($hash, $epoch, $tree, $desc, $text) = explode("", trim($info), 5); $branch = $branches[$name]; $branch['hash'] = $hash; $branch['desc'] = $desc; try { $text = $desc . "\n" . $text; $message = ArcanistDifferentialCommitMessage::newFromRawCorpus($text); $id = $message->getRevisionID(); $branch += array('epoch' => (int) $epoch, 'tree' => $tree, 'revisionID' => $id); } catch (ArcanistUsageException $ex) { // In case of invalid commit message which fails the parsing, // do nothing. } $commit_map[$hash] = $branch; } return $commit_map; }
public function commitRevisionToWorkspace(DifferentialRevision $revision, ArcanistRepositoryAPI $workspace, PhabricatorUser $user) { $diff_id = $revision->loadActiveDiff()->getID(); $call = new ConduitCall('differential.getrawdiff', array('diffID' => $diff_id)); $call->setUser($user); $raw_diff = $call->execute(); $future = $workspace->execFutureLocal('patch --no-commit -'); $future->write($raw_diff); $future->resolvex(); $workspace->reloadWorkingCopy(); $call = new ConduitCall('differential.getcommitmessage', array('revision_id' => $revision->getID())); $call->setUser($user); $message = $call->execute(); $author = id(new PhabricatorUser())->loadOneWhere('phid = %s', $revision->getAuthorPHID()); $author_string = sprintf('%s <%s>', $author->getRealName(), $author->loadPrimaryEmailAddress()); $author_date = $revision->getDateCreated(); $workspace->execxLocal('commit --date=%s --user=%s ' . '--message=%s', $author_date . ' 0', $author_string, $message); }
public function commitRevisionToWorkspace(DifferentialRevision $revision, ArcanistRepositoryAPI $workspace, PhabricatorUser $user) { $diff_id = $revision->loadActiveDiff()->getID(); $call = new ConduitCall('differential.getrawdiff', array('diffID' => $diff_id)); $call->setUser($user); $raw_diff = $call->execute(); $missing_binary = "\nindex " . "0000000000000000000000000000000000000000.." . "0000000000000000000000000000000000000000\n"; if (strpos($raw_diff, $missing_binary) !== false) { throw new Exception(pht('Patch is missing content for a binary file')); } $future = $workspace->execFutureLocal('apply --index -'); $future->write($raw_diff); $future->resolvex(); $workspace->reloadWorkingCopy(); $call = new ConduitCall('differential.getcommitmessage', array('revision_id' => $revision->getID())); $call->setUser($user); $message = $call->execute(); $author = id(new PhabricatorUser())->loadOneWhere('phid = %s', $revision->getAuthorPHID()); $author_string = sprintf('%s <%s>', $author->getRealName(), $author->loadPrimaryEmailAddress()); $author_date = $revision->getDateCreated(); $workspace->execxLocal('-c user.name=%s -c user.email=%s ' . 'commit --date=%s --author=%s ' . '--message=%s', $user->getRealName(), $user->loadPrimaryEmailAddress(), $author_date, $author_string, $message); }