GitElephant
GitElephant copied to clipboard
Calling Repository::getBranches() will execute "git branch" command the same number of times as the number of branches + 1
I added the following to GitElephant\Command\Caller\Caller::execute
method to see how GitElephant calls the underlying Git binary:
print $cmd.'<br />';
And found out that whenever GitElephant\Repository::getBranches
is called, the command git branch
will be executed the same number of times as the number of local branches plus one. So if I have four branches, the command will be executed five times. Not so optimized.
Diving into the code, I found out that the following method calls happen when calling getBranches:
-
BranchCommand::listBranches
is executed. This is the firstgit branch
command execution. - For each output line,
Branch::createFromOutputLine
is called. - In
Branch::createFromOutputLine
, constructor ofBranch
class is called. - The constructor calls
Branch::createFromCommand
method. - Inside
Branch::createFromCommand
method,BranchCommand::listBranches
is executed. This will be repeated for each output line processed in step 2 above. -
Branch::createFromCommand
method will callBranch::parseOutputLine
. Returning to the constructor and then returning toBranch::createFromOutputLine
method,Branch::parseOutputLine
is called again using output line passed fromRepository::getBranches
method.
In step 6, the parseOutputLine
method is called twice, which can be reduced to one if we can make the Branch::createFromOutputLine
method call the Branch
class constructor without calling Branch::createFromCommand
because the output line needed to be parsed is already been provided as a parameter of Branch::createFromOutputLine
.
Using version 1.1.0 via composer.
Please comment.