Skip to content

Commit 777cc9c

Browse files
author
Alexandre Salomé
committed
Merge pull request #28 from gitonomy/feat-diff-fix
Fixed Diff + Added raw diff
2 parents 6d222ec + 84a7430 commit 777cc9c

File tree

6 files changed

+42
-22
lines changed

6 files changed

+42
-22
lines changed

src/Gitonomy/Git/Blame/Line.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Line
2929
protected $content;
3030

3131
/**
32-
* Instanciates a new Diff File object.
32+
* Instanciates a new Line object.
3333
*/
3434
public function __construct(Commit $commit, $sourceLine, $targetLine, $blockLine, $content)
3535
{

src/Gitonomy/Git/Diff/Diff.php

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ class Diff
3434
/**
3535
* Constructs a new diff for a given revision.
3636
*
37-
* @var Repository $repository
38-
* @var string $revision A string revision, passed to git diff command
39-
* @var boolean $isTree Indicates if revisions are commit-trees to compare
37+
* @param array $files The files
38+
* @param string $rawDiff The raw diff
4039
*/
41-
public function __construct(array $files)
40+
public function __construct(array $files, $rawDiff)
4241
{
4342
$this->files = $files;
43+
$this->rawDiff = $rawDiff;
4444
}
4545

4646
/**
4747
* @return Diff
4848
*/
49-
static public function parse($rawDiff)
49+
public static function parse($rawDiff)
5050
{
5151
$parser = new DiffParser();
5252
$parser->parse($rawDiff);
5353

54-
return new Diff($parser->files);
54+
return new Diff($parser->files, $rawDiff);
5555
}
5656

5757
/**
@@ -73,7 +73,7 @@ public function getFiles()
7373
}
7474

7575
/**
76-
* Get raw diff
76+
* Returns the raw diff
7777
*
7878
* @return string The raw diff
7979
*/
@@ -82,17 +82,39 @@ public function getRawDiff()
8282
return $this->rawDiff;
8383
}
8484

85+
/**
86+
* Export a diff as array
87+
*
88+
* @return array The array
89+
*/
8590
public function toArray()
8691
{
87-
return array_map(function (File $file) {
88-
return $file->toArray();
89-
}, $this->files);
92+
return array(
93+
'rawDiff' => $this->rawDiff,
94+
'files' => array_map(
95+
function (File $file) {
96+
return $file->toArray();
97+
}, $this->files
98+
),
99+
);
90100
}
91101

102+
/**
103+
* Create a new instance of Diff from an array
104+
*
105+
* @param array $array The array
106+
*
107+
* @return Diff The new instance
108+
*/
92109
public static function fromArray(array $array)
93110
{
94-
return new Diff(array_map(function ($array) {
95-
return File::fromArray($array);
96-
}, $array));
111+
return new static(
112+
array_map(
113+
function ($array) {
114+
return File::fromArray($array);
115+
}, $array['files']
116+
),
117+
$array['rawDiff']
118+
);
97119
}
98120
}

src/Gitonomy/Git/Diff/File.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
namespace Gitonomy\Git\Diff;
1414

15-
use Gitonomy\Git\Repository;
16-
1715
/**
1816
* @author Alexandre Salomé <[email protected]>
1917
*/
@@ -60,7 +58,7 @@ class File
6058
protected $changes;
6159

6260
/**
63-
* Instanciates a new Diff File object.
61+
* Instanciates a new File object.
6462
*/
6563
public function __construct($oldName, $newName, $oldMode, $newMode, $oldIndex, $newIndex, $isBinary)
6664
{

src/Gitonomy/Git/Log.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct(Repository $repository, $revisions, $paths, $offset
5858
*/
5959
public function getDiff()
6060
{
61-
return new Diff($this->repository, $this->revisions, false);
61+
return $this->repository->getDiff($this->revisions);
6262
}
6363

6464
/**

src/Gitonomy/Git/Parser/DiffParser.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
use Gitonomy\Git\Diff\File;
1616
use Gitonomy\Git\Diff\FileChange;
17-
use Gitonomy\Git\Repository;
1817

1918
class DiffParser extends ParserBase
2019
{

src/Gitonomy/Git/Repository.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,9 @@ public function getBlame($revision, $file, $lineRange = null)
266266
* any text value type
267267
* @param array $paths Restrict log to modifications occuring on given
268268
* paths.
269-
* @param int $offset Start from a given offset in results.
270-
* @param int $limit Limit number of total results.
269+
*
270+
* @param int $offset Start from a given offset in results.
271+
* @param int $limit Limit number of total results.
271272
*
272273
* @return Log
273274
*/
@@ -283,7 +284,7 @@ public function getDiff($revision)
283284
{
284285
$args = array('-r', '-p', '-m', '-M', '--no-commit-id', '--full-index', $revision);
285286

286-
return new Diff($this->run('diff', $args));
287+
return Diff::parse($this->run('diff', $args));
287288
}
288289

289290
/**

0 commit comments

Comments
 (0)