Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling Repository::getBranches() will execute "git branch" command the same number of times as the number of branches + 1 #101

Open
MLukman opened this issue May 24, 2016 · 0 comments

Comments

@MLukman
Copy link

MLukman commented May 24, 2016

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:

  1. BranchCommand::listBranches is executed. This is the first git branch command execution.
  2. For each output line, Branch::createFromOutputLine is called.
  3. In Branch::createFromOutputLine, constructor of Branch class is called.
  4. The constructor calls Branch::createFromCommand method.
  5. Inside Branch::createFromCommand method, BranchCommand::listBranches is executed. This will be repeated for each output line processed in step 2 above.
  6. Branch::createFromCommand method will call Branch::parseOutputLine. Returning to the constructor and then returning to Branch::createFromOutputLine method, Branch::parseOutputLine is called again using output line passed from Repository::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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant