| | $objects[$sha] = ['type' => $type, 'size' => strlen( $data )]; |
| | |
| | - if( $type === 1 ) { |
| | + if( $type === 1 ) { // Commit |
| | if( preg_match( '/^tree ([0-9a-f]{40})/m', $data, $matches ) ) { |
| | $this->collectObjectsRecursive( $matches[1], $objects, $visited ); |
| | } |
| | - |
| | if( preg_match( '/^parent ([0-9a-f]{40})/m', $data, $matches ) ) { |
| | $this->collectObjectsRecursive( $matches[1], $objects, $visited ); |
| | } |
| | - } elseif( $type === 2 ) { |
| | + } elseif( $type === 2 ) { // Tree |
| | $position = 0; |
| | $length = strlen( $data ); |
| | - |
| | while( $position < $length ) { |
| | $spacePos = strpos( $data, ' ', $position ); |
| | $nullPos = strpos( $data, "\0", $spacePos ); |
| | - |
| | if( $spacePos === false || $nullPos === false ) break; |
| | |
| | $entrySha = bin2hex( substr( $data, $nullPos + 1, 20 ) ); |
| | $this->collectObjectsRecursive( $entrySha, $objects, $visited ); |
| | - |
| | $position = $nullPos + 21; |
| | + } |
| | + } elseif( $type === 4 ) { // Tag |
| | + if( preg_match( '/^object ([0-9a-f]{40})/m', $data, $matches ) ) { |
| | + $this->collectObjectsRecursive( $matches[1], $objects, $visited ); |
| | } |
| | } |
 |
| | if( $this->isTreeData( $data ) ) { |
| | return 2; |
| | + } |
| | + |
| | + if( strpos( $data, "object " ) === 0 ) { |
| | + return 4; |
| | } |
| | |