mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-25 16:22:42 +01:00
Add isHeuristicBinaryFile(), a git-like check for binariness of fiels
Summary: This is separated from D812. See D812, D1008, D1009. Separation allows us to land these patches safely. See T452 for a broader discussion of the issues involved. Test Plan: See D812. Reviewers: davidreuss, jungejason, nh, tuomaspelkonen, aran Reviewed By: davidreuss CC: aran, davidreuss Differential Revision: 1040
This commit is contained in:
parent
fcf37e38e3
commit
21985f3b4e
1 changed files with 14 additions and 0 deletions
|
@ -23,6 +23,20 @@
|
|||
*/
|
||||
final class ArcanistDiffUtils {
|
||||
|
||||
/**
|
||||
* Make a best-effort attempt to determine if a file is definitely binary.
|
||||
*
|
||||
* @return bool If true, the file is almost certainly binary. If false, the
|
||||
* file might still be binary but is subtle about it.
|
||||
*/
|
||||
public static function isHeuristicBinaryFile($data) {
|
||||
// Detect if a file is binary according to the Git heuristic, which is the
|
||||
// presence of NULL ("\0") bytes. Git only examines the first "few" bytes of
|
||||
// each file (8KB or so) as an optimization, but we don't have a reasonable
|
||||
// equivalent in PHP, so just look at all of it.
|
||||
return (strpos($data, "\0") !== false);
|
||||
}
|
||||
|
||||
public static function renderDifferences(
|
||||
$old,
|
||||
$new,
|
||||
|
|
Loading…
Reference in a new issue