/** * @param Glip_GitCommit $a * @param Glip_GitCommit $b * @return array */ public static function treeDiff($a, $b) { return Glip_GitTree::treeDiff($a ? $a->getTree() : null, $b ? $b->getTree() : null); }
/** * @param Glip_GitTree $a_tree * @param Glip_GitTree $b_tree * @return array */ public static function treeDiff($a_tree, $b_tree) { $a_blobs = $a_tree ? $a_tree->listRecursive() : array(); $b_blobs = $b_tree ? $b_tree->listRecursive() : array(); $a_files = array_keys($a_blobs); $b_files = array_keys($b_blobs); $changes = array(); sort($a_files); sort($b_files); $a = $b = 0; while ($a < count($a_files) || $b < count($b_files)) { if ($a < count($a_files) && $b < count($b_files)) { $cmp = strcmp($a_files[$a], $b_files[$b]); } else { $cmp = 0; } if ($b >= count($b_files) || $cmp < 0) { $changes[$a_files[$a]] = self::TREEDIFF_REMOVED; $a++; } else { if ($a >= count($a_files) || $cmp > 0) { $changes[$b_files[$b]] = self::TREEDIFF_ADDED; $b++; } else { if ($a_blobs[$a_files[$a]] != $b_blobs[$b_files[$b]]) { $changes[$a_files[$a]] = self::TREEDIFF_CHANGED; } $a++; $b++; } } } return $changes; }