2011-01-24 20:01:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DifferentialDiff extends DifferentialDAO {
|
|
|
|
|
|
|
|
protected $revisionID;
|
2011-01-30 19:37:36 +01:00
|
|
|
protected $authorPHID;
|
2011-01-24 20:01:53 +01:00
|
|
|
|
|
|
|
protected $sourceMachine;
|
|
|
|
protected $sourcePath;
|
|
|
|
|
|
|
|
protected $sourceControlSystem;
|
|
|
|
protected $sourceControlBaseRevision;
|
|
|
|
protected $sourceControlPath;
|
|
|
|
|
|
|
|
protected $lintStatus;
|
|
|
|
protected $unitStatus;
|
|
|
|
|
|
|
|
protected $lineCount;
|
|
|
|
|
|
|
|
protected $branch;
|
|
|
|
|
|
|
|
protected $parentRevisionID;
|
2011-04-06 05:49:31 +02:00
|
|
|
protected $arcanistProjectPHID;
|
2011-01-24 20:01:53 +01:00
|
|
|
protected $creationMethod;
|
2011-04-06 05:49:31 +02:00
|
|
|
protected $repositoryUUID;
|
2011-01-24 20:01:53 +01:00
|
|
|
|
2011-02-05 02:53:14 +01:00
|
|
|
protected $description;
|
|
|
|
|
2011-01-24 20:36:53 +01:00
|
|
|
private $unsavedChangesets = array();
|
2011-01-25 00:52:35 +01:00
|
|
|
private $changesets;
|
2011-01-24 20:36:53 +01:00
|
|
|
|
|
|
|
public function addUnsavedChangeset(DifferentialChangeset $changeset) {
|
2011-01-25 00:52:35 +01:00
|
|
|
if ($this->changesets === null) {
|
|
|
|
$this->changesets = array();
|
|
|
|
}
|
2011-01-24 20:36:53 +01:00
|
|
|
$this->unsavedChangesets[] = $changeset;
|
2011-01-25 00:52:35 +01:00
|
|
|
$this->changesets[] = $changeset;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attachChangesets(array $changesets) {
|
|
|
|
$this->changesets = $changesets;
|
2011-01-24 20:36:53 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-01-25 00:52:35 +01:00
|
|
|
public function getChangesets() {
|
|
|
|
if ($this->changesets === null) {
|
|
|
|
throw new Exception("Must load and attach changesets first!");
|
|
|
|
}
|
|
|
|
return $this->changesets;
|
|
|
|
}
|
|
|
|
|
2011-01-24 20:01:53 +01:00
|
|
|
public function loadChangesets() {
|
|
|
|
if (!$this->getID()) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
return id(new DifferentialChangeset())->loadAllWhere(
|
|
|
|
'diffID = %d',
|
|
|
|
$this->getID());
|
|
|
|
}
|
|
|
|
|
2011-09-14 19:59:52 +02:00
|
|
|
public function loadArcanistProject() {
|
|
|
|
if (!$this->getArcanistProjectPHID()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return id(new PhabricatorRepositoryArcanistProject())->loadOneWhere(
|
|
|
|
'phid = %s',
|
|
|
|
$this->getArcanistProjectPHID());
|
|
|
|
}
|
|
|
|
|
2011-01-24 20:36:53 +01:00
|
|
|
public function save() {
|
|
|
|
// TODO: sort out transactions
|
|
|
|
// $this->openTransaction();
|
|
|
|
$ret = parent::save();
|
|
|
|
foreach ($this->unsavedChangesets as $changeset) {
|
2011-01-24 21:07:34 +01:00
|
|
|
$changeset->setDiffID($this->getID());
|
|
|
|
$changeset->save();
|
2011-01-24 20:36:53 +01:00
|
|
|
}
|
|
|
|
// $this->saveTransaction();
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2011-01-24 20:01:53 +01:00
|
|
|
public function delete() {
|
2011-01-24 20:36:53 +01:00
|
|
|
// $this->openTransaction();
|
2011-01-24 20:01:53 +01:00
|
|
|
foreach ($this->loadChangesets() as $changeset) {
|
|
|
|
$changeset->delete();
|
|
|
|
}
|
|
|
|
$ret = parent::delete();
|
2011-01-24 20:36:53 +01:00
|
|
|
// $this->saveTransaction();
|
2011-01-24 20:01:53 +01:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function newFromRawChanges(array $changes) {
|
|
|
|
$diff = new DifferentialDiff();
|
|
|
|
|
|
|
|
$lines = 0;
|
|
|
|
foreach ($changes as $change) {
|
|
|
|
$changeset = new DifferentialChangeset();
|
|
|
|
$add_lines = 0;
|
|
|
|
$del_lines = 0;
|
|
|
|
foreach ($change->getHunks() as $hunk) {
|
2011-01-24 20:36:53 +01:00
|
|
|
$dhunk = new DifferentialHunk();
|
2011-01-24 20:01:53 +01:00
|
|
|
$dhunk->setOldOffset($hunk->getOldOffset());
|
|
|
|
$dhunk->setOldLen($hunk->getOldLength());
|
|
|
|
$dhunk->setNewOffset($hunk->getNewOffset());
|
|
|
|
$dhunk->setNewLen($hunk->getNewLength());
|
|
|
|
$dhunk->setChanges($hunk->getCorpus());
|
2011-01-24 20:36:53 +01:00
|
|
|
$changeset->addUnsavedHunk($dhunk);
|
2011-01-24 20:01:53 +01:00
|
|
|
$add_lines += $hunk->getAddLines();
|
|
|
|
$del_lines += $hunk->getDelLines();
|
|
|
|
$lines += $add_lines + $del_lines;
|
|
|
|
}
|
|
|
|
|
|
|
|
$changeset->setOldFile($change->getOldPath());
|
|
|
|
$changeset->setFilename($change->getCurrentPath());
|
|
|
|
$changeset->setChangeType($change->getType());
|
|
|
|
|
|
|
|
$changeset->setFileType($change->getFileType());
|
|
|
|
$changeset->setMetadata($change->getAllMetadata());
|
|
|
|
$changeset->setOldProperties($change->getOldProperties());
|
|
|
|
$changeset->setNewProperties($change->getNewProperties());
|
|
|
|
$changeset->setAwayPaths($change->getAwayPaths());
|
|
|
|
$changeset->setAddLines($add_lines);
|
|
|
|
$changeset->setDelLines($del_lines);
|
|
|
|
|
2011-01-24 20:36:53 +01:00
|
|
|
$diff->addUnsavedChangeset($changeset);
|
2011-01-24 20:01:53 +01:00
|
|
|
}
|
|
|
|
$diff->setLineCount($lines);
|
|
|
|
|
|
|
|
return $diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|