1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-15 01:01:09 +01:00
phorge-phorge/src/applications/phragment/util/PhragmentPatchUtil.php
Joshua Spence 0a62f13464 Change double quotes to single quotes.
Summary: Ran `arc lint --apply-patches --everything` over rP, mainly to change double quotes to single quotes where appropriate. These changes also validate that the `ArcanistXHPASTLinter::LINT_DOUBLE_QUOTE` rule is working as expected.

Test Plan: Eyeballed it.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin, hach-que

Differential Revision: https://secure.phabricator.com/D9431
2014-06-09 11:36:50 -07:00

53 lines
1.2 KiB
PHP

<?php
final class PhragmentPatchUtil extends Phobject {
const EMPTY_HASH = '0000000000000000000000000000000000000000';
/**
* Calculate the DiffMatchPatch patch between two Phabricator files.
*
* @phutil-external-symbol class diff_match_patch
*/
public static function calculatePatch(
PhabricatorFile $old = null,
PhabricatorFile $new = null) {
$root = dirname(phutil_get_library_root('phabricator'));
require_once $root.'/externals/diff_match_patch/diff_match_patch.php';
$old_hash = self::EMPTY_HASH;
$new_hash = self::EMPTY_HASH;
if ($old !== null) {
$old_hash = $old->getContentHash();
}
if ($new !== null) {
$new_hash = $new->getContentHash();
}
$old_content = '';
$new_content = '';
if ($old_hash === $new_hash) {
return null;
}
if ($old_hash !== self::EMPTY_HASH) {
$old_content = $old->loadFileData();
} else {
$old_content = '';
}
if ($new_hash !== self::EMPTY_HASH) {
$new_content = $new->loadFileData();
} else {
$new_content = '';
}
$dmp = new diff_match_patch();
$dmp_patches = $dmp->patch_make($old_content, $new_content);
return $dmp->patch_toText($dmp_patches);
}
}