mirror of
https://github.com/klaussilveira/gitlist.git
synced 2025-11-18 03:30:55 +01:00
Initial commit
This commit is contained in:
67
lib/Git/Model/Blob.php
Normal file
67
lib/Git/Model/Blob.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Git\Model;
|
||||
|
||||
use Git\Client;
|
||||
use Git\Repository;
|
||||
use Git\ScopeAware;
|
||||
|
||||
class Blob extends ScopeAware
|
||||
{
|
||||
protected $mode;
|
||||
protected $hash;
|
||||
protected $name;
|
||||
protected $size;
|
||||
|
||||
public function __construct($hash, Client $client, Repository $repository) {
|
||||
$this->setClient($client);
|
||||
$this->setRepository($repository);
|
||||
$this->setHash($hash);
|
||||
}
|
||||
|
||||
public function output()
|
||||
{
|
||||
$data = $this->getClient()->run($this->getRepository(), 'show ' . $this->getHash());
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getMode()
|
||||
{
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
public function setMode($mode)
|
||||
{
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
public function getHash()
|
||||
{
|
||||
return $this->hash;
|
||||
}
|
||||
|
||||
public function setHash($hash)
|
||||
{
|
||||
$this->hash = $hash;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
public function setSize($size)
|
||||
{
|
||||
$this->size = $size;
|
||||
}
|
||||
}
|
||||
60
lib/Git/Model/Diff.php
Normal file
60
lib/Git/Model/Diff.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Git\Model;
|
||||
|
||||
use Git\Model\Line;
|
||||
|
||||
class Diff
|
||||
{
|
||||
protected $lines;
|
||||
protected $index;
|
||||
protected $old;
|
||||
protected $new;
|
||||
protected $file;
|
||||
|
||||
public function addLine($line)
|
||||
{
|
||||
$this->lines[] = new Line($line);
|
||||
}
|
||||
|
||||
public function getLines()
|
||||
{
|
||||
return $this->lines;
|
||||
}
|
||||
|
||||
public function setIndex($index)
|
||||
{
|
||||
$this->index = $index;
|
||||
}
|
||||
|
||||
public function getIndex()
|
||||
{
|
||||
return $this->index;
|
||||
}
|
||||
|
||||
public function setOld($old)
|
||||
{
|
||||
$this->old = $old;
|
||||
}
|
||||
|
||||
public function getOld()
|
||||
{
|
||||
return $this->old;
|
||||
}
|
||||
|
||||
public function setNew($new)
|
||||
{
|
||||
$this->new = $new;
|
||||
$this->file = substr($new, 6);
|
||||
}
|
||||
|
||||
public function getNew()
|
||||
{
|
||||
return $this->new;
|
||||
}
|
||||
|
||||
public function getFile()
|
||||
{
|
||||
return $this->file;
|
||||
}
|
||||
}
|
||||
48
lib/Git/Model/Line.php
Normal file
48
lib/Git/Model/Line.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Git\Model;
|
||||
|
||||
class Line
|
||||
{
|
||||
protected $line;
|
||||
protected $type;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
if (!empty($data)) {
|
||||
if ($data[0] == '@') {
|
||||
$this->setType('chunk');
|
||||
}
|
||||
|
||||
if ($data[0] == '-') {
|
||||
$this->setType('old');
|
||||
}
|
||||
|
||||
if ($data[0] == '+') {
|
||||
$this->setType('new');
|
||||
}
|
||||
}
|
||||
|
||||
$this->setLine($data);
|
||||
}
|
||||
|
||||
public function getLine()
|
||||
{
|
||||
return $this->line;
|
||||
}
|
||||
|
||||
public function setLine($line)
|
||||
{
|
||||
$this->line = $line;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
}
|
||||
44
lib/Git/Model/Symlink.php
Normal file
44
lib/Git/Model/Symlink.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Git\Model;
|
||||
|
||||
use Git\Client;
|
||||
use Git\Repository;
|
||||
use Git\ScopeAware;
|
||||
|
||||
class Symlink
|
||||
{
|
||||
protected $mode;
|
||||
protected $name;
|
||||
protected $path;
|
||||
|
||||
public function getMode()
|
||||
{
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
public function setMode($mode)
|
||||
{
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
}
|
||||
172
lib/Git/Model/Tree.php
Normal file
172
lib/Git/Model/Tree.php
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
namespace Git\Model;
|
||||
|
||||
use Git\Client;
|
||||
use Git\Repository;
|
||||
use Git\ScopeAware;
|
||||
|
||||
class Tree extends ScopeAware implements \RecursiveIterator
|
||||
{
|
||||
protected $mode;
|
||||
protected $hash;
|
||||
protected $name;
|
||||
protected $data;
|
||||
protected $position = 0;
|
||||
|
||||
public function __construct($hash, Client $client, Repository $repository) {
|
||||
$this->setClient($client);
|
||||
$this->setRepository($repository);
|
||||
$this->setHash($hash);
|
||||
}
|
||||
|
||||
public function parse()
|
||||
{
|
||||
$data = $this->getClient()->run($this->getRepository(), 'ls-tree -l ' . $this->getHash());
|
||||
$lines = explode("\n", $data);
|
||||
$files = array();
|
||||
$root = array();
|
||||
|
||||
foreach ($lines as $key => $line) {
|
||||
if (empty($line)) {
|
||||
unset($lines[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$files[] = preg_split("/[\s]+/", $line);
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
if ($file[1] == 'commit') {
|
||||
// submodule
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($file[0] == '120000') {
|
||||
$show = $this->getClient()->run($this->getRepository(), 'show ' . $file[2]);
|
||||
$tree = new Symlink;
|
||||
$tree->setMode($file[0]);
|
||||
$tree->setName($file[4]);
|
||||
$tree->setPath($show);
|
||||
$root[] = $tree;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($file[1] == 'blob') {
|
||||
$blob = new Blob($file[2], $this->getClient(), $this->getRepository());
|
||||
$blob->setMode($file[0]);
|
||||
$blob->setName($file[4]);
|
||||
$blob->setSize($file[3]);
|
||||
$root[] = $blob;
|
||||
continue;
|
||||
}
|
||||
|
||||
$tree = new Tree($file[2], $this->getClient(), $this->getRepository());
|
||||
$tree->setMode($file[0]);
|
||||
$tree->setName($file[4]);
|
||||
$root[] = $tree;
|
||||
}
|
||||
|
||||
$this->data = $root;
|
||||
}
|
||||
|
||||
public function output()
|
||||
{
|
||||
$files = $folders = array();
|
||||
|
||||
foreach ($this as $node) {
|
||||
if ($node instanceof Blob) {
|
||||
$file['type'] = 'blob';
|
||||
$file['name'] = $node->getName();
|
||||
$file['size'] = $node->getSize();
|
||||
$file['mode'] = $node->getMode();
|
||||
$file['hash'] = $node->getHash();
|
||||
$files[] = $file;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($node instanceof Tree) {
|
||||
$folder['type'] = 'folder';
|
||||
$folder['name'] = $node->getName();
|
||||
$folder['size'] = '';
|
||||
$folder['mode'] = $node->getMode();
|
||||
$folder['hash'] = $node->getHash();
|
||||
$folders[] = $folder;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($node instanceof Symlink) {
|
||||
$folder['type'] = 'symlink';
|
||||
$folder['name'] = $node->getName();
|
||||
$folder['size'] = '';
|
||||
$folder['mode'] = $node->getMode();
|
||||
$folder['hash'] = '';
|
||||
$folder['path'] = $node->getPath();
|
||||
$folders[] = $folder;
|
||||
}
|
||||
}
|
||||
|
||||
// Little hack to make folders appear before files
|
||||
$files = array_merge($folders, $files);
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
public function valid() {
|
||||
return isset($this->data[$this->position]);
|
||||
}
|
||||
|
||||
public function hasChildren() {
|
||||
return is_array($this->data[$this->position]);
|
||||
}
|
||||
|
||||
public function next() {
|
||||
$this->position++;
|
||||
}
|
||||
|
||||
public function current() {
|
||||
return $this->data[$this->position];
|
||||
}
|
||||
|
||||
public function getChildren() {
|
||||
return $this->data[$this->position];
|
||||
}
|
||||
|
||||
public function rewind() {
|
||||
$this->position = 0;
|
||||
}
|
||||
|
||||
public function key() {
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
public function getMode()
|
||||
{
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
public function setMode($mode)
|
||||
{
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
public function getHash()
|
||||
{
|
||||
return $this->hash;
|
||||
}
|
||||
|
||||
public function setHash($hash)
|
||||
{
|
||||
$this->hash = $hash;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user