本文整理汇总了PHP中Git::sha1Hex方法的典型用法代码示例。如果您正苦于以下问题:PHP Git::sha1Hex方法的具体用法?PHP Git::sha1Hex怎么用?PHP Git::sha1Hex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Git
的用法示例。
在下文中一共展示了Git::sha1Hex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRawObject
/**
* @brief Fetch an object in its binary representation by name.
*
* Throws an exception if the object cannot be found.
*
* @param $objectName (string) name of the object (binary SHA1)
* @returns (array) an array consisting of the object type (int) and the
* binary representation of the object (string)
*/
protected function getRawObject($objectName)
{
static $cache = array();
/* FIXME allow limiting the cache to a certain size */
if (isset($cache[$objectName])) {
return $cache[$objectName];
}
$sha1 = Git::sha1Hex($objectName);
$path = sprintf('%s/objects/%s/%s', $this->dir, substr($sha1, 0, 2), substr($sha1, 2));
if (file_exists($path)) {
list($hdr, $objectData) = explode("", gzuncompress(file_get_contents($path)), 2);
sscanf($hdr, "%s %d", $type, $objectSize);
$objectType = Git::getTypeID($type);
$result = array($objectType, $objectData);
} elseif ($packedObject = $this->findPackedObject($objectName)) {
list($packName, $objectOffset) = $packedObject;
$pack = fopen(sprintf('%s/objects/pack/pack-%s.pack', $this->dir, sha1Hex($packName)), 'rb');
flock($pack, LOCK_SH);
/* check magic and version */
$magic = fread($pack, 4);
$version = Binary::fuint32($pack);
if ($magic != 'PACK' || $version != 2) {
throw new Exception('unsupported pack format');
}
$result = $this->unpackObject($pack, $objectOffset);
fclose($pack);
} else {
throw new Exception(sprintf('object not found: %s', sha1Hex($objectName)));
}
$cache[$objectName] = $result;
return $result;
}