Skip to content

Commit 84a7430

Browse files
committed
Fixed Diff + Added raw diff
1 parent 71bcc32 commit 84a7430

File tree

6 files changed

+56
-21
lines changed

6 files changed

+56
-21
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: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,32 @@ class Diff
2626
*/
2727
protected $files;
2828

29+
/**
30+
* @var string
31+
*/
32+
protected $rawDiff;
33+
2934
/**
3035
* Constructs a new diff for a given revision.
3136
*
32-
* @var Repository $repository
33-
* @var string $revision A string revision, passed to git diff command
34-
* @var boolean $isTree Indicates if revisions are commit-trees to compare
37+
* @param array $files The files
38+
* @param string $rawDiff The raw diff
3539
*/
36-
public function __construct(array $files)
40+
public function __construct(array $files, $rawDiff)
3741
{
3842
$this->files = $files;
43+
$this->rawDiff = $rawDiff;
3944
}
4045

4146
/**
4247
* @return Diff
4348
*/
44-
static public function parse($rawDiff)
49+
public static function parse($rawDiff)
4550
{
4651
$parser = new DiffParser();
4752
$parser->parse($rawDiff);
4853

49-
return new Diff($parser->files);
54+
return new Diff($parser->files, $rawDiff);
5055
}
5156

5257
/**
@@ -67,17 +72,49 @@ public function getFiles()
6772
return $this->files;
6873
}
6974

75+
/**
76+
* Returns the raw diff
77+
*
78+
* @return string The raw diff
79+
*/
80+
public function getRawDiff()
81+
{
82+
return $this->rawDiff;
83+
}
84+
85+
/**
86+
* Export a diff as array
87+
*
88+
* @return array The array
89+
*/
7090
public function toArray()
7191
{
72-
return array_map(function (File $file) {
73-
return $file->toArray();
74-
}, $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+
);
75100
}
76101

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+
*/
77109
public static function fromArray(array $array)
78110
{
79-
return new Diff(array_map(function ($array) {
80-
return File::fromArray($array);
81-
}, $array));
111+
return new static(
112+
array_map(
113+
function ($array) {
114+
return File::fromArray($array);
115+
}, $array['files']
116+
),
117+
$array['rawDiff']
118+
);
82119
}
83120
}

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)