1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 14:52:40 +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:
epriestley 2011-10-24 10:33:34 -07:00
parent fcf37e38e3
commit 21985f3b4e

View file

@ -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,