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

Simplify Git resource's get_revision method #313

Merged
merged 2 commits into from
May 15, 2020

Conversation

pocke
Copy link
Contributor

@pocke pocke commented Apr 29, 2020

This pull request simplifies get_revision method of Itamae::Resource::Git.
It will improve performance.

This pull request contains two changes.

First, it replaces git rev-list with git rev-parse.
git rev-parse is faster, and enough. rev-list prints all revisions in the specified branch, but rev-parse only prints the head revision.

It is a really simple benchmark.

require 'benchmark'
Benchmark.bm do |x|
  x.report{100.times{`git rev-parse @`}}
  x.report{100.times{`git rev-list @`}}
end

# In itamae repository
#
#        user     system      total        real
#    0.012472   0.020599   0.245997 (  0.235425)
#    0.124308   0.398403   2.054095 (  1.553693)

Second, it reduces git command executions when git fetch is unnecessary.


I guess this pull request only has a small impact on performance because git resource always try fetching new commits from the remote repository by default.

@unasuke unasuke self-assigned this Apr 29, 2020
@unasuke unasuke self-requested a review April 29, 2020 16:03
@unasuke unasuke removed their assignment Apr 29, 2020
@pocke
Copy link
Contributor Author

pocke commented Apr 29, 2020

I unexpectedly removed stdout method call, so I've fixed it in cb116c2. 🙈
I'll squash the commits if you need it.

@sue445 sue445 self-requested a review May 1, 2020 14:18
Copy link
Member

@unasuke unasuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💨

@unasuke
Copy link
Member

unasuke commented May 15, 2020

@pocke Thank you! I'll release a new version after merge your pull requests.

@unasuke unasuke merged commit af879c1 into itamae-kitchen:master May 15, 2020
@pocke pocke deleted the rev-parse branch May 15, 2020 05:51
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

Successfully merging this pull request may close these issues.

3 participants