Skip to content

Commit 8844c0e

Browse files
committed
Remove unneeded separate call for unstaged changes
See https://stackoverflow.com/a/15765921/9334572
1 parent 1a4d725 commit 8844c0e

File tree

6 files changed

+8
-74
lines changed

6 files changed

+8
-74
lines changed

src/Git/BranchModifications.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@ class BranchModifications
1010
private $modifiedFiles;
1111
/** @var RelativeFile[] */
1212
private $newFiles;
13-
/** @var TouchedLines */
14-
private $unstagedChanges;
13+
1514
/**
1615
* @param TouchedLines $modifiedFiles
1716
* @param RelativeFile[] $newFiles
18-
* @param TouchedLines $unstagedChanges
1917
*/
20-
public function __construct(TouchedLines $modifiedFiles, array $newFiles, TouchedLines $unstagedChanges)
18+
public function __construct(TouchedLines $modifiedFiles, array $newFiles)
2119
{
2220
$this->modifiedFiles = $modifiedFiles;
2321
$this->newFiles = [];
2422
foreach ($newFiles as $newFile) {
2523
$this->newFiles[$newFile->getPath()] = $newFile;
2624
}
27-
$this->unstagedChanges = $unstagedChanges;
2825
}
2926

3027
/**
@@ -35,7 +32,6 @@ public function __construct(TouchedLines $modifiedFiles, array $newFiles, Touche
3532
public function filter(FileFilter $filter)
3633
{
3734
$this->modifiedFiles->filter($filter);
38-
$this->unstagedChanges->filter($filter);
3935
$this->newFiles = $filter->getFilteredFiles($this->newFiles);
4036
}
4137

@@ -50,7 +46,6 @@ public function getModifiedFilePaths()
5046
return array_unique(
5147
array_merge(
5248
$this->modifiedFiles->getModifiedPaths(),
53-
$this->unstagedChanges->getModifiedPaths(),
5449
array_keys($this->newFiles)
5550
)
5651
);
@@ -72,6 +67,6 @@ public function isNewFile(RelativeFile $file)
7267
*/
7368
public function wasModified($file, $line)
7469
{
75-
return $this->unstagedChanges->wasModified($file, $line) || $this->modifiedFiles->wasModified($file, $line);
70+
return $this->modifiedFiles->wasModified($file, $line);
7671
}
7772
}

src/Git/BranchModificationsFactory.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,13 @@ public function getBranchModificationsSpecified(Pointer $ancestorBranch, Pointer
4343
if (isset($this->branchModificationsCached[$cacheKey])) {
4444
return $this->branchModificationsCached[$cacheKey];
4545
}
46-
47-
// New files appear to be being picked up here also now. May be possible to
48-
// drop the separate newly added files method below..
4946
$modifiedFiles = $this->git->parseTouchedLines(
50-
new ComparisonDiffCommand(
51-
$current,
52-
$ancestorBranch
53-
)
47+
"git diff --unified=0 {$ancestorBranch->getName()}"
5448
);
5549
$newFiles = $this->git->getNewlyAddedFiles($mergeBase, $current);
56-
$unstagedChanges = $this->git->parseTouchedLines(new UnstagedDiffCommand());
5750
$this->branchModificationsCached[$cacheKey] = new BranchModifications(
5851
$modifiedFiles,
59-
$newFiles,
60-
$unstagedChanges
52+
$newFiles
6153
);
6254

6355
return $this->branchModificationsCached[$cacheKey];

src/Git/ComparisonDiffCommand.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Git/DiffCommand.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Git/Git.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,18 @@ public function getCommitsBetween(Pointer $mergeBase, Pointer $current)
7373
}
7474

7575
/**
76-
* @param DiffCommand $diffCommand
76+
* @param string $diffCommand
7777
* @return TouchedLines
7878
* @see https://stackoverflow.com/a/24456418
7979
*/
80-
public function parseTouchedLines(DiffCommand $diffCommand)
80+
public function parseTouchedLines($diffCommand)
8181
{
8282
$changes = new TouchedLines();
8383

8484
$modifiedFileRegex = '#^\+\+\+ .\/(.*)#';
8585
$nullFileRegex = '#^\+\+\+ (\/dev\/null)#';
8686
$changedLinesRegex = '#^@@ -[0-9]+(?:,[0-9]+)? \+([0-9]+(?:,[0-9]+)?)(?= @@)#';
87-
$command = $diffCommand->toString();
88-
$unifiedDiffResult = $this->cli->getResultArray($command);
87+
$unifiedDiffResult = $this->cli->getResultArray($diffCommand);
8988

9089
$currentFilePath = null;
9190
foreach ($unifiedDiffResult as $resultLine) {

src/Git/UnstagedDiffCommand.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)