本文整理汇总了PHP中DifferentialDiff::newFromRawChanges方法的典型用法代码示例。如果您正苦于以下问题:PHP DifferentialDiff::newFromRawChanges方法的具体用法?PHP DifferentialDiff::newFromRawChanges怎么用?PHP DifferentialDiff::newFromRawChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DifferentialDiff
的用法示例。
在下文中一共展示了DifferentialDiff::newFromRawChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: newDiffFromCommit
public function newDiffFromCommit(PhabricatorRepositoryCommit $commit)
{
$viewer = $this->getViewer();
$repository = $commit->getRepository();
$identifier = $commit->getCommitIdentifier();
$monogram = $commit->getMonogram();
$drequest = DiffusionRequest::newFromDictionary(array('user' => $viewer, 'repository' => $repository));
$raw_diff = DiffusionQuery::callConduitWithDiffusionRequest($viewer, $drequest, 'diffusion.rawdiffquery', array('commit' => $identifier));
// TODO: Support adds, deletes and moves under SVN.
if (strlen($raw_diff)) {
$changes = id(new ArcanistDiffParser())->parseDiff($raw_diff);
} else {
// This is an empty diff, maybe made with `git commit --allow-empty`.
// NOTE: These diffs have the same tree hash as their ancestors, so
// they may attach to revisions in an unexpected way. Just let this
// happen for now, although it might make sense to special case it
// eventually.
$changes = array();
}
$diff = DifferentialDiff::newFromRawChanges($viewer, $changes)->setRepositoryPHID($repository->getPHID())->setCreationMethod('commit')->setSourceControlSystem($repository->getVersionControlSystem())->setLintStatus(DifferentialLintStatus::LINT_AUTO_SKIP)->setUnitStatus(DifferentialUnitStatus::UNIT_AUTO_SKIP)->setDateCreated($commit->getEpoch())->setDescription($monogram);
$author_phid = $this->getAuthorPHID();
if ($author_phid !== null) {
$diff->setAuthorPHID($author_phid);
}
$parents = DiffusionQuery::callConduitWithDiffusionRequest($viewer, $drequest, 'diffusion.commitparentsquery', array('commit' => $identifier));
if ($parents) {
$diff->setSourceControlBaseRevision(head($parents));
}
// TODO: Attach binary files.
return $diff->save();
}
示例2: execute
protected function execute(ConduitAPIRequest $request)
{
$viewer = $request->getUser();
$raw_diff = $request->getValue('diff');
$repository_phid = $request->getValue('repositoryPHID');
if ($repository_phid) {
$repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withPHIDs(array($repository_phid))->executeOne();
if (!$repository) {
throw new Exception(pht('No such repository "%s"!', $repository_phid));
}
} else {
$repository = null;
}
$parser = new ArcanistDiffParser();
$changes = $parser->parseDiff($raw_diff);
$diff = DifferentialDiff::newFromRawChanges($changes);
$diff->setLintStatus(DifferentialLintStatus::LINT_SKIP);
$diff->setUnitStatus(DifferentialUnitStatus::UNIT_SKIP);
$diff->setAuthorPHID($viewer->getPHID());
$diff->setCreationMethod('web');
if ($repository) {
$diff->setRepositoryPHID($repository->getPHID());
}
id(new DifferentialDiffEditor())->setActor($viewer)->setContentSource(PhabricatorContentSource::newFromConduitRequest($request))->saveDiff($diff);
return $this->buildDiffInfoDictionary($diff);
}
示例3: executeQuery
protected function executeQuery()
{
$drequest = $this->getRequest();
$repository = $drequest->getRepository();
$effective_commit = $this->getEffectiveCommit();
if (!$effective_commit) {
return null;
}
// TODO: This side effect is kind of skethcy.
$drequest->setCommit($effective_commit);
$query = DiffusionRawDiffQuery::newFromDiffusionRequest($drequest);
$raw_diff = $query->loadRawDiff();
$parser = new ArcanistDiffParser();
$try_encoding = $repository->getDetail('encoding');
if ($try_encoding) {
$parser->setTryEncoding($try_encoding);
}
$parser->setDetectBinaryFiles(true);
$changes = $parser->parseDiff($raw_diff);
$diff = DifferentialDiff::newFromRawChanges($changes);
$changesets = $diff->getChangesets();
$changeset = reset($changesets);
$this->renderingReference = $drequest->generateURI(array('action' => 'rendering-ref'));
return $changeset;
}
示例4: executeQuery
protected function executeQuery()
{
$drequest = $this->getRequest();
$repository = $drequest->getRepository();
$effective_commit = $this->getEffectiveCommit();
if (!$effective_commit) {
return null;
}
// TODO: This side effect is kind of skethcy.
$drequest->setCommit($effective_commit);
$path = $drequest->getPath();
list($raw_diff) = $repository->execxLocalCommand('diff -U %d --git --change %s -- %s', 65535, $effective_commit, $path);
$parser = new ArcanistDiffParser();
$try_encoding = $repository->getDetail('encoding');
if ($try_encoding) {
$parser->setTryEncoding($try_encoding);
}
$parser->setDetectBinaryFiles(true);
$changes = $parser->parseDiff($raw_diff);
$diff = DifferentialDiff::newFromRawChanges($changes);
$changesets = $diff->getChangesets();
$changeset = reset($changesets);
$this->renderingReference = $drequest->getBranchURIComponent($drequest->getBranch()) . $drequest->getPath() . ';' . $drequest->getCommit();
return $changeset;
}
示例5: executeQuery
protected function executeQuery()
{
$drequest = $this->getRequest();
$repository = $drequest->getRepository();
if (!$drequest->getRawCommit()) {
$effective_commit = $this->getEffectiveCommit();
if (!$effective_commit) {
return null;
}
// TODO: This side effect is kind of skethcy.
$drequest->setCommit($effective_commit);
} else {
$effective_commit = $drequest->getCommit();
}
$options = array('-M', '-C', '--no-ext-diff', '--no-color', '--src-prefix=a/', '--dst-prefix=b/', '-U65535');
$options = implode(' ', $options);
list($raw_diff) = execx("(cd %s && git diff {$options} %s^ %s -- %s)", $repository->getDetail('local-path'), $effective_commit, $effective_commit, $drequest->getPath());
$parser = new ArcanistDiffParser();
$parser->setDetectBinaryFiles(true);
$changes = $parser->parseDiff($raw_diff);
$diff = DifferentialDiff::newFromRawChanges($changes);
$changesets = $diff->getChangesets();
$changeset = reset($changesets);
$this->renderingReference = $drequest->getBranchURIComponent($drequest->getBranch()) . $drequest->getPath() . ';' . $drequest->getCommit();
return $changeset;
}
示例6: processRequest
public function processRequest()
{
$request = $this->getRequest();
if ($request->isFormPost()) {
$parser = new ArcanistDiffParser();
$diff = null;
try {
$diff = PhabricatorFile::readUploadedFileData($_FILES['diff-file']);
} catch (Exception $ex) {
$diff = $request->getStr('diff');
}
$changes = $parser->parseDiff($diff);
$diff = DifferentialDiff::newFromRawChanges($changes);
$diff->setLintStatus(DifferentialLintStatus::LINT_SKIP);
$diff->setUnitStatus(DifferentialLintStatus::LINT_SKIP);
$diff->setAuthorPHID($request->getUser()->getPHID());
$diff->setCreationMethod('web');
$diff->save();
return id(new AphrontRedirectResponse())->setURI('/differential/diff/' . $diff->getID() . '/');
}
$form = new AphrontFormView();
$arcanist_href = PhabricatorEnv::getDoclink('article/Arcanist_User_Guide.html');
$arcanist_link = phutil_render_tag('a', array('href' => $arcanist_href, 'target' => '_blank'), 'Arcanist');
$form->setAction('/differential/diff/create/')->setEncType('multipart/form-data')->setUser($request->getUser())->appendChild('<p class="aphront-form-instructions">The best way to create a ' . "Differential diff is by using {$arcanist_link}, but you " . 'can also just paste a diff (e.g., from <tt>svn diff</tt> or ' . '<tt>git diff</tt>) into this box or upload it as a file if you ' . 'really want.</p>')->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Raw Diff')->setName('diff')->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL))->appendChild(id(new AphrontFormFileControl())->setLabel('Raw Diff from file')->setName('diff-file'))->appendChild(id(new AphrontFormSubmitControl())->setValue("Create Diff »"));
$panel = new AphrontPanelView();
$panel->setHeader('Create New Diff');
$panel->appendChild($form);
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
return $this->buildStandardPageResponse($panel, array('title' => 'Create Diff', 'tab' => 'create'));
}
示例7: testGenerateHarbormasterAutotargets
public function testGenerateHarbormasterAutotargets()
{
$viewer = $this->generateNewTestUser();
$raw_diff = <<<EODIFF
diff --git a/fruit b/fruit
new file mode 100644
index 0000000..1c0f49d
--- /dev/null
+++ b/fruit
@@ -0,0 +1,2 @@
+apal
+banan
EODIFF;
$parser = new ArcanistDiffParser();
$changes = $parser->parseDiff($raw_diff);
$diff = DifferentialDiff::newFromRawChanges($viewer, $changes)->setLintStatus(DifferentialLintStatus::LINT_AUTO_SKIP)->setUnitStatus(DifferentialUnitStatus::UNIT_AUTO_SKIP)->attachRevision(null)->save();
$params = array('objectPHID' => $diff->getPHID(), 'targetKeys' => array(HarbormasterArcLintBuildStepImplementation::STEPKEY, HarbormasterArcUnitBuildStepImplementation::STEPKEY));
// Creation of autotargets should work from an empty state.
$result = id(new ConduitCall('harbormaster.queryautotargets', $params))->setUser($viewer)->execute();
$targets = idx($result, 'targetMap');
foreach ($params['targetKeys'] as $target_key) {
$this->assertTrue((bool) $result['targetMap'][$target_key]);
}
// Querying the same autotargets again should produce the same results,
// not make new ones.
$retry = id(new ConduitCall('harbormaster.queryautotargets', $params))->setUser($viewer)->execute();
$this->assertEqual($result, $retry);
}
示例8: buildChangesetParser
private function buildChangesetParser($type, $data, $file)
{
$parser = new ArcanistDiffParser();
$changes = $parser->parseDiff($data);
$diff = DifferentialDiff::newFromRawChanges($changes);
if (count($diff->getChangesets()) !== 1) {
throw new Exception("Expected one changeset: {$file}");
}
$changeset = head($diff->getChangesets());
$engine = new PhabricatorMarkupEngine();
$engine->setViewer(new PhabricatorUser());
$cparser = new DifferentialChangesetParser();
$cparser->setDisableCache(true);
$cparser->setChangeset($changeset);
$cparser->setMarkupEngine($engine);
if ($type == 'one') {
$cparser->setRenderer(new DifferentialChangesetOneUpTestRenderer());
} else {
if ($type == 'two') {
$cparser->setRenderer(new DifferentialChangesetTwoUpTestRenderer());
} else {
throw new Exception("Unknown renderer type '{$type}'!");
}
}
return $cparser;
}
示例9: buildChangesetParsers
private function buildChangesetParsers($type, $data, $file)
{
$parser = new ArcanistDiffParser();
$changes = $parser->parseDiff($data);
$diff = DifferentialDiff::newFromRawChanges(PhabricatorUser::getOmnipotentUser(), $changes);
$changesets = $diff->getChangesets();
$engine = new PhabricatorMarkupEngine();
$engine->setViewer(new PhabricatorUser());
$parsers = array();
foreach ($changesets as $changeset) {
$cparser = new DifferentialChangesetParser();
$cparser->setUser(new PhabricatorUser());
$cparser->setDisableCache(true);
$cparser->setChangeset($changeset);
$cparser->setMarkupEngine($engine);
if ($type == 'one') {
$cparser->setRenderer(new DifferentialChangesetOneUpTestRenderer());
} else {
if ($type == 'two') {
$cparser->setRenderer(new DifferentialChangesetTwoUpTestRenderer());
} else {
throw new Exception(pht('Unknown renderer type "%s"!', $type));
}
}
$parsers[] = $cparser;
}
return $parsers;
}
示例10: execute
protected function execute(ConduitAPIRequest $request)
{
$viewer = $request->getUser();
$raw_diff = $request->getValue('diff');
$repository_phid = $request->getValue('repositoryPHID');
if ($repository_phid) {
$repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withPHIDs(array($repository_phid))->executeOne();
if (!$repository) {
throw new Exception(pht('No such repository "%s"!', $repository_phid));
}
}
$parser = new ArcanistDiffParser();
$changes = $parser->parseDiff($raw_diff);
$diff = DifferentialDiff::newFromRawChanges($viewer, $changes);
// We're bounded by doing INSERTs for all the hunks and changesets, so
// estimate the number of inserts we'll require.
$size = 0;
foreach ($diff->getChangesets() as $changeset) {
$hunks = $changeset->getHunks();
$size += 1 + count($hunks);
}
$raw_limit = 10000;
if ($size > $raw_limit) {
throw new Exception(pht('The raw diff you have submitted is too large to parse (it affects ' . 'more than %s paths and hunks). Differential should only be used ' . 'for changes which are small enough to receive detailed human ' . 'review. See "Differential User Guide: Large Changes" in the ' . 'documentation for more information.', new PhutilNumber($raw_limit)));
}
$diff_data_dict = array('creationMethod' => 'web', 'authorPHID' => $viewer->getPHID(), 'repositoryPHID' => $repository_phid, 'lintStatus' => DifferentialLintStatus::LINT_SKIP, 'unitStatus' => DifferentialUnitStatus::UNIT_SKIP);
$xactions = array(id(new DifferentialDiffTransaction())->setTransactionType(DifferentialDiffTransaction::TYPE_DIFF_CREATE)->setNewValue($diff_data_dict));
if ($request->getValue('viewPolicy')) {
$xactions[] = id(new DifferentialDiffTransaction())->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)->setNewValue($request->getValue('viewPolicy'));
}
id(new DifferentialDiffEditor())->setActor($viewer)->setContentSource($request->newContentSource())->setContinueOnNoEffect(true)->setLookupRepository(false)->applyTransactions($diff, $xactions);
return $this->buildDiffInfoDictionary($diff);
}
示例11: testDetectSlowCopiedCode
public function testDetectSlowCopiedCode()
{
// This tests that the detector has a reasonable runtime when a diff
// contains a very large number of identical lines. See T5041.
$parser = new ArcanistDiffParser();
$line = str_repeat('x', 60);
$oline = '-' . $line . "\n";
$nline = '+' . $line . "\n";
$n = 1000;
$oblock = str_repeat($oline, $n);
$nblock = str_repeat($nline, $n);
$raw_diff = <<<EODIFF
diff --git a/dst b/dst
new file mode 100644
index 0000000..1234567
--- /dev/null
+++ b/dst
@@ -0,0 +1,{$n} @@
{$nblock}
diff --git a/src b/src
deleted file mode 100644
index 123457..0000000
--- a/src
+++ /dev/null
@@ -1,{$n} +0,0 @@
{$oblock}
EODIFF;
$diff = DifferentialDiff::newFromRawChanges($parser->parseDiff($raw_diff));
$this->assertTrue(true);
}
示例12: createHunksFromFile
private function createHunksFromFile($name)
{
$data = Filesystem::readFile(dirname(__FILE__) . '/data/' . $name);
$parser = new ArcanistDiffParser();
$changes = $parser->parseDiff($data);
if (count($changes) !== 1) {
throw new Exception("Expected 1 changeset for '{$name}'!");
}
$diff = DifferentialDiff::newFromRawChanges($changes);
return head($diff->getChangesets())->getHunks();
}
示例13: execute
protected function execute(ConduitAPIRequest $request)
{
$raw_diff = $request->getValue('diff');
$parser = new ArcanistDiffParser();
$changes = $parser->parseDiff($raw_diff);
$diff = DifferentialDiff::newFromRawChanges($changes);
$diff->setLintStatus(DifferentialLintStatus::LINT_SKIP);
$diff->setUnitStatus(DifferentialLintStatus::LINT_SKIP);
$diff->setAuthorPHID($request->getUser()->getPHID());
$diff->setCreationMethod('web');
$diff->save();
return $this->buildDiffInfoDictionary($diff);
}
示例14: executeQuery
protected function executeQuery()
{
$drequest = $this->getRequest();
$repository = $drequest->getRepository();
if (!$drequest->getRawCommit()) {
$effective_commit = $this->getEffectiveCommit();
if (!$effective_commit) {
return null;
}
// TODO: This side effect is kind of skethcy.
$drequest->setCommit($effective_commit);
} else {
$effective_commit = $drequest->getCommit();
}
$options = array('-M', '-C', '--no-ext-diff', '--no-color', '--src-prefix=a/', '--dst-prefix=b/', '-U65535');
$options = implode(' ', $options);
try {
list($raw_diff) = $repository->execxLocalCommand('diff %C %s^ %s -- %s', $options, $effective_commit, $effective_commit, $drequest->getPath());
} catch (CommandException $ex) {
// Check if this is the root commit by seeing if it has parents.
list($parents) = $repository->execxLocalCommand('log --format=%s %s --', '%P', $effective_commit);
if (!strlen(trim($parents))) {
// No parents means we're looking at the root revision. Diff against
// the empty tree hash instead, since there is no parent so "^" does
// not work. See ArcanistGitAPI for more discussion.
list($raw_diff) = $repository->execxLocalCommand('diff %C %s %s -- %s', $options, ArcanistGitAPI::GIT_MAGIC_ROOT_COMMIT, $effective_commit, $drequest->getPath());
} else {
throw $ex;
}
}
$parser = new ArcanistDiffParser();
$try_encoding = $repository->getDetail('encoding');
if ($try_encoding) {
$parser->setTryEncoding($try_encoding);
}
$parser->setDetectBinaryFiles(true);
$changes = $parser->parseDiff($raw_diff);
$diff = DifferentialDiff::newFromRawChanges($changes);
$changesets = $diff->getChangesets();
$changeset = reset($changesets);
$this->renderingReference = $drequest->getBranchURIComponent($drequest->getBranch()) . $drequest->getPath() . ';' . $drequest->getCommit();
return $changeset;
}
示例15: processRequest
public function processRequest()
{
$drequest = $this->diffusionRequest;
$viewer = $this->getRequest()->getUser();
$content = array();
$data = $this->callConduitWithDiffusionRequest('diffusion.diffquery', array('commit' => $drequest->getCommit(), 'path' => $drequest->getPath()));
$drequest->updateSymbolicCommit($data['effectiveCommit']);
$raw_changes = ArcanistDiffChange::newFromConduit($data['changes']);
$diff = DifferentialDiff::newFromRawChanges($raw_changes);
$changesets = $diff->getChangesets();
$changeset = reset($changesets);
if (!$changeset) {
// TODO: Refine this.
return new Aphront404Response();
}
$repository = $drequest->getRepository();
$callsign = $repository->getCallsign();
$changesets = array(0 => $changeset);
$changeset_view = new DifferentialChangesetListView();
$changeset_view->setTitle(pht('Change'));
$changeset_view->setChangesets($changesets);
$changeset_view->setVisibleChangesets($changesets);
$changeset_view->setRenderingReferences(array(0 => $drequest->generateURI(array('action' => 'rendering-ref'))));
$raw_params = array('action' => 'browse', 'params' => array('view' => 'raw'));
$right_uri = $drequest->generateURI($raw_params);
$raw_params['params']['before'] = $drequest->getStableCommit();
$left_uri = $drequest->generateURI($raw_params);
$changeset_view->setRawFileURIs($left_uri, $right_uri);
$changeset_view->setRenderURI('/diffusion/' . $callsign . '/diff/');
$changeset_view->setWhitespace(DifferentialChangesetParser::WHITESPACE_SHOW_ALL);
$changeset_view->setUser($this->getRequest()->getUser());
// TODO: This is pretty awkward, unify the CSS between Diffusion and
// Differential better.
require_celerity_resource('differential-core-view-css');
$content[] = $changeset_view->render();
$crumbs = $this->buildCrumbs(array('branch' => true, 'path' => true, 'view' => 'change'));
$links = $this->renderPathLinks($drequest, $mode = 'browse');
$header = id(new PHUIHeaderView())->setHeader($links)->setUser($viewer)->setPolicyObject($drequest->getRepository());
$actions = $this->buildActionView($drequest);
$properties = $this->buildPropertyView($drequest, $actions);
$object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties);
return $this->buildApplicationPage(array($crumbs, $object_box, $content), array('title' => pht('Change'), 'device' => false));
}