Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97025807
PhragmentPatchUtil.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jan 1, 18:33
Size
1 KB
Mime Type
text/x-php
Expires
Fri, Jan 3, 18:33 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23314944
Attached To
rPH Phabricator
PhragmentPatchUtil.php
View Options
<?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
);
}
}
Event Timeline
Log In to Comment